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