xreq: export a function to get req
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 22 Feb 2018 13:54:47 +0000 (14:54 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Thu, 22 Feb 2018 13:54:47 +0000 (14:54 +0100)
Change-Id: Ie7eac225f514349926341b7db61ea0eb9029c5d8
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
include/afb/afb-req-itf.h [new file with mode: 0644]
include/afb/afb-req.h
src/afb-xreq.c
src/afb-xreq.h

diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h
new file mode 100644 (file)
index 0000000..297654c
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "afb-request-itf.h"
+
+/*
+ * Describes the request by bindings from afb-daemon
+ */
+struct afb_req
+{
+       const struct afb_request_itf *itf;      /* the interface to use */
+       struct afb_request *closure;            /* the closure argument for functions of 'itf' */
+};
+
index af33108..1533985 100644 (file)
 
 #pragma once
 
-#include "afb-request-itf.h"
-
+#include "afb-req-itf.h"
 #include "afb-event.h"
 
-/*
- * Describes the request by bindings from afb-daemon
- */
-struct afb_req
-{
-       const struct afb_request_itf *itf;      /* the interface to use */
-       struct afb_request *closure;            /* the closure argument for functions of 'itf' */
-};
-
 /*
  * Converts the 'req' to an afb_request.
  */
index f9a83b5..cee1a66 100644 (file)
@@ -66,13 +66,6 @@ inline void afb_xreq_unhooked_unref(struct afb_xreq *xreq)
 
 /******************************************************************************/
 
-static inline struct afb_req to_req(struct afb_xreq *xreq)
-{
-       return (struct afb_req){ .itf = xreq->request.itf, .closure = &xreq->request };
-}
-
-/******************************************************************************/
-
 struct subcall
 {
        struct afb_xreq xreq;
@@ -179,7 +172,7 @@ static void subcall_on_reply(struct subcall *subcall, int status, struct json_ob
 
 static void subcall_req_on_reply(struct subcall *subcall, int status, struct json_object *result)
 {
-       subcall->callback_req(subcall->closure, status, result, to_req(subcall->xreq.caller));
+       subcall->callback_req(subcall->closure, status, result, xreq_to_req(subcall->xreq.caller));
 }
 
 static void subcall_request_on_reply(struct subcall *subcall, int status, struct json_object *result)
@@ -507,7 +500,7 @@ static void xreq_subcall_req_cb(struct afb_request *closure, const char *api, co
        sc = subcall_alloc(xreq, api, verb, args);
        if (sc == NULL) {
                if (callback)
-                       callback(cb_closure, 1, afb_msg_json_internal_error(), to_req(xreq));
+                       callback(cb_closure, 1, afb_msg_json_internal_error(), xreq_to_req(xreq));
                json_object_put(args);
        } else {
                subcall_req(sc, callback, cb_closure);
@@ -728,7 +721,7 @@ static void xreq_hooked_subcall_req_cb(struct afb_request *closure, const char *
        sc = subcall_alloc(xreq, api, verb, args);
        if (sc == NULL) {
                if (callback)
-                       callback(cb_closure, 1, afb_msg_json_internal_error(), to_req(xreq));
+                       callback(cb_closure, 1, afb_msg_json_internal_error(), xreq_to_req(xreq));
                json_object_put(args);
        } else {
                subcall_req_hooked(sc, callback, cb_closure);
@@ -873,7 +866,7 @@ struct afb_req afb_xreq_unstore(struct afb_stored_req *sreq)
        struct afb_xreq *xreq = (struct afb_xreq *)sreq;
        if (xreq->hookflags)
                afb_hook_xreq_unstore(xreq);
-       return to_req(xreq);
+       return xreq_to_req(xreq);
 }
 
 struct json_object *afb_xreq_json(struct afb_xreq *xreq)
@@ -1033,7 +1026,7 @@ void afb_xreq_call_verb_v1(struct afb_xreq *xreq, const struct afb_verb_desc_v1
                afb_xreq_fail_unknown_verb(xreq);
        else
                if (!xreq_session_check_apply_v1(xreq, verb->session))
-                       verb->callback(to_req(xreq));
+                       verb->callback(xreq_to_req(xreq));
 }
 
 void afb_xreq_call_verb_v2(struct afb_xreq *xreq, const struct afb_verb_v2 *verb)
@@ -1042,7 +1035,7 @@ void afb_xreq_call_verb_v2(struct afb_xreq *xreq, const struct afb_verb_v2 *verb
                afb_xreq_fail_unknown_verb(xreq);
        else
                if (!xreq_session_check_apply_v2(xreq, verb->session, verb->auth))
-                       verb->callback(to_req(xreq));
+                       verb->callback(xreq_to_req(xreq));
 }
 
 void afb_xreq_call_verb_vdyn(struct afb_xreq *xreq, const struct afb_api_dyn_verb *verb)
index 4e79686..6da614e 100644 (file)
@@ -18,6 +18,7 @@
 #pragma once
 
 #include <afb/afb-request-itf.h>
+#include <afb/afb-req-itf.h>
 #include "afb-context.h"
 
 struct json_object;
@@ -147,6 +148,13 @@ extern void afb_xreq_call_verb_v1(struct afb_xreq *xreq, const struct afb_verb_d
 extern void afb_xreq_call_verb_v2(struct afb_xreq *xreq, const struct afb_verb_v2 *verb);
 extern void afb_xreq_call_verb_vdyn(struct afb_xreq *xreq, const struct afb_api_dyn_verb *verb);
 
+/******************************************************************************/
+
+static inline struct afb_req xreq_to_req(struct afb_xreq *xreq)
+{
+       return (struct afb_req){ .itf = xreq->request.itf, .closure = &xreq->request };
+}
+
 static inline struct afb_request *xreq_to_request(struct afb_xreq *xreq)
 {
        return &xreq->request;