summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-07-31 16:27:03 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-07-31 16:27:03 +0200
commitfbe9349a747aba8d7c8c27e51cdd8c3c5ef8b39c (patch)
tree4b363dba9b46f476ef49b8aae941bc649f5265ab
parent11adca199df161b22b7fa387808e987e45e0b2c7 (diff)
afb-evt: add internal push functions
For the implementation of monitoring, the event should be pushed without hooking internal. Change-Id: I4372bbc55e78c851db660a69bb2e60995fbdc88f Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-evt.c33
-rw-r--r--src/afb-evt.h3
2 files changed, 33 insertions, 3 deletions
diff --git a/src/afb-evt.c b/src/afb-evt.c
index 20ef5e9e..0979db82 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,7 +202,7 @@ 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);
@@ -209,6 +210,16 @@ static int evt_push(struct afb_evt_event *evt, struct json_object *obj)
}
/*
+ * 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'.
*/
static const char *evt_name(struct afb_evt_event *evt)
@@ -544,3 +555,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;
+}
+
diff --git a/src/afb-evt.h b/src/afb-evt.h
index 2c8da613..9071b32a 100644
--- a/src/afb-evt.h
+++ b/src/afb-evt.h
@@ -41,6 +41,9 @@ extern struct afb_event afb_evt_create_event(const char *name);
extern const char *afb_evt_event_name(struct afb_event event);
extern int afb_evt_event_id(struct afb_event event);
+extern int afb_evt_push(struct afb_event event, struct json_object *object);
+extern int afb_evt_unhooked_push(struct afb_event event, struct json_object *object);
+
extern int afb_evt_add_watch(struct afb_evt_listener *listener, struct afb_event event);
extern int afb_evt_remove_watch(struct afb_evt_listener *listener, struct afb_event event);