Tizen Native API
5.5
|
This example shows the simplest possible way to register a handler for an ecore event, this way we can focus on the important aspects. The example will start the main loop and quit it when it receives the ECORE_EVENT_SIGNAL_EXIT event. This event is triggered by a SIGTERM(pressing ctrl+c).
So let's start with the function we want called when we receive the event, instead of just stopping the main loop we'll also print a message, that's just so it's clear that it got called:
static Eina_Bool _quitter(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event EINA_UNUSED) { printf("Leaving already?\n"); ecore_main_loop_quit(); return ECORE_CALLBACK_DONE; }
We then have our main function and the obligatory initialization of ecore:
int main(void) { ecore_init();
We then get to the one line of our example that makes everything work, the registering of the callback:
ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, _quitter, NULL);
NULL
there is because there is no need to pass data to the callback.And the all that is left to do is start the main loop:
ecore_main_loop_begin(); return 0; }
Full source code for this example: ecore_event_example_01::c.