void CallbackTestHandler ( uint32_t data, const char* namePtr, int dataFile, void* contextPtr ) { LE_PRINT_VALUE("%d", data); LE_PRINT_VALUE("'%s'", namePtr); LE_PRINT_VALUE("%p", contextPtr); LE_PRINT_VALUE("%i", dataFile); // Read and print out whatever is read from the dataFile fd. writeFdToLog(dataFile); // This should fail, because the callback can only be called once. LE_DEBUG("Triggering CallbackTest second time -- should FATAL"); TriggerCallbackTest(257); // Continue with the next test // todo: can't continue because the previous test fails -- maybe need to separate tests //le_event_QueueFunction(testFinal, NULL, NULL); }
void test3(void) { banner("Test 3"); // Test what happens if an event is triggered, then the handler is removed. The registered // handler should not be called, even if there is a pending event, because the handler has // been removed. TestAHandlerRef_t handlerRef = AddTestAHandler(NewHandleTestA, NULL); LE_PRINT_VALUE("%p", handlerRef); LE_DEBUG("Triggering New TestA\n"); TriggerTestA(); RemoveTestAHandler(handlerRef); // Test function callback parameters. int result; // This is not used in the test; this parameter was added to test a code generation bug fix. uint8_t dataArray[] = { 1, 2 }; result = TestCallback(10, dataArray, 2, CallbackTestHandler, NULL); LE_PRINT_VALUE("%d", result); LE_DEBUG("Triggering CallbackTest"); TriggerCallbackTest(100); // Need to allow the event loop to process the trigger. // The rest of the test will be continued in the handler. }
static void Handle_TriggerCallbackTest ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer __attribute__((unused)) uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Unpack the input parameters from the message uint32_t data; _msgBufPtr = UnpackData( _msgBufPtr, &data, sizeof(uint32_t) ); // Call the function TriggerCallbackTest ( (ServerCmdRef_t)_msgRef, data ); }
static void Handle_TriggerCallbackTest ( le_msg_MessageRef_t _msgRef ) { // Get the message buffer pointer uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer; // Needed if we are returning a result or output values uint8_t* _msgBufStartPtr = _msgBufPtr; // Unpack the input parameters from the message uint32_t data; _msgBufPtr = UnpackData( _msgBufPtr, &data, sizeof(uint32_t) ); // Define storage for output parameters // Call the function TriggerCallbackTest ( data ); // Re-use the message buffer for the response _msgBufPtr = _msgBufStartPtr; // Pack any "out" parameters // Return the response LE_DEBUG("Sending response to client session %p : %ti bytes sent", le_msg_GetSession(_msgRef), _msgBufPtr-_msgBufStartPtr); le_msg_Respond(_msgRef); }