/* declared in naemon/nebmods.h */ int neb_make_callbacks(int callback_type, void *data) { nebcallback *cb; int (*callbackfunc)(int, void *); register int cbresult = 0; int i; /* make sure the callback type is within bounds */ if (callback_type < 0 || callback_type >= NEBCALLBACK_NUMITEMS) return ERROR; switch (callback_type) { case NEBCALLBACK_PROCESS_DATA: for (i = 0; i < MAX_NEB_CB; i++) if (nebcb_process_data[i].callback_func != NULL) { callbackfunc = nebcb_process_data[i].callback_func; cbresult = callbackfunc(NEBCALLBACK_PROCESS_DATA, data); } break; case NEBCALLBACK_TIMED_EVENT_DATA: for (i = 0; i < MAX_NEB_CB; i++) if (nebcb_timed_event_data[i].callback_func != NULL) { callbackfunc = nebcb_timed_event_data[i].callback_func; cbresult = callbackfunc(NEBCALLBACK_TIMED_EVENT_DATA, data); } break; case NEBCALLBACK_SERVICE_CHECK_DATA: for (i = 0; i < MAX_NEB_CB; i++) if (nebcb_service_check_data[i].callback_func != NULL) { callbackfunc = nebcb_service_check_data[i].callback_func; cbresult = callbackfunc(NEBCALLBACK_SERVICE_CHECK_DATA, data); } break; } return cbresult; }
void libClass::update() { uint32_t current_duration = (millis() - lastAction); if (current_duration >= duration) { // reset lastAction = millis(); counter = counter +1; // run callback function if (cbfunc_valid) { // callbackfunc(this); callbackfunc(counter); } } }
/* make callbacks to modules */ int neb_make_callbacks(int callback_type, void *data) { nebcallback *temp_callback = NULL, *next_callback = NULL; int (*callbackfunc)(int, void *); register int cbresult = 0; int total_callbacks = 0; /* make sure callback list is initialized */ if (neb_callback_list == NULL) return ERROR; /* make sure the callback type is within bounds */ if (callback_type < 0 || callback_type >= NEBCALLBACK_NUMITEMS) return ERROR; log_debug_info(DEBUGL_EVENTBROKER, 1, "Making callbacks (type %d)...\n", callback_type); /* make the callbacks... */ for (temp_callback = neb_callback_list[callback_type]; temp_callback; temp_callback = next_callback) { /* Save temp_callback->next because if the callback function de-registers itself temp_callback's */ /* pointer isn't guaranteed to be usable anymore (neb_deregister_callback will free() it) */ next_callback = temp_callback->next; callbackfunc = temp_callback->callback_func; cbresult = callbackfunc(callback_type, data); temp_callback = next_callback; total_callbacks++; log_debug_info(DEBUGL_EVENTBROKER, 2, "Callback #%d (type %d) return code = %d\n", total_callbacks, callback_type, cbresult); /* module wants to cancel callbacks to other modules (and potentially cancel the default Icinga handling of an event) */ if (cbresult == NEBERROR_CALLBACKCANCEL) break; /* module wants to override default Icinga handling of an event */ /* not sure if we should bail out here just because one module wants to override things - what about other modules? EG 12/11/2006 */ else if (cbresult == NEBERROR_CALLBACKOVERRIDE) break; } return cbresult; }