X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-evt.c;h=1c81fd53bee206ff6ef9c9218325185d72668a47;hb=a63851bb4726c89d9a3c5755d78d1c4bbc3f3b2e;hp=20ef5e9e2f47e365f062627a101abffd1d29fc52;hpb=11adca199df161b22b7fa387808e987e45e0b2c7;p=src%2Fapp-framework-binder.git diff --git a/src/afb-evt.c b/src/afb-evt.c index 20ef5e9e..1c81fd53 100644 --- a/src/afb-evt.c +++ b/src/afb-evt.c @@ -179,9 +179,10 @@ int afb_evt_broadcast(const char *event, struct json_object *object) /* * Pushes the event 'evt' with 'obj' to its listeners * 'obj' is released (like json_object_put) + * calls hooks if hookflags isn't 0 * Returns the count of listener taht received the event. */ -static int evt_push(struct afb_evt_event *evt, struct json_object *obj) +static int push(struct afb_evt_event *evt, struct json_object *obj, int hookflags) { int result; struct afb_evt_watch *watch; @@ -189,7 +190,7 @@ static int evt_push(struct afb_evt_event *evt, struct json_object *obj) result = 0; pthread_mutex_lock(&evt->mutex); - if (evt->hookflags & afb_hook_flag_evt_push_before) + if (hookflags & afb_hook_flag_evt_push_before) afb_hook_evt_push_before(evt->name, evt->id, obj); watch = evt->watchs; while(watch) { @@ -201,13 +202,23 @@ static int evt_push(struct afb_evt_event *evt, struct json_object *obj) } watch = watch->next_by_event; } - if (evt->hookflags & afb_hook_flag_evt_push_after) + if (hookflags & afb_hook_flag_evt_push_after) afb_hook_evt_push_after(evt->name, evt->id, obj, result); pthread_mutex_unlock(&evt->mutex); json_object_put(obj); return result; } +/* + * Pushes the event 'evt' with 'obj' to its listeners + * 'obj' is released (like json_object_put) + * Returns the count of listener taht received the event. + */ +static int evt_push(struct afb_evt_event *evt, struct json_object *obj) +{ + return push(evt, obj, evt->hookflags); +} + /* * Returns the name associated to the event 'evt'. */ @@ -301,7 +312,7 @@ static void evt_destroy(struct afb_evt_event *evt) struct afb_event afb_evt_create_event(const char *name) { size_t len; - struct afb_evt_event *evt; + struct afb_evt_event *evt, *oevt; /* allocates the event */ len = strlen(name); @@ -309,10 +320,6 @@ struct afb_event afb_evt_create_event(const char *name) if (evt == NULL) goto error; - /* initialize the event */ - evt->watchs = NULL; - memcpy(evt->name, name, len + 1); - /* allocates the id */ pthread_mutex_lock(&events_mutex); do { @@ -322,10 +329,10 @@ struct afb_event afb_evt_create_event(const char *name) } if (!event_id_wrapped) break; - evt = events; - while(evt != NULL && evt->id != event_id_counter) - evt = evt->next; - } while (evt != NULL); + oevt = events; + while(oevt != NULL && oevt->id != event_id_counter) + oevt = oevt->next; + } while (oevt != NULL); /* initialize the event */ memcpy(evt->name, name, len + 1); @@ -544,3 +551,19 @@ void afb_evt_update_hooks() pthread_mutex_unlock(&events_mutex); } +int afb_evt_push(struct afb_event event, struct json_object *object) +{ + if (event.itf == &afb_evt_event_itf) + return evt_push((struct afb_evt_event *)event.closure, object); + json_object_put(object); + return 0; +} + +int afb_evt_unhooked_push(struct afb_event event, struct json_object *object) +{ + if (event.itf == &afb_evt_event_itf) + return push((struct afb_evt_event *)event.closure, object, 0); + json_object_put(object); + return 0; +} +