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.

443 lines
18 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/backend.h
  3. *
  4. * Purpose: Pantheios back end API
  5. *
  6. * Created: 21st June 2005
  7. * Updated: 26th November 2010
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2005-2010, Matthew Wilson and Synesis Software
  12. * Copyright (c) 1999-2005, Synesis Software and Matthew Wilson
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are
  17. * met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  25. * names of any contributors may be used to endorse or promote products
  26. * derived from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file pantheios/backend.h
  42. *
  43. * [C, C++] Definition of the \ref group__backend.
  44. */
  45. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_BACKEND
  46. #define PANTHEIOS_INCL_PANTHEIOS_H_BACKEND
  47. /* /////////////////////////////////////////////////////////////////////////
  48. * Version information
  49. */
  50. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  51. # define PANTHEIOS_VER_PANTHEIOS_H_BACKEND_MAJOR 3
  52. # define PANTHEIOS_VER_PANTHEIOS_H_BACKEND_MINOR 11
  53. # define PANTHEIOS_VER_PANTHEIOS_H_BACKEND_REVISION 1
  54. # define PANTHEIOS_VER_PANTHEIOS_H_BACKEND_EDIT 31
  55. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  56. /* /////////////////////////////////////////////////////////////////////////
  57. * Includes
  58. */
  59. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  60. # include <pantheios/pantheios.h>
  61. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Back-end API
  64. */
  65. /** \defgroup group__backend Pantheios Back-end API
  66. *
  67. * The Pantheios back-end API describes the required functionality of a back-end
  68. * library. The back-end is responsible solely for translating the log entry -
  69. * severity indicator + length-specified, nul-terminated string - into output,
  70. * as appropriate to its implementation.
  71. *
  72. * There are several stock back-ends supplied with the Pantheios distribution
  73. * (http://pantheios.org/), providing logging to stderr (using \c fprintf()),
  74. * SysLog (using UNIX syslog(), or an emulation library on Windows), Windows
  75. * Debugger, ACE output. You may also supply your own back-end by implementing
  76. * the three simple functions of the API: pantheios_be_init(),
  77. * pantheios_be_uninit(), and pantheios_be_logEntry().
  78. *
  79. * @{
  80. */
  81. /** \defgroup group__backend__stock_backends Pantheios Stock Back-ends
  82. *
  83. * \ingroup group__backend
  84. *
  85. * Pre-built back-ends supplied with the Pantheios library
  86. *
  87. * Pantheios comes with several pre-written stock back-end libraries, which
  88. * cover most common needs for diagnostic logging. They also serve as good
  89. * examples of how to write a custom back-end.
  90. */
  91. /** \defgroup group__backend__stock_ids Pantheios Stock Back-end Ids
  92. *
  93. * \ingroup group__backend
  94. *
  95. * Stock back-end identifiers used by the Pantheios back-end
  96. * libraries.
  97. */
  98. /** \def PANTHEIOS_BEID_ALL
  99. *
  100. * \ingroup group__backend__stock_ids
  101. *
  102. * Indicates that the operation/query applies to all back-ends
  103. */
  104. #define PANTHEIOS_BEID_ALL (0)
  105. /** \def PANTHEIOS_BEID_LOCAL
  106. *
  107. * \ingroup group__backend__stock_ids
  108. *
  109. * Identifies the local (or only) back-end in a link-unit
  110. */
  111. #define PANTHEIOS_BEID_LOCAL (1)
  112. /** \def PANTHEIOS_BEID_REMOTE
  113. *
  114. * \ingroup group__backend__stock_ids
  115. *
  116. * Identifies the remote back-end in a link-unit using local/remote
  117. * splitting.
  118. */
  119. #define PANTHEIOS_BEID_REMOTE (2)
  120. /* /////////////////////////////////////////////////////////////////////////
  121. * Constants
  122. */
  123. /** \defgroup group__backend__init__flags Pantheios Back-end Initialisation Flags
  124. *
  125. * \ingroup group__backend
  126. *
  127. * Flags for the \ref group__backend__stock_backends
  128. */
  129. /** \def PANTHEIOS_BE_INIT_F_NO_PROCESS_ID
  130. * Causes the back-end to
  131. * omit the process identity from emitted log statements.
  132. * \ingroup group__backend__init__flags
  133. */
  134. /** \def PANTHEIOS_BE_INIT_F_NO_THREAD_ID
  135. * Causes the back-end to
  136. * omit the thread identity from emitted log statements.
  137. * \ingroup group__backend__init__flags
  138. */
  139. /** \def PANTHEIOS_BE_INIT_F_NO_DATETIME
  140. * Causes the back-end to
  141. * omit the date/time field from emitted log statements.
  142. * \ingroup group__backend__init__flags
  143. */
  144. /** \def PANTHEIOS_BE_INIT_F_NO_SEVERITY
  145. * Causes the back-end to
  146. * omit the severity from emitted log statements.
  147. * \ingroup group__backend__init__flags
  148. */
  149. /** \def PANTHEIOS_BE_INIT_F_USE_SYSTEM_TIME
  150. * Causes the back-end to
  151. * use system time, rather than local time, from emitted log statements.
  152. * \ingroup group__backend__init__flags
  153. */
  154. /** \def PANTHEIOS_BE_INIT_F_DETAILS_AT_START
  155. * Causes the details
  156. * to be emitted at the start of the statement, rather than after the
  157. * process id, time, and so on.
  158. * \ingroup group__backend__init__flags
  159. */
  160. /** \def PANTHEIOS_BE_INIT_F_USE_UNIX_FORMAT
  161. * Causes the back-end to
  162. * use UNIX format for the date/time field, even on other operating
  163. * systems.
  164. * \ingroup group__backend__init__flags
  165. */
  166. /** \def PANTHEIOS_BE_INIT_F_HIDE_DATE
  167. * Causes the back-end to
  168. * omit the date in the date/time field (if shown).
  169. * \ingroup group__backend__init__flags
  170. */
  171. /** \def PANTHEIOS_BE_INIT_F_HIDE_TIME
  172. * Causes the back-end to
  173. * omit the time in the date/time field (if shown).
  174. * \ingroup group__backend__init__flags
  175. */
  176. /** \def PANTHEIOS_BE_INIT_F_HIGH_RESOLUTION
  177. * Causes the back-end to
  178. * favour high-resolution in the date/time field (if shown).
  179. * \ingroup group__backend__init__flags
  180. */
  181. /** \def PANTHEIOS_BE_INIT_F_LOW_RESOLUTION
  182. * Causes the back-end to
  183. * favour low-resolution in the date/time field (if shown).
  184. * \ingroup group__backend__init__flags
  185. */
  186. #define PANTHEIOS_BE_INIT_F_NO_PROCESS_ID (0x00000001)
  187. #define PANTHEIOS_BE_INIT_F_NO_THREAD_ID (0x00001000)
  188. #define PANTHEIOS_BE_INIT_F_NO_DATETIME (0x00000002)
  189. #define PANTHEIOS_BE_INIT_F_NO_SEVERITY (0x00000004)
  190. #define PANTHEIOS_BE_INIT_F_USE_SYSTEM_TIME (0x00000008)
  191. #define PANTHEIOS_BE_INIT_F_DETAILS_AT_START (0x00000010)
  192. #define PANTHEIOS_BE_INIT_F_USE_UNIX_FORMAT (0x00000020)
  193. #define PANTHEIOS_BE_INIT_F_HIDE_DATE (0x00000040)
  194. #define PANTHEIOS_BE_INIT_F_HIDE_TIME (0x00000080)
  195. #define PANTHEIOS_BE_INIT_F_HIGH_RESOLUTION (0x00000100)
  196. #define PANTHEIOS_BE_INIT_F_LOW_RESOLUTION (0x00000200)
  197. /** \def PANTHEIOS_BE_INIT_F_COMMON_MASK
  198. * Mask of stock back-end flags.
  199. * \ingroup group__backend__init__flags
  200. */
  201. /** \def PANTHEIOS_BE_INIT_F_CUSTOM_MASK
  202. * Mask of custom back-end flags.
  203. * \ingroup group__backend__init__flags
  204. */
  205. #define PANTHEIOS_BE_INIT_F_COMMON_MASK (0x000fffff)
  206. #ifdef __cplusplus
  207. # define PANTHEIOS_BE_INIT_F_CUSTOM_MASK (~static_cast<int>(PANTHEIOS_BE_INIT_F_COMMON_MASK))
  208. #else /* ? __cplusplus */
  209. # define PANTHEIOS_BE_INIT_F_CUSTOM_MASK (~((int)PANTHEIOS_BE_INIT_F_COMMON_MASK))
  210. #endif /* __cplusplus */
  211. /** Initialises the back-end API.
  212. *
  213. * \ingroup group__backend
  214. *
  215. * This function is called once by the Pantheios core library to initialise the
  216. * back-end library. It passes the process identity (in the form of a
  217. * nul-terminated C-style string) and a second parameter (reserved for future
  218. * use; currently always has value 0), which the back-end may use in its
  219. * initialisation. The third parameter is a pointer to a void*, with which the
  220. * back-end may store state, to be passed back to it in the pantheios_be_logEntry()
  221. * and pantheios_be_uninit() functions.
  222. *
  223. * \param processIdentity The identity of the process within which Pantheios is
  224. * being used. Should be a meaningful human-readable string. Must not be NULL.
  225. * Maximum length is limited solely by what the back-end library can accomodate.
  226. * The string pointed to by this parameter may not persist after the call is
  227. * complete, so the back-end should take a copy if required.
  228. * \param reserved Currently reserved. Will contain 0 in the current version of
  229. * the Pantheios library
  230. * \param ptoken Pointer to a variable to receive the back-end token, which will
  231. * be stored in the Pantheios library and passed to the pantheios_be_logEntry()
  232. * and pantheios_be_uninit() functions
  233. *
  234. * \note This function must be defined by each back-end implementation
  235. *
  236. * \note This function is called at most once per process.
  237. *
  238. * \return A status indicating whether the back-end is initialised, and
  239. * therefore whether the Pantheios library as a whole is initialised.
  240. * \retval <0 Initialisation failed.
  241. * \retval >=0 Initialisation succeeded
  242. */
  243. PANTHEIOS_CALL(int) pantheios_be_init(
  244. PAN_CHAR_T const* processIdentity
  245. , void* reserved
  246. , void** ptoken
  247. );
  248. /** Uninitialises the back-end API.
  249. *
  250. * \ingroup group__backend
  251. *
  252. * This function is called to uninitialise the back-end library during the
  253. * uninitialisation of the Pantheios core library. It is passed the value of the
  254. * token stored on its behalf by the Pantheios core library.
  255. *
  256. * \note This function must be defined by each back-end implementation
  257. *
  258. * \note This function is called at most once per process.
  259. *
  260. * \param token The back-end token, created by the pantheios_be_init() function
  261. */
  262. PANTHEIOS_CALL(void) pantheios_be_uninit(void* token);
  263. /** Passes a log-entry to the back-end API.
  264. *
  265. * \ingroup group__backend
  266. *
  267. * This function is called by the Pantheios core library to emit a log entry.
  268. * It is passed five parameters. The \c severity, \c entry and \c cchEntry
  269. * parameters describe the severity level, and the nul-terminated contents of
  270. * the log entry. The \c feToken and \c beToken parameters hold the
  271. * library-specific state of the front-end and back-end librarys, respectively.
  272. *
  273. * \note This function must be defined by each back-end implementation
  274. *
  275. * \note This may be called from any thread in a multi-threaded process.
  276. *
  277. * \param feToken The front-end token, created by the pantheios_fe_init()
  278. * function. This value does not hold any meaning to the back-end library, and
  279. * may be used only to passed back to the front-end in calls to
  280. * pantheios_fe_isSeverityLogged().
  281. * \param beToken The back-end token, created by the pantheios_be_init() function
  282. * \param severity The severity level.
  283. * \param entry The nul-terminated string containing the entry information
  284. * \param cchEntry The number of bytes in the string, not including the
  285. * nul-terminating character
  286. */
  287. PANTHEIOS_CALL(int) pantheios_be_logEntry(
  288. void* feToken
  289. , void* beToken
  290. , int severity
  291. , PAN_CHAR_T const* entry
  292. , size_t cchEntry
  293. );
  294. /** @} group__backend */
  295. /* /////////////////////////////////////////////////////////////////////////
  296. * Generation Macros
  297. */
  298. /** \def PANTHEIOS_BE_DEFINE_BE_FUNCTIONS(expr)
  299. *
  300. * Back-end generation macro for the Pantheios API
  301. *
  302. * Generates the functions <code>pantheios_be_init()</code>,
  303. * <code>pantheios_be_uninit()</code> and
  304. * <code>pantheios_be_logEntry()</code> from the given back-end
  305. * implementation. The given id is assumed to be common to all three
  306. * back-end API functions for the given back-end implementation. In other
  307. * words, for the back-end "be.loader" one would specify the id to be
  308. * <code>loader</code>, from which the macro assumes the existence of the
  309. * three functions <code>pantheios_be_loader_init()</code>,
  310. * <code>pantheios_be_loader_uninit()</code> and
  311. * <code>pantheios_be_loader_logEntry()</code>.
  312. *
  313. * \param id The back-end identifier, e.g. <code>loader</code> for the
  314. * "be.loader" back-end.
  315. */
  316. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  317. # define PANTHEIOS_BE_DEFINE_BE_FUNCTIONS_(fullId) \
  318. \
  319. PANTHEIOS_CALL(int) pantheios_be_init(PAN_CHAR_T const* processIdentity, void* reserved, void** ptoken) \
  320. { return fullId##_init(processIdentity, PANTHEIOS_BEID_LOCAL, NULL, reserved, ptoken); } \
  321. PANTHEIOS_CALL(void) pantheios_be_uninit(void* token) \
  322. { fullId##_uninit(token); } \
  323. PANTHEIOS_CALL(int) pantheios_be_logEntry(void* feToken, void* beToken, int severity, PAN_CHAR_T const* entry, size_t cchEntry) \
  324. { STLSOFT_SUPPRESS_UNUSED(feToken); return fullId##_logEntry(feToken, beToken, severity, entry, cchEntry); }
  325. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  326. #define PANTHEIOS_BE_DEFINE_BE_FUNCTIONS(id) PANTHEIOS_BE_DEFINE_BE_FUNCTIONS_(pantheios_be_##id)
  327. /** \def PANTHEIOS_BE_DEFINE_BEL_FUNCTIONS(expr)
  328. *
  329. * Local back-end generation macro for the Pantheios API
  330. *
  331. * Generates the functions <code>pantheios_be_local_init()</code>,
  332. * <code>pantheios_be_local_uninit()</code> and
  333. * <code>pantheios_be_local_logEntry()</code> from the given back-end
  334. * implementation. The given id is assumed to be common to all three
  335. * back-end API functions for the given back-end implementation. In other
  336. * words, for the back-end "be.loader" one would specify the id to be
  337. * <code>loader</code>, from which the macro assumes the existence of the
  338. * three functions <code>pantheios_be_loader_init()</code>,
  339. * <code>pantheios_be_loader_uninit()</code> and
  340. * <code>pantheios_be_loader_logEntry()</code>.
  341. *
  342. * \param id The back-end identifier, e.g. <code>loader</code> for the
  343. * "be.loader" back-end.
  344. */
  345. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  346. # define PANTHEIOS_BE_DEFINE_BEL_FUNCTIONS_(fullId) \
  347. \
  348. PANTHEIOS_CALL(int) pantheios_be_local_init(PAN_CHAR_T const* processIdentity, void* reserved, void** ptoken) \
  349. { return fullId##_init(processIdentity, PANTHEIOS_BEID_LOCAL, NULL, reserved, ptoken); } \
  350. PANTHEIOS_CALL(void) pantheios_be_local_uninit(void* token) \
  351. { fullId##_uninit(token); } \
  352. PANTHEIOS_CALL(int) pantheios_be_local_logEntry(void* feToken, void* beToken, int severity, PAN_CHAR_T const* entry, size_t cchEntry) \
  353. { STLSOFT_SUPPRESS_UNUSED(feToken); return fullId##_logEntry(feToken, beToken, severity, entry, cchEntry); }
  354. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  355. #define PANTHEIOS_BE_DEFINE_BEL_FUNCTIONS(id) PANTHEIOS_BE_DEFINE_BEL_FUNCTIONS_(pantheios_be_##id)
  356. /** \def PANTHEIOS_BE_DEFINE_BER_FUNCTIONS(expr)
  357. *
  358. * Remote back-end generation macro for the Pantheios API
  359. *
  360. * Generates the functions <code>pantheios_be_remote_init()</code>,
  361. * <code>pantheios_be_remote_uninit()</code> and
  362. * <code>pantheios_be_remote_logEntry()</code> from the given back-end
  363. * implementation. The given id is assumed to be common to all three
  364. * back-end API functions for the given back-end implementation. In other
  365. * words, for the back-end "be.loader" one would specify the id to be
  366. * <code>loader</code>, from which the macro assumes the existence of the
  367. * three functions <code>pantheios_be_loader_init()</code>,
  368. * <code>pantheios_be_loader_uninit()</code> and
  369. * <code>pantheios_be_loader_logEntry()</code>.
  370. *
  371. * \param id The back-end identifier, e.g. <code>loader</code> for the
  372. * "be.loader" back-end.
  373. */
  374. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  375. # define PANTHEIOS_BE_DEFINE_BER_FUNCTIONS_(fullId) \
  376. \
  377. PANTHEIOS_CALL(int) pantheios_be_remote_init(PAN_CHAR_T const* processIdentity, void* reserved, void** ptoken) \
  378. { return fullId##_init(processIdentity, PANTHEIOS_BEID_REMOTE, NULL, reserved, ptoken); } \
  379. PANTHEIOS_CALL(void) pantheios_be_remote_uninit(void* token) \
  380. { fullId##_uninit(token); } \
  381. PANTHEIOS_CALL(int) pantheios_be_remote_logEntry(void* feToken, void* beToken, int severity, PAN_CHAR_T const* entry, size_t cchEntry) \
  382. { STLSOFT_SUPPRESS_UNUSED(feToken); return fullId##_logEntry(feToken, beToken, severity, entry, cchEntry); }
  383. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  384. #define PANTHEIOS_BE_DEFINE_BER_FUNCTIONS(id) PANTHEIOS_BE_DEFINE_BER_FUNCTIONS_(pantheios_be_##id)
  385. /* ////////////////////////////////////////////////////////////////////// */
  386. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_BACKEND */
  387. /* ///////////////////////////// end of file //////////////////////////// */