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.

455 lines
18 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/backends/bec.file.h
  3. *
  4. * Purpose: Declaration of the Pantheios file Stock Back-end API.
  5. *
  6. * Created: 10th July 2006
  7. * Updated: 27th December 2010
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2006-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.file.h
  41. *
  42. * [C, C++] Pantheios file Back-end Common API
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_FILE
  45. #define PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_FILE
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_FILE_MAJOR 4
  51. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_FILE_MINOR 3
  52. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_FILE_REVISION 1
  53. # define PANTHEIOS_VER_PANTHEIOS_BACKENDS_H_BEC_FILE_EDIT 33
  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. /* /////////////////////////////////////////////////////////////////////////
  65. * Documentation
  66. */
  67. /** \defgroup group__backend__stock_backends__file Pantheios file Stock Back-end
  68. * \ingroup group__backend__stock_backends
  69. * Back-end library that outputs to a file.
  70. */
  71. /* /////////////////////////////////////////////////////////////////////////
  72. * Constants
  73. */
  74. /** \defgroup group__backend__stock_backends__file__flags Pantheios file Stock Back-end Flags
  75. * \ingroup group__backend__stock_backends__file
  76. * Flags for the \ref group__backend__stock_backends__file
  77. */
  78. /** \def PANTHEIOS_BE_FILE_F_TRUNCATE
  79. * Causes the \ref group__backend__stock_backends__file to
  80. * truncate the log file.
  81. *
  82. * \ingroup group__backend__stock_backends__file__flags
  83. *
  84. * \note If more than one process is using the same file and either, or
  85. * both, uses this flag, the log file contents cannot be guaranteed to
  86. * be consistent.
  87. */
  88. /** \def PANTHEIOS_BE_FILE_F_DISCARD_CACHED_CONTENTS
  89. * Causes any log statements cached in the
  90. * \ref group__backend__stock_backends__file prior to assignment of the
  91. * file name (via pantheios_be_file_setFilePath()) to be discarded.
  92. *
  93. * \ingroup group__backend__stock_backends__file__flags
  94. */
  95. /** \def PANTHEIOS_BE_FILE_F_SHARE_ON_WINDOWS
  96. * By default, logging on Windows takes a write-exclusive lock on the log
  97. * file. Specifying this flag allows multiple processes to write to the
  98. * same log file. This flag is ignored on UNIX.
  99. *
  100. * \ingroup group__backend__stock_backends__file__flags
  101. */
  102. /** \def PANTHEIOS_BE_FILE_F_WRITE_WIDE_CONTENTS
  103. * By default, files are written in wide or multibyte string encoding
  104. * according to the encoding of the build: e.g. a Windows' wide string build
  105. * program will, by default, write characters in wide string encoding.
  106. * Specifying this flag causes output to be written in widestring encoding
  107. * regardless of the program's encoding.
  108. *
  109. * \ingroup group__backend__stock_backends__file__flags
  110. *
  111. * \see PANTHEIOS_BE_FILE_F_WRITE_MULTIBYTE_CONTENTS
  112. */
  113. /** \def PANTHEIOS_BE_FILE_F_WRITE_MULTIBYTE_CONTENTS
  114. * By default, files are written in wide or multibyte string encoding
  115. * according to the encoding of the build: e.g. a Windows' wide string build
  116. * program will, by default, write characters in wide string encoding.
  117. * Specifying this flag causes output to be written in multibyte string
  118. * encoding regardless of the program's encoding.
  119. *
  120. * \ingroup group__backend__stock_backends__file__flags
  121. *
  122. * \see PANTHEIOS_BE_FILE_F_WRITE_WIDE_CONTENTS
  123. */
  124. /** \def PANTHEIOS_BE_FILE_F_DELETE_IF_EMPTY
  125. * Specifying this flag causes the log file to be deleted, if and only if it
  126. * is empty, when it is closed (which occurs during back-end
  127. * uninitialisation (at program exit), or when another file path is
  128. * specified, for the given back-end, via pantheios_be_file_setFilePath()).
  129. * If the file cannot be deleted, a bail-out message will be written.
  130. *
  131. * \note The current implementation checks the actual file size, as opposed
  132. * to "remembering" whether any writes were made (by Pantheios).
  133. *
  134. * \note No attempt will be made to determine whether another program (such
  135. * as a log viewer) will (be attempting to) use the file; use at your own
  136. * risk.
  137. *
  138. * \ingroup group__backend__stock_backends__file__flags
  139. */
  140. #define PANTHEIOS_BE_FILE_F_TRUNCATE (0x00100000)
  141. #define PANTHEIOS_BE_FILE_F_DISCARD_CACHED_CONTENTS (0x00200000)
  142. #define PANTHEIOS_BE_FILE_F_SHARE_ON_WINDOWS (0x00400000)
  143. #define PANTHEIOS_BE_FILE_F_WRITE_WIDE_CONTENTS (0x00800000)
  144. #define PANTHEIOS_BE_FILE_F_WRITE_MULTIBYTE_CONTENTS (0x00080000)
  145. #define PANTHEIOS_BE_FILE_F_DELETE_IF_EMPTY (0x00040000)
  146. #if 0 /* None of the following are yet supported: */
  147. #define PANTHEIOS_BE_FILE_F_ROLL_ON_SIZE (0x01000000)
  148. #define PANTHEIOS_BE_FILE_F_ROLL_ON_ENTRY_COUNT (0x02000000)
  149. #define PANTHEIOS_BE_FILE_F_ROLL_ON_DATETIME (0x04000000)
  150. #define PANTHEIOS_BE_FILE_F_ROLL_ON_1MB (0x10000000 | PANTHEIOS_BE_FILE_F_ROLL_ON_SIZE)
  151. #define PANTHEIOS_BE_FILE_F_ROLL_ON_8K_ENTRIES (0x10000000 | PANTHEIOS_BE_FILE_F_ROLL_ON_ENTRY_COUNT)
  152. #define PANTHEIOS_BE_FILE_F_ROLL_ON_DAY (0x10000000 | PANTHEIOS_BE_FILE_F_ROLL_ON_DATETIME)
  153. #define PANTHEIOS_BE_FILE_F_ROLL_TO_SELF (0x20000000)
  154. #endif /* 0 */
  155. /* /////////////////////////////////////////////////////////////////////////
  156. * External Declarations
  157. */
  158. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  159. struct Pantheios_be_file_no_longer_defines_the_function_pantheios_be_file_setFileName_and_Use_pantheios_be_file_setFilePath_instead_;
  160. # define Pantheios_be_file_setFileName (_pantheios_be_file_no_longer_defines_the_function_pantheios_be_file_setFileName_and_Use_pantheios_be_file_setFilePath_instead_)
  161. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  162. /* /////////////////////////////////////////////////////////////////////////
  163. * Typedefs
  164. */
  165. /** \def PANTHEIOS_BE_FILE_MAX_FILE_LEN
  166. *
  167. * The maximum length of a file path that can be specified in a
  168. * pan_be_file_init_t instance using the internal buffer
  169. * (<code>pan_be_file_init_t::buff</code>). File paths exceeding this size must be
  170. * represented in caller-side memory (i.e.
  171. * <code>pan_be_file_init_t::fileName != &pan_be_file_init_t::buff[0]</code>).
  172. */
  173. #define PANTHEIOS_BE_FILE_MAX_FILE_LEN (1000)
  174. /** Structure used for specifying initialisation information to the
  175. * be.file library.
  176. * \ingroup group__backend__stock_backends__file
  177. */
  178. struct pan_be_file_init_t
  179. {
  180. #if !defined(PANTHEIOS_DOCUMENTATION_SKIP_SECTION) && \
  181. !defined(PANTHEIOS_NO_NAMESPACE)
  182. typedef pantheios::pan_uint16_t pan_uint16_t;
  183. typedef pantheios::pan_uint32_t pan_uint32_t;
  184. typedef pantheios::pan_uint64_t pan_uint64_t;
  185. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION && !PANTHEIOS_NO_NAMESPACE */
  186. pan_uint32_t version; /*!< Must be initialised to the value of PANTHEIOS_VER */
  187. pan_uint32_t flags; /*!< \ref group__backend__stock_backends__file__flags "Flags" that control the information displayed. */
  188. PAN_CHAR_T buff[1 + (PANTHEIOS_BE_FILE_MAX_FILE_LEN)]; /*!< Buffer for use by client to write file name, to which \link pan_be_file_init_t::fileName fileName\endlink can be pointed. \see PANTHEIOS_BE_FILE_MAX_FILE_LEN*/
  189. PAN_CHAR_T const* fileName; /*!< Must be pointed to the file name. */
  190. #if 0 /* These features are part of a stream of development for log-file rolling that is incomplete. */
  191. union
  192. {
  193. pan_uint64_t fileSizeKB; /*!< Size of file (in KB). Only used if flags contain PANTHEIOS_BE_FILE_F_ROLL_ON_SIZE. */
  194. pan_uint64_t entryCount; /*!< Number of entries in entry count. Only used if flags contain PANTHEIOS_BE_FILE_F_ROLL_ON_ENTRY_COUNT. */
  195. pan_uint64_t interval; /*!< Number of seconds in interval. Only used if flags contain PANTHEIOS_BE_FILE_F_ROLL_ON_DATETIME. */
  196. } roll; /*!< Union of measures used when file-rolling is in used. */
  197. #endif /* 0 */
  198. #ifdef __cplusplus
  199. public: /* Construction */
  200. # ifndef PANTHEIOS_BE_INIT_NO_CPP_STRUCT_INIT
  201. pan_be_file_init_t();
  202. # endif /* !PANTHEIOS_BE_INIT_NO_CPP_STRUCT_INIT */
  203. #endif /* __cplusplus */
  204. };
  205. #ifndef __cplusplus
  206. typedef struct pan_be_file_init_t pan_be_file_init_t;
  207. #endif /* !__cplusplus */
  208. /* /////////////////////////////////////////////////////////////////////////
  209. * Application-defined functions
  210. */
  211. /** \ref page__backend__callbacks "Callback" function defined by
  212. * the application, invoked when the
  213. * API is initialised with a NULL <code>init</code> parameter.
  214. * \ingroup group__backend__stock_backends__file
  215. *
  216. * \param backEndId The back-end identifier passed to the back-end
  217. * during its initialisation.
  218. * \param init A pointer to an already-initialised instance of
  219. * pan_be_file_init_t.
  220. *
  221. * If any application-specific changes are required they can be made to
  222. * the structure to which <code>init</code> points, which will already
  223. * have been initialised. These changes will then be incorporated into
  224. * the back-end state, and reflected in its behaviour.
  225. *
  226. * If no changes are required, then the function can be a simple stub,
  227. * containing no instructions.
  228. *
  229. * \note This function is only required when the
  230. * \ref page__backend__callbacks "callback" version of the library is
  231. * used.
  232. *
  233. * \exception "throw()" This function must <b>not</b> throw any exceptions!
  234. *
  235. * \warning This function will be called during the initialisation of
  236. * Pantheios, and so <b>must not</b> make any calls into Pantheios, either
  237. * directly or indirectly!
  238. */
  239. PANTHEIOS_CALL(void) pantheios_be_file_getAppInit(
  240. int backEndId
  241. , pan_be_file_init_t* init
  242. ) /* throw() */;
  243. /* /////////////////////////////////////////////////////////////////////////
  244. * API
  245. */
  246. /** Fills out a copy of the initialisation structure with default
  247. * values (representative of the default behaviour of the library),
  248. * ready to be customised and passed to the API initialiser function
  249. * pantheios_be_file_init().
  250. */
  251. PANTHEIOS_CALL(void) pantheios_be_file_getDefaultAppInit(
  252. pan_be_file_init_t* init
  253. ) /* throw() */;
  254. /** Implements the functionality for pantheios_be_init() over the file API.
  255. *
  256. * \ingroup group__backend__stock_backends__file
  257. */
  258. PANTHEIOS_CALL(int) pantheios_be_file_init(
  259. PAN_CHAR_T const* processIdentity
  260. , int id
  261. , pan_be_file_init_t const* init
  262. , void* reserved
  263. , void** ptoken
  264. );
  265. /** Implements the functionality for pantheios_be_uninit() over the file API.
  266. *
  267. * \ingroup group__backend__stock_backends__file
  268. */
  269. PANTHEIOS_CALL(void) pantheios_be_file_uninit(void* token);
  270. /** Implements the functionality for pantheios_be_logEntry() over the file API.
  271. *
  272. * \ingroup group__backend__stock_backends__file
  273. */
  274. PANTHEIOS_CALL(int) pantheios_be_file_logEntry(
  275. void* feToken
  276. , void* beToken
  277. , int severity
  278. , PAN_CHAR_T const* entry
  279. , size_t cchEntry
  280. );
  281. /** \fn pantheios_be_file_setFilePath(PAN_CHAR_T const*, pan_be_file_init_t::pan_uint32_t, pan_be_file_init_t::pan_uint32_t, int)
  282. *
  283. * Sets/changes the log file name for a single back-end.
  284. *
  285. * \ingroup group__backend__stock_backends__file
  286. *
  287. * \param fileName The (absolute or relative) name of the log file to be used
  288. * with the given back-end.
  289. * \param fileMask A bitmask that controls which values of
  290. * the \ref group__backend__stock_backends__file__flags "flags" are to be
  291. * interpreted in the <code>fileFlags</code> parameter.
  292. * \param fileFlags The \ref group__backend__stock_backends__file__flags "flags"
  293. * that control the file creation - only
  294. * \ref PANTHEIOS_BE_FILE_F_TRUNCATE
  295. * is recognised by this function.
  296. * \param backEndId The back-end identifier. If this is
  297. * \ref PANTHEIOS_BEID_ALL,
  298. * then all back-ends will be initialised with the file-name.
  299. *
  300. * \note In the case where you are using
  301. * \link group__backend__stock_backends__file be.file\endlink for both
  302. * local <i>and</i> remote back-ends, specifying \ref PANTHEIOS_BEID_ALL
  303. * will, on most platforms, result in the remote back-end failing to write
  304. * output, because the local back-end will hold an exclusive lock on
  305. * the file.
  306. */
  307. PANTHEIOS_CALL(int) pantheios_be_file_setFilePath(
  308. PAN_CHAR_T const* fileName
  309. #ifndef PANTHEIOS_NO_NAMESPACE
  310. , pan_be_file_init_t::pan_uint32_t fileMask
  311. , pan_be_file_init_t::pan_uint32_t fileFlags
  312. #else /* ? !PANTHEIOS_NO_NAMESPACE */
  313. , pan_uint32_t fileMask
  314. , pan_uint32_t fileFlags
  315. #endif /* !PANTHEIOS_NO_NAMESPACE */
  316. , int backEndId
  317. );
  318. #ifdef __cplusplus
  319. /** \overload int pantheios_be_file_setFilePath(PAN_CHAR_T const*)
  320. *
  321. * Sets/changes the log file name for all back-ends.
  322. *
  323. * \ingroup group__backend__stock_backends__file
  324. *
  325. * \param fileName The (absolute or relative) name of the log file to be used
  326. * with the given back-end.
  327. */
  328. inline int pantheios_be_file_setFilePath(PAN_CHAR_T const* fileName)
  329. {
  330. return pantheios_be_file_setFilePath(fileName, 0, 0, PANTHEIOS_BEID_ALL);
  331. }
  332. /** \overload int pantheios_be_file_setFilePath(PAN_CHAR_T const*, int)
  333. *
  334. * Sets/changes the log file name for all back-ends.
  335. *
  336. * \ingroup group__backend__stock_backends__file
  337. *
  338. * \param fileName The (absolute or relative) name of the log file to be used
  339. * with the given back-end.
  340. * \param backEndId The back-end identifier. If this is
  341. * \ref PANTHEIOS_BEID_ALL,
  342. * then all back-ends will be initialised with the file-name.
  343. */
  344. inline int pantheios_be_file_setFilePath(PAN_CHAR_T const* fileName, int backEndId)
  345. {
  346. return pantheios_be_file_setFilePath(fileName, 0, 0, backEndId);
  347. }
  348. #endif /* __cplusplus */
  349. /** Flushes one/all back-ends.
  350. *
  351. * \ingroup group__backend__stock_backends__file
  352. *
  353. * \param backEndId The back-end identifier. If this is
  354. * \ref PANTHEIOS_BEID_ALL,
  355. * then all back-ends will be flushed.
  356. */
  357. PANTHEIOS_CALL(int) pantheios_be_file_flush(int backEndId);
  358. /** Parses the be.file back-end flags
  359. *
  360. * \ingroup group__backend
  361. *
  362. * Processes an argument list in the same way as
  363. * pantheios_be_parseStockArgs(), filling out the
  364. * pan_be_COMErrorObject_init_t in accordance with the arguments
  365. * found.
  366. *
  367. * Recognises the following standard argument names:
  368. * - "showProcessId" (Boolean)
  369. * - "showTime" (Boolean)
  370. * - "showSeverity" (Boolean)
  371. * - "useSystemTime" (Boolean)
  372. * - "showDetailsAtStart" (Boolean)
  373. * - "useUnixFormat" (Boolean)
  374. * - "showDate" (Boolean)
  375. * - "showTime" (Boolean)
  376. * - "highResolution" (Boolean)
  377. * - "lowResolution" (Boolean)
  378. *
  379. * Recognises the following back-end specific argument names:
  380. * - "fileName" (String)
  381. * - "truncate" (Boolean)
  382. * - "discardCachedContents" (Boolean)
  383. * - "writeMultibyteContents" (Boolean)
  384. * - "writeWideContents" (Boolean)
  385. */
  386. PANTHEIOS_CALL(int) pantheios_be_file_parseArgs(
  387. size_t numArgs
  388. #ifdef PANTHEIOS_NO_NAMESPACE
  389. , struct pan_slice_t* const args
  390. #else /* ? PANTHEIOS_NO_NAMESPACE */
  391. , pantheios::pan_slice_t* const args
  392. #endif /* PANTHEIOS_NO_NAMESPACE */
  393. , pan_be_file_init_t* init
  394. );
  395. /* ////////////////////////////////////////////////////////////////////// */
  396. #ifdef __cplusplus
  397. # ifndef PANTHEIOS_BE_INIT_NO_CPP_STRUCT_INIT
  398. inline pan_be_file_init_t::pan_be_file_init_t()
  399. {
  400. pantheios_be_file_getDefaultAppInit(this);
  401. }
  402. # endif /* !PANTHEIOS_BE_INIT_NO_CPP_STRUCT_INIT */
  403. #endif /* __cplusplus */
  404. /* ////////////////////////////////////////////////////////////////////// */
  405. #endif /* PANTHEIOS_INCL_PANTHEIOS_BACKENDS_H_BEC_FILE */
  406. /* ///////////////////////////// end of file //////////////////////////// */