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.

243 lines
8.3 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/inserters/processid.hpp
  3. *
  4. * Purpose: String inserter for process identity.
  5. *
  6. * Created: 16th October 2006
  7. * Updated: 14th February 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/inserters/processid.hpp
  41. *
  42. * [C++ only] String inserter for process identity.
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_PROCESSID
  45. #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_PROCESSID
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_PROCESSID_MAJOR 2
  51. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_PROCESSID_MINOR 2
  52. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_PROCESSID_REVISION 3
  53. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_PROCESSID_EDIT 19
  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_INSERTERS_HPP_FMT
  62. # include <pantheios/inserters/fmt.hpp>
  63. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_FMT */
  64. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
  65. # include <stlsoft/shims/access/string/fwd.h>
  66. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
  67. /* /////////////////////////////////////////////////////////////////////////
  68. * Namespace
  69. */
  70. #if !defined(PANTHEIOS_NO_NAMESPACE)
  71. namespace pantheios
  72. {
  73. #endif /* !PANTHEIOS_NO_NAMESPACE */
  74. /* /////////////////////////////////////////////////////////////////////////
  75. * Typedefs
  76. */
  77. /** Global instance that may be used to insert a process identity into a log
  78. * statement.
  79. *
  80. * \ingroup group__application_layer_interface__inserters
  81. * \code
  82. pantheios::log_NOTICE("process id=", pantheios::processId);
  83. * \endcode
  84. *
  85. * This will produce output such as the following:
  86. \htmlonly
  87. <pre>
  88. <b>process id=2436</b>
  89. </pre>
  90. \endhtmlonly
  91. */
  92. extern struct processId_t const* processId;
  93. /* /////////////////////////////////////////////////////////////////////////
  94. * Worker functions
  95. */
  96. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  97. PANTHEIOS_CALL(pan_char_t const*) pantheios_getCurrentProcessIdString(void);
  98. PANTHEIOS_CALL(size_t) pantheios_getCurrentProcessIdStringLength(void);
  99. PANTHEIOS_CALL_DEPRECATED(pan_char_t const*, pantheios_processId, pantheios_getCurrentProcessIdString) pantheios_processId(void);
  100. PANTHEIOS_CALL_DEPRECATED(size_t, pantheios_processIdLength, pantheios_getCurrentProcessIdStringLength) pantheios_processIdLength(void);
  101. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  102. /* /////////////////////////////////////////////////////////////////////////
  103. * String Access Shims
  104. */
  105. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  106. # if !defined(PANTHEIOS_NO_NAMESPACE)
  107. namespace shims
  108. {
  109. # endif /* !PANTHEIOS_NO_NAMESPACE */
  110. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  111. inline wchar_t const* c_str_data_w(struct processId_t const*)
  112. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  113. inline char const* c_str_data_a(struct processId_t const*)
  114. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  115. {
  116. return pantheios_getCurrentProcessIdString();
  117. }
  118. inline pan_char_t const* c_str_data(struct processId_t const*)
  119. {
  120. return pantheios_getCurrentProcessIdString();
  121. }
  122. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  123. inline size_t c_str_len_w(struct processId_t const*)
  124. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  125. inline size_t c_str_len_a(struct processId_t const*)
  126. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  127. {
  128. return pantheios_getCurrentProcessIdStringLength();
  129. }
  130. inline size_t c_str_len(struct processId_t const*)
  131. {
  132. return pantheios_getCurrentProcessIdStringLength();
  133. }
  134. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  135. inline wchar_t const* c_str_ptr_w(struct processId_t const*)
  136. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  137. inline char const* c_str_ptr_a(struct processId_t const*)
  138. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  139. {
  140. return pantheios_getCurrentProcessIdString();
  141. }
  142. inline pan_char_t const* c_str_ptr(struct processId_t const*)
  143. {
  144. return pantheios_getCurrentProcessIdString();
  145. }
  146. # if !defined(PANTHEIOS_NO_NAMESPACE)
  147. } /* namespace shims */
  148. # if defined(STLSOFT_COMPILER_IS_GCC)
  149. /* GCC does not seem to correctly handle the phases of
  150. * processing of C++ templates, so we need to 'use' the
  151. * shims into the same namespace as the inserter class
  152. * in order that ADL can suffice instead.
  153. */
  154. # ifdef PANTHEIOS_USE_WIDE_STRINGS
  155. using ::pantheios::shims::c_str_data_w;
  156. using ::pantheios::shims::c_str_len_w;
  157. using ::pantheios::shims::c_str_ptr_w;
  158. # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  159. using ::pantheios::shims::c_str_data_a;
  160. using ::pantheios::shims::c_str_len_a;
  161. using ::pantheios::shims::c_str_ptr_a;
  162. # endif /* PANTHEIOS_USE_WIDE_STRINGS */
  163. using ::pantheios::shims::c_str_data;
  164. using ::pantheios::shims::c_str_len;
  165. using ::pantheios::shims::c_str_ptr;
  166. # endif /* compiler */
  167. # endif /* !PANTHEIOS_NO_NAMESPACE */
  168. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  169. /* /////////////////////////////////////////////////////////////////////////
  170. * Namespace
  171. */
  172. #if !defined(PANTHEIOS_NO_NAMESPACE)
  173. } /* namespace pantheios */
  174. namespace stlsoft
  175. {
  176. // 'Export' the string access shims into the STLSoft namespace
  177. //
  178. // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
  179. // defined and exported in order to allow for the case where someone
  180. // may find a legitimate use for the conversion classes additional to
  181. // the type-tunneling of the Pantheios API.
  182. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  183. using ::pantheios::shims::c_str_data_w;
  184. using ::pantheios::shims::c_str_len_w;
  185. using ::pantheios::shims::c_str_ptr_w;
  186. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  187. using ::pantheios::shims::c_str_data_a;
  188. using ::pantheios::shims::c_str_len_a;
  189. using ::pantheios::shims::c_str_ptr_a;
  190. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  191. using ::pantheios::shims::c_str_data;
  192. using ::pantheios::shims::c_str_len;
  193. using ::pantheios::shims::c_str_ptr;
  194. }
  195. #endif /* !PANTHEIOS_NO_NAMESPACE */
  196. /* /////////////////////////////////////////////////////////////////////////
  197. * Inclusion
  198. */
  199. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  200. # pragma once
  201. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  202. /* ////////////////////////////////////////////////////////////////////// */
  203. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_PROCESSID */
  204. /* ///////////////////////////// end of file //////////////////////////// */