diff options
author | José Bollo <jose.bollo@iot.bzh> | 2016-06-09 07:54:31 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2016-06-09 08:39:02 +0200 |
commit | 7e0abe76db7b90369429bf387d7aad0fb5a42328 (patch) | |
tree | eedf5609a588f0d9d743fb941bc8727ff1356b21 /src/afb-hreq.c | |
parent | c37c8e6291c36665dd23601a8ce1449afd43e6df (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 'src/afb-hreq.c')
-rw-r--r-- | src/afb-hreq.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/afb-hreq.c b/src/afb-hreq.c index 4ca8441e..1e38b412 100644 --- a/src/afb-hreq.c +++ b/src/afb-hreq.c @@ -74,8 +74,9 @@ static void req_fail(struct afb_hreq *hreq, const char *status, const char *info static void req_success(struct afb_hreq *hreq, json_object *obj, const char *info); static const char *req_raw(struct afb_hreq *hreq, size_t *size); static void req_send(struct afb_hreq *hreq, const char *buffer, size_t size); +static int req_subscribe_unsubscribe_error(struct afb_hreq *hreq, struct afb_event event); -static const struct afb_req_itf afb_hreq_itf = { +const struct afb_req_itf afb_hreq_req_itf = { .json = (void*)req_json, .get = (void*)req_get, .success = (void*)req_success, @@ -87,7 +88,9 @@ static const struct afb_req_itf afb_hreq_itf = { .addref = (void*)afb_hreq_addref, .unref = (void*)afb_hreq_unref, .session_close = (void*)afb_context_close, - .session_set_LOA = (void*)afb_context_change_loa + .session_set_LOA = (void*)afb_context_change_loa, + .subscribe = (void*)req_subscribe_unsubscribe_error, + .unsubscribe = (void*)req_subscribe_unsubscribe_error }; static struct hreq_data *get_data(struct afb_hreq *hreq, const char *key, int create) @@ -697,7 +700,7 @@ int afb_hreq_post_add_file(struct afb_hreq *hreq, const char *key, const char *f struct afb_req afb_hreq_to_req(struct afb_hreq *hreq) { - return (struct afb_req){ .itf = &afb_hreq_itf, .closure = hreq }; + return (struct afb_req){ .itf = &afb_hreq_req_itf, .closure = hreq }; } static struct afb_arg req_get(struct afb_hreq *hreq, const char *name) @@ -798,6 +801,12 @@ static void req_success(struct afb_hreq *hreq, json_object *obj, const char *inf req_reply(hreq, MHD_HTTP_OK, "success", info, obj); } +static int req_subscribe_unsubscribe_error(struct afb_hreq *hreq, struct afb_event event) +{ + errno = EINVAL; + return -1; +} + int afb_hreq_init_context(struct afb_hreq *hreq) { const char *uuid; |