| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /*************************************************************************
- 【文件名】 MsgCenter.h
- 【功能模块和目的】 消息分派中心类头文件
- 【开发者及日期】 郑石诺 2015/01/04
- 【版本】 V1.0.0
- 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
- 【更改记录】
- *************************************************************************/
- #pragma once
- #include <map>
- using namespace std;
- class IMsgObserver;
- /*************************************************************************
- 【类名】 CMsgCenter
- 【功能】 消息分派中心类
- 【接口说明】
- 【开发者及日期】 郑石诺 2015/01/04
- 【版本】 V1.0.0
- 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
- 【更改记录】
- *************************************************************************/
- class CMsgCenter
- {
- SINGLETON_DECLARE(CMsgCenter)
- public:
- ~CMsgCenter(void);
- void regist(UINT MsgType, IMsgObserver* pObserver); // 订阅消息
- void unregist(UINT MsgType, IMsgObserver* pObserver); // 取消订阅
- void pushMsg(UINT MsgType, const PARAM lpContent); // 设备消息变化通知接口
- private:
- CMsgCenter(void);
- void __wait(void); // 无消息时置线程于等待信号状态
- void __releaseMsg(UINT MsgType, PARAM lpContent); // 释放消息
- int __dispatchMsg(void); // 处理事件消息,线程函数调用
- void __sendMsgToObserver(UINT MsgType, const PARAM lpContent); // 发送消息给订阅者
- static UINT __dipatchThreadFunc(LPVOID pParam); // 处理消息事件线程函数
- private:
- typedef struct
- {
- UINT MsgType; // 事件类型
- PARAM Content; // 事件内容
- } MSG_INNER;
- typedef multimap<UINT, IMsgObserver*> ObsvrMap;
- typedef CList<MSG_INNER*, MSG_INNER*> MsgList;
- volatile bool m_Stop;
- ObsvrMap m_ObsvrMap; // 消息订阅者存储结构
- MsgList m_MsgList; // 消息缓存队列
- CWinThread* m_pThreadObj; // 消息分发线程对象
- CCriticalSection m_RWLock; // 事件缓冲队列的互斥对象
- CEvent m_ThreadSleepFlag; // 消息分发线程睡眠的信号事件
- };
|