X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ditf.c;h=66bdb9df146ec0fab4876a29049535437c506011;hb=8a30491d5e60239a338e485311a29c43398726e9;hp=fde9e043ef3303cf1f63cc5260209933570a8da7;hpb=acca25c347b35a720c005436160ad623767b5eb1;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ditf.c b/src/afb-ditf.c index fde9e043..66bdb9df 100644 --- a/src/afb-ditf.c +++ b/src/afb-ditf.c @@ -16,22 +16,28 @@ */ #define _GNU_SOURCE -#define NO_BINDING_VERBOSE_MACRO +#include #include #include #include -#include +#include +#include #include "afb-ditf.h" #include "afb-evt.h" #include "afb-common.h" +#include "afb-xreq.h" +#include "afb-api.h" +#include "afb-apiset.h" #include "afb-hook.h" #include "jobs.h" #include "verbose.h" +extern struct afb_apiset *main_apiset; + /********************************************** * normal flow **********************************************/ @@ -43,7 +49,7 @@ static void vverbose_cb(void *closure, int level, const char *file, int line, co if (vasprintf(&p, fmt, args) < 0) vverbose(level, file, line, function, fmt, args); else { - verbose(level, file, line, function, "%s {binding %s}", p, ditf->prefix); + verbose(level, file, line, function, "[API %s] %s", ditf->api, p); free(p); } } @@ -60,10 +66,10 @@ static struct afb_event event_make_cb(void *closure, const char *name) struct afb_ditf *ditf = closure; /* makes the event name */ - plen = strlen(ditf->prefix); + plen = strlen(ditf->api); nlen = strlen(name); event = alloca(nlen + plen + 2); - memcpy(event, ditf->prefix, plen); + memcpy(event, ditf->api, plen); event[plen] = '/'; memcpy(event + plen + 1, name, nlen + 1); @@ -78,10 +84,10 @@ static int event_broadcast_cb(void *closure, const char *name, struct json_objec struct afb_ditf *ditf = closure; /* makes the event name */ - plen = strlen(ditf->prefix); + plen = strlen(ditf->api); nlen = strlen(name); event = alloca(nlen + plen + 2); - memcpy(event, ditf->prefix, plen); + memcpy(event, ditf->api, plen); event[plen] = '/'; memcpy(event + plen + 1, name, nlen + 1); @@ -99,14 +105,28 @@ static int queue_job_cb(void *closure, void (*callback)(int signum, void *arg), return jobs_queue(group, timeout, callback, argument); } +static struct afb_req unstore_req_cb(void *closure, struct afb_stored_req *sreq) +{ + return afb_xreq_unstore(sreq); +} + +static int require_api_cb(void *closure, const char *name, int initialized) +{ + struct afb_api a; + return (initialized ? afb_apiset_get_started : afb_apiset_get)(main_apiset, name, &a); +} + /********************************************** * hooked flow **********************************************/ static void hooked_vverbose_cb(void *closure, int level, const char *file, int line, const char *function, const char *fmt, va_list args) { struct afb_ditf *ditf = closure; + va_list ap; + va_copy(ap, args); vverbose_cb(closure, level, file, line, function, fmt, args); - afb_hook_ditf_vverbose(ditf, level, file, line, function, fmt, args); + afb_hook_ditf_vverbose(ditf, level, file, line, function, fmt, ap); + va_end(ap); } static void hooked_old_vverbose_cb(void *closure, int level, const char *file, int line, const char *fmt, va_list args) @@ -175,8 +195,28 @@ static int hooked_queue_job_cb(void *closure, void (*callback)(int signum, void return afb_hook_ditf_queue_job(ditf, callback, argument, group, timeout, r); } +static struct afb_req hooked_unstore_req_cb(void *closure, struct afb_stored_req *sreq) +{ + struct afb_ditf *ditf = closure; + afb_hook_ditf_unstore_req(ditf, sreq); + return unstore_req_cb(closure, sreq); +} + +static int hooked_require_api_cb(void *closure, const char *name, int initialized) +{ + int result; + struct afb_ditf *ditf = closure; + afb_hook_ditf_require_api(ditf, name, initialized); + result = require_api_cb(closure, name, initialized); + return afb_hook_ditf_require_api_result(ditf, name, initialized, result); +} + +/********************************************** +* vectors +**********************************************/ static const struct afb_daemon_itf daemon_itf = { - .vverbose = old_vverbose_cb, + .vverbose_v1 = old_vverbose_cb, + .vverbose_v2 = vverbose_cb, .event_make = event_make_cb, .event_broadcast = event_broadcast_cb, .get_event_loop = afb_common_get_event_loop, @@ -184,11 +224,14 @@ static const struct afb_daemon_itf daemon_itf = { .get_system_bus = afb_common_get_system_bus, .rootdir_get_fd = afb_common_rootdir_get_fd, .rootdir_open_locale = rootdir_open_locale_cb, - .queue_job = queue_job_cb + .queue_job = queue_job_cb, + .unstore_req = unstore_req_cb, + .require_api = require_api_cb }; static const struct afb_daemon_itf hooked_daemon_itf = { - .vverbose = hooked_old_vverbose_cb, + .vverbose_v1 = hooked_old_vverbose_cb, + .vverbose_v2 = hooked_vverbose_cb, .event_make = hooked_event_make_cb, .event_broadcast = hooked_event_broadcast_cb, .get_event_loop = hooked_get_event_loop, @@ -196,28 +239,46 @@ static const struct afb_daemon_itf hooked_daemon_itf = { .get_system_bus = hooked_get_system_bus, .rootdir_get_fd = hooked_rootdir_get_fd, .rootdir_open_locale = hooked_rootdir_open_locale_cb, - .queue_job = hooked_queue_job_cb + .queue_job = hooked_queue_job_cb, + .unstore_req = hooked_unstore_req_cb, + .require_api = hooked_require_api_cb }; -void afb_ditf_init(struct afb_ditf *ditf, const char *prefix) +void afb_ditf_init_v2(struct afb_ditf *ditf, const char *api, struct afb_binding_data_v2 *data) { - ditf->interface.verbosity = verbosity; - ditf->interface.mode = AFB_MODE_LOCAL; - ditf->interface.daemon.closure = ditf; - afb_ditf_rename(ditf, prefix); + ditf->version = 2; + ditf->v2 = data; + data->daemon.closure = ditf; + afb_ditf_rename(ditf, api); } -void afb_ditf_rename(struct afb_ditf *ditf, const char *prefix) +void afb_ditf_init_v1(struct afb_ditf *ditf, const char *api, struct afb_binding_interface_v1 *itf) { - ditf->prefix = prefix; + ditf->version = 1; + ditf->v1 = itf; + itf->verbosity = verbosity; + itf->mode = AFB_MODE_LOCAL; + itf->daemon.closure = ditf; + afb_ditf_rename(ditf, api); +} + +void afb_ditf_rename(struct afb_ditf *ditf, const char *api) +{ + ditf->api = api; afb_ditf_update_hook(ditf); } void afb_ditf_update_hook(struct afb_ditf *ditf) { - if (afb_hook_flags_ditf(ditf->prefix)) - ditf->interface.daemon.itf = &hooked_daemon_itf; - else - ditf->interface.daemon.itf = &daemon_itf; + int hooked = !!afb_hook_flags_ditf(ditf->api); + switch (ditf->version) { + case 1: + ditf->v1->daemon.itf = hooked ? &hooked_daemon_itf : &daemon_itf; + break; + default: + case 2: + ditf->v2->daemon.itf = hooked ? &hooked_daemon_itf : &daemon_itf; + break; + } }