3 typedef struct _E_Msg_Event E_Msg_Event;
7 void (*func) (void *data, const char *name, const char *info, int val, E_Object *obj, void *msgdata);
9 unsigned char delete_me : 1;
19 void (*afterfunc) (void *data, E_Object *obj, void *msgdata);
23 /* local subsystem functions */
24 static Eina_Bool _e_msg_event_cb(void *data, int ev_type, void *ev);
25 static void _e_msg_event_free(void *data, void *ev);
27 /* local subsystem globals */
28 static Eina_List *handlers = NULL;
29 static Eina_List *del_handlers = NULL;
30 static int processing_handlers = 0;
31 static int E_EVENT_MSG = 0;
32 static Ecore_Event_Handler *hand = NULL;
34 /* externally accessible functions */
38 E_EVENT_MSG = ecore_event_type_new();
39 hand = ecore_event_handler_add(E_EVENT_MSG, _e_msg_event_cb, NULL);
46 while (handlers) e_msg_handler_del(eina_list_data_get(handlers));
48 if (hand) ecore_event_handler_del(hand);
54 e_msg_send(const char *name, const char *info, int val, E_Object *obj, void *msgdata, void (*afterfunc) (void *data, E_Object *obj, void *msgdata), void *afterdata)
56 unsigned int size, pos, name_len, info_len;
59 name_len = info_len = 0;
60 size = sizeof(E_Msg_Event);
61 if (name) name_len = strlen(name) + 1;
62 if (info) info_len = strlen(info) + 1;
63 ev = malloc(size + name_len + info_len);
68 ev->name = ((char *)ev) + pos;
70 strcpy(ev->name, name);
74 ev->info = ((char *)ev) + pos;
75 strcpy(ev->info, info);
79 ev->msgdata = msgdata;
80 ev->afterfunc = afterfunc;
81 ev->afterdata = afterdata;
82 if (ev->obj) e_object_ref(ev->obj);
83 ecore_event_add(E_EVENT_MSG, ev, _e_msg_event_free, NULL);
87 e_msg_handler_add(void (*func) (void *data, const char *name, const char *info, int val, E_Object *obj, void *msgdata), void *data)
91 emsgh = calloc(1, sizeof(E_Msg_Handler));
92 if (!emsgh) return NULL;
95 handlers = eina_list_append(handlers, emsgh);
100 e_msg_handler_del(E_Msg_Handler *emsgh)
102 if (processing_handlers > 0)
104 emsgh->delete_me = 1;
105 del_handlers = eina_list_append(del_handlers, emsgh);
109 handlers = eina_list_remove(handlers, emsgh);
114 /* local subsystem functions */
117 _e_msg_event_cb(void *data __UNUSED__, int ev_type __UNUSED__, void *ev)
121 E_Msg_Handler *emsgh;
123 processing_handlers++;
125 EINA_LIST_FOREACH(handlers, l, emsgh)
127 if (!emsgh->delete_me)
128 emsgh->func(emsgh->data, e->name, e->info, e->val, e->obj, e->msgdata);
130 if (e->afterfunc) e->afterfunc(e->afterdata, e->obj, e->msgdata);
131 processing_handlers--;
132 if ((processing_handlers == 0) && (del_handlers))
134 E_FREE_LIST(del_handlers, e_msg_handler_del);
140 _e_msg_event_free(void *data __UNUSED__, void *ev)
145 if (e->obj) e_object_unref(e->obj);