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 #include "stdafx.h"
00037 #include "Win32Event.h"
00038
00039 #include <string>
00040
00041 #ifdef _MEMORY_DEBUG
00042 #define new DEBUG_NEW
00043 #define malloc DEBUG_MALLOC
00044 static char THIS_FILE[] = __FILE__;
00045 #endif
00046
00047 KOMODIA_NAMESPACE_START
00048
00049 CWin32Event::CWin32Event(BOOL bInitialState,
00050 BOOL bManualReset,
00051 const char* pEventName,
00052 LPVOID lpSecurity) : CGenericEvent(bInitialState,
00053 bManualReset,
00054 pEventName),
00055 m_hEvent(NULL)
00056 {
00057
00058 m_hEvent=CreateEvent((LPSECURITY_ATTRIBUTES)lpSecurity,
00059 bManualReset,
00060 bInitialState,
00061 pEventName);
00062
00063
00064 if (!m_hEvent)
00065 throw std::string("Failed to create event!");
00066
00067
00068 if (pEventName &&
00069 GetLastError()!=ERROR_ALREADY_EXISTS)
00070 SetFirst();
00071 }
00072
00073 CWin32Event::CWin32Event(BOOL bInitialState,
00074 BOOL bManualReset,
00075 const char* pEventName,
00076 bool bNext) : CGenericEvent(bInitialState,
00077 bManualReset,
00078 pEventName),
00079 m_hEvent(NULL)
00080 {
00081 }
00082
00083 CWin32Event::~CWin32Event()
00084 {
00085 if (m_hEvent)
00086 CloseHandle(m_hEvent);
00087 }
00088
00089 void CWin32Event::SetHandle(HANDLE hEvent)
00090 {
00091 m_hEvent=hEvent;
00092 }
00093
00094 void CWin32Event::Set()
00095 {
00096 if (m_hEvent)
00097 SetEvent(m_hEvent);
00098 }
00099
00100 BOOL CWin32Event::Wait(unsigned long ulMSTimeout)
00101 {
00102 DWORD dwWaitResult;
00103
00104
00105 dwWaitResult=WaitForSingleObject(m_hEvent,
00106 ulMSTimeout);
00107
00108
00109 return dwWaitResult==WAIT_TIMEOUT;
00110 }
00111
00112 HANDLE CWin32Event::GetHandle()const
00113 {
00114 return m_hEvent;
00115 }
00116
00117 void CWin32Event::Reset()
00118 {
00119 if (m_hEvent)
00120 ResetEvent(m_hEvent);
00121 }
00122
00123 void CWin32Event::Pulse()
00124 {
00125 if (m_hEvent)
00126 PulseEvent(m_hEvent);
00127 }
00128
00129 void CWin32Event::ReleaseObject()
00130 {
00131 Reset();
00132 }
00133
00134 void CWin32Event::PopulateOverlapped(OVERLAPPED& rOverlapped)
00135 {
00136 rOverlapped.hEvent=m_hEvent;
00137 }
00138
00139 KOMODIA_NAMESPACE_END