--- /dev/null
+/*
+ * 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' */
+};
+
/******************************************************************************/
-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;
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)
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);
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);
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)
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)
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)
#pragma once
#include <afb/afb-request-itf.h>
+#include <afb/afb-req-itf.h>
#include "afb-context.h"
struct json_object;
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;