| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #pragma once
- #include "BaseDefine.h"
- #include "YD_DBOperator.h"
- #include <SubSys_RollBack_I.h>
- #include <FrameTool_I.h>
- #include <NetWorkMng_I.h>
- #include <DispatchMng_I.h>
- #include <Debug_Module_I.h>
- #include <YD_RedisClient.h>
- enum TRAIN_RESET_TYPE
- {
- eTrainReset_Type_RollBack = 1, //复位类型-将回滚
- eTrainReset_Type_PlayBack = 2, //复位类型-将回放
- };
- #if defined(_MSC_VER) || defined(WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32)
- #ifdef _YD_OCC_BASEDISPATCH_SDK
- #define _YD_OCC_BASEDISPATCH_MODE __declspec(dllexport)
- #else
- #define _YD_OCC_BASEDISPATCH_MODE __declspec(dllimport)
- #endif
- #else //linux
- #ifdef _YD_OCC_BASEDISPATCH_SDK
- #define _YD_OCC_BASEDISPATCH_MODE __attribute__ ((visibility("default")))
- #else
- #define _YD_OCC_BASEDISPATCH_MODE
- #endif
- #endif
- class _YD_OCC_BASEDISPATCH_MODE CBaseDispatch
- {
- public:
- CBaseDispatch(void);
- virtual ~CBaseDispatch(void);
- public:
- virtual BOOL InitInstance() = 0;
- virtual int ExitInstance() = 0;
-
- //////////////////////////////////////////////////////////////////////////
- // 重要事件处理辅助函数
- // 返回true表示需要默认函数继续处理
- virtual bool EventF1Ass(NORMALCMDC& NCC1) = 0;
- //////////////////////////////////////////////////////////////////////////
- // 普通事件处理辅助函数
- // 返回true表示需要默认函数继续处理
- virtual bool EventF2Ass(NORMALCMDC& NCC1) = 0;
- //////////////////////////////////////////////////////////////////////////
- // 事件发起辅助函数
- // 返回true表示需要重设时间
- virtual bool EventBeginAss(const time_t& time1, const time_t &lpTimeSpan) = 0;
- //////////////////////////////////////////////////////////////////////////
- // 对象计算辅助函数
- // 返回true表示需要重设时间
- virtual bool ObjectCPAss(const time_t& time1, const time_t &lpTimeSpan) = 0;
- // 数据初始化处理辅助函数
- // 返回true表示成功
- virtual bool InitSubSysDBDate(int courseid,int parm1,int parm2,InitCourInfo* curseinfo) = 0;
- //任务控制
- virtual bool StartTask (int& ret) = 0;
- virtual bool StopTask (int& ret) = 0;
- virtual bool PauseTask (int& ret) = 0;
- virtual bool ResumeTask(int& ret) = 0;
- //回滚控制
- virtual BOOL RollBack_Prepare(CRollBack_ITool* pRollBack);
- virtual BOOL RollBack_Excute (CRollBack_ITool* pRollBack);
- virtual BOOL RollBack_Finish (CRollBack_ITool* pRollBack);
- virtual BOOL RollBack_Record (CRollBack_ITool* pRollBack);
- virtual int GetSim_NumberTime() { return -1; }
- //处理特殊UDP数据
- virtual void DealWith_Special_UDPData(long lSysID, char* pDataBuf, int nLength) {}
- public:
- bool OpenWork( int nTrainID,int nSysType,
- CommandQueue* pTCPSendList,
- CommandQueue* pGroupSendList,
- CommandQueue* pUDPSendList ); //连接数据库并创建相关线程等准备工作
- bool OpenDB( std::string Str_IP, std::string Str_Name,std::string Str_User,
- std::string Str_Psw,int nCourseID,int nRunLineID,int nPara1,
- int nPara2,int nDB_Type,InitCourInfo* pCourseInfo); //连接数据库并初始化程序
- BOOL ReadCourInfo( int nCourseID,int nPara1,int nPara2,InitCourInfo* pCourseInfo ); //更多公用课程信息可在此处理
- void ReceiveMsg( OCCCOMMAND& NetCmd );
- void AddLogItem( std::string strvalue,int Pri = LOG_LEVEL_NORMAL );
- void Excute_Sql( std::string Str_Sql );
- void Exit();
- void Dispatch_ModuleInit(CDispatchMng_I* pDispatchMngI);
- void Add_Module_Watch();
- private:
- void ThreadFun_EventF1(); //线程函数_F1
- void ThreadFun_EventF2(); //线程函数_F2
- void ThreadFun_EventBegin(); //线程函数_EventBegin
- void ThreadFun_ObjectCP(); //线程函数_ObjectCP
- public:
- int m_courseid; //课程号
- int m_trianid; //训练号
- int m_nRunLineID; //运营线路号
- int m_subsystype; //子系统类型
- CMDQueue _QI_eventF1List;
- CMDQueue _QI_eventF2List;
- InitCourInfo m_curseinfo; //课程相关信息
- COURSE_CAL_INFO m_CourseCalInfo; //课程计算信息
- Map_RollBackSubSys m_RollBackSysMap; //回滚子模块
- bool m_EventF1ThreadOut;
- bool m_EventF2ThreadOut;
- bool m_EventBeginThreadOut;
- bool m_ObjectCPThreadOut;
- double m_ObjectCPThreadTimeDur;
- double m_EventBeginThreadTimeDur;
- double m_EventF2ThreadTimeDur;
- double m_EventF1ThreadTimeDur;
- int m_RunStatus;
- protected:
- bool m_bF1ThreadFinish;
- bool m_bF2ThreadFinish;
- bool m_bBeginThreadFinish;
- bool m_bObjectCPThreadFinish;
- private:
- double m_dInitTime;
- double m_dTaskStartTime;
- protected:
- CommandQueue m_QI_GetCommands; //接受命令及数据交互时使用该表
- CommandQueue* m_pQI_SendCmdsList;
- CommandQueue* m_pQI_SendGroupList;
- CommandQueue* m_pQI_SendRealList;
- std::thread m_Thread_EventF1;
- std::thread m_Thread_EventF2;
- std::thread m_Thread_EventBegin;
- std::thread m_Thread_ObjectCP;
- CNetWorkMng_I* m_pNetWork;
- CDebug_Module_I* m_pDebugModule;
- YD_RedisClient* m_pRedisClient;
- CDispatchMng_I* m_pDispatchMngI;
- YD_DBOperator* m_pDataBaseOper;
- public:
- CFrameTool_I* m_pFrmTool;
-
- protected:
- bool InitDate();
- bool ReleaseDate();
- bool CreateWorkThread();
- void StopWorkThreads();
- bool Wait_AllThread_Finish( int nTimeOut_T = 60 );
- protected:
- virtual bool Send_TrainReset_Cmd();
- virtual bool Send_DispatchSys_OperR( OCCCOMMAND NetCmd,int nResultCode );
- };
- typedef map<std::string,CBaseDispatch*> DISTASKMAP;
|