Prepare xreq to be aware of the version
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 4 May 2017 11:06:02 +0000 (13:06 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Thu, 4 May 2017 11:06:02 +0000 (13:06 +0200)
Change-Id: If8a1ac53e58ff644d7903aebd263d7d42308c756
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-so-v1.c
src/afb-api-so-v2.c
src/afb-xreq.c
src/afb-xreq.h

index a81ec17..eedfc01 100644 (file)
@@ -70,11 +70,7 @@ static void call_cb(void *closure, struct afb_xreq *xreq)
        struct api_so_v1 *desc = closure;
 
        verb = search(desc, xreq->verb);
-       if (!verb)
-               afb_xreq_fail_unknown_verb(xreq);
-       else
-               if (!xreq_session_check_apply(xreq, verb->session))
-                       afb_xreq_call(xreq, verb->callback);
+       afb_xreq_call_verb_v1(xreq, verb);
 }
 
 static int service_start_cb(void *closure, int share_session, int onneed, struct afb_apiset *apiset)
index 1207474..092fd31 100644 (file)
@@ -89,11 +89,7 @@ static void call_cb(void *closure, struct afb_xreq *xreq)
        const struct afb_verb_v2 *verb;
 
        verb = search(desc, xreq->verb);
-       if (!verb)
-               afb_xreq_fail_unknown_verb(xreq);
-       else
-               if (!xreq_session_check_apply(xreq, verb->session))
-                       afb_xreq_call(xreq, verb->callback);
+       afb_xreq_call_verb_v2(xreq, verb);
 }
 
 static int service_start_cb(void *closure, int share_session, int onneed, struct afb_apiset *apiset)
index 143048c..d6cf91f 100644 (file)
@@ -439,7 +439,7 @@ void afb_xreq_subcall(struct afb_xreq *xreq, const char *api, const char *verb,
        afb_req_subcall(to_req(xreq), api, verb, args, callback, cb_closure);
 }
 
-int xreq_session_check(struct afb_xreq *xreq, int sessionflags)
+static int xreq_session_check_apply(struct afb_xreq *xreq, int sessionflags)
 {
        int loa;
 
@@ -470,11 +470,6 @@ int xreq_session_check(struct afb_xreq *xreq, int sessionflags)
                }
        }
 
-       return 0;
-}
-
-void xreq_session_apply(struct afb_xreq *xreq, int sessionflags)
-{
        if ((sessionflags & AFB_SESSION_RENEW) != 0) {
                afb_context_refresh(&xreq->context);
        }
@@ -482,26 +477,26 @@ void xreq_session_apply(struct afb_xreq *xreq, int sessionflags)
                afb_context_change_loa(&xreq->context, 0);
                afb_context_close(&xreq->context);
        }
-}
 
-int xreq_session_check_apply(struct afb_xreq *xreq, int sessionflags)
-{
-       int rc = xreq_session_check(xreq, sessionflags);
-       if (!rc)
-               xreq_session_apply(xreq, sessionflags);
-
-       return rc;
+       return 0;
 }
 
-void afb_xreq_call(struct afb_xreq *xreq, void (*method)(struct afb_req req))
+void afb_xreq_call_verb_v1(struct afb_xreq *xreq, const struct afb_verb_desc_v1 *verb)
 {
-       method(to_req(xreq));
+       if (!verb)
+               afb_xreq_fail_unknown_verb(xreq);
+       else
+               if (!xreq_session_check_apply(xreq, verb->session))
+                       verb->callback(to_req(xreq));
 }
 
-void afb_xreq_check_apply_call(struct afb_xreq *xreq, int sessionflags, void (*method)(struct afb_req req))
+void afb_xreq_call_verb_v2(struct afb_xreq *xreq, const struct afb_verb_v2 *verb)
 {
-       if (!xreq_session_check_apply(xreq, sessionflags))
-               method(to_req(xreq));
+       if (!verb)
+               afb_xreq_fail_unknown_verb(xreq);
+       else
+               if (!xreq_session_check_apply(xreq, verb->session))
+                       verb->callback(to_req(xreq));
 }
 
 void afb_xreq_init(struct afb_xreq *xreq, const struct afb_xreq_query_itf *queryitf)
index a7b086b..7327c22 100644 (file)
@@ -124,10 +124,6 @@ extern void afb_xreq_init(struct afb_xreq *xreq, const struct afb_xreq_query_itf
 
 extern void afb_xreq_process(struct afb_xreq *xreq, struct afb_apiset *apiset);
 
-extern int xreq_session_check(struct afb_xreq *xreq, int sessionflags);
-extern void xreq_session_apply(struct afb_xreq *xreq, int sessionflags);
-extern int xreq_session_check_apply(struct afb_xreq *xreq, int sessionflags);
-
-extern void afb_xreq_call(struct afb_xreq *xreq, void (*callback)(struct afb_req req));
-extern void afb_xreq_check_apply_call(struct afb_xreq *xreq, int sessionflags, void (*callback)(struct afb_req req));
+extern void afb_xreq_call_verb_v1(struct afb_xreq *xreq, const struct afb_verb_desc_v1 *verb);
+extern void afb_xreq_call_verb_v2(struct afb_xreq *xreq, const struct afb_verb_v2 *verb);