summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-08-02 19:14:09 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-08-03 11:45:26 +0200
commit04186fd953298be8b8c5673b5fcd01f0893986ff (patch)
tree030e077e7dc7f84e7c3894111f451088255256eb /bindings
parent6d124e683d2511ac02a1cbe61fca3d230bda4f0c (diff)
subcall_req: introduce afb_req_subcall_req
The function 'afb_req_subcall_req' can be used to make asynchronous subcalls. It improves the function 'afb_req_subcall' by automatically keeping the request opened for the callback and by passing it, the request, as an extra argument of the callback. Change-Id: I2dc79c01fc25c7a65b9c8cc9e001a5b85fba99df Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'bindings')
-rw-r--r--bindings/samples/HelloWorld.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/bindings/samples/HelloWorld.c b/bindings/samples/HelloWorld.c
index 731ea530..002c4721 100644
--- a/bindings/samples/HelloWorld.c
+++ b/bindings/samples/HelloWorld.c
@@ -192,6 +192,27 @@ static void subcall (afb_req request)
afb_req_subcall(request, api, verb, object, subcallcb, afb_req_store(request));
}
+static void subcallreqcb (void *prequest, int status, json_object *object, afb_req request)
+{
+ if (status < 0)
+ afb_req_fail(request, "failed", json_object_to_json_string(object));
+ else
+ afb_req_success(request, json_object_get(object), NULL);
+}
+
+static void subcallreq (afb_req request)
+{
+ const char *api = afb_req_value(request, "api");
+ const char *verb = afb_req_value(request, "verb");
+ const char *args = afb_req_value(request, "args");
+ json_object *object = api && verb && args ? json_tokener_parse(args) : NULL;
+
+ if (object == NULL)
+ afb_req_fail(request, "failed", "bad arguments");
+ else
+ afb_req_subcall_req(request, api, verb, object, subcallreqcb, NULL);
+}
+
static void subcallsync (afb_req request)
{
int rc;
@@ -418,6 +439,7 @@ static const afb_verb_v2 verbs[]= {
{ .verb="pingJson", .callback=pingJson },
{ .verb="pingevent", .callback=pingEvent },
{ .verb="subcall", .callback=subcall },
+ { .verb="subcallreq", .callback=subcallreq },
{ .verb="subcallsync", .callback=subcallsync },
{ .verb="eventadd", .callback=eventadd },
{ .verb="eventdel", .callback=eventdel },