HP-UX Event ManagerProgrammer's Guide

Example 4-10 Dealing with Missed Events
#include <stdio.h>
#include <evm/evm.h>
#include<unistd.h>
void EventCB(EvmConnection_t conn, EvmCallbackArg_t cbarg, EvmCallbackData_t *cbdata);
/*===============================================* Function:
main()*===============================================*/
int main()
{ EvmConnection_t conn; EvmStatus_t status; int conn_fd;
status = EvmConnCreate(EvmCONNECTION_LISTEN, EvmRESPONSE_CALLBACK,NULL,EventCB,NULL,&conn);
if (status != EvmERROR_NONE)
{ fprintf(stderr,"Failed to create EVM listening connection\n");
exit(1); }
status = EvmConnSubscribe(conn,NULL,"[name *]");
/* This code segment subscribes for notification of all events. */
if (status != EvmERROR_NONE)
{ fprintf(stderr,"Failed to subscribe for event notification\n");
exit(1); }
for (;;)
{ status = EvmConnWait(conn,NULL);
if (status != EvmERROR_NONE)
{ fprintf(stderr,"Connection error\n");
exit(1); }
if (EvmConnDispatch(conn) != EvmERROR_NONE)
{ fprintf(stderr,"Connection dispatch error\n");
exit(1); } }}
/*===============================================* Function:
EventCB()*===============================================*/
void EventCB(EvmConnection_t conn, EvmCallbackArg_t cbarg, EvmCallbackData_t *cbdata)
{ char buff[256]; switch (cbdata->reason)
{ case EvmREASON_EVENT_DELIVERED:
EvmEventFormat(buff, sizeof(buff), cbdata->event);
fprintf(stdout,"Event: %s\n",buff);
EvmEventDestroy(cbdata->event);
/* To demonstrate missing events, sleep for one second after each event is received.
This simulates a heavy processing load and ensures that the input connection buffer will be filled if the
event load is heavy.*/
sleep(1);
break;
/* The callback function is invoked with reason code EvmREASON_EVENTS_MISSED if the daemon is unable to
send one or more missed events. The callback data member extension.eventMissedData.missedCount contains
a count of the number of missed events.*/
case EvmREASON_EVENTS_MISSED:
fprintf(stdout,"*** Missed %d incoming events\n",cbdata->extension.eventMissedData.missedCount);
break;
default: break; }}
Adding an Event Channel to EVM
The term event channel describes any facility that you can use to publish or retrieve event
information. It can also refer to any of the following:
Simple log file
Event management system
Program that can be run to obtain a snapshot of status information
An event channel may be an active channel, in which case it posts its own event information to
EVM as soon as the event occurs, or a passive channel, in which the information may accumulate
within the channel but EVM has to take the action to look for it.
An event channel does not have to be a formal event notification mechanism. It can be anything
that is capable of storing information or showing a status or a change of state. For example:
If an application or a system component writes state information to its own log file, each
entry in the log file is considered as an event. The log file can be checked periodically for
new entries, and an event can be posted for each new entry that is found. The log file also
serves as a place from which events can be retrieved.
Some applications and system components provide a means of querying status. In these
cases, the status can be monitored periodically, and an event can be posted whenever a
significant change is detected. This type of event channel typically does not include a means
of storing event information. Therefore EVM's own logging mechanism can be used to log
the events.
If a central part of an application handles all event information for the application, you can
modify the handling code so that it also forwards event information to EVM. This is an
example of an active event channel.
52 Sample EVM Programming Operations