#include /* This is a simple cnet protocol source file which demonstrates the use of timer events in cnet. The function reboot_node() will first be called for each node. reboot_node() informs cnet that the node is interested in the EV_TIMER1 event and that cnet should call timeouts() each time EV_TIMER1 occurs. Finally, reboot_node() requests that EV_TIMER1 occurs in 1000000us (1sec). When EV_TIMER1 occurs, cnet will call timeouts(), which will print either tick or tock. As each timer event occurs only once, timeouts() must finally reschedule EV_TIMER1 to occur again in another 1000000us. */ void timeouts(CnetEvent ev, CnetTimerID timer, CnetData data) { static int which = 0; ++which; printf("%3d.\t%s\n", which, ((which%2) == 0) ? "tick" : "\ttock"); /* Reschedule EV_TIMER1 to occur again in 1sec */ CNET_start_timer(EV_TIMER1, 1000000, 0); } void reboot_node(CnetEvent ev, CnetTimerID timer, CnetData data) { /* Indicate that we are interested in the EV_TIMER1 event */ CHECK(CNET_set_handler(EV_TIMER1, timeouts, 0)); /* Request that EV_TIMER1 occur in 1sec, ignoring the return value */ CNET_start_timer(EV_TIMER1, 1000000, 0); }