summaryrefslogtreecommitdiffstats
path: root/include/afb/afb-req-itf.h
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-06-09 07:54:31 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-06-09 08:39:02 +0200
commit7e0abe76db7b90369429bf387d7aad0fb5a42328 (patch)
treeeedf5609a588f0d9d743fb941bc8727ff1356b21 /include/afb/afb-req-itf.h
parentc37c8e6291c36665dd23601a8ce1449afd43e6df (diff)
Events: refactoring
This new version allows to subscribe a client for an event. The event should first be created for the API (the API's prefix is added) using 'afb_daemon_make_event'. After that, plugins can subscribe or unsubscribe their clients (identified through requests) to the events that it generates. See 'afb_req_subscribe' and 'afb_req_unsubscribe'. Events created by 'afb_daemon_make_event' can be widely broadcasted using 'afb_event_broadcast' or pushed only to suscribers using 'afb_event_push'. Events can be destroyed using 'afb_event_drop'. Change-Id: I7c0bed5e625c2052dcd81c6bfe960def1fa032f3 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'include/afb/afb-req-itf.h')
-rw-r--r--include/afb/afb-req-itf.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h
index f4fab551..2b3bc467 100644
--- a/include/afb/afb-req-itf.h
+++ b/include/afb/afb-req-itf.h
@@ -25,6 +25,8 @@
#include <stdarg.h>
#include <stdio.h>
+#include <afb/afb-event-itf.h>
+
/* avoid inclusion of <json-c/json.h> */
struct json_object;
@@ -65,6 +67,9 @@ struct afb_req_itf {
void (*session_close)(void *closure);
int (*session_set_LOA)(void *closure, unsigned level);
+
+ int (*subscribe)(void *closure, struct afb_event event);
+ int (*unsubscribe)(void *closure, struct afb_event event);
};
/*
@@ -315,6 +320,29 @@ static inline struct afb_req afb_req_unstore(struct afb_req *req)
return result;
}
+/*
+ * Establishes for the client link identified by 'req' a subscription
+ * to the 'event'.
+ * Returns 0 in case of successful subscription or -1 in case of error.
+ */
+static inline int afb_req_subscribe(struct afb_req req, struct afb_event event)
+{
+ return req.itf->subscribe(req.closure, event);
+}
+
+/*
+ * Revokes the subscription established to the 'event' for the client
+ * link identified by 'req'.
+ * Returns 0 in case of successful subscription or -1 in case of error.
+ */
+static inline int afb_req_unsubscribe(struct afb_req req, struct afb_event event)
+{
+ return req.itf->unsubscribe(req.closure, event);
+}
+
+
+
+
/* internal use */
static inline const char *afb_req_raw(struct afb_req req, size_t *size)
{