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.

342 lines
12 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.fe/test.scratch.fe.cpp
  3. *
  4. * Purpose: Implementation file for the test.scratch.fe project.
  5. *
  6. * Created: 21st June 2005
  7. * Updated: 6th August 2012
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * www: http://www.synesis.com.au/software
  14. *
  15. * This source code is placed into the public domain 2005
  16. * by Synesis Software Pty Ltd. There are no restrictions
  17. * whatsoever to your use of the software.
  18. *
  19. * This source code is provided by Synesis Software Pty Ltd "as is"
  20. * and any warranties, whether expressed or implied, including, but
  21. * not limited to, the implied warranties of merchantability and
  22. * fitness for a particular purpose are disclaimed. In no event
  23. * shall the Synesis Software Pty Ltd be liable for any direct,
  24. * indirect, incidental, special, exemplary, or consequential
  25. * damages (including, but not limited to, procurement of
  26. * substitute goods or services; loss of use, data, or profits; or
  27. * business interruption) however caused and on any theory of
  28. * liability, whether in contract, strict liability, or tort
  29. * (including negligence or otherwise) arising in any way out of
  30. * the use of this software, even if advised of the possibility of
  31. * such damage.
  32. *
  33. * Neither the name of Synesis Software Pty Ltd nor the names of
  34. * any subdivisions, employees or agents of Synesis Software Pty
  35. * Ltd, nor the names of any other contributors to this software
  36. * may be used to endorse or promote products derived from this
  37. * software without specific prior written permission.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. #define PANTHEIOS_NO_INCLUDE_OS_AND_3PTYLIB_STRING_ACCESS
  41. /* This inclusion required for suppressing warnings during NoX (No eXception-support) configurations. */
  42. #include <pantheios/util/test/compiler_warnings_suppression.first_include.h>
  43. /* Pantheios Header Files */
  44. #include <pantheios/pantheios.hpp>
  45. #include <pantheios/inserters/integer.hpp>
  46. #include <pantheios/inserters/pointer.hpp>
  47. #include <pantheios/inserters/real.hpp>
  48. #include <pantheios/backend.h>
  49. #include <pantheios/frontend.h>
  50. #include <pantheios/quality/contract.h>
  51. /* STLSoft Header Files */
  52. #include <stlsoft/stlsoft.h>
  53. /* Standard C++ Header Files */
  54. #include <exception>
  55. #include <iostream>
  56. #include <string>
  57. using std::cerr;
  58. using std::cin;
  59. using std::cout;
  60. using std::endl;
  61. /* Standard C Header Files */
  62. #include <stdio.h>
  63. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  64. /* /////////////////////////////////////////////////////////////////////////
  65. * Forward declarations
  66. */
  67. #if ( defined(_WIN32) || \
  68. defined(_WIN64)) && \
  69. !defined(_INC_WINDOWS)
  70. extern "C" void __stdcall Sleep(unsigned long);
  71. #endif /* WIN32 */
  72. /* /////////////////////////////////////////////////////////////////////////
  73. * Globals
  74. */
  75. static int severities[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
  76. /* ////////////////////////////////////////////////////////////////////// */
  77. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  78. int main()
  79. {
  80. return 0;
  81. }
  82. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  83. /* ////////////////////////////////////////////////////////////////////// */
  84. //static void call_all_severities();
  85. static void call_all_severities()
  86. {
  87. pantheios::log_DEBUG("I'm so gorgeous, there's a six month waiting list for birds to suddenly appear, every time I am near!");
  88. pantheios::log_INFORMATIONAL("Your nickname was never Ace. Maybe Ace Hole.");
  89. pantheios::log_NOTICE("Please rush me my portable walrus polishing kit. Four super brushes that will clean even the trickiest of seabound mammals.");
  90. pantheios::log_WARNING("Now kindly cluck off, before I extract your gibblets, and shove a large seasoned onion between the lips you never kiss with.");
  91. pantheios::log_ERROR("So this is really me? A no-style gimbo with teeth druids could use as a place of worship?");
  92. pantheios::log_CRITICAL("Well, the thing about a black hole - it's main distinguishing feature - is it's black. And the thing about space, your basic space colour is black. So how are you supposed to see them?");
  93. pantheios::log_ALERT("You actually expect something to go right for me? Arnold schmucko Rimmer? Tosspot by royal appointment?");
  94. pantheios::log_EMERGENCY("Emergency, there's an emergency going on, it's still going on, it's still an emergency");
  95. }
  96. static int main_(int /* argc */, char ** /*argv*/)
  97. {
  98. #if defined(_DEBUG)
  99. {
  100. using namespace pantheios;
  101. short s = 123;
  102. int i = 456;
  103. long l = 789;
  104. float f = static_cast<float>(0.123);
  105. double d = 0.456;
  106. long double ld = 0.789;
  107. void *p = &l;
  108. #if 0
  109. char const *lstr = "{a pointer to a C-style string}";
  110. std::string str = "{an instance of std::string}";
  111. stlsoft::simple_string sstr = "{an instance of stlsoft::simple_string}";
  112. #if defined(PLATFORMSTL_OS_IS_WINDOWS)
  113. SYSTEMTIME tm = GetCurrentTime_SYSTEMTIME();
  114. #else /* ? PLATFORMSTL_OS_IS_???? */
  115. struct tm const *tm = GetCurrentTime_tm();
  116. #endif /* PLATFORMSTL_OS_IS_???? */
  117. #endif /* 0 */
  118. #if 0
  119. log_INFORMATIONAL("This is a (hopefully) typical error string, containing: "
  120. , "some integers (", integer(s), ", ", integer(i), ", ", integer(l), "); "
  121. , "some real numbers (", real(f), ", ", real(d), ", ", real(ld), "); "
  122. , "a pointer (", pointer(p, fmt::hex), "); "
  123. , "some strings (", lstr, ", ", str, ", ", sstr, "); "
  124. , "and a converted time value (", tm, ")"
  125. );
  126. #else /* ? 0 */
  127. log_INFORMATIONAL(
  128. "Integers (", integer(s, 4 | fmt::zeroPad), ", ", integer(i), ", ", integer(l), "); "
  129. , "floating points (", real(f), ", ", real(d), ", ", real(ld), "); "
  130. , "and a pointer (", pointer(p, fmt::hex | fmt::zeroXPrefix), ")");
  131. #endif /* 0 */
  132. }
  133. # if defined(PLATFORMSTL_OS_IS_WINDOWS)
  134. {
  135. VARIANT var;
  136. ::VariantInit(&var);
  137. var.vt = VT_I4;
  138. var.lVal = 12345678;
  139. HWND hwnd = ::GetDesktopWindow();
  140. pantheios::log_INFORMATIONAL("v=", var, "; h=", hwnd);
  141. }
  142. # endif /* PLATFORMSTL_OS_IS_WIN?? */
  143. #endif
  144. cout << endl << "Output with all severity levels on:" << endl;
  145. call_all_severities();
  146. cout << endl << "Output after switching off PANTHEIOS_SEV_CRITICAL:" << endl;
  147. severities[PANTHEIOS_SEV_CRITICAL] = 0;
  148. call_all_severities();
  149. cout << endl << "Output after switching off PANTHEIOS_SEV_DEBUG:" << endl;
  150. severities[PANTHEIOS_SEV_DEBUG] = 0;
  151. call_all_severities();
  152. cout << endl << "Output after switching off PANTHEIOS_SEV_WARNING:" << endl;
  153. severities[PANTHEIOS_SEV_WARNING] = 0;
  154. call_all_severities();
  155. cout << endl << "Output after switching off PANTHEIOS_SEV_INFORMATIONAL:" << endl;
  156. severities[PANTHEIOS_SEV_INFORMATIONAL] = 0;
  157. call_all_severities();
  158. cout << endl << "Output after switching off PANTHEIOS_SEV_ERROR:" << endl;
  159. severities[PANTHEIOS_SEV_ERROR] = 0;
  160. call_all_severities();
  161. cout << endl << "Output after switching off PANTHEIOS_SEV_EMERGENCY:" << endl;
  162. severities[PANTHEIOS_SEV_EMERGENCY] = 0;
  163. call_all_severities();
  164. cout << endl << "Output after switching off PANTHEIOS_SEV_ALERT:" << endl;
  165. severities[PANTHEIOS_SEV_ALERT] = 0;
  166. call_all_severities();
  167. cout << endl << "Output after switching off PANTHEIOS_SEV_NOTICE:" << endl;
  168. severities[PANTHEIOS_SEV_NOTICE] = 0;
  169. call_all_severities();
  170. cout << endl << "Output complete" << endl;
  171. return 0;
  172. }
  173. int main(int argc, char *argv[])
  174. {
  175. #if 0
  176. for(;;) {}
  177. #endif /* 0 */
  178. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  179. try
  180. {
  181. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  182. return main_(argc, argv);
  183. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  184. }
  185. catch(std::exception &x)
  186. {
  187. fprintf(stderr, "Unhandled error: %s\n", x.what());
  188. }
  189. catch(...)
  190. {
  191. pantheios::logputs(pantheios::emergency, "Unhandled unknown error");
  192. }
  193. return EXIT_FAILURE;
  194. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  195. }
  196. /* ////////////////////////////////////////////////////////////////////// */
  197. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  198. /* ////////////////////////////////////////////////////////////////////// */
  199. void* const BACKEND_TOKEN_VALUE = NULL;
  200. PANTHEIOS_CALL(int) pantheios_be_init(
  201. PAN_CHAR_T const* processIdentity
  202. , void* reserved
  203. , void** ptoken
  204. )
  205. {
  206. STLSOFT_SUPPRESS_UNUSED(reserved);
  207. PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(NULL != ptoken, "token pointer may not be null");
  208. *ptoken = BACKEND_TOKEN_VALUE;
  209. // Normally one would likely not seek to do anything at this point, since
  210. // it's *very* early in the process initialisation, and the raison d'etre
  211. // of Pantheios is to be the output library! ;-)
  212. //
  213. // However, for pedagogical purposes in this case, we seek to print out the
  214. // initialisation criteria.
  215. //
  216. // But this illustrates an important point: we can't use use IOStreams,
  217. // because some libraries are not initialised by this point and the process
  218. // actually crashes.
  219. //
  220. // So, _if_ you seek to do some output you should bear in mind the very
  221. // early nature of this call and, at most, use the C streams. (Even better
  222. // would be to use underlying OS calls, e.g. ::write() or
  223. // ::OutputDebugString().
  224. ::fprintf(stdout, "Pantheios initialised (%s, %p)\n", processIdentity, reserved);
  225. // cout << "Pantheios initialised (" << processIdentity << ", " << reserved << ")" << endl;
  226. return 0;
  227. }
  228. PANTHEIOS_CALL(void) pantheios_be_uninit(void *token)
  229. {
  230. PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(BACKEND_TOKEN_VALUE == token, "back-end token is not expected value");
  231. ::fprintf(stdout, "Pantheios uninitialised (%p)\n", token);
  232. // cout << "Pantheios uninitialised (" << token << ")" << endl;
  233. }
  234. PANTHEIOS_CALL(int) pantheios_be_logEntry(
  235. void* feToken
  236. , void* beToken
  237. , int severity
  238. , PAN_CHAR_T const* entry
  239. , size_t /* cchEntry */
  240. )
  241. {
  242. PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(BACKEND_TOKEN_VALUE == beToken, "back-end token is not expected value");
  243. STLSOFT_SUPPRESS_UNUSED(feToken);
  244. STLSOFT_SUPPRESS_UNUSED(beToken);
  245. cout << "Pantheios log entry [" << severity << ": " << pantheios::pantheios_getSeverityString(static_cast<pantheios::pan_sev_t>(severity)) << "]: " << entry << endl;
  246. return 0;
  247. }
  248. /* ////////////////////////////////////////////////////////////////////// */
  249. PANTHEIOS_CALL(int) pantheios_fe_init(
  250. void* reserved
  251. , void** ptoken
  252. )
  253. {
  254. STLSOFT_SUPPRESS_UNUSED(reserved);
  255. STLSOFT_SUPPRESS_UNUSED(ptoken);
  256. return 0;
  257. }
  258. PANTHEIOS_CALL(void) pantheios_fe_uninit(void *token)
  259. {
  260. STLSOFT_SUPPRESS_UNUSED(token);
  261. }
  262. PANTHEIOS_CALL(PAN_CHAR_T const*) pantheios_fe_getProcessIdentity(void *token)
  263. {
  264. STLSOFT_SUPPRESS_UNUSED(token);
  265. return PANTHEIOS_LITERAL_STRING("panetheios::test.scratch.fe");
  266. }
  267. PANTHEIOS_CALL(int) pantheios_fe_isSeverityLogged(void *token, int severity, int backEndId)
  268. {
  269. STLSOFT_SUPPRESS_UNUSED(token);
  270. STLSOFT_SUPPRESS_UNUSED(backEndId);
  271. return severities[severity];
  272. }
  273. /* ///////////////////////////// end of file //////////////////////////// */