struct event
{
struct event *next;
- struct afb_eventid *eventid;
+ afb_eventid *eventid;
char tag[1];
};
{
AFB_DYNAPI_NOTICE(dynapi, "received event %s(%s) by AVE(%s)",
event, json_object_to_json_string(object),
- (const char*)dynapi->userdata);
+ (const char*)afb_dynapi_get_userdata(dynapi));
}
// NOTE: this sample does not use session to keep test a basic as possible
{ .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)
+static int build_api(void *closure, afb_dynapi *dynapi)
{
int i, rc;
- dynapi->userdata = closure;
- AFB_DYNAPI_NOTICE(dynapi, "dynamic binding AVE(%s) comes to live", (const char*)dynapi->userdata);
+ afb_dynapi_set_userdata(dynapi, closure);
+ AFB_DYNAPI_NOTICE(dynapi, "dynamic binding AVE(%s) comes to live", (const char*)afb_dynapi_get_userdata(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;
int i, rc;
for (i = 0; apis[i] ; i++) {
- rc = afb_dynapi_new_api(dynapi, apis[i], NULL, api_preinit, (void*)apis[i]);
+ rc = afb_dynapi_new_api(dynapi, apis[i], NULL, 0, build_api, (void*)apis[i]);
+ if (rc < 0)
+ AFB_DYNAPI_ERROR(dynapi, "can't create API %s", apis[i]);
}
return 0;
}