EMS Manual

Example of Retrieving Event Messages
EMS Manual426909-005
A-36
Stopping at the End of the Logged Messages
Stopping at the End of the Logged Messages
In the modifications discussed so far, the distributor waits for more event messages
when it has read all the messages logged so far. The distributor has an option to stop
when it reaches the end of the logged messages. The application must do two things
to select this option:
Request the distributor to send an end-of-log-file warning.
Check whether it has received the warning.
To request the warning, insert these statements just before the comment “Save the
original command” in the getevent^loop procedure:
! Include the EOFSTOP token, which will cause the distributor
! to send an ZEMS^WRN^EOF token when it has read all event
! messages currently on hand.
ivalue := ZSPI^VAL^TRUE;
spi^err := SSPUTTKN(spi^buf, ZEMS^TKN^EOFSTOP,
ivalue );
IF spi^err <> ZSPI^ERR^OK THEN
CALL DEBUG;
These statements add the appropriate token to the GETEVENT command message.
To test whether the application has received the warning, insert this procedure after the
get^cpu^num procedure:
?PAGE
INT PROC get^warning;
BEGIN
INT warning;
! This procedure returns true (1) or false (0), depending
! on whether the GETEVENT response contains an error list
! with the warning token ZEMS^WRN^EOF or not,
! respectively. True indicates that the distributor has
! read all messages up to the present time.
! Return right away if no error list
spi^err := EMSGETTKN(spi^buf,
ZSPI^TKN^ERRLIST, , 1 );
IF spi^err <> ZSPI^ERR^OK
AND spi^err <> ZSPI^ERR^MISTKN THEN
CALL DEBUG;
IF spi^err = ZSPI^ERR^MISTKN THEN
RETURN(false);
! Error list found, now retrieve ERROR token and look
! for an EOF warning code as a STOP request
spi^err := EMSGETTKN(spi^buf,
ZSPI^TKN^ERROR, err^buf, 1 );
IF spi^err <> ZSPI^ERR^OK THEN
CALL DEBUG;
warning := (err^buf.z^error = ZEMS^WRN^EOF);