Boolean timerSetup(IntervalTimer *itimers) { Boolean ret = TRUE; /* WARNING: these descriptions MUST be in the same order, * and in the same number as the enum in ptp_timers.h */ static const char* timerDesc[PTP_MAX_TIMER] = { "PDELAYREQ_INTERVAL", "DELAYREQ_INTERVAL", "SYNC_INTERVAL", "ANNOUNCE_RECEIPT", "ANNOUNCE_INTERVAL", "SYNC_RECEIPT", "DELAY_RECEIPT", "UNICAST_GRANT", "OPERATOR_MESSAGES", "LEAP_SECOND_PAUSE", "STATUSFILE_UPDATE", "PERIODIC_INFO", "STATISTICS_UPDATE", "ALARM_UPDATE", "MASTER_NETREFRESH", "CALIBRATION_DELAY", "CLOCK_UPDATE", "TIMINGDOMAIN_UPDATE", "INTERFACE_CHECK", "CLOCK_SYNC", "CLOCK_DRIVER_UPDATE" }; int i = 0; startEventTimers(); for(i=0; i<PTP_MAX_TIMER; i++) { itimers[i].data = NULL; itimers[i].data = (void *)(createEventTimer(timerDesc[i])); if(itimers[i].data == NULL) { ret = FALSE; } } return ret; }
int main() { struct sigaction action_cleanup; memset(&action_cleanup, 0, sizeof(struct sigaction)); action_cleanup.sa_handler = exitClean; action_cleanup.sa_flags = 0; sigaction(SIGINT, &action_cleanup, NULL); sigaction(SIGTERM, &action_cleanup, NULL); et = createEventTimer(NULL, NULL); pthread_t et_thread; pthread_create(&et_thread, NULL, et->start_event_timer, (void*)et); sleep(2); #ifdef TEST1 uint32_t i = 0; for (; i < 10; i++) { struct timeval now; gettimeofday(&now, NULL); // now.tv_usec = (10 - i) * 10000; now.tv_sec += 3; uint32_t* val = newTaskArg(i); et->add_timed_event(et, &now, testTaskHandler, (void*)val); } #else struct timeval now; gettimeofday(&now, NULL); // now.tv_usec += 500 * 1000; now.tv_sec += 3; uint32_t* val = newTaskArg(0); et->add_timed_event_ms(et, 5, testTaskHandler_Rec, (void*)val); #endif pthread_join(et_thread, NULL); //sleep(20); et->delete_event_timer(et); return 0; }