Purpose of Timer Client
This example illustrates a client that creates a timer. This requires an event loop because timer expiration is an asynchronous 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.
Code
void timerCallback (
SPD_timeoutTP,
SPD_passbackTP
);
main(
int argc,
char **argv
)
{
/* Initialize the API.
Application name = "timer example"
No application qualifier.
*/
SPD_InitClient("timer example", NULL);
/* Create the timer.
The interval is 10 seconds.
No passback data is specified.
*/
SPD_AddTimeOut(10000, timerCallback, NULL);
/* Enter the SPD main loop to wait for the
expiration of the timer.
*/
SPD_MainLoop();
}
/* Callback which handles timer expiration */
void timerCallback(
SPD_timeoutTP id, /* timer handle */
SPD_passbackTP passback
)
{
/* Client processing... */
/* The timer is gone. It must be recreated if we want it
to go off again in the future.
*/
SPD_AddTimeOut(10000, timerCallback, NULL);
}