Writing Monitors for the Event Monitoring Service (December 1999)

150 Chapter5
Writing a Target Application
Processing a Notification Message
Processing a Notification Message
This section applies only to target applications that receive notification
messages via TCP or UDP. Other notification methods may define
different ways to transport the information from the resource monitor to
the target application.
The format of the notification message is as follows: A 9 byte header is
followed by a message buffer. The header is made up of an 8 byte value
(in ASCII) representing the length of the rest of the message followed by
a semicolon. The rest of the message can be passed to
rm_uncompress_object() in the buf parameter. The length field
specifies the length of the message buffer without the header. For
example, the notification message might look like this:
Figure 5-1 Notification Message Format
Since UDP messages must be read in one operation, the normal
procedure is to read 9 bytes using the MSG_PEEK flag of recvfrom(2), then
allocate enough memory to receive the whole message, then receive the
whole message. Finally, the message buffer without the header is passed
to rm_uncompress_object().
Processing notification messages received via TCP is somewhat easier.
TCP messages may be read in parts. Using recv(2), read the 9 byte
header, allocate enough memory to receive the message buffer, then read
the message buffer. The message buffer can be passed directly to
rm_uncompress_object().
The object returned by rm_uncompress_object() will be a Notify
Object, a Restart Notification object, or possibly an object that is defined
in a future version of EMS. The target application must check the
RmObjectType to determine whether it is an object of interest to the
target.