00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef APR_HOOKS_H
00018 #define APR_HOOKS_H
00019
00020 #include "apu.h"
00021
00022 #include "apr_tables.h"
00023
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032
00038 #define APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
00039 link##_DECLARE(apr_array_header_t *) ns##_hook_get_##name(void)
00040
00042 #define APR_DECLARE_EXTERNAL_HOOK(ns,link,ret,name,args) \
00043 typedef ret ns##_HOOK_##name##_t args; \
00044 link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf, \
00045 const char * const *aszPre, \
00046 const char * const *aszSucc, int nOrder); \
00047 link##_DECLARE(ret) ns##_run_##name args; \
00048 APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name); \
00049 typedef struct ns##_LINK_##name##_t \
00050 { \
00051 ns##_HOOK_##name##_t *pFunc; \
00052 const char *szName; \
00053 const char * const *aszPredecessors; \
00054 const char * const *aszSuccessors; \
00055 int nOrder; \
00056 } ns##_LINK_##name##_t;
00057
00059 #define APR_HOOK_STRUCT(members) \
00060 static struct { members } _hooks;
00061
00063 #define APR_HOOK_LINK(name) \
00064 apr_array_header_t *link_##name;
00065
00067 #define APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
00068 link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf,const char * const *aszPre, \
00069 const char * const *aszSucc,int nOrder) \
00070 { \
00071 ns##_LINK_##name##_t *pHook; \
00072 if(!_hooks.link_##name) \
00073 { \
00074 _hooks.link_##name=apr_array_make(apr_hook_global_pool,1,sizeof(ns##_LINK_##name##_t)); \
00075 apr_hook_sort_register(#name,&_hooks.link_##name); \
00076 } \
00077 pHook=apr_array_push(_hooks.link_##name); \
00078 pHook->pFunc=pf; \
00079 pHook->aszPredecessors=aszPre; \
00080 pHook->aszSuccessors=aszSucc; \
00081 pHook->nOrder=nOrder; \
00082 pHook->szName=apr_hook_debug_current; \
00083 if(apr_hook_debug_enabled) \
00084 apr_hook_debug_show(#name,aszPre,aszSucc); \
00085 } \
00086 APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
00087 { \
00088 return _hooks.link_##name; \
00089 }
00090
00103 #define APR_IMPLEMENT_EXTERNAL_HOOK_VOID(ns,link,name,args_decl,args_use) \
00104 APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
00105 link##_DECLARE(void) ns##_run_##name args_decl \
00106 { \
00107 ns##_LINK_##name##_t *pHook; \
00108 int n; \
00109 \
00110 if(!_hooks.link_##name) \
00111 return; \
00112 \
00113 pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
00114 for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
00115 pHook[n].pFunc args_use; \
00116 }
00117
00118
00119
00120
00136 #define APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \
00137 APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
00138 link##_DECLARE(ret) ns##_run_##name args_decl \
00139 { \
00140 ns##_LINK_##name##_t *pHook; \
00141 int n; \
00142 ret rv; \
00143 \
00144 if(!_hooks.link_##name) \
00145 return ok; \
00146 \
00147 pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
00148 for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
00149 { \
00150 rv=pHook[n].pFunc args_use; \
00151 \
00152 if(rv != ok && rv != decline) \
00153 return rv; \
00154 } \
00155 return ok; \
00156 }
00157
00158
00173 #define APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(ns,link,ret,name,args_decl,args_use,decline) \
00174 APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ns,link,name) \
00175 link##_DECLARE(ret) ns##_run_##name args_decl \
00176 { \
00177 ns##_LINK_##name##_t *pHook; \
00178 int n; \
00179 ret rv; \
00180 \
00181 if(!_hooks.link_##name) \
00182 return decline; \
00183 \
00184 pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
00185 for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
00186 { \
00187 rv=pHook[n].pFunc args_use; \
00188 \
00189 if(rv != decline) \
00190 return rv; \
00191 } \
00192 return decline; \
00193 }
00194
00195
00197 #define APR_HOOK_REALLY_FIRST (-10)
00198
00199 #define APR_HOOK_FIRST 0
00200
00201 #define APR_HOOK_MIDDLE 10
00202
00203 #define APR_HOOK_LAST 20
00204
00205 #define APR_HOOK_REALLY_LAST 30
00206
00210 APU_DECLARE_DATA extern apr_pool_t *apr_hook_global_pool;
00211
00216 APU_DECLARE_DATA extern int apr_hook_debug_enabled;
00217
00221 APU_DECLARE_DATA extern const char *apr_hook_debug_current;
00222
00228 APU_DECLARE(void) apr_hook_sort_register(const char *szHookName,
00229 apr_array_header_t **aHooks);
00233 APU_DECLARE(void) apr_hook_sort_all(void);
00234
00242 APU_DECLARE(void) apr_hook_debug_show(const char *szName,
00243 const char * const *aszPre,
00244 const char * const *aszSucc);
00245
00249 APU_DECLARE(void) apr_hook_deregister_all(void);
00250
00252 #ifdef __cplusplus
00253 }
00254 #endif
00255
00256 #endif