diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/examples/ecore_event_example.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/libraries/ecore/src/examples/ecore_event_example.c b/libraries/ecore/src/examples/ecore_event_example.c new file mode 100644 index 0000000..ef3f187 --- /dev/null +++ b/libraries/ecore/src/examples/ecore_event_example.c | |||
@@ -0,0 +1,86 @@ | |||
1 | #include <Ecore.h> | ||
2 | #include <unistd.h> | ||
3 | |||
4 | struct context { // helper struct to give some context to the callbacks | ||
5 | const char *str1, *str2; | ||
6 | Ecore_Event_Handler *handler1; | ||
7 | Ecore_Event_Handler *handler2; | ||
8 | }; | ||
9 | |||
10 | static _event_type = 0; // a new type of event will be defined and stored here | ||
11 | |||
12 | static Eina_Bool | ||
13 | _event_handler1_cb(void *data, int type, void *event) | ||
14 | { | ||
15 | int *number = event; | ||
16 | const char *str = data; | ||
17 | |||
18 | printf("event_handler1: number=%d, data=\"%s\".\n", *number, str); | ||
19 | |||
20 | if ((*number % 2) == 0) | ||
21 | return ECORE_CALLBACK_DONE; | ||
22 | |||
23 | return ECORE_CALLBACK_PASS_ON; | ||
24 | } | ||
25 | |||
26 | static Eina_Bool | ||
27 | _event_handler2_cb(void *data, int type, void *event) // event callback | ||
28 | { | ||
29 | struct context *ctxt = data; | ||
30 | int *number = event; | ||
31 | |||
32 | printf("event_handler2: number=%d.\n", *number); | ||
33 | |||
34 | if (*number == 5) | ||
35 | { | ||
36 | const char *old = NULL; | ||
37 | old = ecore_event_handler_data_set(ctxt->handler1, (void *)ctxt->str2); | ||
38 | printf("changed handler1 data from \"%s\" to \"%s\".\n", | ||
39 | old, ctxt->str2); | ||
40 | } | ||
41 | else if (*number >= 10) | ||
42 | { | ||
43 | printf("finish main loop.\n"); | ||
44 | ecore_main_loop_quit(); | ||
45 | } | ||
46 | |||
47 | return ECORE_CALLBACK_DONE; // same as EINA_FALSE | ||
48 | } | ||
49 | |||
50 | int main(int argc, char **argv) | ||
51 | { | ||
52 | struct context ctxt = {0}; | ||
53 | int i; | ||
54 | ctxt.str1 = "dataone"; | ||
55 | ctxt.str2 = "datatwo"; | ||
56 | |||
57 | if (!ecore_init()) | ||
58 | { | ||
59 | printf("ERROR: Cannot init Ecore!\n"); | ||
60 | return -1; | ||
61 | } | ||
62 | |||
63 | _event_type = ecore_event_type_new(); | ||
64 | |||
65 | ctxt.handler1 = ecore_event_handler_add(_event_type, | ||
66 | _event_handler1_cb, | ||
67 | ctxt.str1); | ||
68 | ctxt.handler2 = ecore_event_handler_add(_event_type, | ||
69 | _event_handler2_cb, | ||
70 | &ctxt); | ||
71 | |||
72 | for (i = 0; i <= 15; i++) | ||
73 | { | ||
74 | int *event_data = malloc(sizeof(*event_data)); | ||
75 | *event_data = i; | ||
76 | ecore_event_add(_event_type, event_data, NULL, NULL); | ||
77 | } | ||
78 | |||
79 | printf("start the main loop.\n"); | ||
80 | |||
81 | ecore_main_loop_begin(); | ||
82 | |||
83 | ecore_shutdown(); | ||
84 | |||
85 | return 0; | ||
86 | } | ||