1251876Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251876Speter * contributor license agreements.  See the NOTICE file distributed with
3251876Speter * this work for additional information regarding copyright ownership.
4251876Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251876Speter * (the "License"); you may not use this file except in compliance with
6251876Speter * the License.  You may obtain a copy of the License at
7251876Speter *
8251876Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251876Speter *
10251876Speter * Unless required by applicable law or agreed to in writing, software
11251876Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251876Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251876Speter * See the License for the specific language governing permissions and
14251876Speter * limitations under the License.
15251876Speter */
16251876Speter
17251876Speter#ifndef APR_OPTIONAL_H
18251876Speter#define APR_OPTIONAL_H
19251876Speter
20251876Speter#include "apu.h"
21251876Speter/**
22251876Speter * @file apr_optional.h
23251876Speter * @brief APR-UTIL registration of functions exported by modules
24251876Speter */
25251876Speter#ifdef __cplusplus
26251876Speterextern "C" {
27251876Speter#endif
28251876Speter
29251876Speter/**
30251876Speter * @defgroup APR_Util_Opt Optional Functions
31251876Speter * @ingroup APR_Util
32251876Speter *
33251876Speter * Typesafe registration and retrieval of functions that may not be present
34251876Speter * (i.e. functions exported by optional modules)
35251876Speter * @{
36251876Speter */
37251876Speter
38251876Speter/**
39251876Speter * The type of an optional function.
40251876Speter * @param name The name of the function
41251876Speter */
42251876Speter#define APR_OPTIONAL_FN_TYPE(name) apr_OFN_##name##_t
43251876Speter
44251876Speter/**
45251876Speter * Declare an optional function.
46251876Speter * @param ret The return type of the function
47251876Speter * @param name The name of the function
48251876Speter * @param args The function arguments (including brackets)
49251876Speter */
50251876Speter#define APR_DECLARE_OPTIONAL_FN(ret,name,args) \
51251876Spetertypedef ret (APR_OPTIONAL_FN_TYPE(name)) args
52251876Speter
53251876Speter/**
54251876Speter * XXX: This doesn't belong here, then!
55251876Speter * Private function! DO NOT USE!
56251876Speter * @internal
57251876Speter */
58251876Speter
59251876Spetertypedef void (apr_opt_fn_t)(void);
60251876Speter/** @internal */
61251876SpeterAPU_DECLARE_NONSTD(void) apr_dynamic_fn_register(const char *szName,
62251876Speter                                                  apr_opt_fn_t *pfn);
63251876Speter
64251876Speter/**
65251876Speter * Register an optional function. This can be later retrieved, type-safely, by
66251876Speter * name. Like all global functions, the name must be unique. Note that,
67251876Speter * confusingly but correctly, the function itself can be static!
68251876Speter * @param name The name of the function
69251876Speter */
70251876Speter#define APR_REGISTER_OPTIONAL_FN(name) do { \
71251876Speter  APR_OPTIONAL_FN_TYPE(name) *apu__opt = name; \
72251876Speter  apr_dynamic_fn_register(#name,(apr_opt_fn_t *)apu__opt); \
73251876Speter} while (0)
74251876Speter
75251876Speter/** @internal
76251876Speter * Private function! DO NOT USE!
77251876Speter */
78251876SpeterAPU_DECLARE(apr_opt_fn_t *) apr_dynamic_fn_retrieve(const char *szName);
79251876Speter
80251876Speter/**
81251876Speter * Retrieve an optional function. Returns NULL if the function is not present.
82251876Speter * @param name The name of the function
83251876Speter */
84251876Speter#define APR_RETRIEVE_OPTIONAL_FN(name) \
85251876Speter	(APR_OPTIONAL_FN_TYPE(name) *)apr_dynamic_fn_retrieve(#name)
86251876Speter
87251876Speter/** @} */
88251876Speter#ifdef __cplusplus
89251876Speter}
90251876Speter#endif
91251876Speter
92251876Speter#endif /* APR_OPTIONAL_H */
93