GME  13
apr_optional_hooks.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00022 #ifndef APR_OPTIONAL_HOOK_H
00023 #define APR_OPTIONAL_HOOK_H
00024 
00025 #include "apr_tables.h"
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00048 APU_DECLARE(void) apr_optional_hook_add(const char *szName,void (*pfn)(void),
00049                                         const char * const *aszPre,
00050                                         const char * const *aszSucc,
00051                                         int nOrder);
00052 
00064 #define APR_OPTIONAL_HOOK(ns,name,pfn,aszPre,aszSucc,nOrder) do { \
00065   ns##_HOOK_##name##_t *apu__hook = pfn; \
00066   apr_optional_hook_add(#name,(void (*)(void))apu__hook,aszPre, aszSucc, nOrder); \
00067 } while (0)
00068 
00074 APU_DECLARE(apr_array_header_t *) apr_optional_hook_get(const char *szName);
00075 
00090 #define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns,link,ret,name,args_decl,args_use,ok,decline) \
00091 link##_DECLARE(ret) ns##_run_##name args_decl \
00092     { \
00093     ns##_LINK_##name##_t *pHook; \
00094     int n; \
00095     ret rv; \
00096     apr_array_header_t *pHookArray=apr_optional_hook_get(#name); \
00097 \
00098     if(!pHookArray) \
00099         return ok; \
00100 \
00101     pHook=(ns##_LINK_##name##_t *)pHookArray->elts; \
00102     for(n=0 ; n < pHookArray->nelts ; ++n) \
00103         { \
00104         rv=(pHook[n].pFunc)args_use; \
00105 \
00106         if(rv != ok && rv != decline) \
00107             return rv; \
00108         } \
00109     return ok; \
00110     }
00111 
00113 #ifdef __cplusplus
00114 }
00115 #endif
00116 
00117 #endif /* APR_OPTIONAL_HOOK_H */