BaseDispatch.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #pragma once
  2. #include "BaseDefine.h"
  3. #include "YD_DBOperator.h"
  4. #include <SubSys_RollBack_I.h>
  5. #include <FrameTool_I.h>
  6. #include <NetWorkMng_I.h>
  7. #include <DispatchMng_I.h>
  8. #include <Debug_Module_I.h>
  9. #include <YD_RedisClient.h>
  10. enum TRAIN_RESET_TYPE
  11. {
  12. eTrainReset_Type_RollBack = 1, //复位类型-将回滚
  13. eTrainReset_Type_PlayBack = 2, //复位类型-将回放
  14. };
  15. #if defined(_MSC_VER) || defined(WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32)
  16. #ifdef _YD_OCC_BASEDISPATCH_SDK
  17. #define _YD_OCC_BASEDISPATCH_MODE __declspec(dllexport)
  18. #else
  19. #define _YD_OCC_BASEDISPATCH_MODE __declspec(dllimport)
  20. #endif
  21. #else //linux
  22. #ifdef _YD_OCC_BASEDISPATCH_SDK
  23. #define _YD_OCC_BASEDISPATCH_MODE __attribute__ ((visibility("default")))
  24. #else
  25. #define _YD_OCC_BASEDISPATCH_MODE
  26. #endif
  27. #endif
  28. class _YD_OCC_BASEDISPATCH_MODE CBaseDispatch
  29. {
  30. public:
  31. CBaseDispatch(void);
  32. virtual ~CBaseDispatch(void);
  33. public:
  34. virtual BOOL InitInstance() = 0;
  35. virtual int ExitInstance() = 0;
  36. //////////////////////////////////////////////////////////////////////////
  37. // 重要事件处理辅助函数
  38. // 返回true表示需要默认函数继续处理
  39. virtual bool EventF1Ass(NORMALCMDC& NCC1) = 0;
  40. //////////////////////////////////////////////////////////////////////////
  41. // 普通事件处理辅助函数
  42. // 返回true表示需要默认函数继续处理
  43. virtual bool EventF2Ass(NORMALCMDC& NCC1) = 0;
  44. //////////////////////////////////////////////////////////////////////////
  45. // 事件发起辅助函数
  46. // 返回true表示需要重设时间
  47. virtual bool EventBeginAss(const time_t& time1, const time_t &lpTimeSpan) = 0;
  48. //////////////////////////////////////////////////////////////////////////
  49. // 对象计算辅助函数
  50. // 返回true表示需要重设时间
  51. virtual bool ObjectCPAss(const time_t& time1, const time_t &lpTimeSpan) = 0;
  52. // 数据初始化处理辅助函数
  53. // 返回true表示成功
  54. virtual bool InitSubSysDBDate(int courseid,int parm1,int parm2,InitCourInfo* curseinfo) = 0;
  55. //任务控制
  56. virtual bool StartTask (int& ret) = 0;
  57. virtual bool StopTask (int& ret) = 0;
  58. virtual bool PauseTask (int& ret) = 0;
  59. virtual bool ResumeTask(int& ret) = 0;
  60. //回滚控制
  61. virtual BOOL RollBack_Prepare(CRollBack_ITool* pRollBack);
  62. virtual BOOL RollBack_Excute (CRollBack_ITool* pRollBack);
  63. virtual BOOL RollBack_Finish (CRollBack_ITool* pRollBack);
  64. virtual BOOL RollBack_Record (CRollBack_ITool* pRollBack);
  65. virtual int GetSim_NumberTime() { return -1; }
  66. //处理特殊UDP数据
  67. virtual void DealWith_Special_UDPData(long lSysID, char* pDataBuf, int nLength) {}
  68. public:
  69. bool OpenWork( int nTrainID,int nSysType,
  70. CommandQueue* pTCPSendList,
  71. CommandQueue* pGroupSendList,
  72. CommandQueue* pUDPSendList ); //连接数据库并创建相关线程等准备工作
  73. bool OpenDB( std::string Str_IP, std::string Str_Name,std::string Str_User,
  74. std::string Str_Psw,int nCourseID,int nRunLineID,int nPara1,
  75. int nPara2,int nDB_Type,InitCourInfo* pCourseInfo); //连接数据库并初始化程序
  76. BOOL ReadCourInfo( int nCourseID,int nPara1,int nPara2,InitCourInfo* pCourseInfo ); //更多公用课程信息可在此处理
  77. void ReceiveMsg( OCCCOMMAND& NetCmd );
  78. void AddLogItem( std::string strvalue,int Pri = LOG_LEVEL_NORMAL );
  79. void Excute_Sql( std::string Str_Sql );
  80. void Exit();
  81. void Dispatch_ModuleInit(CDispatchMng_I* pDispatchMngI);
  82. void Add_Module_Watch();
  83. private:
  84. void ThreadFun_EventF1(); //线程函数_F1
  85. void ThreadFun_EventF2(); //线程函数_F2
  86. void ThreadFun_EventBegin(); //线程函数_EventBegin
  87. void ThreadFun_ObjectCP(); //线程函数_ObjectCP
  88. public:
  89. int m_courseid; //课程号
  90. int m_trianid; //训练号
  91. int m_nRunLineID; //运营线路号
  92. int m_subsystype; //子系统类型
  93. CMDQueue _QI_eventF1List;
  94. CMDQueue _QI_eventF2List;
  95. InitCourInfo m_curseinfo; //课程相关信息
  96. COURSE_CAL_INFO m_CourseCalInfo; //课程计算信息
  97. Map_RollBackSubSys m_RollBackSysMap; //回滚子模块
  98. bool m_EventF1ThreadOut;
  99. bool m_EventF2ThreadOut;
  100. bool m_EventBeginThreadOut;
  101. bool m_ObjectCPThreadOut;
  102. double m_ObjectCPThreadTimeDur;
  103. double m_EventBeginThreadTimeDur;
  104. double m_EventF2ThreadTimeDur;
  105. double m_EventF1ThreadTimeDur;
  106. int m_RunStatus;
  107. protected:
  108. bool m_bF1ThreadFinish;
  109. bool m_bF2ThreadFinish;
  110. bool m_bBeginThreadFinish;
  111. bool m_bObjectCPThreadFinish;
  112. private:
  113. double m_dInitTime;
  114. double m_dTaskStartTime;
  115. protected:
  116. CommandQueue m_QI_GetCommands; //接受命令及数据交互时使用该表
  117. CommandQueue* m_pQI_SendCmdsList;
  118. CommandQueue* m_pQI_SendGroupList;
  119. CommandQueue* m_pQI_SendRealList;
  120. std::thread m_Thread_EventF1;
  121. std::thread m_Thread_EventF2;
  122. std::thread m_Thread_EventBegin;
  123. std::thread m_Thread_ObjectCP;
  124. CNetWorkMng_I* m_pNetWork;
  125. CDebug_Module_I* m_pDebugModule;
  126. YD_RedisClient* m_pRedisClient;
  127. CDispatchMng_I* m_pDispatchMngI;
  128. YD_DBOperator* m_pDataBaseOper;
  129. public:
  130. CFrameTool_I* m_pFrmTool;
  131. protected:
  132. bool InitDate();
  133. bool ReleaseDate();
  134. bool CreateWorkThread();
  135. void StopWorkThreads();
  136. bool Wait_AllThread_Finish( int nTimeOut_T = 60 );
  137. protected:
  138. virtual bool Send_TrainReset_Cmd();
  139. virtual bool Send_DispatchSys_OperR( OCCCOMMAND NetCmd,int nResultCode );
  140. };
  141. typedef map<std::string,CBaseDispatch*> DISTASKMAP;