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.

215 lines
9.1 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/frontend.h
  3. *
  4. * Purpose: Pantheios front end API
  5. *
  6. * Created: 21st June 2005
  7. * Updated: 7th August 2012
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2005-2012, 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/frontend.h
  42. *
  43. * [C, C++] Definition of the \ref group__frontend.
  44. */
  45. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_FRONTEND
  46. #define PANTHEIOS_INCL_PANTHEIOS_H_FRONTEND
  47. /* /////////////////////////////////////////////////////////////////////////
  48. * Version information
  49. */
  50. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  51. # define PANTHEIOS_VER_PANTHEIOS_H_FRONTEND_MAJOR 3
  52. # define PANTHEIOS_VER_PANTHEIOS_H_FRONTEND_MINOR 2
  53. # define PANTHEIOS_VER_PANTHEIOS_H_FRONTEND_REVISION 1
  54. # define PANTHEIOS_VER_PANTHEIOS_H_FRONTEND_EDIT 20
  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. * Front-end API
  64. */
  65. /** \defgroup group__frontend Pantheios Front-end API
  66. *
  67. * The Pantheios front-end API describes the required functionality of a
  68. * front-end library. The front-end is responsible solely for providing
  69. * process identity information and arbitrating logging requests, based on
  70. * severity level (and local/remote destination).
  71. *
  72. * Process identity is defined by the front-end according to the
  73. * return-value of pantheios_fe_getProcessIdentity(), which should return a
  74. * nul-terminated C-style string representing the host process,
  75. * e.g. \c "MyDaemon"
  76. *
  77. * Filtering is carried out by pantheios_fe_isSeverityLogged(), which
  78. * receives three parameters: the front-end state, the log entry severity
  79. * level, and a back-end identifier. The back-end identifier value
  80. * represents one of three 'questions' that are to be asked of the
  81. * front-end. If \c backEndId is 0, then the question is whether any logging
  82. * should occur for the given severity level. If \c backEndId is 1, then the
  83. * question is whether logging should occur for the local back-end. If
  84. * \c backEndId is 2, then the question is whether logging should occur for
  85. * the remote back-end.
  86. *
  87. * @{
  88. */
  89. /** Initialises the front-end API.
  90. *
  91. * \param reserved Currently reserved. Will be NULL in the current version
  92. * of the Pantheios library
  93. * \param ptoken Pointer to a variable to receive the front-end token, which
  94. * will be stored in the Pantheios library and passed to the
  95. * pantheios_fe_getProcessIdentity(), pantheios_fe_isSeverityLogged()
  96. * and pantheios_fe_uninit() functions.
  97. *
  98. * This function must be defined by each front-end implementation. It
  99. * initialises the front-end. If the implementation requires any context,
  100. * e.g. a front-end class instance, this can be allocated and placed into
  101. * <code>*ptoken</code>, and it will be passed back to the other functions.
  102. *
  103. * \note This function is called at most once per process.
  104. *
  105. * \return A status indicating whether the front-end is initialised, and
  106. * therefore whether the Pantheios library as a whole is initialised.
  107. * \retval <0 Initialisation failed.
  108. * \retval >=0 Initialisation succeeded
  109. */
  110. PANTHEIOS_CALL(int) pantheios_fe_init(
  111. void* reserved
  112. , void** ptoken
  113. );
  114. /** Uninitialises the front-end API.
  115. *
  116. * This function must be defined by each front-end implementation. It
  117. * uninitialises the front-end.
  118. *
  119. * \param token The front-end token, created by the pantheios_fe_init()
  120. * function.
  121. *
  122. * \note This function is called at most once per process.
  123. */
  124. PANTHEIOS_CALL(void) pantheios_fe_uninit(void* token);
  125. /** Defines the process identity
  126. *
  127. * This function must be defined by each front-end implementation. It
  128. * defines the name of the process, that may be used in the emission of log
  129. * statements by back-ends.
  130. *
  131. * \param token The front-end token, created by the pantheios_fe_init()
  132. * function.There is no strict maximum length as far as Pantheios is
  133. * concerned, but it should not exceed the limitation provided by the
  134. * implementing back-end library.
  135. *
  136. * \return A pointer to a nul-terminated C-style string containing the
  137. * process identity. May not be \c NULL, except on the first invocation,
  138. * which is an indication to the Pantheios core library (and congnisant
  139. * custom back-ends; no stock back-ends use his behaviour) that the
  140. * front-end may provide changing process identity at different times and
  141. * that multiple calls are supported (and, presumably, desired). The
  142. * maximum length of the returned string is 1000 characters.
  143. *
  144. * \note When the first invocation returns \c NULL, to denote that a dynamic
  145. * process identity, the second invocation (which must
  146. * <strong>not</strong> return \c NULL) will be called on the same thread,
  147. * and at a time when no other (Pantheios-related) threads will call it,
  148. * enabling implementations to use simple static flag variables to handle
  149. * their switching logic (should they so wish).
  150. *
  151. * \note When the first invocation returns non-<code>NULL</code>, to denote
  152. * a "classic" non-dynamic process identity, then the function is called
  153. * at most once during successful
  154. * initialisation, but in the case where initialisation fails it may be
  155. * called additional times by the bail out handler
  156. * (\link pantheios::util::pantheios_onBailOut4 pantheios_onBailOut4()\endlink).
  157. * It may also be called if the application, or the front-end or
  158. * back-end(s) invoke the bail out handler at any other time.
  159. */
  160. PANTHEIOS_CALL(PAN_CHAR_T const*) pantheios_fe_getProcessIdentity(void* token);
  161. /** Determines whether a given severity is being logged
  162. *
  163. * This function must be defined by each front-end implementation. It
  164. * is called by the Pantheios core library and, optionally, a
  165. * back-end library, to determine whether, for the given \c severity,
  166. * any/all logging is enabled (\c backEndId == 0), or whether local
  167. * (\c backEndId == 1) or remote (\c backEndId == 2) logging is enabled. It
  168. * is passed the token returned in pantheios_fe_init(), which the front-end
  169. * implementation may use to access its state
  170. *
  171. * \param token The front-end token, created by the pantheios_fe_init()
  172. * function.
  173. * \param severity The severity level
  174. * \param backEndId A front-end+back-end specific parameter. This is used to
  175. * enable a back-end, such as the be.lrsplit library, to simultaneously
  176. * provide multiple actual back-ends and query the front-end for their
  177. * respective. The value 0 is used within the Pantheios library and
  178. * stands for every back-end. All other values indicate specific
  179. * back-end splits, although by convention 1 indicates local logging
  180. * and 2 indicates remote logging.
  181. *
  182. * \return A status indicating whether the given severity level is being
  183. * logged.
  184. * \retval non-0 Severity is being logged.
  185. * \retval 0 Severity is not being logged.
  186. *
  187. * \note This may be called from any thread in a multi-threaded process, and
  188. * so it must be safely callable by multiple threads concurrently.
  189. */
  190. PANTHEIOS_CALL(int) pantheios_fe_isSeverityLogged(
  191. void* token
  192. , int severity
  193. , int backEndId
  194. );
  195. /** @} // group__frontend */
  196. /* ////////////////////////////////////////////////////////////////////// */
  197. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_FRONTEND */
  198. /* ///////////////////////////// end of file //////////////////////////// */