apr_optional.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_OPTIONAL_H
  17. #define APR_OPTIONAL_H
  18. #include "apu.h"
  19. /**
  20. * @file apr_optional.h
  21. * @brief APR-UTIL registration of functions exported by modules
  22. */
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /**
  27. * @defgroup APR_Util_Opt Optional Functions
  28. * @ingroup APR_Util
  29. *
  30. * Typesafe registration and retrieval of functions that may not be present
  31. * (i.e. functions exported by optional modules)
  32. * @{
  33. */
  34. /**
  35. * The type of an optional function.
  36. * @param name The name of the function
  37. */
  38. #define APR_OPTIONAL_FN_TYPE(name) apr_OFN_##name##_t
  39. /**
  40. * Declare an optional function.
  41. * @param ret The return type of the function
  42. * @param name The name of the function
  43. * @param args The function arguments (including brackets)
  44. */
  45. #define APR_DECLARE_OPTIONAL_FN(ret,name,args) \
  46. typedef ret (APR_OPTIONAL_FN_TYPE(name)) args
  47. /**
  48. * XXX: This doesn't belong here, then!
  49. * Private function! DO NOT USE!
  50. * @internal
  51. */
  52. typedef void (apr_opt_fn_t)(void);
  53. /** @internal */
  54. APU_DECLARE_NONSTD(void) apr_dynamic_fn_register(const char *szName,
  55. apr_opt_fn_t *pfn);
  56. /**
  57. * Register an optional function. This can be later retrieved, type-safely, by
  58. * name. Like all global functions, the name must be unique. Note that,
  59. * confusingly but correctly, the function itself can be static!
  60. * @param name The name of the function
  61. */
  62. #define APR_REGISTER_OPTIONAL_FN(name) do { \
  63. APR_OPTIONAL_FN_TYPE(name) *apu__opt = name; \
  64. apr_dynamic_fn_register(#name,(apr_opt_fn_t *)apu__opt); \
  65. } while (0)
  66. /** @internal
  67. * Private function! DO NOT USE!
  68. */
  69. APU_DECLARE(apr_opt_fn_t *) apr_dynamic_fn_retrieve(const char *szName);
  70. /**
  71. * Retrieve an optional function. Returns NULL if the function is not present.
  72. * @param name The name of the function
  73. */
  74. #define APR_RETRIEVE_OPTIONAL_FN(name) \
  75. (APR_OPTIONAL_FN_TYPE(name) *)apr_dynamic_fn_retrieve(#name)
  76. /** @} */
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* APR_OPTIONAL_H */