Thanks for the response kdunwoody.
I’ll have to admit that I read the paragraphs that you provided a link for at least 3 times and I still cannot make heads nor tails of what it means. Perhaps an example would help me understand it better. Being new to Legato, I have a feeling that I am going about this the wrong way and am totally off base.
Unfortunately, this forum will not let new users upload code files, so I’ll have to paste my simplified code here. Please excuse the formatting mess. Hopefully it is understandable.
Structure:
eventTestApp
—Component1
------component1.c
------component1.h
------Component.cdef
—Component2
------component2.c
------Component.cdef
—eventTestApp.adef
—component1.h-------
ifndef EVENT_TEST_H
define EVENT_TEST_H
include “legato.h”
include “interfaces.h”
ifdef __cplusplus
extern “C” {
endif
typedef enum {
ZERO,
ONE,
TWO
} EventReport_t;
extern le_event_Id_t eventId;
endif // EVENT_TEST_H
----component1.c------
include “component1.h”
include “legato.h”
include “interfaces.h”
static le_timer_Ref_t timerRef;
le_event_Id_t eventId = NULL;
//-------------------------------------------------------------------------------------------------
/**
- Callback function for event handler
*/
// -------------------------------------------------------------------------------------------------
static void Component1EventHandler(void* reportPayloadPtr)
{
EventReport_t testReportPtr = reportPayloadPtr;
LE_INFO(“Event received by event handler: %d”, testReportPtr);
}
//-------------------------------------------------------------------------------------------------
/
- Callback function for timer
*/
// -------------------------------------------------------------------------------------------------
static void TimerCallback(le_timer_Ref_t timerRef)
{
EventReport_t eventReport = ONE;
le_event_Report(eventId, &eventReport, sizeof(eventReport));
}
COMPONENT_INIT
{
le_clk_Time_t interval;
eventId = le_event_CreateId("Test Event", sizeof(EventReport_t));
le_event_AddHandler("Handler Name", eventId, Component1EventHandler);
interval.sec = 10; // Create a 10 sec repeating timer with a handler
interval.usec = 0;
timerRef = le_timer_Create("Test Timer");
LE_ASSERT(le_timer_SetInterval(timerRef, interval) == LE_OK);
LE_ASSERT(le_timer_SetRepeat(timerRef, 0) == LE_OK); // A "0" implies "repeat forever"
LE_ASSERT(le_timer_SetContextPtr(timerRef, NULL) == LE_OK);
LE_ASSERT(le_timer_SetHandler(timerRef, TimerCallback) == LE_OK);
LE_INFO("Start timer");
LE_ASSERT(le_timer_Start(timerRef) == LE_OK);
return;
}
----component2.c
include “legato.h”
include “…/Component1/component1.h”
include “interfaces.h”
//-------------------------------------------------------------------------------------------------
/**
- Callback function for event handler
*/
// -------------------------------------------------------------------------------------------------
static void Component2EventHandler(void* reportPayloadPtr)
{
EventReport_t *testReportPtr = reportPayloadPtr;
LE_INFO(“Event received by event handler: %d”, *testReportPtr);
}
COMPONENT_INIT
{
le_event_AddHandler(“Handler Name”, eventId, Component2EventHandler);
return;
}
----Component.cdef (for component 1)
sources:
{
component1.c
}
-----Component.cdef (for component 2)
sources:
{
component2.c
}
requires:
{
component:
{
component1
}
}