00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef WINSTL_INCL_WINSTL_SYNCH_HPP_EVENT
00048 #define WINSTL_INCL_WINSTL_SYNCH_HPP_EVENT
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_SYNCH_HPP_EVENT_MAJOR 4
00052 # define WINSTL_VER_WINSTL_SYNCH_HPP_EVENT_MINOR 3
00053 # define WINSTL_VER_WINSTL_SYNCH_HPP_EVENT_REVISION 1
00054 # define WINSTL_VER_WINSTL_SYNCH_HPP_EVENT_EDIT 59
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00062 # include <winstl/winstl.h>
00063 #endif
00064 #ifndef STLSOFT_INCL_STLSOFT_SYNCH_HPP_CONCEPTS
00065 # include <stlsoft/synch/concepts.hpp>
00066 #endif
00067 #ifndef WINSTL_INCL_WINSTL_SYNCH_ERROR_HPP_EXCEPTIONS
00068 # include <winstl/synch/error/exceptions.hpp>
00069 #endif
00070
00071
00072
00073
00074
00075 #ifndef _WINSTL_NO_NAMESPACE
00076 # if defined(_STLSOFT_NO_NAMESPACE) || \
00077 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00078
00079 namespace winstl
00080 {
00081 # else
00082
00083
00084 namespace stlsoft
00085 {
00086
00087 namespace winstl_project
00088 {
00089
00090 # endif
00091 #endif
00092
00093
00094
00095
00096
00101 class event
00102 : public stlsoft_ns_qual(synchronisable_object_tag)
00103 {
00104 public:
00106 typedef event class_type;
00107 typedef HANDLE synch_handle_type;
00108
00109 typedef HANDLE resource_type;
00110
00113 public:
00115 event(ws_bool_t bManualReset, ws_bool_t bInitialState)
00116 : m_ev(create_event_(NULL, bManualReset, bInitialState, static_cast<ws_char_a_t const*>(0)))
00117 , m_bOwnHandle(true)
00118 {}
00120 ss_explicit_k event(ws_char_a_t const* name, ws_bool_t bManualReset, ws_bool_t bInitialState)
00121 : m_ev(create_event_(NULL, bManualReset, bInitialState, name))
00122 , m_bOwnHandle(true)
00123 {}
00125 ss_explicit_k event(ws_char_w_t const* name, ws_bool_t bManualReset, ws_bool_t bInitialState)
00126 : m_ev(create_event_(NULL, bManualReset, bInitialState, name))
00127 , m_bOwnHandle(true)
00128 {}
00130 ss_explicit_k event(ws_char_a_t const* name, ws_bool_t bManualReset, ws_bool_t bInitialState, LPSECURITY_ATTRIBUTES psa)
00131 : m_ev(create_event_(psa, bManualReset, bInitialState, name))
00132 , m_bOwnHandle(true)
00133 {}
00135 ss_explicit_k event(ws_char_w_t const* name, ws_bool_t bManualReset, ws_bool_t bInitialState, LPSECURITY_ATTRIBUTES psa)
00136 : m_ev(create_event_(psa, bManualReset, bInitialState, name))
00137 , m_bOwnHandle(true)
00138 {}
00140 ~event() stlsoft_throw_0()
00141 {
00142 if( NULL != m_ev &&
00143 m_bOwnHandle)
00144 {
00145 ::CloseHandle(m_ev);
00146 }
00147 }
00149
00152 public:
00154 void set()
00155 {
00156 WINSTL_ASSERT(NULL != m_ev);
00157
00158 if(!::SetEvent(m_ev))
00159 {
00160 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00161 STLSOFT_THROW_X(synchronisation_exception("event set operation failed", ::GetLastError()));
00162 #endif
00163 }
00164 }
00166 void reset()
00167 {
00168 WINSTL_ASSERT(NULL != m_ev);
00169
00170 if(!::ResetEvent(m_ev))
00171 {
00172 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00173 STLSOFT_THROW_X(synchronisation_exception("event reset operation failed", ::GetLastError()));
00174 #endif
00175 }
00176 }
00178
00181 public:
00183 HANDLE handle()
00184 {
00185 return m_ev;
00186 }
00188 HANDLE get()
00189 {
00190 return m_ev;
00191 }
00193
00194
00195 private:
00196 static HANDLE create_event_(LPSECURITY_ATTRIBUTES psa, ws_bool_t bManualReset, ws_bool_t bInitialState, ws_char_a_t const* name)
00197 {
00198 HANDLE h = ::CreateEventA(psa, bManualReset, bInitialState, name);
00199
00200 if(NULL == h)
00201 {
00202 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00203 STLSOFT_THROW_X(synchronisation_exception("Failed to create kernel event object", ::GetLastError()));
00204 #endif
00205 }
00206
00207 return h;
00208 }
00209 static HANDLE create_event_(LPSECURITY_ATTRIBUTES psa, ws_bool_t bManualReset, ws_bool_t bInitialState, ws_char_w_t const* name)
00210 {
00211 HANDLE h = ::CreateEventW(psa, bManualReset, bInitialState, name);
00212
00213 if(NULL == h)
00214 {
00215 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00216 STLSOFT_THROW_X(synchronisation_exception("Failed to create kernel event object", ::GetLastError()));
00217 #endif
00218 }
00219
00220 return h;
00221 }
00222
00223
00224 private:
00225 HANDLE m_ev;
00226 const ws_bool_t m_bOwnHandle;
00227
00228
00229 private:
00230 event(class_type const& rhs);
00231 event& operator =(class_type const& rhs);
00232 };
00233
00234
00235
00236
00237
00245 inline HANDLE get_synch_handle(event &ev)
00246 {
00247 return ev.get();
00248 }
00249
00259 inline HANDLE get_kernel_handle(event &ev)
00260 {
00261 return ev.get();
00262 }
00263
00265
00266
00267 #ifdef STLSOFT_UNITTEST
00268 # include "./unittest/event_unittest_.h"
00269 #endif
00270
00271
00272
00273 #ifndef _WINSTL_NO_NAMESPACE
00274 # if defined(_STLSOFT_NO_NAMESPACE) || \
00275 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00276 }
00277 # else
00278 }
00279 }
00280 # endif
00281 #endif
00282
00283
00284
00285 #endif
00286
00287