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.

145 lines
5.4 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/util/severity/WindowsEventLog.h
  3. *
  4. * Purpose: Translations from Pantheios stock severity to Windows Event
  5. * Log type.
  6. *
  7. * Created: 13th November 2007
  8. * Updated: 14th February 2010
  9. *
  10. * Home: http://www.pantheios.org/
  11. *
  12. * Copyright (c) 2007-2010, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are
  17. * met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  25. * names of any contributors may be used to endorse or promote products
  26. * derived from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file pantheios/util/severity/WindowsEventLog.h
  42. *
  43. * [C, C++] Translations from Pantheios stock severity to Windows Event Log
  44. * type.
  45. */
  46. #ifndef PANTHEIOS_INCL_PANTHEIOS_UTIL_SEVERITY_H_WINDOWSEVENTLOG
  47. #define PANTHEIOS_INCL_PANTHEIOS_UTIL_SEVERITY_H_WINDOWSEVENTLOG
  48. /* /////////////////////////////////////////////////////////////////////////
  49. * Version information
  50. */
  51. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  52. # define PANTHEIOS_VER_PANTHEIOS_UTIL_SEVERITY_H_WINDOWSEVENTLOG_MAJOR 1
  53. # define PANTHEIOS_VER_PANTHEIOS_UTIL_SEVERITY_H_WINDOWSEVENTLOG_MINOR 2
  54. # define PANTHEIOS_VER_PANTHEIOS_UTIL_SEVERITY_H_WINDOWSEVENTLOG_REVISION 2
  55. # define PANTHEIOS_VER_PANTHEIOS_UTIL_SEVERITY_H_WINDOWSEVENTLOG_EDIT 15
  56. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  57. /* /////////////////////////////////////////////////////////////////////////
  58. * Includes
  59. */
  60. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  61. # include <pantheios/pantheios.h>
  62. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  63. #ifndef PANTHEIOS_INCL_PANTHEIOS_QUALITY_H_CONTRACT
  64. # include <pantheios/quality/contract.h>
  65. #endif /* !PANTHEIOS_INCL_PANTHEIOS_QUALITY_H_CONTRACT */
  66. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  67. # include <winstl/winstl.h>
  68. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  69. /* /////////////////////////////////////////////////////////////////////////
  70. * Namespace
  71. */
  72. #if !defined(PANTHEIOS_NO_NAMESPACE)
  73. namespace pantheios
  74. {
  75. #endif /* !PANTHEIOS_NO_NAMESPACE */
  76. /* /////////////////////////////////////////////////////////////////////////
  77. * Functions
  78. */
  79. /** Converts a Pantheios severity level to a Windows Event Log event type
  80. *
  81. * \param severity The Pantheios \link pantheios::pan_severity_t severity level\endlink
  82. *
  83. * \return The Windows Event Log event type
  84. */
  85. #ifdef __cplusplus
  86. inline
  87. #else /* ? __cplusplus */
  88. static
  89. #endif /* __cplusplus */
  90. WORD pantheios_severity_to_WindowsEventLog_type(int severity)
  91. {
  92. WORD type;
  93. PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API((severity >= 0 && severity < 16), "invalid severity");
  94. switch(severity)
  95. {
  96. case PANTHEIOS_SEV_EMERGENCY: type = EVENTLOG_ERROR_TYPE; break;
  97. case PANTHEIOS_SEV_ALERT: type = EVENTLOG_ERROR_TYPE; break;
  98. case PANTHEIOS_SEV_CRITICAL: type = EVENTLOG_ERROR_TYPE; break;
  99. case PANTHEIOS_SEV_ERROR: type = EVENTLOG_ERROR_TYPE; break;
  100. case PANTHEIOS_SEV_WARNING: type = EVENTLOG_WARNING_TYPE; break;
  101. case PANTHEIOS_SEV_NOTICE: type = EVENTLOG_INFORMATION_TYPE; break;
  102. case PANTHEIOS_SEV_INFORMATIONAL: type = EVENTLOG_INFORMATION_TYPE; break;
  103. default:
  104. case PANTHEIOS_SEV_DEBUG: type = EVENTLOG_INFORMATION_TYPE; break;
  105. }
  106. return type;
  107. }
  108. /* /////////////////////////////////////////////////////////////////////////
  109. * Namespace
  110. */
  111. #if !defined(PANTHEIOS_NO_NAMESPACE)
  112. } /* namespace pantheios */
  113. #endif /* !PANTHEIOS_NO_NAMESPACE */
  114. /* /////////////////////////////////////////////////////////////////////////
  115. * Inclusion
  116. */
  117. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  118. # pragma once
  119. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  120. /* ////////////////////////////////////////////////////////////////////// */
  121. #endif /* !PANTHEIOS_INCL_PANTHEIOS_UTIL_SEVERITY_H_WINDOWSEVENTLOG */
  122. /* ///////////////////////////// end of file //////////////////////////// */