| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610 |
- /*******************************************************************************
- 版权声明: Copyright (C), 2024-2034, Yunda Tech. Co., Ltd.
- 文件名 : NetWork_Alone.cpp
- 描 述 : 作为动态库输出时网络实现类
- 其 他 : 无
- 历史记录:
- 1. 时间: 2024-05-22
- 作者: masq
- 修改描述: 新创建
- 2. ...
- *******************************************************************************/
- #include "pch.h"
- #include <YD_Public_OCC.h>
- #include "NetWork_Alone.h"
- /*******************************************************
- 函数名称: ThreadFun_TCP_Send
- 函数功能: TCP数据发送线程函数
- 输入参数: lpParameter - 线程参数
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::ThreadFun_TCP_Send()
- {
- m_SendTCPThreadOut = false;
- try
- {
- while ( !m_SendTCPThreadOut )
- {
- if ( !DealWith_TCP_Send() )
- {
- Thread_Sleep(TIMESPAN_LVT);
- }
- }
- }
- catch (...)
- {
- //DWORD error = GetLastError();
- std::string errorstr = Str_Format("DisPatchServer NetMsgSendDealThread Have a Error errorcode");
- //lpthis->AddLogItem(errorstr, LOG_LEVEL_ERROR);
- }
- }
- /*******************************************************
- 函数名称: UDP_Send_Thread
- 函数功能: UDP数据发送线程函数
- 输入参数: lpParameter - 线程参数
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::ThreadFun_UDP_Send()
- {
- m_SendTCPThreadOut = false;
- try
- {
- while ( !m_SendTCPThreadOut )
- {
- if ( !DealWith_UDP_Send() )
- {
- Thread_Sleep(TIMESPAN_LVT);
- }
- }
- }
- catch (...)
- {
- //DWORD error = GetLastError();
- std::string errorstr = Str_Format("DisPatchServer NetMsgSendDealThread Have a Error errorcode");
- //lpthis->AddLogItem(errorstr, LOG_LEVEL_ERROR);
- }
- }
- /*******************************************************
- 函数名称: Group_Send_Thread
- 函数功能: 组播数据发送线程函数
- 输入参数: lpParameter - 线程参数
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::ThreadFun_Group_Send()
- {
- m_SendTCPThreadOut = false;
- try
- {
- while ( !m_SendTCPThreadOut )
- {
- if ( !DealWith_Group_Send() )
- {
- Thread_Sleep(TIMESPAN_LVT);
- }
- }
- }
- catch (...)
- {
- //DWORD error = GetLastError();
- std::string errorstr = Str_Format("DisPatchServer NetMsgSendDealThread Have a Error errorcode");
- //lpthis->AddLogItem(errorstr, LOG_LEVEL_ERROR);
- }
- }
- //构造函数
- CNetWork_Alone::CNetWork_Alone( CDispatchMng_I* pDispatchMng )
- {
- m_pSendList_TCP = nullptr;
- m_pSendList_UDP = nullptr;
- m_pSendList_Group = nullptr;
- m_pRecvList_TCP = nullptr;
- m_pRecvList_UDP = nullptr;
- m_pRecvList_Group = nullptr;
- m_pTCPSendCallBack = nullptr;
- m_pUDPSendCallBack = nullptr;
- m_SendTCPThreadID = 0; //线程ID-TCP数据发送
- m_SendUDPThreadID = 0; //线程ID-UDP数据发送
- m_SendGroupThreadID = 0; //线程ID-组播数据发送
- m_SendTCPThreadOut = true; //线程退出标志-TCP数据发送
- m_SendUDPThreadOut = true; //线程退出标志-UDP数据发送
- m_SendGroupThreadOut= true; //线程退出标志-组播数据发送
- InitAlone_NetWork(pDispatchMng);
- }
- //析构函数
- CNetWork_Alone::~CNetWork_Alone(void)
- {
- }
- /*******************************************************
- 函数名称: _IGet_System_ID
- 函数功能: 获取服务器的系统号
- 输入参数: NULL
- 输出参数: NULL
- 返 回 值: int - 系统号
- *******************************************************/
- int CNetWork_Alone::_IGet_System_ID()
- {
- return -1;
- }
- /*******************************************************
- 函数名称: _IGetTrainID
- 函数功能: 获取训练号
- 输入参数: NULL
- 输出参数: NULL
- 返 回 值: int - 训练号
- *******************************************************/
- int CNetWork_Alone::_IGetTrainID()
- {
- return -1;
- }
- /*******************************************************
- 函数名称: _IConnectToTech
- 函数功能: 接口-连接到教员
- 输入参数: NULL
- 输出参数: NULL
- 返 回 值: int - 结果
- *******************************************************/
- int CNetWork_Alone::_IConnectToTech()
- {
- return -1;
- }
- /*******************************************************
- 函数名称: _IClose
- 函数功能: 关闭网络
- 输入参数: NULL
- 输出参数: NULL
- 返 回 值: bool - 结果
- *******************************************************/
- bool CNetWork_Alone::_IClose()
- {
- //1、数据发送线程关闭-TCP
- m_SendTCPThreadOut = true;
- if ( m_ThreadSend_TCP.joinable() )
- {
- m_ThreadSend_TCP.join();
- }
- //2、数据发送线程关闭-UDP
- m_SendUDPThreadOut = true;
- if ( m_ThreadSend_UDP.joinable() )
- {
- m_ThreadSend_UDP.join();
- }
- //3、数据发送线程关闭-GROUP
- m_SendGroupThreadOut = true;
- if ( m_ThreadSend_Group.joinable() )
- {
- m_ThreadSend_Group.join();
- }
- //4、其他状态指针赋值初始化
- m_pSendList_TCP = nullptr;
- m_pSendList_UDP = nullptr;
- m_pSendList_Group = nullptr;
- m_pRecvList_TCP = nullptr;
- m_pRecvList_UDP = nullptr;
- m_pRecvList_Group = nullptr;
- m_pTCPSendCallBack = nullptr;
- m_pUDPSendCallBack = nullptr;
- return false;
- }
- /*******************************************************
- 函数名称: _ICreate_TCP_Connect
- 函数功能: 创建TCP连接
- 输入参数: NULL
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ICreate_TCP_Connect( int nSysID )
- {
- }
- /*******************************************************
- 函数名称: _ISend_TCPData_RightNow
- 函数功能: 立即发送-TCP数据
- 输入参数: NetCmd - 网络命令
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISend_TCPData_RightNow( OCCCOMMAND NetCmd )
- {
- //1、判断是否服务器自身数据
- BOOL bOwnerSelfCmd = FALSE;
- switch ( NetCmd.DesSysType )
- {
- case OCC_SYS_LS_SVR:
- case OCC_SYS_XD_SVR:
- case OCC_SYS_DD_SVR:
- case OCC_SYS_HD_SVR:
- case OCC_SYS_FS_SVR:
- case OCC_SYS_TC_SVR:
- case OCC_SYS_JT_SVR:
- case OCC_SYS_TS_SVR:
- case OCC_SYS_KC_SVR:
- bOwnerSelfCmd = TRUE;
- break;
- default:
- break;
- }
- //2、发送服务器自身数据
- if ( bOwnerSelfCmd && NULL != m_pRecvList_TCP )
- {
- m_pRecvList_TCP->push(NetCmd);
- }
- //3、发送非服务器自身数据
- if ( !bOwnerSelfCmd && NULL != m_pTCPSendCallBack )
- {
- m_pTCPSendCallBack((char*)&NetCmd, sizeof(NetCmd));
- }
- }
- /*******************************************************
- 函数名称: _ISend_UDPData_RightNow
- 函数功能: 立即发送-UDP数据
- 输入参数: NetCmd - 网络命令
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISend_UDPData_RightNow( OCCCOMMAND NetCmd )
- {
- //1、判断是否服务器自身数据
- BOOL bOwnerSelfCmd = FALSE;
- switch (NetCmd.DesSysType)
- {
- case OCC_SYS_LS_SVR:
- case OCC_SYS_XD_SVR:
- case OCC_SYS_DD_SVR:
- case OCC_SYS_HD_SVR:
- case OCC_SYS_FS_SVR:
- case OCC_SYS_TC_SVR:
- case OCC_SYS_JT_SVR:
- case OCC_SYS_TS_SVR:
- case OCC_SYS_KC_SVR:
- bOwnerSelfCmd = TRUE;
- break;
- default:
- break;
- }
- //2、发送服务器自身数据
- if ( bOwnerSelfCmd && NULL != m_pRecvList_UDP )
- {
- m_pRecvList_UDP->push(NetCmd);
- }
- //3、发送非服务器自身数据
- if ( !bOwnerSelfCmd && NULL != m_pUDPSendCallBack )
- {
- m_pUDPSendCallBack((char*)&NetCmd, sizeof(NetCmd));
- }
- }
- /*******************************************************
- 函数名称: _ISetRepeat_MainCtrl_SysID
- 函数功能: 设置复示显示的系统号
- 输入参数: nSysID - 系统号
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISetRepeat_MainCtrl_SysID( int nSysID )
- {
- }
- /*******************************************************
- 函数名称: _ISetRepeat_MainCtrl_ClientID
- 函数功能: 设置复示显示客户端的系统号
- 输入参数: nSysID - 系统号
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISetRepeat_MainCtrl_ClientID( int nSysID )
- {
- }
- /*******************************************************
- 函数名称: _ISetTechID
- 函数功能: 设置教员系统号
- 输入参数: nTeachSysID - 教员系统号
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISetTechID(int nTeachSysID)
- {
- }
- /*******************************************************
- 函数名称: _ISetTrainID
- 函数功能: 设置训练号
- 输入参数: nTrainingID - 训练号
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISetTrainID(int nTrainingID)
- {
- }
- /*******************************************************
- 函数名称: _IRecord_Training_Sys
- 函数功能: 记录参与训练的系统号
- 输入参数: nSysType - 系统类型
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_IRecord_Training_Sys(int nSysType)
- {
- }
- /*******************************************************
- 函数名称: _IRecord_Key_System
- 函数功能: 记录关键系统
- 输入参数: nSysType - 系统类型
- nSysID - 系统号
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_IRecord_Key_System(int nSysType, int nSysID)
- {
- }
- /*******************************************************
- 函数名称: _ISetNetData_MonitorS
- 函数功能: 设置网络数据监视开关
- 输入参数: bNetData_MonitorS - OCC网络监视开关
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISetNetData_MonitorS( BOOL bNetData_MonitorS )
- {
- }
- /*******************************************************
- 函数名称: _IStart_Training
- 函数功能: 开始训练
- 输入参数: nTrainingID - 训练号
- nCourseID - 课程号
- nSimTime - 仿真时间
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_IStart_Training( int nTrainingID, int nCourseID, int nSimTime )
- {
- }
- /*******************************************************
- 函数名称: _IEnd_Training
- 函数功能: 结束训练
- 输入参数: nTrainingID - 训练号
- nCourseID - 课程号
- nSimTime - 仿真时间
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_IEnd_Training(int nTrainingID, int nCourseID, int nSimTime)
- {
- }
- /*******************************************************
- 函数名称: _ISend_TCP_OtherCmd
- 函数功能: 数据发送 - TCP非OCC封装
- 输入参数: OtherCmd_TCP - 数据
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISend_TCP_OtherCmd(OTHER_CMD_TCP OtherCmd_TCP)
- {
- }
- /*******************************************************
- 函数名称: _ISend_UDP_OtherCmd
- 函数功能: 数据发送 - TCP非OCC封装
- 输入参数: OtherCmd_UDP - 数据
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::_ISend_UDP_OtherCmd(OTHER_CMD_UDP OtherCmd_UDP)
- {
- }
- /*******************************************************
- 函数名称: InitAlone_NetWork
- 函数功能: 初始化独立网络
- 输入参数: pDispatchMng - 调度管理
- 输出参数: NULL
- 返 回 值: void
- *******************************************************/
- void CNetWork_Alone::InitAlone_NetWork( CDispatchMng_I* pDispatchMng )
- {
- m_pSendList_TCP = (CommandQueue*)pDispatchMng->_IGetPtr_CmdQueue(CmdQueueType_Send_TCP);
- m_pSendList_UDP = (CommandQueue*)pDispatchMng->_IGetPtr_CmdQueue(CmdQueueType_Send_UDP);
- m_pSendList_Group = (CommandQueue*)pDispatchMng->_IGetPtr_CmdQueue(CmdQueueType_Send_GROUP);
- m_pRecvList_TCP = (CommandQueue*)pDispatchMng->_IGetPtr_CmdQueue(CmdQueueType_Recv_TCP);
- m_pRecvList_UDP = (CommandQueue*)pDispatchMng->_IGetPtr_CmdQueue(CmdQueueType_Recv_UDP);
- m_pRecvList_Group = (CommandQueue*)pDispatchMng->_IGetPtr_CmdQueue(CmdQueueType_Recv_GROUP);
- m_pTCPSendCallBack = (NETDATA_CALLBACK)pDispatchMng->_IGetPtr_TCPSend_CallBack();
- m_pUDPSendCallBack = (NETDATA_CALLBACK)pDispatchMng->_IGetPtr_UDPSend_CallBack();
- m_ThreadSend_TCP = std::thread(std::bind(&CNetWork_Alone::ThreadFun_TCP_Send, this));
- m_ThreadSend_UDP = std::thread(std::bind(&CNetWork_Alone::ThreadFun_UDP_Send, this));
- m_ThreadSend_Group = std::thread(std::bind(&CNetWork_Alone::ThreadFun_Group_Send, this));
- }
- /*******************************************************
- 函数名称: DealWith_TCP_Send
- 函数功能: 处理数据发送-TCP
- 输入参数: NULL
- 输出参数: NULL
- 返 回 值: BOOL - TRUE:成功,FALSE:失败
- *******************************************************/
- BOOL CNetWork_Alone::DealWith_TCP_Send()
- {
- //1、队列弹出网络命令
- OCCCOMMAND NetCmd;
- if ( !m_pSendList_TCP->pop(NetCmd) )
- {
- return FALSE;
- }
- //2、判断是否服务器自身命令
- BOOL bOwnerSelfCmd = FALSE;
- switch ( NetCmd.DesSysType )
- {
- case OCC_SYS_LS_SVR:
- case OCC_SYS_XD_SVR:
- case OCC_SYS_DD_SVR:
- case OCC_SYS_HD_SVR:
- case OCC_SYS_FS_SVR:
- case OCC_SYS_TC_SVR:
- case OCC_SYS_JT_SVR:
- case OCC_SYS_TS_SVR:
- case OCC_SYS_KC_SVR:
- bOwnerSelfCmd = TRUE;
- break;
- default:
- break;
- }
- //3、发送服务器自身命令
- if ( bOwnerSelfCmd && NULL != m_pRecvList_TCP )
- {
- m_pRecvList_TCP->push(NetCmd);
- }
- //4、发送非服务器自身命令
- if ( !bOwnerSelfCmd && NULL != m_pTCPSendCallBack )
- {
- m_pTCPSendCallBack((char*)&NetCmd, sizeof(NetCmd));
- }
- return TRUE;
- }
- /*******************************************************
- 函数名称: DealWith_UDP_Send
- 函数功能: 处理数据发送-UDP
- 输入参数: NULL
- 输出参数: NULL
- 返 回 值: BOOL - TRUE:成功,FALSE:失败
- *******************************************************/
- BOOL CNetWork_Alone::DealWith_UDP_Send()
- {
- //1、队列弹出网络命令
- OCCCOMMAND NetCmd;
- if ( !m_pSendList_UDP->pop(NetCmd) )
- {
- return FALSE;
- }
- //2、判断是否服务器自身命令
- BOOL bOwnerSelfCmd = FALSE;
- switch ( NetCmd.DesSysType )
- {
- case OCC_SYS_LS_SVR:
- case OCC_SYS_XD_SVR:
- case OCC_SYS_DD_SVR:
- case OCC_SYS_HD_SVR:
- case OCC_SYS_FS_SVR:
- case OCC_SYS_TC_SVR:
- case OCC_SYS_JT_SVR:
- case OCC_SYS_TS_SVR:
- case OCC_SYS_KC_SVR:
- bOwnerSelfCmd = TRUE;
- break;
- default:
- break;
- }
- //3、发送服务器自身命令
- if ( bOwnerSelfCmd && NULL != m_pRecvList_UDP )
- {
- m_pRecvList_UDP->push(NetCmd);
- }
- //4、发送非服务器自身命令
- if ( !bOwnerSelfCmd && NULL != m_pUDPSendCallBack )
- {
- m_pUDPSendCallBack((char*)&NetCmd, sizeof(NetCmd));
- }
- return TRUE;
- }
- /*******************************************************
- 函数名称: DealWith_Group_Send
- 函数功能: 处理数据发送-组播
- 输入参数: NULL
- 输出参数: NULL
- 返 回 值: BOOL - TRUE:成功,FALSE:失败
- *******************************************************/
- BOOL CNetWork_Alone::DealWith_Group_Send()
- {
- OCCCOMMAND NetCmd;
- if ( !m_pSendList_Group->pop(NetCmd) )
- {
- return FALSE;
- }
- //NOTE:组播数据即将淘汰,这里只将数据弹出,不做其他处理
- return TRUE;
- }
|