Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Event.cpp
Package: SwordOnline.rar [view]
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 2k
Category:
Game Server Simulator
Development Platform:
C/C++
- #include "Event.h"
- #include "Win32Exception.h"
- /*
- * namespace OnlineGameLib::Win32
- */
- namespace OnlineGameLib {
- namespace Win32 {
- /*
- * Static helper methods
- */
- static HANDLE Create(
- LPSECURITY_ATTRIBUTES lpEventAttributes,
- bool bManualReset,
- bool bInitialState,
- LPCTSTR lpName);
- static HANDLE Create(
- LPSECURITY_ATTRIBUTES lpEventAttributes,
- bool bManualReset,
- bool bInitialState,
- LPCTSTR lpName)
- {
- HANDLE hEvent = ::CreateEvent( lpEventAttributes, bManualReset, bInitialState, lpName );
- if ( NULL == hEvent )
- {
- throw CWin32Exception( _T("CEvent::Create()"), ::GetLastError() );
- }
- return hEvent;
- }
- CEvent::CEvent(
- LPSECURITY_ATTRIBUTES lpEventAttributes,
- bool bManualReset,
- bool bInitialState)
- : m_hEvent( Create( lpEventAttributes, bManualReset, bInitialState, 0 ) )
- {
- }
- CEvent::CEvent(
- LPSECURITY_ATTRIBUTES lpEventAttributes,
- bool bManualReset,
- bool bInitialState,
- const _tstring &name)
- : m_hEvent( Create( lpEventAttributes, bManualReset, bInitialState, name.c_str() ) )
- {
- }
- CEvent::~CEvent()
- {
- ::CloseHandle( m_hEvent );
- }
- HANDLE CEvent::GetEvent() const
- {
- return m_hEvent;
- }
- void CEvent::Wait() const
- {
- if ( !Wait( INFINITE ) )
- {
- throw CException( _T("CEvent::Wait()"), _T("Unexpected timeout on infinite wait") );
- }
- }
- bool CEvent::Wait( DWORD timeoutMillis ) const
- {
- bool ok;
- DWORD result = ::WaitForSingleObject( m_hEvent, timeoutMillis );
- if ( result == WAIT_TIMEOUT )
- {
- ok = false;
- }
- else if ( result == WAIT_OBJECT_0 )
- {
- ok = true;
- }
- else
- {
- throw CWin32Exception( _T("CEvent::Wait() - WaitForSingleObject"), ::GetLastError() );
- }
- return ok;
- }
- void CEvent::Reset()
- {
- if ( !::ResetEvent( m_hEvent ) )
- {
- throw CWin32Exception( _T("CEvent::Reset()"), ::GetLastError() );
- }
- }
- void CEvent::Set()
- {
- if ( !::SetEvent( m_hEvent ) )
- {
- throw CWin32Exception( _T("CEvent::Set()"), ::GetLastError() );
- }
- }
- void CEvent::Pulse()
- {
- if ( !::PulseEvent( m_hEvent ) )
- {
- throw CWin32Exception( _T("CEvent::Pulse()"), ::GetLastError() );
- }
- }
- } // End of namespace OnlineGameLib
- } // End of namespace Win32