X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ditf.c;h=012ef029579c6acbc178159dd2584c90a84045cc;hb=5d248158cc380d0a164fa56b46a7bdede4115407;hp=414824f5fc64228a6c60f51cccbdf3e2ce361840;hpb=e62227977bbc161d2d0ae49951f9a4fbf02a354e;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ditf.c b/src/afb-ditf.c index 414824f5..012ef029 100644 --- a/src/afb-ditf.c +++ b/src/afb-ditf.c @@ -21,43 +21,37 @@ #include #include +#include + #include #include "afb-ditf.h" #include "afb-evt.h" #include "afb-common.h" +#include "afb-hook.h" #include "verbose.h" - -static struct afb_event event_make_cb(void *closure, const char *name); -static int event_broadcast_cb(void *closure, const char *name, struct json_object *object); -static void vverbose_cb(void *closure, int level, const char *file, int line, const char *fmt, va_list args); -static int rootdir_open_locale_cb(void *closure, const char *filename, int flags, const char *locale); - -static const struct afb_daemon_itf daemon_itf = { - .vverbose = vverbose_cb, - .event_make = event_make_cb, - .event_broadcast = event_broadcast_cb, - .get_event_loop = afb_common_get_event_loop, - .get_user_bus = afb_common_get_user_bus, - .get_system_bus = afb_common_get_system_bus, - .rootdir_get_fd = afb_common_rootdir_get_fd, - .rootdir_open_locale = rootdir_open_locale_cb -}; - -static void vverbose_cb(void *closure, int level, const char *file, int line, const char *fmt, va_list args) +/********************************************** +* normal flow +**********************************************/ +static void vverbose_cb(void *closure, int level, const char *file, int line, const char *function, const char *fmt, va_list args) { char *p; struct afb_ditf *ditf = closure; if (vasprintf(&p, fmt, args) < 0) - vverbose(level, file, line, fmt, args); + vverbose(level, file, line, function, fmt, args); else { - verbose(level, file, line, "%s {binding %s}", p, ditf->prefix); + verbose(level, file, line, function, "%s {binding %s}", p, ditf->prefix); free(p); } } +static void old_vverbose_cb(void *closure, int level, const char *file, int line, const char *fmt, va_list args) +{ + vverbose_cb(closure, level, file, line, "?", fmt, args); +} + static struct afb_event event_make_cb(void *closure, const char *name) { size_t plen, nlen; @@ -99,11 +93,104 @@ static int rootdir_open_locale_cb(void *closure, const char *filename, int flags return afb_common_rootdir_open_locale(filename, flags, locale); } +/********************************************** +* 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; + vverbose_cb(closure, level, file, line, function, fmt, args); + afb_hook_ditf_vverbose(ditf, level, file, line, function, fmt, args); + vverbose_cb(closure, level, file, line, function, fmt, args); +} + +static void hooked_old_vverbose_cb(void *closure, int level, const char *file, int line, const char *fmt, va_list args) +{ + struct afb_ditf *ditf = closure; + old_vverbose_cb(closure, level, file, line, fmt, args); + afb_hook_ditf_vverbose(ditf, level, file, line, "", fmt, args); +} + +static struct afb_event hooked_event_make_cb(void *closure, const char *name) +{ + struct afb_ditf *ditf = closure; + struct afb_event r = event_make_cb(closure, name); + return afb_hook_ditf_event_make(ditf, name, r); +} + +static int hooked_event_broadcast_cb(void *closure, const char *name, struct json_object *object) +{ + int r; + struct afb_ditf *ditf = closure; + json_object_get(object); + afb_hook_ditf_event_broadcast_before(ditf, name, json_object_get(object)); + r = event_broadcast_cb(closure, name, object); + afb_hook_ditf_event_broadcast_after(ditf, name, object, r); + json_object_put(object); + return r; +} + +static struct sd_event *hooked_get_event_loop(void *closure) +{ + struct afb_ditf *ditf = closure; + struct sd_event *r = afb_common_get_event_loop(); + return afb_hook_ditf_get_event_loop(ditf, r); +} + +static struct sd_bus *hooked_get_user_bus(void *closure) +{ + struct afb_ditf *ditf = closure; + struct sd_bus *r = afb_common_get_user_bus(); + return afb_hook_ditf_get_user_bus(ditf, r); +} + +static struct sd_bus *hooked_get_system_bus(void *closure) +{ + struct afb_ditf *ditf = closure; + struct sd_bus *r = afb_common_get_system_bus(); + return afb_hook_ditf_get_system_bus(ditf, r); +} + +static int hooked_rootdir_get_fd(void *closure) +{ + struct afb_ditf *ditf = closure; + int r = afb_common_rootdir_get_fd(); + return afb_hook_ditf_rootdir_get_fd(ditf, r); +} + +static int hooked_rootdir_open_locale_cb(void *closure, const char *filename, int flags, const char *locale) +{ + struct afb_ditf *ditf = closure; + int r = rootdir_open_locale_cb(closure, filename, flags, locale); + return afb_hook_ditf_rootdir_open_locale(ditf, filename, flags, locale, r); +} + +static const struct afb_daemon_itf daemon_itf = { + .vverbose = old_vverbose_cb, + .event_make = event_make_cb, + .event_broadcast = event_broadcast_cb, + .get_event_loop = afb_common_get_event_loop, + .get_user_bus = afb_common_get_user_bus, + .get_system_bus = afb_common_get_system_bus, + .rootdir_get_fd = afb_common_rootdir_get_fd, + .rootdir_open_locale = rootdir_open_locale_cb +}; + +static const struct afb_daemon_itf hooked_daemon_itf = { + .vverbose = hooked_old_vverbose_cb, + .event_make = hooked_event_make_cb, + .event_broadcast = hooked_event_broadcast_cb, + .get_event_loop = hooked_get_event_loop, + .get_user_bus = hooked_get_user_bus, + .get_system_bus = hooked_get_system_bus, + .rootdir_get_fd = hooked_rootdir_get_fd, + .rootdir_open_locale = hooked_rootdir_open_locale_cb +}; + void afb_ditf_init(struct afb_ditf *ditf, const char *prefix) { ditf->interface.verbosity = verbosity; ditf->interface.mode = AFB_MODE_LOCAL; - ditf->interface.daemon.itf = &daemon_itf; ditf->interface.daemon.closure = ditf; afb_ditf_rename(ditf, prefix); } @@ -111,5 +198,14 @@ void afb_ditf_init(struct afb_ditf *ditf, const char *prefix) void afb_ditf_rename(struct afb_ditf *ditf, const char *prefix) { ditf->prefix = prefix; + 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; }