+static int queue_job_cb(void *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
+{
+ 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_ditf *ditf = closure;
+ if (ditf->state != Daemon_Init) {
+ ERROR("[API %s] Bad call to 'afb_daemon_require(%s, %d)', must be in Init", ditf->api, name, initialized);
+ errno = EINVAL;
+ return -1;
+ }
+ return -!(initialized ? afb_apiset_lookup_started : afb_apiset_lookup)(main_apiset, name, 1);
+}
+
+static int rename_api_cb(void *closure, const char *name)
+{
+ struct afb_ditf *ditf = closure;
+ if (ditf->state != Daemon_Pre_Init) {
+ ERROR("[API %s] Bad call to 'afb_daemon_rename(%s)', must be in PreInit", ditf->api, name);
+ errno = EINVAL;
+ return -1;
+ }
+ if (!afb_api_is_valid_name(name)) {
+ ERROR("[API %s] Can't rename to %s: bad API name", ditf->api, name);
+ errno = EINVAL;
+ return -1;
+ }
+ NOTICE("[API %s] renamed to [API %s]", ditf->api, name);
+ afb_ditf_rename(ditf, name);
+ return 0;
+}
+
+/**********************************************
+* 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, 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)
+{
+ hooked_vverbose_cb(closure, level, file, line, NULL, 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 int hooked_queue_job_cb(void *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
+{
+ struct afb_ditf *ditf = closure;
+ int r = queue_job_cb(closure, callback, argument, group, timeout);
+ 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);
+}
+
+static int hooked_rename_api_cb(void *closure, const char *name)
+{
+ struct afb_ditf *ditf = closure;
+ const char *oldname = ditf->api;
+ int result = rename_api_cb(closure, name);
+ return afb_hook_ditf_rename_api(ditf, oldname, name, result);
+}
+
+/**********************************************
+* vectors
+**********************************************/