Purpose of Command Submission Client
This example illustrates a client that submits a command to a host system in response to an attribute change event.
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. However, the destination of the command submitted by SPD_Command cannot be a Windows host.
Code
void commandCallback (
char *,
char *,
char *,
void *,
SPD_commandStatusTP,
SPD_passbackTP
);
void eventCallbackTP (
SPD_eventTypeTP,
SPD_eventTP *,
SPD_passbackTP
);
main(
int argc,
char **argv
)
{
/* Initialize the API.
Application name = "command submission example"
No application qualifier.
*/
SPD_InitClient("command submission example", NULL);
/* Register a callback to handle attribute change events.
No passback data is specified.
*/
SPD_HandleEvent(SPD_attributeChangeEventCN, eventCallback,
NULL);
/* Enter the SPD main loop to wait for the
receipt of data.
*/
SPD_MainLoop();
}
/* Callback which handles attribute change events */
void eventCallback(
SPD_eventTypeTP type, /* event type */
SPD_eventTP *event, /* event info */
SPD_passbackTP passback
)
{
char *severity;
/* Handle attribute change events */
if (type == SPD_attributeChangeEventCN) {
/* Determine if attribute change means a command should be sent */
/* Send a "who" command to the host that reported the
attribute change. Register callback for command ack */
SPD_Command("host", event->host, "who", SPD_reservedValueCN,
commandCallback, NULL, NULL, NULL, 0);
}
else {
/* Process other event types (or error if none registered) */
}
}
/* Callback for command acknowledgment */
void commandCallback(
char *class, /* class of the destination host */
char *host, /* destination of the command */
char *command, /* the command */
void *res, /* reserved for future use */
SPD_commandStatusTP status, /* command submission status */
SPD_passbackTP passback /* passback data */
)
{
switch (status) {
case SPD_commandSuccessCN:
/* command was submitted */
break;
case SPD_unknownHostCN:
case SPD_unreachableHostCN:
/* something went wrong - command did not make it */
break;
}
}Data Flow Diagram
This illustration shows the flow of information for the command submission client.