Prepare subscription to eventid
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 22 Sep 2017 05:58:05 +0000 (07:58 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 9 Oct 2017 12:08:32 +0000 (14:08 +0200)
Change-Id: Ie3f75377009be36f7f5bd52bdb31d0611cd49778
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
include/afb/afb-request-itf.h
include/afb/afb-request.h
src/afb-xreq.c

index 4c62b3d..a5c3f82 100644 (file)
@@ -163,5 +163,13 @@ struct afb_request_itf
                        void *(*create_value)(void *creation_closure),
                        void (*free_value)(void*),
                        void *creation_closure);
+
+       int (*subscribe_eventid)(
+                       struct afb_request *request,
+                       struct afb_eventid *eventid);
+
+       int (*unsubscribe_eventid)(
+                       struct afb_request *request,
+                       struct afb_eventid *eventid);
 };
 
index c2585fc..acfb7ea 100644 (file)
@@ -21,8 +21,6 @@
 
 typedef struct afb_request afb_request;
 
-#include "afb-event.h"
-
 /*
  * Gets from the request 'request' the argument of 'name'.
  * Returns a PLAIN structure of type 'struct afb_arg'.
@@ -244,9 +242,9 @@ static inline int afb_request_session_set_LOA(struct afb_request *request, unsig
  * to the 'event'.
  * Returns 0 in case of successful subscription or -1 in case of error.
  */
-static inline int afb_request_subscribe(struct afb_request *request, struct afb_event event)
+static inline int afb_request_subscribe(struct afb_request *request, struct afb_eventid *eventid)
 {
-       return request->itf->subscribe(request, event);
+       return request->itf->subscribe_eventid(request, eventid);
 }
 
 /*
@@ -254,9 +252,9 @@ static inline int afb_request_subscribe(struct afb_request *request, struct afb_
  * link identified by 'request'.
  * Returns 0 in case of successful subscription or -1 in case of error.
  */
-static inline int afb_request_unsubscribe(struct afb_request *request, struct afb_event event)
+static inline int afb_request_unsubscribe(struct afb_request *request, struct afb_eventid *eventid)
 {
-       return request->itf->unsubscribe(request, event);
+       return request->itf->unsubscribe_eventid(request, eventid);
 }
 
 /*
index b091bd1..ed5f30b 100644 (file)
@@ -639,18 +639,30 @@ static int xreq_hooked_session_set_LOA_cb(struct afb_request *closure, unsigned
        return afb_hook_xreq_session_set_LOA(xreq, level, r);
 }
 
+static int xreq_hooked_subscribe_eventid_cb(struct afb_request *closure, struct afb_eventid *eventid);
 static int xreq_hooked_subscribe_cb(struct afb_request *closure, struct afb_event event)
 {
-       int r = xreq_subscribe_cb(closure, event);
+       return xreq_hooked_subscribe_eventid_cb(closure, event.closure);
+}
+
+static int xreq_hooked_subscribe_eventid_cb(struct afb_request *closure, struct afb_eventid *eventid)
+{
+       int r = xreq_subscribe_eventid_cb(closure, eventid);
        struct afb_xreq *xreq = from_request(closure);
-       return afb_hook_xreq_subscribe(xreq, event.closure, r);
+       return afb_hook_xreq_subscribe(xreq, eventid, r);
 }
 
+static int xreq_hooked_unsubscribe_eventid_cb(struct afb_request *closure, struct afb_eventid *eventid);
 static int xreq_hooked_unsubscribe_cb(struct afb_request *closure, struct afb_event event)
 {
-       int r = xreq_unsubscribe_cb(closure, event);
+       return xreq_hooked_unsubscribe_eventid_cb(closure, event.closure);
+}
+
+static int xreq_hooked_unsubscribe_eventid_cb(struct afb_request *closure, struct afb_eventid *eventid)
+{
+       int r = xreq_unsubscribe_eventid_cb(closure, eventid);
        struct afb_xreq *xreq = from_request(closure);
-       return afb_hook_xreq_unsubscribe(xreq, event.closure, r);
+       return afb_hook_xreq_unsubscribe(xreq, eventid, r);
 }
 
 static void xreq_hooked_subcall_cb(struct afb_request *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure)
@@ -757,7 +769,9 @@ const struct afb_request_itf xreq_itf = {
        .subcall_req = xreq_subcall_req_cb,
        .has_permission = xreq_has_permission_cb,
        .get_application_id = xreq_get_application_id_cb,
-       .context_make = xreq_context_make_cb
+       .context_make = xreq_context_make_cb,
+       .subscribe_eventid = xreq_subscribe_eventid_cb,
+       .unsubscribe_eventid = xreq_unsubscribe_eventid_cb,
 };
 
 const struct afb_request_itf xreq_hooked_itf = {
@@ -782,7 +796,9 @@ const struct afb_request_itf xreq_hooked_itf = {
        .subcall_req = xreq_hooked_subcall_req_cb,
        .has_permission = xreq_hooked_has_permission_cb,
        .get_application_id = xreq_hooked_get_application_id_cb,
-       .context_make = xreq_hooked_context_make_cb
+       .context_make = xreq_hooked_context_make_cb,
+       .subscribe_eventid = xreq_hooked_subscribe_eventid_cb,
+       .unsubscribe_eventid = xreq_hooked_unsubscribe_eventid_cb,
 };
 
 /******************************************************************************/