-#define TRACE_REQX(what,tr) do{\
- struct hook_req_observer *observer = tr->observers;\
- while (observer != NULL) {\
- struct afb_hook *hook = observer->hook;\
- observer = observer->next;\
- if (hook->reqitf && hook->reqitf->hook_req_##what)\
- hook->reqitf->hook_req_##what(hook->closure, tr);\
- }\
- }while(0)
-
-#define TRACE_REQ_(what,tr) do{\
- struct hook_req_observer *observer = tr->observers;\
- while (observer != NULL) {\
- struct afb_hook *hook = observer->hook;\
- observer = observer->next;\
- if ((hook->flags & afb_hook_flag_req_##what) && hook->reqitf && hook->reqitf->hook_req_##what)\
- hook->reqitf->hook_req_##what(hook->closure, tr);\
- }\
- }while(0)
-
-#define TRACE_REQ(what,tr,...) do{\
- struct hook_req_observer *observer = tr->observers;\
- while (observer != NULL) {\
- struct afb_hook *hook = observer->hook;\
- observer = observer->next;\
- if ((hook->flags & afb_hook_flag_req_##what) && hook->reqitf && hook->reqitf->hook_req_##what)\
- hook->reqitf->hook_req_##what(hook->closure, tr, __VA_ARGS__);\
- }\
- }while(0)
+#define _HOOK_XREQ_(what,...) \
+ struct afb_hook_xreq *hook; \
+ pthread_rwlock_rdlock(&rwlock); \
+ hook = list_of_xreq_hooks; \
+ while (hook) { \
+ if (hook->itf->hook_xreq_##what \
+ && (hook->flags & afb_hook_flag_req_##what) != 0 \
+ && (!hook->session || hook->session == xreq->context.session) \
+ && (!hook->api || !strcasecmp(hook->api, xreq->api)) \
+ && (!hook->verb || !strcasecmp(hook->verb, xreq->verb))) { \
+ hook->itf->hook_xreq_##what(hook->closure, __VA_ARGS__); \
+ } \
+ hook = hook->next; \
+ } \
+ pthread_rwlock_unlock(&rwlock);
+
+
+void afb_hook_xreq_begin(const struct afb_xreq *xreq)
+{
+ _HOOK_XREQ_(begin, xreq);
+}
+
+void afb_hook_xreq_end(const struct afb_xreq *xreq)
+{
+ _HOOK_XREQ_(end, xreq);
+}
+
+struct json_object *afb_hook_xreq_json(const struct afb_xreq *xreq, struct json_object *obj)
+{
+ _HOOK_XREQ_(json, xreq, obj);
+ return obj;
+}
+
+struct afb_arg afb_hook_xreq_get(const struct afb_xreq *xreq, const char *name, struct afb_arg arg)
+{
+ _HOOK_XREQ_(get, xreq, name, arg);
+ return arg;
+}
+
+void afb_hook_xreq_success(const struct afb_xreq *xreq, struct json_object *obj, const char *info)
+{
+ _HOOK_XREQ_(success, xreq, obj, info);
+}
+
+void afb_hook_xreq_fail(const struct afb_xreq *xreq, const char *status, const char *info)
+{
+ _HOOK_XREQ_(fail, xreq, status, info);
+}
+
+void *afb_hook_xreq_context_get(const struct afb_xreq *xreq, void *value)
+{
+ _HOOK_XREQ_(context_get, xreq, value);
+ return value;
+}
+
+void afb_hook_xreq_context_set(const struct afb_xreq *xreq, void *value, void (*free_value)(void*))
+{
+ _HOOK_XREQ_(context_set, xreq, value, free_value);
+}
+
+void afb_hook_xreq_addref(const struct afb_xreq *xreq)
+{
+ _HOOK_XREQ_(addref, xreq);
+}
+
+void afb_hook_xreq_unref(const struct afb_xreq *xreq)
+{
+ _HOOK_XREQ_(unref, xreq);
+}
+
+void afb_hook_xreq_session_close(const struct afb_xreq *xreq)
+{
+ _HOOK_XREQ_(session_close, xreq);
+}
+
+int afb_hook_xreq_session_set_LOA(const struct afb_xreq *xreq, unsigned level, int result)
+{
+ _HOOK_XREQ_(session_set_LOA, xreq, level, result);
+ return result;
+}
+
+int afb_hook_xreq_subscribe(const struct afb_xreq *xreq, struct afb_event event, int result)
+{
+ _HOOK_XREQ_(subscribe, xreq, event, result);
+ return result;
+}
+
+int afb_hook_xreq_unsubscribe(const struct afb_xreq *xreq, struct afb_event event, int result)
+{
+ _HOOK_XREQ_(unsubscribe, xreq, event, result);
+ return result;
+}
+
+void afb_hook_xreq_subcall(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args)
+{
+ _HOOK_XREQ_(subcall, xreq, api, verb, args);
+}
+
+void afb_hook_xreq_subcall_result(const struct afb_xreq *xreq, int status, struct json_object *result)
+{
+ _HOOK_XREQ_(subcall_result, xreq, status, result);
+}
+
+void afb_hook_xreq_subcallsync(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args)
+{
+ _HOOK_XREQ_(subcallsync, xreq, api, verb, args);
+}
+
+int afb_hook_xreq_subcallsync_result(const struct afb_xreq *xreq, int status, struct json_object *result)
+{
+ _HOOK_XREQ_(subcallsync_result, xreq, status, result);
+ return status;
+}
+
+void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args)
+{
+ _HOOK_XREQ_(vverbose, xreq, level, file ?: "?", line, func ?: "?", fmt, args);
+}