PARCEventSignal * metisDispatcher_CreateSignalEvent(MetisDispatcher *dispatcher, PARCEventSignal_Callback *callback, void *userData, int signal) { assertNotNull(dispatcher, "Parameter dispatcher must be non-null"); assertNotNull(callback, "Parameter callback must be non-null"); PARCEventSignal *event = parcEventSignal_Create(dispatcher->Base, signal, PARCEventType_Signal | PARCEventType_Persist, callback, userData); assertNotNull(event, "Got null event when creating signal catcher for signal %d", signal); return event; }
LONGBOW_TEST_CASE(Global, parc_EventSignal_Create_Destroy) { PARCEventScheduler *parcEventScheduler = parcEventScheduler_Create(); assertNotNull(parcEventScheduler, "parcEventScheduler_Create returned a null reference"); PARCEventSignal *parcEventSignal = parcEventSignal_Create(parcEventScheduler, SIGUSR1, PARCEventType_Signal | PARCEventType_Persist, _empty_event, NULL); assertNotNull(parcEventSignal, "parcEventSignal_Create returned a null reference"); _parc_event_signal_callback(0, 0, (void *)parcEventSignal); assertTrue(_empty_event_called == 1, "Event handler never called."); parcEventSignal_Destroy(&parcEventSignal); parcEventScheduler_Destroy(&parcEventScheduler); }
LONGBOW_TEST_CASE(Global, parc_EventSignal_Stop) { _test_event_called = 0; PARCEventScheduler *parcEventScheduler = parcEventScheduler_Create(); assertNotNull(parcEventScheduler, "parcEventScheduler_Create returned a null reference"); PARCEventSignal *parcEventSignal = parcEventSignal_Create(parcEventScheduler, SIGUSR1, PARCEventType_Signal | PARCEventType_Persist, _test_stop_event, &parcEventSignal); assertNotNull(parcEventSignal, "parcEventSignal_Create returned a null reference"); parcEventSignal_Start(parcEventSignal); kill(getpid(), SIGUSR1); parcEventScheduler_Start(parcEventScheduler, PARCEventSchedulerDispatchType_Blocking); assertTrue(_test_event_called == 1, "Event never called."); parcEventSignal_Destroy(&parcEventSignal); parcEventScheduler_Destroy(&parcEventScheduler); }
LONGBOW_TEST_CASE(Global, parc_EventSignal_Start_Stop) { PARCEventScheduler *parcEventScheduler = parcEventScheduler_Create(); assertNotNull(parcEventScheduler, "parcEventScheduler_Create returned a null reference"); PARCEventSignal *parcEventSignal = parcEventSignal_Create(parcEventScheduler, SIGUSR1, PARCEventType_Signal | PARCEventType_Persist, _signal_event, &parcEventSignal); assertNotNull(parcEventSignal, "parcEventSignal_Create returned a null reference"); parcEventSignal_Start(parcEventSignal); pthread_t thread; pthread_create(&thread, NULL, _run_scheduler, parcEventScheduler); kill(getpid(), SIGUSR1); pthread_join(thread, NULL); assertTrue(_test_event_called == 1, "Event never called."); parcEventSignal_Destroy(&parcEventSignal); parcEventScheduler_Destroy(&parcEventScheduler); }