event.hpp 6.9 KB

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