Input Monitoring

Purpose of Input Monitoring Client

This example illustrates a UNIX client that monitors a file descriptor for input events. This requires an event loop because input events occur asynchronously.

Note: Note: This example does not apply for clients on Windows systems, where SPD_AddInput is not supported.

Code

void input Callback (
   SPD_inputTP, 
   SPD_passbackTP
);
/* global file descriptor variable */
int fd
main(
   int argc,
   char **argv
)
{
   /* Initialize the API.
      Application name = "input monitor example"
      No application qualifier.
   */
   SPD_InitClient("input monitor example", NULL);
 
   /* Create the I/O handler.
      The file descriptor in the global variable "fd".
      We are only interested in input events.
      No passback data is specified.
   */
   SPD_AddInput(fd, SPD_readCN, inputCallback, NULL);
 
   /* Enter the SPD main loop to wait for the
      receipt of data.
   */
   SPD_MainLoop();
}
/* Callback which handles input events */
void inputCallback(
   SPD_inputTP id,                  /* I/O handler handle */
   SPD_passbackTP passback
)
{
   /* Client processing... */
 
   /* The I/O handler remains active until it is removed. */
}