If anyone is interested, I've attached the patch to hooks that provides
a trace callback... if I could resolve the issue described under this
message thread, and the fact that args_use is actually () wrapped
so that the patch attempts to invoke the cb with the args
(foo_run_something, NULL, 0, NULL, (arg1, arg2, arg3), NULL)
where the nested parens cause us to choke.
Bill
Index: hooks/apr_hooks.c
===================================================================
RCS file: /home/cvs/apr-util/hooks/apr_hooks.c,v
retrieving revision 1.47
diff -u -r1.47 apr_hooks.c
--- hooks/apr_hooks.c 7 Feb 2003 18:03:35 -0000 1.47
+++ hooks/apr_hooks.c 25 Apr 2003 21:05:32 -0000
@@ -75,6 +75,8 @@
APU_DECLARE_DATA int apr_hook_debug_enabled = 0;
APU_DECLARE_DATA const char *apr_hook_debug_current = NULL;
+APU_DECLARE_DATA apr_hook_trace_cb_t apr_hook_trace_cb = NULL;
+
/** @deprecated @see apr_hook_global_pool */
APU_DECLARE_DATA apr_pool_t *apr_global_hook_pool = NULL;
Index: include/apr_hooks.h
===================================================================
RCS file: /home/cvs/apr-util/include/apr_hooks.h,v
retrieving revision 1.47
diff -u -r1.47 apr_hooks.h
--- include/apr_hooks.h 1 Jan 2003 00:02:20 -0000 1.47
+++ include/apr_hooks.h 25 Apr 2003 21:05:32 -0000
@@ -76,6 +76,12 @@
#define APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
link##_DECLARE(apr_array_header_t *) ns##_hook_get_##name(void)
+#ifdef APR_HOOK_TRACE
+#define APR_HOOK_TRACE_DEFINED 1
+#else
+#define APR_HOOK_TRACE_DEFINED 0
+#endif
+
/** macro to declare the hook correctly */
#define APR_DECLARE_EXTERNAL_HOOK(ns,link,ret,name,args) \
typedef ret ns##_HOOK_##name##_t args; \
@@ -126,6 +132,7 @@
return _hooks.link_##name; \
}
+
/**
* Implement a hook that has no return code, and therefore runs all of the
* registered functions
@@ -145,12 +152,20 @@
ns##_LINK_##name##_t *pHook; \
int n; \
\
- if(!_hooks.link_##name) \
+ if(!_hooks.link_##name) { \
+ if (APR_HOOK_TRACE_DEFINED && apr_hook_trace_cb) { \
+ (apr_hook_trace_cb)(#ns "_run_" #name, NULL, 0, NULL, args_use,
NULL); \
+ } \
return; \
+ } \
\
pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
- pHook[n].pFunc args_use; \
+ pHook[n].pFunc args_use; \
+\
+ if (APR_HOOK_TRACE_DEFINED && apr_hook_trace_cb) { \
+ (apr_hook_trace_cb)(#ns "_run_" #name, pHook[n].szName, 0, NULL,
args_use, NULL); \
+ } \
}
/* FIXME: note that this returns ok when nothing is run. I suspect it should
@@ -179,14 +194,25 @@
int n; \
ret rv; \
\
- if(!_hooks.link_##name) \
+ if(!_hooks.link_##name) { \
+ if (APR_HOOK_TRACE_DEFINED && apr_hook_trace_cb) { \
+ (apr_hook_trace_cb)(#ns "_run_" #name, NULL, \
+ -1, ok, args_use, NULL); \
+ } \
return ok; \
+ } \
\
pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
{ \
rv=pHook[n].pFunc args_use; \
\
+ if (APR_HOOK_TRACE_DEFINED && apr_hook_trace_cb) { \
+ (apr_hook_trace_cb)(#ns "_run_" #name, pHook[n].szName, \
+ (rv != decline) + 2 * (rv != ok), rv, \
+ args_use, NULL); \
+ } \
+\
if(rv != ok && rv != decline) \
return rv; \
} \
@@ -216,14 +242,24 @@
int n; \
ret rv; \
\
- if(!_hooks.link_##name) \
+ if(!_hooks.link_##name) { \
+ if (APR_HOOK_TRACE_DEFINED && apr_hook_trace_cb) { \
+ (apr_hook_trace_cb)(#ns "_run_" #name, NULL, \
+ 0, decline, args_use, NULL); \
+ } \
return decline; \
+ } \
\
pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
{ \
rv=pHook[n].pFunc args_use; \
\
+ if (APR_HOOK_TRACE_DEFINED && apr_hook_trace_cb) { \
+ (apr_hook_trace_cb)(#ns "_run_" #name, pHook[n].szName, \
+ rv != decline, rv, args_use, NULL); \
+ } \
+\
if(rv != decline) \
return rv; \
} \
@@ -266,6 +302,28 @@
/** @deprecated @see apr_hook_debug_current */
APU_DECLARE_DATA extern const char *apr_current_hooking_module;
+
+/**
+ * Prototype of the global callback to trace hook invocations
+ * @param hook_name The hook function performed (e.g. foo_run_hook)
+ * @param fn_name The name of the function invoked (e.g. bar_hook_fn)
+ * @param result Interpreted value
+ * 0 if continued
+ * 1 if !declined
+ * 2 if !ok
+ * @param rvalue The value returned (hard to use)
+ * @note the remaining args follow rvalue. For hooks returning void,
+ * a NULL will be provided for the rvalue position, followed by the
+ * remaining args.
+ */
+typedef void (APR_THREAD_FUNC *apr_hook_trace_cb_t)(const char* hook_name,
+ const char* fn_name,
+ int result, ...);
+
+/**
+ * A global callback that traces hook invocations
+ */
+APU_DECLARE_DATA apr_hook_trace_cb_t apr_hook_trace_cb;
/**
* Register a hook function to be sorted