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.

195 lines
6.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.be.speech/test.scratch.be.speech.cpp
  3. *
  4. * Purpose: C++ example program for Pantheios. Demonstrates:
  5. *
  6. * - use of custom severity level information for tabbing output
  7. * - definition of a custom back-end that supports tabbed output
  8. * - use of pantheios::logputs() in bail-out conditions
  9. *
  10. * Created: 31st August 2006
  11. * Updated: 6th August 2012
  12. *
  13. * www: http://www.pantheios.org/
  14. *
  15. * License: This source code is placed into the public domain 2006
  16. * by Synesis Software Pty Ltd. There are no restrictions
  17. * whatsoever to your use of the software.
  18. *
  19. * This software is provided "as is", and any warranties,
  20. * express or implied, of any kind and for any purpose, are
  21. * disclaimed.
  22. *
  23. * ////////////////////////////////////////////////////////////////////// */
  24. /* This inclusion required for suppressing warnings during NoX (No eXception-support) configurations. */
  25. #include <pantheios/util/test/compiler_warnings_suppression.first_include.h>
  26. /* Pantheios Header Files */
  27. #include <pantheios/pantheios.hpp>
  28. #include <pantheios/backend.h>
  29. #include <pantheios/implicit_link/core.h>
  30. #include <pantheios/implicit_link/fe.simple.h>
  31. #include <pantheios/implicit_link/be.lrsplit.h>
  32. #include <pantheios/implicit_link/bel.WindowsConsole.h>
  33. #include <pantheios/implicit_link/bec.speech.WithCallback.h>
  34. #include <pantheios/backends/bec.speech.h>
  35. /* Standard C/C++ Header Files */
  36. #include <exception> // for std::exception
  37. #include <string> // for std::string
  38. #include <stdio.h> // for fprintf()
  39. #include <stdlib.h> // for exit codes
  40. #include <string.h> // for memset()
  41. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  42. /* ////////////////////////////////////////////////////////////////////// */
  43. // Define the fe.simple process identity, so that it links when using fe.simple
  44. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.speech");
  45. /* ////////////////////////////////////////////////////////////////////// */
  46. //PANTHEIOS_BE_DEFINE_BE_FUNCTIONS(speech)
  47. PANTHEIOS_BE_DEFINE_BER_FUNCTIONS(speech)
  48. PANTHEIOS_CALL(void) pantheios_be_speech_getAppInit(int backEndId, pan_be_speech_init_t* init) /* throw() */
  49. {
  50. // init->flags |= PANTHEIOS_BE_SPEECH_F_SYNCHRONOUS;
  51. // init->flags |= PANTHEIOS_BE_SPEECH_F_PURGE_BEFORE_SPEAK;
  52. // init->flags |= PANTHEIOS_BE_SPEECH_F_SPEAK_PUNCTUATION;
  53. // init->flags |= PANTHEIOS_BE_SPEECH_F_SYNCHRONOUS_ON_CRITICAL;
  54. }
  55. /* ////////////////////////////////////////////////////////////////////// */
  56. int main()
  57. {
  58. DWORD shortPause = 1250;
  59. try
  60. {
  61. // pantheios::log(pantheios::notice, "Hello");
  62. // ::Sleep(shortPause);
  63. // pantheios::log(pantheios::notice(2), "Hello");
  64. // ::Sleep(shortPause);
  65. // pantheios::log(pantheios::notice(2), "Hello, boys. This is your daddy, telling you to turn around and eat your dinner. Now!");
  66. // ::Sleep(shortPause);
  67. short s = SHRT_MIN;
  68. unsigned short us = USHRT_MAX;
  69. int i = INT_MIN;
  70. unsigned int ui = UINT_MAX;
  71. long l = LONG_MIN;
  72. unsigned long ul = ULONG_MAX;
  73. #if 0
  74. // Log a short in decimal; Output: "s: [-32768]"
  75. pantheios::log_NOTICE("s: [", pantheios::integer(s), "]");
  76. ::Sleep(shortPause);
  77. // Log a unsigned short as hexadecimal; Output: "us: [ffff]"
  78. pantheios::log_NOTICE("us: [", pantheios::integer(us, pantheios::fmt::hex), "]");
  79. ::Sleep(shortPause);
  80. // Log an int, into a width of 20; Output: "i: [-2147483648 ]"
  81. pantheios::log_NOTICE("i: [", pantheios::integer(i, -20), "]");
  82. ::Sleep(shortPause);
  83. // Log an unsigned int as hexadecimal with 0x prefix; Output: "ui: [0xffffffff]"
  84. pantheios::log_NOTICE("ui: [", pantheios::integer(ui, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix), "]");
  85. ::Sleep(shortPause);
  86. // Log a long; Output: "l: [ -2147483648]"
  87. pantheios::log_NOTICE("l: [", pantheios::integer(l, 20), "]");
  88. ::Sleep(shortPause);
  89. // Log an unsigned long; Output: "ul: [4294967295]"
  90. pantheios::log_NOTICE("ul: [", pantheios::integer(ul), "]");
  91. ::Sleep(shortPause);
  92. #else /* ? 0 */
  93. pantheios::log_NOTICE("Hi!");
  94. ::Sleep(shortPause);
  95. pantheios::log_NOTICE("This is your logger, calling.");
  96. ::Sleep(shortPause);
  97. pantheios::log_NOTICE("Here come some diagnostic logging statements ...");
  98. ::Sleep(shortPause);
  99. #endif /* 0 */
  100. pantheios::log_DEBUG("just being pedantic");
  101. ::Sleep(shortPause);
  102. pantheios::log_INFORMATIONAL("you can ignore this");
  103. ::Sleep(shortPause);
  104. pantheios::log_NOTICE("this is noteworthy");
  105. ::Sleep(shortPause);
  106. pantheios::log_WARNING("there may be a problem");
  107. ::Sleep(shortPause);
  108. pantheios::log_ERROR("there is a problem");
  109. ::Sleep(shortPause);
  110. pantheios::log_CRITICAL("there is a serious problem");
  111. ::Sleep(shortPause);
  112. pantheios::log_ALERT("there is a very serious problem");
  113. ::Sleep(shortPause);
  114. pantheios::log_EMERGENCY("aargh! I'm operating in contradiction to my design!");
  115. ::Sleep(90000);
  116. return EXIT_SUCCESS;
  117. }
  118. catch(std::bad_alloc &)
  119. {
  120. pantheios::log_CRITICAL("out of memory");
  121. }
  122. catch(std::exception &x)
  123. {
  124. pantheios::log_ALERT("Exception: ", x);
  125. }
  126. catch(...)
  127. {
  128. pantheios::logputs(pantheios::emergency, "Unexpected unknown error");
  129. }
  130. return EXIT_FAILURE;
  131. }
  132. /* ////////////////////////////////////////////////////////////////////// */