Guardian Programmer's Guide

Table Of Contents
Communicating With Processes
Guardian Programmer’s Guide 421922-014
6 - 63
Programming the Server
!------------------------------------------------------------
! This is the main procedure. It calls the INIT procedure to
! initialize, then it goes into a loop calling GET^COMMAND
! to get the next user request and calling the procedure
! to carry out that request.
!------------------------------------------------------------
PROC PARTS MAIN;
BEGIN
CALL INIT;
! Loop indefinitely:
WHILE 1 DO
BEGIN
! Read a message from $RECEIVE:
CALL READUPDATEX(RECV^NUM,REQUEST,$LEN(REQUEST));
IF <> THEN CALL FILE^ERRORS(RECV^NUM);
! Select procedure based on request function:
CASE REQUEST.REQUEST^FUNCTION OF
BEGIN
READ^APPROX -> CALL READ^APPROX^RECORD;
READ^EXACT -> CALL READ^EXACT^RECORD;
WRITE^ONE -> CALL WRITE^RECORD;
UPDATE^ONE -> CALL UPDATE^RECORD;
READ^NEXT -> CALL READ^NEXT^RECORD;
OTHERWISE -> CALL PROCESS_STOP_;
END;
! Send the reply back to the requester:
CALL REPLYX(PART^RECORD,$LEN(PART^RECORD),
!count^written!,
!message^tag!,
REPLY^ERROR);
IF <> THEN CALL PROCESS_STOP_;
END;
END;