-static const struct afb_verb_v2 *search(struct api_so_v2 *desc, const char *verb)
-{
- const struct afb_verb_v2 *result;
-
- result = desc->binding->verbs;
- while (result->verb && strcasecmp(result->verb, verb))
- result++;
- return result->verb ? result : NULL;
-}
-
-static void call_cb(void *closure, struct afb_req req, struct afb_context *context, const char *name)
-{
- struct api_so_v2 *desc = closure;
- const struct afb_verb_v2 *verb;
-
- verb = search(desc, name);
- if (!verb)
- afb_req_fail_f(req, "unknown-verb", "verb %s unknown within api %s", name, desc->binding->api);
- else if (call_check(req, context, verb)) {
- afb_thread_req_call(req, verb->callback, afb_api_so_timeout, desc);
- }
-}
-
-static void xcall_cb(void *closure, struct afb_xreq *xreq)
-{
- struct api_so_v2 *desc = closure;
- const struct afb_verb_v2 *verb;
-
- verb = search(desc, xreq->verb);
- if (!verb)
- afb_xreq_fail_f(xreq, "unknown-verb", "verb %s unknown within api %s", xreq->verb, desc->binding->api);
- else {
- xreq->timeout = afb_api_so_timeout;
- xreq->sessionflags = (int)verb->session;
- xreq->group = desc;
- xreq->callback = verb->callback;
- afb_xreq_call(xreq);
- }
-}
-
-static int service_start_cb(void *closure, int share_session, int onneed)
-{
- int (*start)(const struct afb_binding_interface *interface, struct afb_service service);
- void (*onevent)(const char *event, struct json_object *object);
-
- struct api_so_v2 *desc = closure;
-
- /* check state */
- if (desc->service != NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* already started: it is an error */
- ERROR("Service %s already started", desc->binding->api);
- return -1;
- }
-
- /* get the initialisation */
- start = desc->binding->start;
- if (start == NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* no initialisation method */
- ERROR("Binding %s is not a service", desc->binding->api);
- return -1;
- }
-
- /* get the event handler if any */
- onevent = desc->binding->onevent;
- desc->service = afb_svc_create_v2(share_session, onevent, start, &desc->interface);
- if (desc->service == NULL) {
- /* starting error */
- ERROR("Starting service %s failed", desc->binding->api);
- return -1;
- }