中间件标准版5.1git,去除基础模块

MsgCenter.h 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*************************************************************************
  2. 【文件名】 MsgCenter.h
  3. 【功能模块和目的】 消息分派中心类头文件
  4. 【开发者及日期】 郑石诺 2015/01/04
  5. 【版本】 V1.0.0
  6. 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
  7. 【更改记录】
  8. *************************************************************************/
  9. #pragma once
  10. #include <map>
  11. using namespace std;
  12. class IMsgObserver;
  13. /*************************************************************************
  14. 【类名】 CMsgCenter
  15. 【功能】 消息分派中心类
  16. 【接口说明】
  17. 【开发者及日期】 郑石诺 2015/01/04
  18. 【版本】 V1.0.0
  19. 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
  20. 【更改记录】
  21. *************************************************************************/
  22. class CMsgCenter
  23. {
  24. SINGLETON_DECLARE(CMsgCenter)
  25. public:
  26. ~CMsgCenter(void);
  27. void regist(UINT MsgType, IMsgObserver* pObserver); // 订阅消息
  28. void unregist(UINT MsgType, IMsgObserver* pObserver); // 取消订阅
  29. void pushMsg(UINT MsgType, const PARAM lpContent); // 设备消息变化通知接口
  30. private:
  31. CMsgCenter(void);
  32. void __wait(void); // 无消息时置线程于等待信号状态
  33. void __releaseMsg(UINT MsgType, PARAM lpContent); // 释放消息
  34. int __dispatchMsg(void); // 处理事件消息,线程函数调用
  35. void __sendMsgToObserver(UINT MsgType, const PARAM lpContent); // 发送消息给订阅者
  36. static UINT __dipatchThreadFunc(LPVOID pParam); // 处理消息事件线程函数
  37. private:
  38. typedef struct
  39. {
  40. UINT MsgType; // 事件类型
  41. PARAM Content; // 事件内容
  42. } MSG_INNER;
  43. typedef multimap<UINT, IMsgObserver*> ObsvrMap;
  44. typedef CList<MSG_INNER*, MSG_INNER*> MsgList;
  45. volatile bool m_Stop;
  46. ObsvrMap m_ObsvrMap; // 消息订阅者存储结构
  47. MsgList m_MsgList; // 消息缓存队列
  48. CWinThread* m_pThreadObj; // 消息分发线程对象
  49. CCriticalSection m_RWLock; // 事件缓冲队列的互斥对象
  50. CEvent m_ThreadSleepFlag; // 消息分发线程睡眠的信号事件
  51. };