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) : CGenericEvent(bInitialState,
00052 bManualReset,
00053 pEventName),
00054 m_hEvent(NULL)
00055 {
00056
00057 m_hEvent=CreateEvent(NULL,
00058 bManualReset,
00059 bInitialState,
00060 pEventName);
00061
00062
00063 if (!m_hEvent)
00064 throw std::string("Failed to create event!");
00065
00066
00067 if (pEventName &&
00068 GetLastError()!=ERROR_ALREADY_EXISTS)
00069 SetFirst();
00070 }
00071
00072 CWin32Event::~CWin32Event()
00073 {
00074 if (m_hEvent)
00075 CloseHandle(m_hEvent);
00076 }
00077
00078 void CWin32Event::Set()
00079 {
00080 if (m_hEvent)
00081 SetEvent(m_hEvent);
00082 }
00083
00084 BOOL CWin32Event::Wait(unsigned long ulMSTimeout)
00085 {
00086 DWORD dwWaitResult;
00087
00088
00089 dwWaitResult=WaitForSingleObject(m_hEvent,
00090 ulMSTimeout);
00091
00092
00093 return dwWaitResult==WAIT_TIMEOUT;
00094 }
00095
00096 HANDLE CWin32Event::GetHandle()const
00097 {
00098 return m_hEvent;
00099 }
00100
00101 void CWin32Event::Reset()
00102 {
00103 if (m_hEvent)
00104 ResetEvent(m_hEvent);
00105 }
00106
00107 void CWin32Event::Pulse()
00108 {
00109 if (m_hEvent)
00110 PulseEvent(m_hEvent);
00111 }
00112
00113 void CWin32Event::ReleaseObject()
00114 {
00115 Reset();
00116 }
00117
00118 void CWin32Event::PopulateOverlapped(OVERLAPPED& rOverlapped)
00119 {
00120 rOverlapped.hEvent=m_hEvent;
00121 }
00122
00123 KOMODIA_NAMESPACE_END