aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-ws-json1.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2019-07-16 14:12:35 +0200
committerJose Bollo <jose.bollo@iot.bzh>2019-07-18 15:38:02 +0200
commit5b5968815dc672467f40ed6b49f05a590bdb8b4d (patch)
treea850a00955f697eb2766027e8f60731af344a2cc /src/afb-ws-json1.c
parent6fe59e27c0640462f92133106b4d4d52d77683f9 (diff)
afb-evt: Refactor processing of broadcasted events
Solving the bug SPEC-2625 needs to rework the broadcasting of events. It appeared that the numerical event identifier passed for broadcast wasn't used by called function except for hooking. Suppressing it introduces a clear distinction between the push and the broadcast paths. The file afb-ws-json1 is changed to avoid casting of functions. Bug-AGL: SPEC-2625 Change-Id: I9fe75adc8086812b21b70ce28baffcf77bd5e1cf Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-ws-json1.c')
-rw-r--r--src/afb-ws-json1.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/afb-ws-json1.c b/src/afb-ws-json1.c
index 197d0c86..9d6bfc3c 100644
--- a/src/afb-ws-json1.c
+++ b/src/afb-ws-json1.c
@@ -44,9 +44,10 @@ struct afb_ws_json1;
struct afb_wsreq;
/* predeclaration of websocket callbacks */
-static void aws_on_hangup(struct afb_ws_json1 *ws, struct afb_wsj1 *wsj1);
-static void aws_on_call(struct afb_ws_json1 *ws, const char *api, const char *verb, struct afb_wsj1_msg *msg);
-static void aws_on_event(struct afb_ws_json1 *ws, const char *event, int eventid, struct json_object *object);
+static void aws_on_hangup_cb(void *closure, struct afb_wsj1 *wsj1);
+static void aws_on_call_cb(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
+static void aws_on_push_cb(void *closure, const char *event, int eventid, struct json_object *object);
+static void aws_on_broadcast_cb(void *closure, const char *event, struct json_object *object);
/* predeclaration of wsreq callbacks */
static void wsreq_destroy(struct afb_xreq *xreq);
@@ -77,8 +78,8 @@ struct afb_wsreq
/* interface for afb_ws_json1 / afb_wsj1 */
static struct afb_wsj1_itf wsj1_itf = {
- .on_hangup = (void*)aws_on_hangup,
- .on_call = (void*)aws_on_call
+ .on_hangup = aws_on_hangup_cb,
+ .on_call = aws_on_call_cb
};
/* interface for xreq */
@@ -89,8 +90,8 @@ const struct afb_xreq_query_itf afb_ws_json1_xreq_itf = {
/* the interface for events */
static const struct afb_evt_itf evt_itf = {
- .broadcast = (void*)aws_on_event,
- .push = (void*)aws_on_event
+ .broadcast = aws_on_broadcast_cb,
+ .push = aws_on_push_cb
};
/***************************************************************
@@ -163,13 +164,15 @@ void afb_ws_json1_unref(struct afb_ws_json1 *ws)
}
}
-static void aws_on_hangup(struct afb_ws_json1 *ws, struct afb_wsj1 *wsj1)
+static void aws_on_hangup_cb(void *closure, struct afb_wsj1 *wsj1)
{
+ struct afb_ws_json1 *ws = closure;
afb_ws_json1_unref(ws);
}
-static void aws_on_call(struct afb_ws_json1 *ws, const char *api, const char *verb, struct afb_wsj1_msg *msg)
+static void aws_on_call_cb(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
{
+ struct afb_ws_json1 *ws = closure;
struct afb_wsreq *wsreq;
DEBUG("received websocket request for %s/%s: %s", api, verb, afb_wsj1_msg_object_s(msg));
@@ -205,8 +208,14 @@ static void aws_on_call(struct afb_ws_json1 *ws, const char *api, const char *ve
afb_xreq_process(&wsreq->xreq, ws->apiset);
}
-static void aws_on_event(struct afb_ws_json1 *aws, const char *event, int eventid, struct json_object *object)
+static void aws_on_push_cb(void *closure, const char *event, int eventid, struct json_object *object)
{
+ aws_on_broadcast_cb(closure, event, object);
+}
+
+static void aws_on_broadcast_cb(void *closure, const char *event, struct json_object *object)
+{
+ struct afb_ws_json1 *aws = closure;
afb_wsj1_send_event_j(aws->wsj1, event, afb_msg_json_event(event, object));
}