event.hpp 7.2 KB

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