diff options
author | Stefan Fritsch <sf@sfritsch.de> | 2012-01-29 13:30:57 +0100 |
---|---|---|
committer | Stefan Fritsch <sf@sfritsch.de> | 2012-01-29 13:30:57 +0100 |
commit | d1d018768afd79cb2ecd1805f0d8f3ed23f4076b (patch) | |
tree | 04d53b0a9786234f3bbd3badffdb22dbe2b74d03 /srclib/apr-util/include/apr_hooks.h | |
parent | 0890390c00801651d08d3794e13b31a5dabbf5ef (diff) | |
download | apache2-upstream/2.2.22.tar.gz |
Upstream tarball 2.2.22upstream/2.2.22
Diffstat (limited to 'srclib/apr-util/include/apr_hooks.h')
-rw-r--r-- | srclib/apr-util/include/apr_hooks.h | 156 |
1 files changed, 129 insertions, 27 deletions
diff --git a/srclib/apr-util/include/apr_hooks.h b/srclib/apr-util/include/apr_hooks.h index 1a528332..b675711e 100644 --- a/srclib/apr-util/include/apr_hooks.h +++ b/srclib/apr-util/include/apr_hooks.h @@ -34,6 +34,82 @@ extern "C" { * @ingroup APR_Util * @{ */ + +/** + * @defgroup apr_hook_probes Hook probe capability + * APR hooks provide a trace probe capability for capturing + * the flow of control and return values with hooks. + * + * In order to use this facility, the application must define + * the symbol APR_HOOK_PROBES_ENABLED and the four APR_HOOK_PROBE_ + * macros described below before including apr_hooks.h in files + * that use the APR_IMPLEMENT_EXTERNAL_HOOK_* macros. + * + * This probe facility is not provided for APR optional hooks. + * @{ + */ + +#ifdef APR_HOOK_PROBES_ENABLED +#define APR_HOOK_INT_DCL_UD void *ud = NULL +#else +/** internal implementation detail to avoid the ud declaration when + * hook probes are not used + */ +#define APR_HOOK_INT_DCL_UD +/** + * User-defined hook probe macro that is invoked when the hook + * is run, before calling any hook functions. + * @param ud A void * user data field that should be filled in by + * this macro, and will be provided to the other hook probe macros. + * @param ns The namespace prefix of the hook functions + * @param name The name of the hook + * @param args The argument list to the hook functions, with enclosing + * parens. + */ +#define APR_HOOK_PROBE_ENTRY(ud,ns,name,args) +/** + * User-defined hook probe macro that is invoked after the hook + * has run. + * @param ud A void * user data field that was filled in by the user- + * provided APR_HOOK_PROBE_ENTRY(). + * @param ns The namespace prefix of the hook functions + * @param name The name of the hook + * @param rv The return value of the hook, or 0 if the hook is void. + * @param args The argument list to the hook functions, with enclosing + * parens. + */ +#define APR_HOOK_PROBE_RETURN(ud,ns,name,rv,args) +/** + * User-defined hook probe macro that is invoked before calling a + * hook function. + * @param ud A void * user data field that was filled in by the user- + * provided APR_HOOK_PROBE_ENTRY(). + * @param ns The namespace prefix of the hook functions + * @param name The name of the hook + * @param src The value of apr_hook_debug_current at the time the function + * was hooked (usually the source file implementing the hook function). + * @param args The argument list to the hook functions, with enclosing + * parens. + */ +#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src,args) +/** + * User-defined hook probe macro that is invoked after calling a + * hook function. + * @param ud A void * user data field that was filled in by the user- + * provided APR_HOOK_PROBE_ENTRY(). + * @param ns The namespace prefix of the hook functions + * @param name The name of the hook + * @param src The value of apr_hook_debug_current at the time the function + * was hooked (usually the source file implementing the hook function). + * @param rv The return value of the hook function, or 0 if the hook is void. + * @param args The argument list to the hook functions, with enclosing + * parens. + */ +#define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv,args) +#endif + +/** @} */ + /** macro to return the prototype of the hook function */ #define APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \ link##_DECLARE(apr_array_header_t *) ns##_hook_get_##name(void) @@ -106,13 +182,23 @@ link##_DECLARE(void) ns##_run_##name args_decl \ { \ ns##_LINK_##name##_t *pHook; \ int n; \ + APR_HOOK_INT_DCL_UD; \ \ - if(!_hooks.link_##name) \ - return; \ + APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \ +\ + if(_hooks.link_##name) \ + { \ + pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \ + for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \ + { \ + APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, args_use); \ + pHook[n].pFunc args_use; \ + APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, 0, args_use); \ + } \ + } \ +\ + APR_HOOK_PROBE_RETURN(ud, ns, name, 0, args_use); \ \ - pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \ - for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \ - pHook[n].pFunc args_use; \ } /* FIXME: note that this returns ok when nothing is run. I suspect it should @@ -139,20 +225,28 @@ link##_DECLARE(ret) ns##_run_##name args_decl \ { \ ns##_LINK_##name##_t *pHook; \ int n; \ - ret rv; \ + ret rv = ok; \ + APR_HOOK_INT_DCL_UD; \ \ - if(!_hooks.link_##name) \ - return ok; \ + APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \ \ - 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(_hooks.link_##name) \ + { \ + pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \ + for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \ + { \ + APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, args_use); \ + rv=pHook[n].pFunc args_use; \ + APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, rv, args_use); \ + if(rv != ok && rv != decline) \ + break; \ + rv = ok; \ + } \ + } \ \ - if(rv != ok && rv != decline) \ - return rv; \ - } \ - return ok; \ + APR_HOOK_PROBE_RETURN(ud, ns, name, rv, args_use); \ +\ + return rv; \ } @@ -176,20 +270,28 @@ link##_DECLARE(ret) ns##_run_##name args_decl \ { \ ns##_LINK_##name##_t *pHook; \ int n; \ - ret rv; \ + ret rv = decline; \ + APR_HOOK_INT_DCL_UD; \ \ - if(!_hooks.link_##name) \ - return decline; \ + APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \ \ - 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(_hooks.link_##name) \ + { \ + pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \ + for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \ + { \ + APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, args_use); \ + rv=pHook[n].pFunc args_use; \ + APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, rv, args_use); \ \ - if(rv != decline) \ - return rv; \ - } \ - return decline; \ + if(rv != decline) \ + break; \ + } \ + } \ +\ + APR_HOOK_PROBE_RETURN(ud, ns, name, rv, args_use); \ +\ + return rv; \ } /* Hook orderings */ |