summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-04-04 14:52:40 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-04-04 14:52:40 +0200
commitede362db9ea82b85a531849c21582f1692bf0d4d (patch)
treecc2b274cc66cf959613230d447d03233b3c29033 /include
parent66c2dc7476c4a5105bcf233dd4e08f0466e7f3dc (diff)
Add synchronous subcalls
Synchronous subcalls are more easy for writing simple applications with sequential logic. Change-Id: I76a0231a64a6db8270014cd2a64284e1b0fc16ec Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'include')
-rw-r--r--include/afb/afb-req-itf.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h
index 6b6c8b70..8f8dc8a9 100644
--- a/include/afb/afb-req-itf.h
+++ b/include/afb/afb-req-itf.h
@@ -72,6 +72,7 @@ struct afb_req_itf {
int (*unsubscribe)(void *closure, struct afb_event event);
void (*subcall)(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure);
+ int (*subcallsync)(void *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result);
};
/*
@@ -365,6 +366,19 @@ static inline void afb_req_subcall(struct afb_req req, const char *api, const ch
req.itf->subcall(req.closure, api, verb, args, callback, closure);
}
+/*
+ * Makes a call to the method of name 'api' / 'verb' with the object 'args'.
+ * This call is made in the context of the request 'req'.
+ * This call is synchronous, it waits untill completion of the request.
+ * It returns 0 on an error answer and returns 1 when no error was detected.
+ * The object pointed by 'result' is filled and must be released by the caller
+ * after its use by calling 'json_object_put'.
+ */
+static inline int afb_req_subcall_sync(struct afb_req req, const char *api, const char *verb, struct json_object *args, struct json_object **result)
+{
+ return req.itf->subcallsync(req.closure, api, verb, args, result);
+}
+
/* internal use */
static inline const char *afb_req_raw(struct afb_req req, size_t *size)
{