You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
12 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/backends/be.N.h
  3. *
  4. * Purpose: Declaration of the Pantheios be.N Stock Back-end API.
  5. *
  6. * Created: 18th October 2006
  7. * Updated: 26th November 2010
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2006-2010, Matthew Wilson and Synesis Software
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are
  15. * met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  23. * names of any contributors may be used to endorse or promote products
  24. * derived from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  32. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  36. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file pantheios/backends/be.N.h
  40. *
  41. * [C,C++] Pantheios be.N Stock Back-end API
  42. */
  43. #ifndef PANTHEIOS_INCL_PANTHEIOS_FRONTENDS_H_BE_N
  44. #define PANTHEIOS_INCL_PANTHEIOS_FRONTENDS_H_BE_N
  45. /* /////////////////////////////////////////////////////////////////////////
  46. * Version information
  47. */
  48. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  49. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BE_N_MAJOR 1
  50. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BE_N_MINOR 6
  51. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BE_N_REVISION 2
  52. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BE_N_EDIT 21
  53. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  58. # include <pantheios/pantheios.h>
  59. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  60. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_BACKEND
  61. # include <pantheios/backend.h>
  62. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_BACKEND */
  63. #include <limits.h>
  64. /* /////////////////////////////////////////////////////////////////////////
  65. * Documentation
  66. */
  67. /** \defgroup group__backend__stock_backends__N Pantheios N Stock Back-end
  68. * \ingroup group__backend__stock_backends
  69. * Back-end library that splits output to N back-ends.
  70. */
  71. /* /////////////////////////////////////////////////////////////////////////
  72. * API
  73. */
  74. /* /////////////////////////////////////////////////////////////////////////
  75. * Constants
  76. */
  77. /** \defgroup group__backend__stock_backends__N__flags Pantheios be.N Stock Back-end Flags
  78. * \ingroup group__backend__stock_backends__N
  79. * Flags for the \ref group__backend__stock_backends__N
  80. */
  81. /** \def PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE
  82. * Cause the \ref group__backend__stock_backends__N to
  83. * ignore initialisation failure of the given back-end.
  84. * \ingroup group__backend__stock_backends__N__flags
  85. */
  86. #define PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE (0x00100000)
  87. /** \def PANTHEIOS_BE_N_F_ID_MUST_MATCH_CUSTOM28
  88. ` * Cause the \ref group__backend__stock_backends__N to
  89. * only output to a given back-end if the custom-28 value
  90. * matches the back-end's Id.
  91. * \ingroup group__backend__stock_backends__N__flags
  92. */
  93. #define PANTHEIOS_BE_N_F_ID_MUST_MATCH_CUSTOM28 (0x00200000)
  94. /** \def PANTHEIOS_BE_N_F_IGNORE_NONMATCHED_CUSTOM28_ID
  95. * Cause the \ref group__backend__stock_backends__N to
  96. * only output to a given back-end if the custom-28 value
  97. * does not match the back-end's Id.
  98. * \ingroup group__backend__stock_backends__N__flags
  99. */
  100. #define PANTHEIOS_BE_N_F_IGNORE_NONMATCHED_CUSTOM28_ID (0x00400000)
  101. /** \def PANTHEIOS_BE_N_F_INIT_ONLY_IF_PREVIOUS_FAILED
  102. * Cause the \ref group__backend__stock_backends__N to
  103. * initialise the given back-end only if all others have failed.
  104. * \ingroup group__backend__stock_backends__N__flags
  105. */
  106. #define PANTHEIOS_BE_N_F_INIT_ONLY_IF_PREVIOUS_FAILED (0x00800000)
  107. /* /////////////////////////////////////////////////////////////////////////
  108. * Typedefs
  109. */
  110. /** Structure that describes a back-end to be used by the \ref group__backend__stock_backends__N.
  111. *
  112. * \ingroup group__backend__stock_backends__N
  113. *
  114. * \see PANTHEIOS_BE_N_STDFORM_ENTRY
  115. */
  116. struct pan_be_N_t
  117. {
  118. /** A combination of the
  119. * \ref group__backend__stock_backends__N__flags "be.N flags" that control
  120. * the behaviour of the given back-end
  121. */
  122. int flags;
  123. /** The back-end Id
  124. *
  125. * Must be >0.
  126. */
  127. int backEndId;
  128. /** Pointer to the back-end's initialisation function */
  129. int (PANTHEIOS_CALLCONV *pfnInit)(
  130. PAN_CHAR_T const*
  131. , int
  132. , void const*
  133. , void*
  134. , void**
  135. );
  136. /** Pointer to the back-end's uninitialisation function */
  137. void (PANTHEIOS_CALLCONV *pfnUninit)( void*);
  138. /** Pointer to the back-end's log-entry function */
  139. int (PANTHEIOS_CALLCONV *pfnLogEntry)(
  140. void*
  141. , void*
  142. , int
  143. , PAN_CHAR_T const*
  144. , size_t
  145. );
  146. /** A per-back-end static severity ceiling
  147. */
  148. int severityCeiling;
  149. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  150. /* INTERNAL USE ONLY */
  151. void* token;
  152. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  153. };
  154. #ifndef __cplusplus
  155. typedef struct pan_be_N_t pan_be_N_t;
  156. #endif /* __cplusplus */
  157. /* PANTHEIOS_BE_N_ENTRY has been removed */
  158. /** \def PANTHEIOS_BE_N_STDFORM_ENTRY
  159. *
  160. * Defines an entry in an array of pan_be_N_t.
  161. *
  162. * \param backEndId The back-end identifier. Must be >0
  163. * \param be_prefix The prefix of all the back-end functions, e.g. <b>pantheios_be_speech</b>
  164. * \param flags A combination of the
  165. * \ref group__backend__stock_backends__N__flags "be.N flags" that control
  166. * the behaviour of the given back-end
  167. *
  168. * This is used in combination with PANTHEIOS_BE_N_TERMINATOR_ENTRY to
  169. * define the set of concrete back-ends are to be attached to the program:
  170. <pre>
  171. pan_be_N_t PAN_BE_N_BACKEND_LIST[] =
  172. {
  173. PANTHEIOS_BE_N_STDFORM_ENTRY(1, pantheios_be_file, 0)
  174. , PANTHEIOS_BE_N_STDFORM_ENTRY(2, pantheios_be_fprintf, 0)
  175. , PANTHEIOS_BE_N_STDFORM_ENTRY(3, pantheios_be_null, 0)
  176. \#if defined(PLATFORMSTL_OS_IS_UNIX)
  177. , PANTHEIOS_BE_N_STDFORM_ENTRY(4, pantheios_be_syslog, 0)
  178. \#elif defined(PLATFORMSTL_OS_IS_WIN32) || \
  179. defined(PLATFORMSTL_OS_IS_WIN64)
  180. , PANTHEIOS_BE_N_STDFORM_ENTRY(4, pantheios_be_WindowsSyslog, 0)
  181. \#endif
  182. , PANTHEIOS_BE_N_STDFORM_ENTRY(5, pantheios_be_file, 0)
  183. , PANTHEIOS_BE_N_TERMINATOR_ENTRY
  184. };
  185. </pre>
  186. *
  187. * \ingroup group__backend__stock_backends__N
  188. *
  189. * \note This is to be used insead of PANTHEIOS_BE_N_ENTRY
  190. */
  191. #define PANTHEIOS_BE_N_STDFORM_ENTRY(backEndId, be_prefix, flags) \
  192. { \
  193. flags \
  194. , backEndId \
  195. , (int(PANTHEIOS_CALLCONV *)(PAN_CHAR_T const*,int,void const*,void*,void**))be_prefix ## _init \
  196. , be_prefix ## _uninit \
  197. , be_prefix ## _logEntry \
  198. , INT_MAX \
  199. , NULL \
  200. }
  201. /** \def PANTHEIOS_BE_N_FILTERED_ENTRY
  202. *
  203. * Defines an entry in an array of pan_be_N_t.
  204. *
  205. * \param backEndId The back-end identifier. Must be >0.
  206. * \param be_prefix The prefix of all the back-end functions, e.g. <b>pantheios_be_speech</b>.
  207. * \param severityCeiling A static severity level, used to filter out
  208. * messages of a given severity level prior to passing to the given
  209. * specific back-end.
  210. * \param flags A combination of the
  211. * \ref group__backend__stock_backends__N__flags "be.N flags" that control
  212. * the behaviour of the given back-end.
  213. *
  214. * This is used in combination with PANTHEIOS_BE_N_TERMINATOR_ENTRY to
  215. * define the set of concrete back-ends are to be attached to the program:
  216. <pre>
  217. pan_be_N_t PAN_BE_N_BACKEND_LIST[] =
  218. {
  219. PANTHEIOS_BE_N_STDFORM_ENTRY(1, pantheios_be_file, 0)
  220. , PANTHEIOS_BE_N_STDFORM_ENTRY(2, pantheios_be_fprintf, 0)
  221. , PANTHEIOS_BE_N_STDFORM_ENTRY(3, pantheios_be_null, 0)
  222. \#if defined(PLATFORMSTL_OS_IS_UNIX)
  223. , PANTHEIOS_BE_N_FILTERED_ENTRY(4, pantheios_be_syslog, PANTHEIOS_SEV_WARNING, 0)
  224. \#elif defined(PLATFORMSTL_OS_IS_WIN32) || \
  225. defined(PLATFORMSTL_OS_IS_WIN64)
  226. , PANTHEIOS_BE_N_FILTERED_ENTRY(4, pantheios_be_WindowsSyslog, PANTHEIOS_SEV_WARNING, 0)
  227. \#endif
  228. , PANTHEIOS_BE_N_STDFORM_ENTRY(5, pantheios_be_file, 0)
  229. , PANTHEIOS_BE_N_TERMINATOR_ENTRY
  230. };
  231. </pre>
  232. *
  233. * The output to back-end 4 is statically filtered, so that any statement
  234. * with severity less than or equal to the specified level will be output,
  235. * subject to dynamic filtering via pantheios_fe_isSeverityLogged().
  236. *
  237. * \ingroup group__backend__stock_backends__N
  238. */
  239. #define PANTHEIOS_BE_N_FILTERED_ENTRY(backEndId, be_prefix, severityCeiling, flags) \
  240. { \
  241. flags \
  242. , backEndId \
  243. , (int(PANTHEIOS_CALLCONV*)(PAN_CHAR_T const*,int,void const*,void*,void**))be_prefix ## _init \
  244. , be_prefix ## _uninit \
  245. , be_prefix ## _logEntry \
  246. , severityCeiling \
  247. , NULL \
  248. }
  249. /** \def PANTHEIOS_BE_N_TERMINATOR_ENTRY
  250. *
  251. * Defines a terminating entry in an array of pan_be_N_t.
  252. *
  253. * \ingroup group__backend__stock_backends__N
  254. *
  255. * \see PANTHEIOS_BE_N_STDFORM_ENTRY
  256. */
  257. #define PANTHEIOS_BE_N_TERMINATOR_ENTRY { 0, 0, NULL, NULL, NULL, -1, NULL }
  258. /* /////////////////////////////////////////////////////////////////////////
  259. * External Declarations
  260. */
  261. /** The application-defined array of back-end descriptors that specify what
  262. * concrete back-ends are to be attached to the program.
  263. *
  264. * \note The array must be defined with a last terminator element whose
  265. * <code>pfnInit</code> member is <code>NULL</code>.
  266. *
  267. * \ingroup group__backend__stock_backends__N
  268. */
  269. PANTHEIOS_EXTERN_C pan_be_N_t PAN_BE_N_BACKEND_LIST[];
  270. /* ////////////////////////////////////////////////////////////////////// */
  271. #endif /* PANTHEIOS_INCL_PANTHEIOS_FRONTENDS_H_BE_N */
  272. /* ///////////////////////////// end of file //////////////////////////// */