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.

166 lines
4.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.be.N.with.custom.fe/test.scratch.be.N.with.custom.fe.cpp
  3. *
  4. * Purpose: Implementation file for the test.scratch.be.N.with.custom.fe project.
  5. *
  6. * Created: 23rd December 2010
  7. * Updated: 6th August 2012
  8. *
  9. * Thanks: To wassime, for submitting the original program definition.
  10. *
  11. * Status: Wizard-generated
  12. *
  13. * License: (Licensed under the Synesis Software Open License)
  14. *
  15. * Copyright (c) 2010-2012, Synesis Software Pty Ltd.
  16. * All rights reserved.
  17. *
  18. * www: http://www.synesis.com.au/software
  19. *
  20. * ////////////////////////////////////////////////////////////////////// */
  21. #define PANTHEIOS_NO_INCLUDE_OS_AND_3PTYLIB_STRING_ACCESS
  22. /* Pantheios Header Files */
  23. #include <pantheios/pan.hpp>
  24. #include <pantheios/backends/be.N.h>
  25. #include <pantheios/backends/bec.file.h>
  26. #include <pantheios/backends/bec.console.h>
  27. #include <pantheios/frontend.h>
  28. /* STLSoft Header Files */
  29. #include <stlsoft/stlsoft.h>
  30. #include <platformstl/platformstl.hpp>
  31. /* Standard C++ Header Files */
  32. #include <exception>
  33. #include <iostream>
  34. /* Standard C Header Files */
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. /* /////////////////////////////////////////////////////////////////////////
  38. * Macros and definitions
  39. */
  40. #define WG_LOG_FILE_ID 1
  41. #define WG_LOG_CONSOLE_ID 2
  42. #define WG_LOG_FILE_ERROR_ID 3
  43. namespace
  44. {
  45. static int iCeilingConsole = PANTHEIOS_SEV_DEBUG;
  46. static int iCeilingMain = PANTHEIOS_SEV_NOTICE;
  47. static int iCeilingError = PANTHEIOS_SEV_ERROR;
  48. } /* anonymous namespace */
  49. /* /////////////////////////////////////////////////////////////////////////
  50. * Globals
  51. */
  52. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.be.N.with.custom.fe");
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * main()
  55. */
  56. static int main_(int /* argc */, char** /*argv*/)
  57. {
  58. pantheios_be_file_setFilePath("normal.log", 0, 0, WG_LOG_FILE_ID);
  59. pantheios_be_file_setFilePath("error.log", 0, 0, WG_LOG_FILE_ERROR_ID);
  60. pantheios::log_WARNING("hello there all of you");
  61. pantheios::log_NOTICE("hello there console and main log");
  62. pantheios::log_DEBUG("hello there console");
  63. return EXIT_SUCCESS;
  64. }
  65. int main(int argc, char** argv)
  66. {
  67. try
  68. {
  69. return main_(argc, argv);
  70. }
  71. catch(std::exception& x)
  72. {
  73. pantheios::log_ALERT("Unexpected general error: ", x, ". Application terminating");
  74. }
  75. catch(...)
  76. {
  77. pantheios::logputs(pantheios::emergency, "Unhandled unknown error");
  78. }
  79. return EXIT_FAILURE;
  80. }
  81. /* /////////////////////////////////////////////////////////////////////////
  82. * Back-end configuration
  83. */
  84. pan_be_N_t PAN_BE_N_BACKEND_LIST[] =
  85. {
  86. PANTHEIOS_BE_N_STDFORM_ENTRY(WG_LOG_CONSOLE_ID, pantheios_be_console, 0),
  87. PANTHEIOS_BE_N_STDFORM_ENTRY(WG_LOG_FILE_ID, pantheios_be_file, 0),
  88. PANTHEIOS_BE_N_STDFORM_ENTRY(WG_LOG_FILE_ERROR_ID, pantheios_be_file, 0),
  89. PANTHEIOS_BE_N_TERMINATOR_ENTRY
  90. };
  91. /* /////////////////////////////////////////////////////////////////////////
  92. * Custom front-end
  93. */
  94. PANTHEIOS_CALL(int) pantheios_fe_init( void*,void** ptoken)
  95. {
  96. *ptoken = NULL;
  97. return 0;
  98. }
  99. PANTHEIOS_CALL(void) pantheios_fe_uninit(void*)
  100. {}
  101. PANTHEIOS_CALL(PAN_CHAR_T const*) pantheios_fe_getProcessIdentity(void*)
  102. {
  103. return "BE.N.Experimenting";
  104. }
  105. PANTHEIOS_CALL(int) pantheios_fe_isSeverityLogged(void*, int severity, int beid)
  106. {
  107. switch(beid)
  108. {
  109. // Must handle PANTHEIOS_BEID_ALL, as that's the Application Layer's
  110. // (initial) enquiry as to whether anything should be logged at all
  111. case PANTHEIOS_BEID_ALL:
  112. #if 0
  113. // The inefficient way to do this is to just 'return true'
  114. return true;
  115. #else /* ? 0 */
  116. // The efficient (but complicated) way to do this is to see if
  117. // *any* back-end wants output, in which case we say yes
  118. return severity <= iCeilingMain ||
  119. severity <= iCeilingConsole ||
  120. severity <= iCeilingError;
  121. #endif /* 0 */
  122. // Now handle each specified back-end, which will come from be.N
  123. // multiplexing the output(s)
  124. case WG_LOG_FILE_ID:
  125. return severity <= iCeilingMain;
  126. case WG_LOG_CONSOLE_ID:
  127. return severity <= iCeilingConsole;
  128. case WG_LOG_FILE_ERROR_ID:
  129. return severity <= iCeilingError;
  130. // Don't know about anything else
  131. default:
  132. PANTHEIOS_CONTRACT_ENFORCE_UNEXPECTED_CONDITION_API("unexpected back-end identifier");
  133. return false;
  134. }
  135. }
  136. /* ///////////////////////////// end of file //////////////////////////// */