Also demonstrate the mix of api v2 with dynapi.
Change-Id: I95e8d32ac836590ce3f7b3f0b5f29e5574808976
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
{ .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)
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;
const char *verb,
const char *info,
void (*callback)(struct afb_request *request),
+ void *vcbdata,
const struct afb_auth *auth,
uint32_t session);
const char *verb,
const char *info,
void (*callback)(struct afb_request *request),
+ void *vcbdata,
const struct afb_auth *auth,
uint32_t session)
{
- return dynapi->itf->api_add_verb(dynapi, verb, info, callback, auth, session);
+ return dynapi->itf->api_add_verb(dynapi, verb, info, callback, vcbdata, auth, session);
}
/* current dynapi if dynapi (is NULL for bindings v1 and v2) */
struct afb_dynapi *dynapi;
+
+ /* closure associated with the callback processing the verb of the request
+ * as given at its declaration */
+ void *vcbdata;
};
/*
const char *verb,
const char *info,
void (*callback)(struct afb_request *request),
+ void *vcbdata,
const struct afb_auth *auth,
uint32_t session)
{
struct afb_api_dyn_verb *v, **vv;
+ afb_api_dyn_sub_verb(dynapi, verb);
+
vv = realloc(dynapi->verbs, (1 + dynapi->count) * sizeof *vv);
if (!vv)
goto oom;
goto oom;
v->callback = callback;
+ v->vcbdata = vcbdata;
v->auth = auth;
v->session = session;
static void call_cb(void *closure, struct afb_xreq *xreq)
{
struct afb_api_dyn *dynapi = closure;
- struct afb_api_dyn_verb **verbs;
+ struct afb_api_dyn_verb **verbs, *v;
const struct afb_verb_v2 *verbsv2;
int i;
const char *name;
verbs = dynapi->verbs;
i = dynapi->count;
while (i) {
- if (!strcasecmp(verbs[--i]->verb, name)) {
+ v = verbs[--i];
+ if (!strcasecmp(v->verb, name)) {
+ xreq->request.vcbdata = v->vcbdata;
afb_xreq_call_verb_vdyn(xreq, verbs[i]);
return;
}
struct afb_api_dyn_verb
{
void (*callback)(struct afb_request *request);
+ void *vcbdata;
const struct afb_auth *auth;
const char *info;
int session;
const char *verb,
const char *info,
void (*callback)(struct afb_request *request),
+ void *vcbdata,
const struct afb_auth *auth,
uint32_t session);
const char *verb,
const char *info,
void (*callback)(struct afb_request *request),
+ void *vcbdata,
const struct afb_auth *auth,
uint32_t session)
{
struct afb_export *export = from_dynapi(dynapi);
if (export->apidyn)
- return afb_api_dyn_add_verb(export->apidyn, verb, info, callback, auth, session);
+ return afb_api_dyn_add_verb(export->apidyn, verb, info, callback, vcbdata, auth, session);
errno = EPERM;
return -1;
const char *verb,
const char *info,
void (*callback)(struct afb_request *request),
+ void *vcbdata,
const struct afb_auth *auth,
uint32_t session)
{
/* TODO */
- return api_add_verb_cb(dynapi, verb, info, callback, auth, session);
+ return api_add_verb_cb(dynapi, verb, info, callback, vcbdata, auth, session);
}
static int hooked_api_sub_verb_cb(