1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/private/event.h
// Purpose: Simple Windows 'event object' wrapper.
// Author: Troelsk, Vadim Zeitlin
// Created: 2014-05-07
// Copyright: (c) 2014 wxWidgets team
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_PRIVATE_EVENT_H_
#define _WX_MSW_PRIVATE_EVENT_H_
#include "wx/msw/private.h"
namespace wxWinAPI
{
class Event : public AutoHANDLE<0>
{
public:
enum Kind
{
ManualReset,
AutomaticReset
};
enum InitialState
{
Signaled,
Nonsignaled
};
Event()
{
}
// Wrappers around {Create,Set,Reset}Event() Windows API functions, with
// the same semantics.
bool Create(Kind kind = AutomaticReset,
InitialState initialState = Nonsignaled,
const wxChar* name = NULL);
bool Set();
bool Reset();
private:
wxDECLARE_NO_COPY_CLASS(Event);
};
} // namespace wxWinAPI
// ----------------------------------------------------------------------------
// Implementations requiring windows.h; these are to moved out-of-line if
// this class is moved to a public header, or if [parts of] msw/private.h is
// changed to not depend on windows.h being included.
// ----------------------------------------------------------------------------
inline bool
wxWinAPI::Event::Create(wxWinAPI::Event::Kind kind,
wxWinAPI::Event::InitialState initialState,
const wxChar* name)
{
wxCHECK_MSG( !IsOk(), false, wxS("Event can't be created twice") );
WXHANDLE handle = ::CreateEvent(NULL,
kind == ManualReset,
initialState == Signaled,
name);
if ( !handle )
{
wxLogLastError(wxS("CreateEvent"));
return false;
}
m_handle = handle;
return true;
}
inline bool wxWinAPI::Event::Set()
{
wxCHECK_MSG( m_handle, false, wxS("Event must be valid") );
if ( !::SetEvent(m_handle) )
{
wxLogLastError(wxS("SetEvent"));
return false;
}
return true;
}
inline bool wxWinAPI::Event::Reset()
{
wxCHECK_MSG( m_handle, false, wxS("Event must be valid") );
if ( !::ResetEvent(m_handle) )
{
wxLogLastError(wxS("ResetEvent"));
return false;
}
return true;
}
#endif // _WX_MSW_PRIVATE_EVENT_H_
|