87 lines
1.5 KiB
C++
87 lines
1.5 KiB
C++
#ifndef _THREAD_EVENT_HPP_
|
|
#define _THREAD_EVENT_HPP_
|
|
#ifndef _COMMON_STDIO_HPP_
|
|
#include <common/stdio.hpp>
|
|
#endif
|
|
#ifndef _COMMON_WINDOWS_HPP_
|
|
#include <common/windows.hpp>
|
|
#endif
|
|
#ifndef _COMMON_STRING_HPP_
|
|
#include <common/string.hpp>
|
|
#endif
|
|
|
|
class Event
|
|
{
|
|
public:
|
|
Event(BOOL manualReset=TRUE);
|
|
Event(const String &eventName,BOOL postFixup=TRUE,BOOL manualReset=TRUE);
|
|
virtual ~Event();
|
|
operator HANDLE(void);
|
|
WORD setEvent(void)const;
|
|
WORD pulseEvent(void)const;
|
|
WORD resetEvent(void)const;
|
|
WORD waitEvent(DWORD timeOut=INFINITE,WORD alertable=FALSE)const;
|
|
WORD closeEvent(void);
|
|
BOOL openEvent(const String &strEventName);
|
|
BOOL isOkay(void)const;
|
|
const String &eventName(void)const;
|
|
private:
|
|
HANDLE mhEvent;
|
|
String mEventName;
|
|
};
|
|
|
|
inline
|
|
Event::~Event()
|
|
{
|
|
closeEvent();
|
|
}
|
|
|
|
inline
|
|
Event::operator HANDLE(void)
|
|
{
|
|
return mhEvent;
|
|
}
|
|
|
|
inline
|
|
WORD Event::setEvent(void)const
|
|
{
|
|
if(!mhEvent)return FALSE;
|
|
return ::SetEvent(mhEvent);
|
|
}
|
|
|
|
inline
|
|
WORD Event::pulseEvent(void)const
|
|
{
|
|
if(!mhEvent)return FALSE;
|
|
return ::PulseEvent(mhEvent);
|
|
}
|
|
|
|
inline
|
|
WORD Event::resetEvent(void)const
|
|
{
|
|
if(!mhEvent)return FALSE;
|
|
return ::ResetEvent(mhEvent);
|
|
}
|
|
|
|
inline
|
|
const String &Event::eventName(void)const
|
|
{
|
|
return mEventName;
|
|
}
|
|
|
|
inline
|
|
BOOL Event::isOkay(void)const
|
|
{
|
|
return mhEvent?TRUE:FALSE;
|
|
}
|
|
|
|
inline
|
|
BOOL Event::openEvent(const String &strEventName)
|
|
{
|
|
closeEvent();
|
|
mEventName=strEventName;
|
|
mhEvent=::OpenEvent(EVENT_ALL_ACCESS,TRUE,(LPSTR)(String&)strEventName);
|
|
return isOkay();
|
|
}
|
|
#endif
|