| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /*************************************************************************
- 【文件名】 NetLinkMain.h
- 【功能模块和目的】 网络连接主管理类头文件
- 【开发者及日期】 郑石诺 2015/07/19
- 【版本】 V1.0.0
- 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
- 【更改记录】
- *************************************************************************/
- #pragma once
- #include "NetCtrlInterface.h"
- #include "NetRepInterface.h"
- #include "PduEventHost.h"
- #include "ClientContainer.h"
- class CNetClient;
- class CNetServer;
- class CSocketBase;
- /*************************************************************************
- 【类名】 CNetLinkMain
- 【功能】
- 【接口说明】 网络连接主管理类
- 【开发者及日期】 郑石诺 2015/07/19
- 【版本】 V1.0.0
- 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
- 【更改记录】
- *************************************************************************/
- class CNetLinkMain : public IPduComm, public IPduLink
- {
- SINGLETON_DECLARE(CNetLinkMain)
- public:
- CNetLinkMain(void);
- virtual ~CNetLinkMain(void);
- BOOL Send(CPduEntity* a_pCmd, PDU_DEV_TYPE a_nDestType, int a_nDestId); // 发送PDU
- void Send2All(CPduEntity* a_pCmd);
-
- // 连接管理
- void getLocalInfo(PDU_DEV_TYPE& a_DevType, int& a_DevId); // 获取本端设备类型及ID
- BOOL GetLinkInfo(CString& a_strIp, int& a_nPort, PDU_DEV_TYPE a_nType, int a_nId); // 获取指定连接的网络信息
- BOOL GetPeerIp(CString& a_strIp, CPduEntity* a_pCmd); // 获取PDU命令的发送方IP
- BOOL CreatePduServer(int a_nListenPort, PDU_DEV_TYPE a_nLocalType, int a_nLocalId); // 创建PDU通讯服务器
- BOOL CreatePduClient(CString a_strFarIp, int a_nFarPort, PDU_DEV_TYPE a_nLocalType, int a_nLocalId,
- PDU_DEV_TYPE a_nFarType, int a_nFarId, bool IsAutoReconnect); // 创建PDU通讯客户端
- BOOL ClosePduClient(PDU_DEV_TYPE a_nFarType, int a_nFarId); // 关闭PDU通讯客户端
- void StopAll(void);
- // 事件订阅接口实现(注:事件订阅应在创建操作之前调用)
- BOOL RegistPduLinkProc(IPduLinkProc* a_pPduLinkProc, BOOL bIsInsert);
- BOOL RegistPduCommProc(IPduCommProc* a_pPduCommProc, BOOL bIsInsert);
- CNetClient* getClient(CNetClient* a_pClient) { return m_ClientContainer.getClient(a_pClient); }
- // 绑定通信一端
- bool waitNetEnd(CSocketBase* pNetEnd);
- // 客户端逻辑控制相关操作
- void onConnEstablished(CNetClient* a_pClient); // 连接建立处理
- void onConnFailed(CNetClient* a_pClient); // 连接失败/断开处理
- void onConnRegistOK(CNetClient* a_pClient); // 注册成功
- void onConnRegistFailed(CNetClient* a_pClient); // 注册失败
- void onRecvCommand(CPduEntity* a_pCmd); // 命令接收处理
- private:
- static DWORD WINAPI __workerThread(LPVOID lpParam);
- int __getCountOfProcessors(void);
- int __getThreadCount(PDU_DEV_TYPE a_LocalType);
- bool __setupIocp(PDU_DEV_TYPE a_LocalType);
- bool __handleNetEndError(CSocketBase* pNetEnd, DWORD ErrorCode);
- void __setLocalInfo(PDU_DEV_TYPE a_nDevType, int a_nDevId); // 设定PDU本端设备类型及ID
- void __setLinkContent(PduLinkContent& linkContent, PDU_LINK_STATE a_nLinkInfo, CNetClient* a_pClient); // 生成连接信息内容
- void __setLinkContent(PduLinkContent& linkContent, CNetClient* a_pClient); // 生成连接信息内容
- bool __isClientExisted(CSocketBase* pClient); // 判断客户端是否还存在
- private:
- CPduEventHost m_EventHost; // 事件订阅宿主类
- CClientContainer m_ClientContainer; // 客户端容器
- CNetServer* m_pServer;
- HANDLE m_hIocp; // 完成端口的句柄
- HANDLE* m_phWorkerThreads; // 工作者线程的句柄指针
- int m_ThreadCount;
- bool m_ThreadStop;
- // 属性
- PDU_DEV_TYPE m_DevType; // 本端设备类型
- int m_DevId; // 本端设备ID
- };
|