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.

253 lines
9.7 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/backends/bec.fprintf.h
  3. *
  4. * Purpose: Declaration of the Pantheios fprintf Stock Back-end API.
  5. *
  6. * Created: 21st June 2005
  7. * Updated: 30th April 2010
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2005-2010, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are
  16. * met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  24. * names of any contributors may be used to endorse or promote products
  25. * derived from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file pantheios/backends/bec.fprintf.h
  41. *
  42. * [C, C++] Pantheios fprintf() Back-end Common API
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_FPRINTF
  45. #define PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_FPRINTF
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_FPRINTF_MAJOR 2
  51. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_FPRINTF_MINOR 1
  52. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_FPRINTF_REVISION 1
  53. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_FPRINTF_EDIT 21
  54. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  55. /* /////////////////////////////////////////////////////////////////////////
  56. * Includes
  57. */
  58. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  59. # include <pantheios/pantheios.h>
  60. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  61. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_BACKEND
  62. # include <pantheios/backend.h>
  63. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_BACKEND */
  64. #ifndef PANTHEIOS_INCL_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS
  65. # include <pantheios/util/backends/arguments.h>
  66. #endif /* !PANTHEIOS_INCL_PANTHEIOS_UTIL_BACKENDS_H_ARGUMENTS */
  67. /* /////////////////////////////////////////////////////////////////////////
  68. * Documentation
  69. */
  70. /** \defgroup group__backend__stock_backends__fprintf Pantheios fprintf() Stock Back-end
  71. * \ingroup group__backend__stock_backends
  72. * Back-end library that writes to the standard output or error stream
  73. * via <code>fprintf()</code>.
  74. */
  75. /* /////////////////////////////////////////////////////////////////////////
  76. * Constants
  77. */
  78. /** \defgroup group__backend__stock_backends__fprintf__flags Pantheios fprintf() Stock Back-end Flags
  79. *
  80. * \ingroup group__backend__stock_backends__fprintf
  81. * Flags for the \ref group__backend__stock_backends__fprintf
  82. */
  83. /* /////////////////////////////////////////////////////////////////////////
  84. * Typedefs
  85. */
  86. /** Structure used for specifying initialisation information to the
  87. * be.fprintf library.
  88. * \ingroup group__backend__stock_backends__fprintf
  89. */
  90. struct pan_be_fprintf_init_t
  91. {
  92. #if !defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION) && \
  93. !defined(PANTHEIOS_NO_NAMESPACE)
  94. typedef pantheios::pan_uint16_t pan_uint16_t;
  95. typedef pantheios::pan_uint32_t pan_uint32_t;
  96. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION && !PANTHEIOS_NO_NAMESPACE */
  97. pan_uint32_t version; /*!< Must be initialised to the value of PANTHEIOS_VER */
  98. pan_uint32_t flags; /*!< \ref group__backend__stock_backends__fprintf__flags "Flags" that control the information displayed. */
  99. #ifdef __cplusplus
  100. public: /* Construction */
  101. # ifndef PANTHEIOS_BE_INIT_NO_CPP_STRUCT_INIT
  102. pan_be_fprintf_init_t();
  103. # endif /* !PANTHEIOS_BE_INIT_NO_CPP_STRUCT_INIT */
  104. #endif /* __cplusplus */
  105. };
  106. #ifndef __cplusplus
  107. typedef struct pan_be_fprintf_init_t pan_be_fprintf_init_t;
  108. #endif /* !__cplusplus */
  109. /* /////////////////////////////////////////////////////////////////////////
  110. * Application-defined functions
  111. */
  112. /** \ref page__backend__callbacks "Callback" function defined by
  113. * the application, invoked when the
  114. * API is initialised with a NULL <code>init</code> parameter.
  115. * \ingroup group__backend__stock_backends__fprintf
  116. *
  117. * \param backEndId The back-end identifier passed to the back-end
  118. * during its initialisation.
  119. * \param init A pointer to an already-initialised instance of
  120. * pan_be_fprintf_init_t.
  121. *
  122. * If any application-specific changes are required they can be made to
  123. * the structure to which <code>init</code> points, which will already
  124. * have been initialised. These changes will then be incorporated into
  125. * the back-end state, and reflected in its behaviour.
  126. *
  127. * If no changes are required, then the function can be a simple stub,
  128. * containing no instructions.
  129. *
  130. * \note This function is only required when the
  131. * \ref page__backend__callbacks "callback" version of the library is
  132. * used.
  133. *
  134. * \exception "throw()" This function must <b>not</b> throw any exceptions!
  135. *
  136. * \warning This function will be called during the initialisation of
  137. * Pantheios, and so <b>must not</b> make any calls into Pantheios, either
  138. * directly or indirectly!
  139. */
  140. PANTHEIOS_CALL(void) pantheios_be_fprintf_getAppInit(
  141. int backEndId
  142. , pan_be_fprintf_init_t* init
  143. ) /* throw() */;
  144. /* /////////////////////////////////////////////////////////////////////////
  145. * API
  146. */
  147. /** Fills out a copy of the initialisation structure with default
  148. * values (representative of the default behaviour of the library),
  149. * ready to be customised and passed to the API initialiser function
  150. * pantheios_be_fprintf_init().
  151. * \ingroup group__backend__stock_backends__fprintf
  152. *
  153. * \note This function should <b>not</b> be called on an
  154. * already-initialised instance, as is the case in the implementation
  155. * of the pantheios_be_fprintf_getAppInit() function, as it will
  156. * already have been called by pantheios_be_fprintf_init() prior
  157. * to the callback.
  158. */
  159. PANTHEIOS_CALL(void) pantheios_be_fprintf_getDefaultAppInit(pan_be_fprintf_init_t* init) /* throw() */;
  160. /** Implements the functionality for pantheios_be_init() over the fprintf() function.
  161. * \ingroup group__backend__stock_backends__fprintf
  162. */
  163. PANTHEIOS_CALL(int) pantheios_be_fprintf_init(
  164. PAN_CHAR_T const* processIdentity
  165. , int id
  166. , pan_be_fprintf_init_t const* unused
  167. , void* reserved
  168. , void** ptoken
  169. );
  170. /** Implements the functionality for pantheios_be_uninit() over the fprintf() function.
  171. * \ingroup group__backend__stock_backends__fprintf
  172. */
  173. PANTHEIOS_CALL(void) pantheios_be_fprintf_uninit(void* token);
  174. /** Implements the functionality for pantheios_be_logEntry() over the fprintf() function.
  175. * \ingroup group__backend__stock_backends__fprintf
  176. */
  177. PANTHEIOS_CALL(int) pantheios_be_fprintf_logEntry(
  178. void* feToken
  179. , void* beToken
  180. , int severity
  181. , PAN_CHAR_T const* entry
  182. , size_t cchEntry
  183. );
  184. /** \def pantheios_be_fprintf_parseArgs
  185. *
  186. * Parses the be.fprintf back-end flags
  187. *
  188. * \ingroup group__backend
  189. *
  190. * Processes an argument list in the same way as
  191. * pantheios_be_parseStockArgs(), filling out the
  192. * pan_be_fprintf_init_t in accordance with the arguments
  193. * found.
  194. *
  195. * Recognises the following standard argument names:
  196. * - "showProcessId" (Boolean)
  197. * - "showTime" (Boolean)
  198. * - "showSeverity" (Boolean)
  199. * - "useSystemTime" (Boolean)
  200. * - "showDetailsAtStart" (Boolean)
  201. * - "useUnixFormat" (Boolean)
  202. * - "showDate" (Boolean)
  203. * - "showTime" (Boolean)
  204. * - "highResolution" (Boolean)
  205. * - "lowResolution" (Boolean)
  206. *
  207. * There are currently no back-end specific arguments, hence
  208. * pantheios_be_fprintf_parseArgs is actually a \#define for
  209. * pantheios_be_parseStockArgs. At such time as back-end specific arguments
  210. * are required, it will become a first-class function.
  211. */
  212. #define pantheios_be_fprintf_parseArgs(num, args, init) pantheios_be_parseStockArgs((num), (args), (NULL == (init)) ? NULL : (&(init)->flags))
  213. /* ////////////////////////////////////////////////////////////////////// */
  214. #ifdef __cplusplus
  215. # ifndef PANTHEIOS_BE_INIT_NO_CPP_STRUCT_INIT
  216. inline pan_be_fprintf_init_t::pan_be_fprintf_init_t()
  217. {
  218. pantheios_be_fprintf_getDefaultAppInit(this);
  219. }
  220. # endif /* !PANTHEIOS_BE_INIT_NO_CPP_STRUCT_INIT */
  221. #endif /* __cplusplus */
  222. /* ////////////////////////////////////////////////////////////////////// */
  223. #endif /* PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_FPRINTF */
  224. /* ///////////////////////////// end of file //////////////////////////// */