diff options
author | José Bollo <jose.bollo@iot.bzh> | 2018-02-22 14:54:47 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2018-02-22 14:54:47 +0100 |
commit | d69f7604c515e211f8021306b5aa51044f927add (patch) | |
tree | 8cd7862eb6568b48f29efdc164e1f086a4ed458d | |
parent | ca820c65c2b03a24e8936218171c6c1d138fd1f7 (diff) |
xreq: export a function to get req
Change-Id: Ie7eac225f514349926341b7db61ea0eb9029c5d8
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | include/afb/afb-req-itf.h | 30 | ||||
-rw-r--r-- | include/afb/afb-req.h | 12 | ||||
-rw-r--r-- | src/afb-xreq.c | 19 | ||||
-rw-r--r-- | src/afb-xreq.h | 8 |
4 files changed, 45 insertions, 24 deletions
diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h new file mode 100644 index 00000000..297654ca --- /dev/null +++ b/include/afb/afb-req-itf.h @@ -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' */ +}; + diff --git a/include/afb/afb-req.h b/include/afb/afb-req.h index af33108c..1533985f 100644 --- a/include/afb/afb-req.h +++ b/include/afb/afb-req.h @@ -17,20 +17,10 @@ #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. */ static inline struct afb_request *afb_req_to_request(struct afb_req req) diff --git a/src/afb-xreq.c b/src/afb-xreq.c index f9a83b5c..cee1a668 100644 --- a/src/afb-xreq.c +++ b/src/afb-xreq.c @@ -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) diff --git a/src/afb-xreq.h b/src/afb-xreq.h index 4e79686c..6da614e1 100644 --- a/src/afb-xreq.h +++ b/src/afb-xreq.h @@ -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; |