X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-so-v1.c;h=a09b0f517a0fc493476eaa014f7ceeb78bcb9398;hb=19175241afd5bec09fb6688ff835fc30fc24a8dd;hp=4fafb1383a2aad4a6df2567088aaebf7d2f987a7;hpb=63c32ff0f0ee13b505d252821fe1fd55816699e1;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-so-v1.c b/src/afb-api-so-v1.c index 4fafb138..a09b0f51 100644 --- a/src/afb-api-so-v1.c +++ b/src/afb-api-so-v1.c @@ -31,6 +31,7 @@ #include "afb-context.h" #include "afb-api-so.h" #include "afb-thread.h" +#include "afb-xreq.h" #include "verbose.h" /* @@ -173,21 +174,46 @@ static int call_check(struct afb_req req, struct afb_context *context, const str return 1; } -static void call_cb(void *closure, struct afb_req req, struct afb_context *context, const char *strverb) +static const struct afb_verb_desc_v1 *search(struct api_so_v1 *desc, const char *name) { const struct afb_verb_desc_v1 *verb; - struct api_so_v1 *desc = closure; verb = desc->binding->v1.verbs; - while (verb->name && strcasecmp(verb->name, strverb)) + while (verb->name && strcasecmp(verb->name, name)) verb++; - if (!verb->name) + return verb->name ? verb : NULL; +} + +static void call_cb(void *closure, struct afb_req req, struct afb_context *context, const char *strverb) +{ + const struct afb_verb_desc_v1 *verb; + struct api_so_v1 *desc = closure; + + verb = search(desc, strverb); + if (!verb) afb_req_fail_f(req, "unknown-verb", "verb %s unknown within api %s", strverb, desc->binding->v1.prefix); 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) +{ + const struct afb_verb_desc_v1 *verb; + struct api_so_v1 *desc = closure; + + verb = search(desc, xreq->verb); + if (!verb) + afb_xreq_fail_f(xreq, "unknown-verb", "verb %s unknown within api %s", xreq->verb, desc->binding->v1.prefix); + 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 (*init)(struct afb_service service); @@ -300,6 +326,7 @@ int afb_api_so_v1_add(const char *path, void *handle) if (afb_apis_add(desc->binding->v1.prefix, (struct afb_api){ .closure = desc, .call = call_cb, + .xcall = xcall_cb, .service_start = service_start_cb }) < 0) { ERROR("binding [%s] can't be registered...", path); goto error2;