Alert Recipient

Purpose of Alert Recipient Client

This example illustrates a UNIX client that receives notification of alert events from the Event Server. This requires an event loop because events are received asynchronously. A single client can send as well as receive events. See [xref text to replace] for other details that you can incorporate into this program.

Note: Note: You cannot use the API function SPD_MainLoop in client programs developed for Windows systems. For clients on Windows systems, use SPD_ProcessEvents, as illustrated in 2.2.

Code

void eventCallback (
   SPD_eventTypeTP,
   SPD_eventTP *,
   SPD_passbackTP
);
main(
   int argc,
   char **argv
)
{
   /* Initialize the API.
      Application name = "alarm recipient"
      No application qualifier.
   */
   SPD_InitClient("alarm recipient", NULL);
 
   /* Register a callback to handle alarm events.
      No passback data is specified.
   */
   SPD_HandleEvent(SPD_alarmEventCN, eventCallback, NULL);
 
   /* Enter the SPD main loop to wait for the
      receipt of alarm events.
   */
   SPD_MainLoop();
}
 
 
/* Callback which handles alarm events */
void eventCallback(
   SPD_eventTypeTP type,             /* event type */
   SPD_eventTP *event,               /* event info */
   SPD_passbackTP passback
)
{
   char *severity;
   int  i; 
   /* Handle alarm events */
   if (type == SPD_alarmEventCN) {
 
      /* Display data that is common to all events */
      printf("class=%s  name=%s  appl=%s  applqual=%s\n",
         event->objectClass,
         event->objectName,
         event->applicationName,
         event->applicationQualifier);
 
      /* Convert severity type to string */
      switch (event->eventData.alarm.severity) {
         case SPD_criticalCN:
            severity = "critical";
            break;
         case SPD_majorCN:
            severity = "major";
            break;
         /* etc. */
      }
 
     /* Display alarm event information */
      printf("id=%s  qual=%s  severity=%s  text=%s\n",
         event->eventData.alarm.alarmIdentifier,
         event->eventData.alarm.alarmQualifier,
         severity,
         event->eventData.alarm.alarmText);
     /* Display user defined attributes and their values */
     for(i=0;<event-> variableCount; i++){
         printf("Attribute name:%s\n",event->variableData[i].attribute);
         printf("Attribute value:%s\n\n",event->variableData[i].value);
}
   else {
      /* Process other event types (or error if none registered) */
   }
}

Data Flow Diagram

This illustration shows the flow of information for the alert recipient client.