⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.h.bak

📁 网络socket,IO,线程池
💻 BAK
字号:

#ifndef _M_EVENT_ZHY_H
#define _M_EVENT_ZHY_H


#include "mexception.h"
#include <windows.h>
#include <string>

#include <cassert>
using namespace std;

namespace MYACE{

class Event
{
public:
	
	Event() : handle(NULL)
	{
	};
	

	virtual ~Event()
	{
		if(handle)	
			::CloseHandle(handle);
	}
	
	
	virtual void signal() = 0;

	// 隐式转换
	operator void*() const
	{
		return handle;
	}

protected:
	void *handle;
};

class AutoEvent :	public Event
{
public:
	
	AutoEvent(const char* eventName="anonymous") throw(MException)
	{
		handle = reinterpret_cast<void*>(::CreateEvent(NULL, false, false, eventName));
		if(handle == INVALID_HANDLE_VALUE)
			throw MException(CREATE_AUTOEVENT_ERROR,eventName);
	}

	
	void signal()
	{
		::SetEvent(handle);
	}
};

class ManualEvent :	public Event
{
public:
	
	ManualEvent(const char* eventName=NULL)
	{
		// Note that the handle is closed in the base Event class.
		handle = ::CreateEvent(NULL, true, false, eventName);
		if(handle == NULL)
			throw MException(CREATE_MENALEVENT_ERROR,eventName);
		assert(handle);
	}
	
	void signal() throw()
	{
		assert(handle);
		::SetEvent(handle);
	}
	
	void reset() throw()
	{
		assert(handle);
		::ResetEvent(handle);
	}
};

}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -