diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-09-22 15:59:48 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-10-09 14:08:33 +0200 |
commit | f30be1ca9ce04cfab55b9e6ce25cec6952f7e21d (patch) | |
tree | 88a0d681faa3604202cfbda4a94584b950ec4a74 /bindings/samples/ave.c | |
parent | 9a304ebddac4deb4992ea931ea1131b639798b3b (diff) |
Add a closure argument to dynamic verbs
Also demonstrate the mix of api v2 with dynapi.
Change-Id: I95e8d32ac836590ce3f7b3f0b5f29e5574808976
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'bindings/samples/ave.c')
-rw-r--r-- | bindings/samples/ave.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/bindings/samples/ave.c b/bindings/samples/ave.c index 3ddfda62..e6b195b8 100644 --- a/bindings/samples/ave.c +++ b/bindings/samples/ave.c @@ -447,6 +447,18 @@ static const struct { { .verb=NULL} }; +static void pingoo(afb_req req) +{ + json_object *args = afb_req_json(req); + afb_req_success_f(req, json_object_get(args), "You reached pingoo \\o/ nice args: %s", json_object_to_json_string(args)); +} + +static const afb_verb_v2 verbsv2[]= { + { .verb="pingoo", .callback=pingoo }, + { .verb="ping", .callback=pingoo }, + { .verb=NULL} +}; + static const char *apis[] = { "ave", "hi", "salut", NULL }; static int api_preinit(void *closure, afb_dynapi *dynapi) @@ -458,8 +470,9 @@ static int api_preinit(void *closure, afb_dynapi *dynapi) afb_dynapi_on_init(dynapi, init); afb_dynapi_on_event(dynapi, onevent); + rc = afb_dynapi_set_verbs_v2(dynapi, verbsv2); for (i = rc = 0; verbs[i].verb && rc >= 0 ; i++) { - rc = afb_dynapi_add_verb(dynapi, verbs[i].verb, NULL, verbs[i].callback, NULL, 0); + rc = afb_dynapi_add_verb(dynapi, verbs[i].verb, NULL, verbs[i].callback, (void*)(intptr_t)i, NULL, 0); } afb_dynapi_seal(dynapi); return rc; |