event.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright 2010 Vicente J. Botet Escriba
  3. * Copyright 2015, 2017 Andrey Semashev
  4. *
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * See http://www.boost.org/LICENSE_1_0.txt
  7. */
  8. #ifndef BOOST_WINAPI_EVENT_HPP_INCLUDED_
  9. #define BOOST_WINAPI_EVENT_HPP_INCLUDED_
  10. #include <boost/winapi/basic_types.hpp>
  11. #ifdef BOOST_HAS_PRAGMA_ONCE
  12. #pragma once
  13. #endif
  14. #if !defined( BOOST_USE_WINDOWS_H ) && BOOST_WINAPI_PARTITION_APP_SYSTEM
  15. extern "C" {
  16. #if !defined( BOOST_NO_ANSI_APIS )
  17. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  18. CreateEventA(
  19. ::_SECURITY_ATTRIBUTES* lpEventAttributes,
  20. boost::winapi::BOOL_ bManualReset,
  21. boost::winapi::BOOL_ bInitialState,
  22. boost::winapi::LPCSTR_ lpName);
  23. #endif
  24. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  25. CreateEventW(
  26. ::_SECURITY_ATTRIBUTES* lpEventAttributes,
  27. boost::winapi::BOOL_ bManualReset,
  28. boost::winapi::BOOL_ bInitialState,
  29. boost::winapi::LPCWSTR_ lpName);
  30. } // extern "C"
  31. #endif // !defined( BOOST_USE_WINDOWS_H ) && BOOST_WINAPI_PARTITION_APP_SYSTEM
  32. #if !defined( BOOST_USE_WINDOWS_H )
  33. extern "C" {
  34. #if !defined( BOOST_NO_ANSI_APIS )
  35. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  36. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  37. CreateEventExA(
  38. ::_SECURITY_ATTRIBUTES *lpEventAttributes,
  39. boost::winapi::LPCSTR_ lpName,
  40. boost::winapi::DWORD_ dwFlags,
  41. boost::winapi::DWORD_ dwDesiredAccess);
  42. #endif
  43. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  44. OpenEventA(
  45. boost::winapi::DWORD_ dwDesiredAccess,
  46. boost::winapi::BOOL_ bInheritHandle,
  47. boost::winapi::LPCSTR_ lpName);
  48. #endif // !defined( BOOST_NO_ANSI_APIS )
  49. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  50. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  51. CreateEventExW(
  52. ::_SECURITY_ATTRIBUTES *lpEventAttributes,
  53. boost::winapi::LPCWSTR_ lpName,
  54. boost::winapi::DWORD_ dwFlags,
  55. boost::winapi::DWORD_ dwDesiredAccess);
  56. #endif
  57. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  58. OpenEventW(
  59. boost::winapi::DWORD_ dwDesiredAccess,
  60. boost::winapi::BOOL_ bInheritHandle,
  61. boost::winapi::LPCWSTR_ lpName);
  62. // Windows CE define SetEvent/ResetEvent as inline functions in kfuncs.h
  63. #if !defined( UNDER_CE )
  64. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  65. SetEvent(boost::winapi::HANDLE_ hEvent);
  66. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  67. ResetEvent(boost::winapi::HANDLE_ hEvent);
  68. #endif
  69. } // extern "C"
  70. #endif
  71. namespace boost {
  72. namespace winapi {
  73. #if !defined( BOOST_NO_ANSI_APIS )
  74. using ::OpenEventA;
  75. #endif
  76. using ::OpenEventW;
  77. using ::SetEvent;
  78. using ::ResetEvent;
  79. #if defined( BOOST_USE_WINDOWS_H )
  80. BOOST_CONSTEXPR_OR_CONST DWORD_ EVENT_ALL_ACCESS_ = EVENT_ALL_ACCESS;
  81. BOOST_CONSTEXPR_OR_CONST DWORD_ EVENT_MODIFY_STATE_ = EVENT_MODIFY_STATE;
  82. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  83. BOOST_CONSTEXPR_OR_CONST DWORD_ CREATE_EVENT_INITIAL_SET_ = CREATE_EVENT_INITIAL_SET;
  84. BOOST_CONSTEXPR_OR_CONST DWORD_ CREATE_EVENT_MANUAL_RESET_ = CREATE_EVENT_MANUAL_RESET;
  85. #endif
  86. #else // defined( BOOST_USE_WINDOWS_H )
  87. BOOST_CONSTEXPR_OR_CONST DWORD_ EVENT_ALL_ACCESS_ = 0x001F0003;
  88. BOOST_CONSTEXPR_OR_CONST DWORD_ EVENT_MODIFY_STATE_ = 0x00000002;
  89. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  90. BOOST_CONSTEXPR_OR_CONST DWORD_ CREATE_EVENT_INITIAL_SET_ = 0x00000002;
  91. BOOST_CONSTEXPR_OR_CONST DWORD_ CREATE_EVENT_MANUAL_RESET_ = 0x00000001;
  92. #endif
  93. #endif // defined( BOOST_USE_WINDOWS_H )
  94. // Undocumented and not present in Windows SDK. Enables NtQueryEvent.
  95. // http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FNT%20Objects%2FEvent%2FNtQueryEvent.html
  96. BOOST_CONSTEXPR_OR_CONST DWORD_ EVENT_QUERY_STATE_ = 0x00000001;
  97. BOOST_CONSTEXPR_OR_CONST DWORD_ event_all_access = EVENT_ALL_ACCESS_;
  98. BOOST_CONSTEXPR_OR_CONST DWORD_ event_modify_state = EVENT_MODIFY_STATE_;
  99. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  100. BOOST_CONSTEXPR_OR_CONST DWORD_ create_event_initial_set = CREATE_EVENT_INITIAL_SET_;
  101. BOOST_CONSTEXPR_OR_CONST DWORD_ create_event_manual_reset = CREATE_EVENT_MANUAL_RESET_;
  102. #endif
  103. #if !defined( BOOST_NO_ANSI_APIS )
  104. BOOST_FORCEINLINE HANDLE_ CreateEventA(SECURITY_ATTRIBUTES_* lpEventAttributes, BOOL_ bManualReset, BOOL_ bInitialState, LPCSTR_ lpName)
  105. {
  106. #if !BOOST_WINAPI_PARTITION_APP_SYSTEM && BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  107. const DWORD_ flags = (bManualReset ? create_event_manual_reset : 0u) | (bInitialState ? create_event_initial_set : 0u);
  108. return ::CreateEventExA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpEventAttributes), lpName, flags, event_all_access);
  109. #else
  110. return ::CreateEventA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpEventAttributes), bManualReset, bInitialState, lpName);
  111. #endif
  112. }
  113. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  114. BOOST_FORCEINLINE HANDLE_ CreateEventExA(SECURITY_ATTRIBUTES_* lpEventAttributes, LPCSTR_ lpName, DWORD_ dwFlags, DWORD_ dwDesiredAccess)
  115. {
  116. return ::CreateEventExA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpEventAttributes), lpName, dwFlags, dwDesiredAccess);
  117. }
  118. #endif
  119. #endif
  120. BOOST_FORCEINLINE HANDLE_ CreateEventW(SECURITY_ATTRIBUTES_* lpEventAttributes, BOOL_ bManualReset, BOOL_ bInitialState, LPCWSTR_ lpName)
  121. {
  122. #if !BOOST_WINAPI_PARTITION_APP_SYSTEM && BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  123. const DWORD_ flags = (bManualReset ? create_event_manual_reset : 0u) | (bInitialState ? create_event_initial_set : 0u);
  124. return ::CreateEventExW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpEventAttributes), lpName, flags, event_all_access);
  125. #else
  126. return ::CreateEventW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpEventAttributes), bManualReset, bInitialState, lpName);
  127. #endif
  128. }
  129. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  130. BOOST_FORCEINLINE HANDLE_ CreateEventExW(SECURITY_ATTRIBUTES_* lpEventAttributes, LPCWSTR_ lpName, DWORD_ dwFlags, DWORD_ dwDesiredAccess)
  131. {
  132. return ::CreateEventExW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpEventAttributes), lpName, dwFlags, dwDesiredAccess);
  133. }
  134. #endif
  135. #if !defined( BOOST_NO_ANSI_APIS )
  136. BOOST_FORCEINLINE HANDLE_ create_event(SECURITY_ATTRIBUTES_* lpEventAttributes, BOOL_ bManualReset, BOOL_ bInitialState, LPCSTR_ lpName)
  137. {
  138. return winapi::CreateEventA(lpEventAttributes, bManualReset, bInitialState, lpName);
  139. }
  140. BOOST_FORCEINLINE HANDLE_ open_event(DWORD_ dwDesiredAccess, BOOL_ bInheritHandle, LPCSTR_ lpName)
  141. {
  142. return ::OpenEventA(dwDesiredAccess, bInheritHandle, lpName);
  143. }
  144. #endif
  145. BOOST_FORCEINLINE HANDLE_ create_event(SECURITY_ATTRIBUTES_* lpEventAttributes, BOOL_ bManualReset, BOOL_ bInitialState, LPCWSTR_ lpName)
  146. {
  147. return winapi::CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpName);
  148. }
  149. BOOST_FORCEINLINE HANDLE_ open_event(DWORD_ dwDesiredAccess, BOOL_ bInheritHandle, LPCWSTR_ lpName)
  150. {
  151. return ::OpenEventW(dwDesiredAccess, bInheritHandle, lpName);
  152. }
  153. BOOST_FORCEINLINE HANDLE_ create_anonymous_event(SECURITY_ATTRIBUTES_* lpEventAttributes, BOOL_ bManualReset, BOOL_ bInitialState)
  154. {
  155. return winapi::CreateEventW(lpEventAttributes, bManualReset, bInitialState, 0);
  156. }
  157. }
  158. }
  159. #endif // BOOST_WINAPI_EVENT_HPP_INCLUDED_