2 * Copyright (C) 2017 "IoT.bzh"
3 * Author José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #define NO_BINDING_VERBOSE_MACRO
22 #include <afb/afb-binding.h>
23 #include "afb-context.h"
27 struct afb_evt_listener;
29 struct afb_xreq_query_itf {
30 struct json_object *(*json)(void *closure);
31 struct afb_arg (*get)(void *closure, const char *name);
32 void (*success)(void *closure, struct json_object *obj, const char *info);
33 void (*fail)(void *closure, const char *status, const char *info);
34 void (*reply)(void *closure, int iserror, struct json_object *obj);
35 void (*unref)(void *closure);
36 int (*subscribe)(void *closure, struct afb_event event);
37 int (*unsubscribe)(void *closure, struct afb_event event);
38 void (*subcall)(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure);
43 * Internal data for requests
47 struct afb_context context; /**< context of the request */
48 const char *api; /**< the requested API */
49 const char *verb; /**< the requested VERB */
50 struct json_object *json; /**< the json object (or NULL) */
51 void *query; /**< closure for the query */
52 const struct afb_xreq_query_itf *queryitf;
53 int refcount; /**< current ref count */
54 int replied; /**< is replied? */
55 int hookflags; /**< flags for hooking */
56 int hookindex; /**< index for hooking */
57 struct afb_evt_listener *listener;
60 extern void afb_xreq_addref(struct afb_xreq *xreq);
61 extern void afb_xreq_unref(struct afb_xreq *xreq);
62 extern void afb_xreq_success(struct afb_xreq *xreq, struct json_object *obj, const char *info);
63 extern void afb_xreq_fail(struct afb_xreq *xreq, const char *status, const char *info);
64 extern void afb_xreq_fail_f(struct afb_xreq *xreq, const char *status, const char *info, ...);
65 extern void afb_xreq_success_f(struct afb_xreq *xreq, struct json_object *obj, const char *info, ...);
66 extern const char *afb_xreq_raw(struct afb_xreq *xreq, size_t *size);
67 extern int afb_xreq_subscribe(struct afb_xreq *xreq, struct afb_event event);
68 extern int afb_xreq_unsubscribe(struct afb_xreq *xreq, struct afb_event event);
69 extern void afb_xreq_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure);
70 extern void afb_xreq_unhooked_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure);
72 extern void afb_xreq_begin(struct afb_xreq *xreq);
73 extern void afb_xreq_call(struct afb_xreq *xreq, int sessionflags, void (*callback)(struct afb_req req));