eventdispatcher.h

来自「.net 方面的开发说明资料。」· C头文件 代码 · 共 99 行

H
99 行
字号
// ========================================================
// Event Dispatching
//
// Design and Implementation by Floris van den Berg
// ========================================================

#ifndef EVENTDISPATCHER_H
#define EVENTDISPATCHER_H

#ifndef _LIST_
#include <list>
#endif

#ifndef _MAP_
#include <map>
#endif

#ifndef _VECTOR_
#include <vector>
#endif

#ifndef _MEMORY_
#include <memory>
#endif

#ifndef OPENNET_H
#include "OpenNet.h"
#endif

#ifndef BOOST_THREAD_WEK070601_HPP
#include <boost/thread/thread.hpp>
#endif

// --------------------------------------------------------

struct EpEventEx;
struct TransportEntry;
class ThreadBalancer;
class EventDispatcher;

// --------------------------------------------------------

typedef _STL::list<EpEventEx *> EventList;

// --------------------------------------------------------

struct DispatchFunctor {
public :
	DispatchFunctor(EventDispatcher *entry);
	bool operator()();
private :
	bool DispatchEvent(TransportEntry *plug_entry, GUID &guid, EpEvent *event);
public :
	EventDispatcher *m_entry;
};

// --------------------------------------------------------

class EventDispatcher {
	friend struct DispatchFunctor;
	friend struct SystemFunctor;

public :
	EpEventEx *createEventEntry(TRANSPORT_HANDLE transport, EpEvent *event);
	void pushEventEntry(EpEventEx *entry);
	void clearPendingEventEntries();
	void clearPendingEventEntries(TRANSPORT_HANDLE transport);
	void clearPendingEventEntries(TRANSPORT_HANDLE transport, CLSID protocol);
	void destroyEventEntry(EpEventEx *event);
	bool heartBeat();
	~EventDispatcher();

private :
	void setCallback(CallbackProc proc);
	void clearPendingEventEntries(EventList &list);
	void clearPendingEventEntries(TRANSPORT_HANDLE transport, EventList &list);
	void clearPendingEventEntries(TRANSPORT_HANDLE transport, CLSID protocol, EventList &list);

public :
	static EventDispatcher *getInstance();
	static bool isInstantiated();
	static void destroyInstance();

private :
	static EventDispatcher *instance;

private : // private constructor
	EventDispatcher();

private :
	DispatchFunctor *m_dispatch_functor;
	boost::mutex m_mutex;
	EventList m_event_list;
	DWORD m_time_stamp;
	DWORD m_delay;
};

#endif

⌨️ 快捷键说明

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