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.

125 lines
3.7 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: examples/cpp/backends/example.cpp.backends.mx.2/example.cpp.backends.mx.2.cpp
  3. *
  4. * Purpose: Implementation file for the example.cpp.backends.mx.2 project.
  5. *
  6. * Created: 19th September 2008
  7. * Updated: 11th December 2010
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * Copyright (c) 2008-2010, Synesis Software Pty Ltd.
  14. * All rights reserved.
  15. *
  16. * www: http://www.synesis.com.au/software
  17. *
  18. * ////////////////////////////////////////////////////////////////////// */
  19. #define PANTHEIOS_NO_INCLUDE_OS_AND_3PTYLIB_STRING_ACCESS // Faster compilation
  20. /* Pantheios Header Files */
  21. #include <pantheios/pantheios.hpp>
  22. #include <pantheios/inserters/args.hpp>
  23. #include <pantheios/frontends/fe.simple.h>
  24. #include <pantheios/backends/be.N.h>
  25. #include <platformstl/platformstl.h>
  26. #if defined(PLATFORMSTL_OS_IS_UNIX)
  27. # include <pantheios/backends/bec.fprintf.h>
  28. # include <pantheios/backends/bec.syslog.h>
  29. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  30. # include <pantheios/backends/bec.WindowsConsole.h>
  31. # include <pantheios/backends/bec.WindowsSyslog.h>
  32. #else /* ? OS */
  33. # error Platform not discriminated
  34. #endif /* OS */
  35. /* STLSoft Header Files */
  36. #include <stlsoft/stlsoft.h>
  37. /* Standard C++ Header Files */
  38. #include <exception>
  39. /* Standard C Header Files */
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. /* /////////////////////////////////////////////////////////////////////////
  43. * Globals
  44. */
  45. extern "C" const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.cpp.backends.mx.2");
  46. /* ////////////////////////////////////////////////////////////////////// */
  47. #define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
  48. /* /////////////////////////////////////////////////////////////////////////
  49. * Logging management
  50. */
  51. enum
  52. {
  53. beid_Console = 1,
  54. beid_Syslog = 2
  55. };
  56. pan_be_N_t PAN_BE_N_BACKEND_LIST[] =
  57. {
  58. #if defined(PLATFORMSTL_OS_IS_UNIX)
  59. PANTHEIOS_BE_N_STDFORM_ENTRY(beid_Console, pantheios_be_fprintf, PANTHEIOS_BE_N_F_IGNORE_NONMATCHED_CUSTOM28_ID),
  60. PANTHEIOS_BE_N_STDFORM_ENTRY(beid_Syslog, pantheios_be_syslog, PANTHEIOS_BE_N_F_ID_MUST_MATCH_CUSTOM28),
  61. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  62. PANTHEIOS_BE_N_STDFORM_ENTRY(beid_Console, pantheios_be_WindowsConsole, PANTHEIOS_BE_N_F_IGNORE_NONMATCHED_CUSTOM28_ID),
  63. PANTHEIOS_BE_N_STDFORM_ENTRY(beid_Syslog, pantheios_be_WindowsSyslog, PANTHEIOS_BE_N_F_ID_MUST_MATCH_CUSTOM28),
  64. #else /* ? OS */
  65. # error Platform not discriminated
  66. #endif /* OS */
  67. PANTHEIOS_BE_N_TERMINATOR_ENTRY
  68. };
  69. /* ////////////////////////////////////////////////////////////////////// */
  70. static int main_(int argc, char** argv)
  71. {
  72. // This goes only to debugger
  73. #ifndef PANTHEIOS_USE_WIDE_STRINGS
  74. pantheios::log_NOTICE(PSTR("main("), pantheios::args(argc, argv), PSTR(")"));
  75. #else /* ? !PANTHEIOS_USE_WIDE_STRINGS */
  76. STLSOFT_SUPPRESS_UNUSED(argc); STLSOFT_SUPPRESS_UNUSED(argv);
  77. #endif /* !PANTHEIOS_USE_WIDE_STRINGS */
  78. // This goes to console and debugger
  79. pantheios::log(pantheios::notice(beid_Syslog), PSTR("Isn't targeted multiplexing great?!"));
  80. return EXIT_SUCCESS;
  81. }
  82. int main(int argc, char** argv)
  83. {
  84. try
  85. {
  86. return main_(argc, argv);
  87. }
  88. catch(std::bad_alloc&)
  89. {
  90. pantheios::log(pantheios::alert, PSTR("out of memory"));
  91. }
  92. catch(std::exception& x)
  93. {
  94. pantheios::log_CRITICAL(PSTR("Exception: "), x);
  95. }
  96. catch(...)
  97. {
  98. pantheios::logputs(pantheios::emergency, PSTR("Unhandled unknown error"));
  99. }
  100. return EXIT_FAILURE;
  101. }
  102. /* ///////////////////////////// end of file //////////////////////////// */