Guardian Programmer's Guide

Table Of Contents
Communicating With Processes
Guardian Programmer’s Guide 421922-014
6 - 29
Processing Open and Close System Messages
Processing Open and Close System Messages
Message number -103 (the Open message) is delivered to a process when another
process tries to open the process (using the FILE_OPEN_, OPEN, or OPEN^FILE
procedure). Similarly, message number -104 (the Close message) is delivered to a
process when another process tries to close the process (either explicitly using
FILE_CLOSE_, CLOSE, or CLOSE^FILE or implicitly by calling PROCESS_STOP_,
STOP, or ABEND).
You might want your program to receive the Open and Close system messages if your
program is a server to more than one requester process. This way, your program can
control the number of requester processes that simultaneously have the server
process open.
The following example allows up to 5 processes to have the server process open at
one time:
LITERAL LIMIT^REACHED = 5;
ERROR^CODE := 0;
CASE BUFFER OF
BEGIN
!Process the Open system message:
ZSYS^VAL^SMSG^OPEN -> BEGIN
IF OPENERS >= LIMIT^REACHED
THEN ERROR^CODE := 12
ELSE OPENERS := OPENERS + 1;
END;
!Process the Process Close system message:
ZSYS^VAL^SMSG^CLOSE -> BEGIN
OPENERS := OPENERS - 1;
END;
!Reject any other system message:
OTHERWISE BEGIN !returns with
ERROR^CODE := 2; ! ERROR^CODE = 2
END;
END;
!Reply to the sender:
CALL REPLYX(!buffer!,
!write^count!,
!count^written!,
!message^tag!,
ERROR^CODE);
This example uses the variable OPENERS to indicate how many processes currently
have this process open. When the process receives an Open message, it adds one to
OPENERS. When the process receives a Close message it subtracts one from
OPENERS. Once the limit of five has been reached, then the process rejects the open
with error number 12.