诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

138 lines
3.5 KiB

  1. #ifndef QUEUE_SERVICE_HEAD_FILE
  2. #define QUEUE_SERVICE_HEAD_FILE
  3. #include "KernelEngineHead.h"
  4. #define VER_IQueueServiceSink INTERFACE_VERSION(1,1)
  5. static const GUID IID_IQueueServiceSink = { 0x88b5bf59, 0x3a98, 0x43b1, 0xac, 0x85, 0xf1, 0x17, 0x5b, 0x29, 0x69, 0x40 };
  6. //数据队列类钩子接口
  7. interface IQueueServiceSink : public IUnknownEx
  8. {
  9. //通知回调函数
  10. virtual void OnQueueServiceSink(WORD wIdentifier, void * pBuffer, WORD wDataSize) = NULL;
  11. };
  12. //////////////////////////////////////////////////////////////////////////
  13. #define VER_IQueueService INTERFACE_VERSION(1,1)
  14. static const GUID IID_IQueueService = { 0xcc5310b5, 0x3709, 0x40aa, 0x85, 0x24, 0xd6, 0xc5, 0x87, 0xb0, 0x32, 0x22 };
  15. //队列接口
  16. interface IQueueService : public IServiceModule
  17. {
  18. //设置接口
  19. virtual bool SetQueueServiceSink(IUnknownEx * pIUnknownEx) = NULL;
  20. //负荷信息
  21. virtual bool GetBurthenInfo(tagBurthenInfo & BurthenInfo) = NULL;
  22. //加入数据
  23. virtual bool AddToQueue(WORD wIdentifier, void * const pBuffer, WORD wDataSize) = NULL;
  24. };
  25. //////////////////////////////////////////////////////////////////////////
  26. //队列线程类
  27. class CQueueServiceThread : public CWHThread
  28. {
  29. //友员定义
  30. friend class CQueueService;
  31. //配置定义
  32. protected:
  33. HANDLE m_hCompletionPort; //完成端口
  34. //辅助变量
  35. private:
  36. BYTE m_cbBuffer[MAX_ASYNCHRONISM_DATA]; //接收缓冲
  37. //函数定义
  38. protected:
  39. //构造函数
  40. CQueueServiceThread(void);
  41. //析构函数
  42. virtual ~CQueueServiceThread(void);
  43. //功能函数
  44. public:
  45. //配置函数
  46. bool InitThread(HANDLE hCompletionPort);
  47. //取消配置
  48. bool UnInitThread();
  49. //重载函数
  50. private:
  51. //运行函数
  52. virtual bool OnEventThreadRun();
  53. };
  54. //////////////////////////////////////////////////////////////////////////
  55. //数据队列类
  56. class CQueueService : public IQueueService
  57. {
  58. friend class CQueueServiceThread;
  59. //变量定义
  60. protected:
  61. bool m_bService; //服务标志
  62. HANDLE m_hCompletionPort; //完成端口
  63. IQueueServiceSink * m_pIQueueServiceSink; //回调接口
  64. //组件变量
  65. protected:
  66. CCriticalSection m_CriticalSection; //线程锁
  67. CWHDataQueue m_DataQueue; //数据存储
  68. CQueueServiceThread m_QueueServiceThread; //队列线程
  69. //函数定义
  70. public:
  71. //构造函数
  72. CQueueService(void);
  73. //析构函数
  74. virtual ~CQueueService(void);
  75. //基础接口
  76. public:
  77. //释放对象
  78. virtual VOID Release()
  79. {
  80. if (IsValid()) delete this; //
  81. }
  82. //是否有效
  83. virtual bool IsValid()
  84. {
  85. return AfxIsValidAddress(this, sizeof(CQueueService)) ? true : false;
  86. }
  87. //接口查询
  88. virtual void * QueryInterface(const IID & Guid, DWORD dwQueryVer);
  89. //管理接口
  90. public:
  91. //开始服务
  92. virtual bool StartService();
  93. //停止服务
  94. virtual bool ConcludeService();
  95. //线程句柄
  96. HANDLE GetThreadHandle();
  97. //队列接口
  98. public:
  99. //加入数据
  100. virtual bool AddToQueue(WORD wIdentifier, void * const pBuffer, WORD wDataSize);
  101. //设置接口
  102. virtual bool SetQueueServiceSink(IUnknownEx * pIUnknownEx);
  103. //负荷信息
  104. virtual bool GetBurthenInfo(tagBurthenInfo & BurthenInfo);
  105. //辅助函数
  106. private:
  107. //提取数据
  108. bool GetData(tagDataHead & DataHead, void * pBuffer, WORD wBufferSize);
  109. //数据消息
  110. void OnQueueServiceThread(const tagDataHead & DataHead, void * pBuffer, WORD wDataSize);
  111. };
  112. //////////////////////////////////////////////////////////////////////////
  113. #endif