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.

297 lines
12 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/backends/bec.console.h
  3. *
  4. * Purpose: Platform-specific console back-end
  5. *
  6. * Created: 3rd July 2009
  7. * Updated: 26th November 2010
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2009-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.console.h
  41. *
  42. * [C, C++] Platform-specific console back-end
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_CONSOLE
  45. #define PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_CONSOLE
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_CONSOLE_MAJOR 1
  51. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_CONSOLE_MINOR 0
  52. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_CONSOLE_REVISION 1
  53. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_CONSOLE_EDIT 2
  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 PLATFORMSTL_INCL_PLATFORMSTL_H_PLATFORMSTL
  65. # include <platformstl/platformstl.h>
  66. #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_H_PLATFORMSTL */
  67. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  68. # ifndef PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_WINDOWSCONSOLE
  69. # include <pantheios/backends/bec.WindowsConsole.h>
  70. # endif /* !PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_WINDOWSCONSOLE */
  71. #else /* ? OS */
  72. # ifndef PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_FPRINTF
  73. # include <pantheios/backends/bec.fprintf.h>
  74. # endif /* !PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_FPRINTF */
  75. #endif /* OS */
  76. /* /////////////////////////////////////////////////////////////////////////
  77. * Documentation
  78. */
  79. /** \defgroup group__backend__stock_backends__console Pantheios Console Stock Back-end
  80. * \ingroup group__backend__stock_backends
  81. * Back-end library that outputs to the console, providing colour-coding
  82. * options as available on the given platform.
  83. *
  84. * \note The Console back-end does not actually exist; rather it is the
  85. * \ref group__backend__stock_backends__WindowsConsole for Windows, or the
  86. * \ref group__backend__stock_backends__fprintf otherwise. All types,
  87. * functions and constants are actually those of the underlying
  88. * platform-specific back-end.
  89. */
  90. /* /////////////////////////////////////////////////////////////////////////
  91. * Constants
  92. */
  93. /** \defgroup group__backend__stock_backends__console__flags Pantheios Console Stock Back-end Flags
  94. * \ingroup group__backend__stock_backends__console
  95. * Flags for the \ref group__backend__stock_backends__console
  96. */
  97. /** \def PANTHEIOS_BE_CONSOLE_F_NO_COLOURS
  98. * Causes the \ref group__backend__stock_backends__console to
  99. * emit log statements without colouring based on severity.
  100. * \ingroup group__backend__stock_backends__console__flags
  101. */
  102. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  103. # define PANTHEIOS_BE_CONSOLE_F_NO_COLOURS PANTHEIOS_BE_WINDOWSCONSOLE_F_NO_COLOURS
  104. #else /* ? OS */
  105. # define PANTHEIOS_BE_CONSOLE_F_NO_COLOURS (0)
  106. #endif /* OS */
  107. /* /////////////////////////////////////////////////////////////////////////
  108. * Typedefs
  109. */
  110. /** Structure used for specifying initialisation information to the
  111. * be.console library.
  112. * \ingroup group__backend__stock_backends__console
  113. */
  114. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  115. typedef pan_be_WindowsConsole_init_t pan_be_console_init_t;
  116. #else /* ? OS */
  117. typedef pan_be_fprintf_init_t pan_be_console_init_t;
  118. #endif /* OS */
  119. /* /////////////////////////////////////////////////////////////////////////
  120. * Application-defined functions
  121. */
  122. #if defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION)
  123. /** \ref page__backend__callbacks "Callback" function defined by
  124. * the application, invoked when the
  125. * API is initialised with a NULL <code>init</code> parameter.
  126. * \ingroup group__backend__stock_backends__console
  127. *
  128. * \param backEndId The back-end identifier passed to the back-end
  129. * during its initialisation.
  130. * \param init A pointer to an already-initialised instance of
  131. * <code>pan_be_console_init_t</code>.
  132. *
  133. * If any application-specific changes are required they can be made to
  134. * the structure to which <code>init</code> points, which will already
  135. * have been initialised. These changes will then be incorporated into
  136. * the back-end state, and reflected in its behaviour.
  137. *
  138. * If no changes are required, then the function can be a simple stub,
  139. * containing no instructions.
  140. *
  141. * \note This function is only required when the
  142. * \ref page__backend__callbacks "callback" version of the library is
  143. * used.
  144. *
  145. * \exception "throw()" This function must <b>not</b> throw any exceptions!
  146. *
  147. * \warning This function will be called during the initialisation of
  148. * Pantheios, and so <b>must not</b> make any calls into Pantheios, either
  149. * directly or indirectly!
  150. *
  151. * \note This function is actually an alias for the actual console required,
  152. * depending on your operating system. If your operating system is
  153. * Windows, then you are actually using
  154. * the \ref group__backend__stock_backends__WindowsConsole, which means
  155. * that the name of the callback function will be
  156. * <code>pantheios_be_WindowsConsole_getAppInit()</code>; if your
  157. * operating system is UNIX, then you are actually using
  158. * the \ref group__backend__stock_backends__fprintf, which means that the
  159. * name of the callback function will be
  160. * <code>pantheios_be_fprintf_getAppInit()</code>.
  161. */
  162. PANTHEIOS_CALL(void) pantheios_be_console_getAppInit(
  163. int backEndId
  164. , pan_be_console_init_t* init
  165. ) /* throw() */;
  166. #else /* ? PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  167. # if defined(PLATFORMSTL_OS_IS_WINDOWS)
  168. # define pantheios_be_console_getAppInit(backEndId, init) pantheios_be_WindowsConsole_getAppInit(backEndId, init)
  169. # else /* ? OS */
  170. # define pantheios_be_console_getAppInit(backEndId, init) pantheios_be_fprintf_getAppInit(backEndId, init)
  171. # endif /* OS */
  172. #endif /* PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  173. /* /////////////////////////////////////////////////////////////////////////
  174. * API functions
  175. */
  176. /** Fills out a copy of the initialisation structure with default
  177. * values (representative of the default behaviour of the library),
  178. * ready to be customised and passed to the API initialiser function
  179. * pantheios_be_console_init().
  180. * \ingroup group__backend__stock_backends__console
  181. *
  182. * \note This function should <b>not</b> be called on an
  183. * already-initialised instance, as is the case in the implementation
  184. * of the pantheios_be_console_getAppInit() function, as it will
  185. * already have been called by pantheios_be_console_init() prior
  186. * to the callback.
  187. */
  188. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  189. # define pantheios_be_console_getDefaultAppInit(init) pantheios_be_WindowsConsole_getAppInit(init)
  190. #else /* ? OS */
  191. # define pantheios_be_console_getDefaultAppInit(init) pantheios_be_fprintf_getAppInit(init)
  192. #endif /* OS */
  193. /** \def pantheios_be_console_init(processIdentity, id, init, param, ptoken)
  194. *
  195. * Implements the functionality for pantheios_be_init() over the Console API.
  196. * \ingroup group__backend__stock_backends__console
  197. */
  198. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  199. # define pantheios_be_console_init pantheios_be_WindowsConsole_init
  200. #else /* ? OS */
  201. # define pantheios_be_console_init pantheios_be_fprintf_init
  202. #endif /* OS */
  203. /** \def pantheios_be_console_uninit(token)
  204. *
  205. * Implements the functionality for pantheios_be_uninit() over the Console API.
  206. * \ingroup group__backend__stock_backends__console
  207. */
  208. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  209. # define pantheios_be_console_uninit pantheios_be_WindowsConsole_uninit
  210. #else /* ? OS */
  211. # define pantheios_be_console_uninit pantheios_be_fprintf_uninit
  212. #endif /* OS */
  213. /** \def pantheios_be_console_logEntry(feToken, beToken, severity, entry, cchEntry)
  214. *
  215. * Implements the functionality for pantheios_be_logEntry() over the Console API.
  216. * \ingroup group__backend__stock_backends__console
  217. */
  218. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  219. # define pantheios_be_console_logEntry pantheios_be_WindowsConsole_logEntry
  220. #else /* ? OS */
  221. # define pantheios_be_console_logEntry pantheios_be_fprintf_logEntry
  222. #endif /* OS */
  223. /** \def pantheios_be_console_parseArgs(numArgs, args, init)
  224. *
  225. * Parses the be.console back-end flags
  226. *
  227. * \ingroup group__backend
  228. *
  229. * Processes an argument list in the same way as
  230. * pantheios_be_parseStockArgs(), filling out the
  231. * pan_be_console_init_t in accordance with the arguments
  232. * found.
  233. *
  234. * Recognises the following standard argument names:
  235. * - "showProcessId" (Boolean)
  236. * - "showTime" (Boolean)
  237. * - "showSeverity" (Boolean)
  238. * - "useSystemTime" (Boolean)
  239. * - "showDetailsAtStart" (Boolean)
  240. * - "useUnixFormat" (Boolean)
  241. * - "showDate" (Boolean)
  242. * - "showTime" (Boolean)
  243. * - "highResolution" (Boolean)
  244. * - "lowResolution" (Boolean)
  245. *
  246. * Recognises the following back-end specific argument names:
  247. * - "noColours" (Boolean) - Windows-only
  248. * - "noColors" (Boolean) - Windows-only
  249. */
  250. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  251. # define pantheios_be_console_parseArgs(numArgs, args, init) pantheios_be_WindowsConsole_parseArgs(numArgs, args, init)
  252. #else /* ? OS */
  253. # define pantheios_be_console_parseArgs(numArgs, args, init) pantheios_be_fprintf_parseArgs(numArgs, args, init)
  254. #endif /* OS */
  255. /* ////////////////////////////////////////////////////////////////////// */
  256. #endif /* PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_CONSOLE */
  257. /* ///////////////////////////// end of file //////////////////////////// */