TaskMNG.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #pragma once
  2. #include <string>
  3. #include <map>
  4. #include "platform.h"
  5. #include "BaseDispatch.h"
  6. #if defined(_MSC_VER) || defined(WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
  7. #define STD_CALL __stdcall
  8. #else
  9. #define STD_CALL __attribute__((__stdcall__))
  10. #endif
  11. //模块创建和释放的函数指针
  12. typedef CBaseDispatch* (STD_CALL* _CreateSubModule)();
  13. typedef void(STD_CALL* _FreeSubModule)(void*);
  14. using namespace std;
  15. //模块管理信息
  16. struct sPlugin
  17. {
  18. int nModuleID;
  19. void* nFileDll; //库的句柄
  20. _CreateSubModule nCreatePlug; //创建模块的函数指针
  21. _FreeSubModule nFreePlug; //释放模块的函数指针
  22. bool bInitOk; //是否初始化成功
  23. string Str_ModuleName; //模块名称
  24. void Check_Is_OK()
  25. {
  26. if (NULL == nCreatePlug || NULL == nFreePlug)
  27. {
  28. bInitOk = false;
  29. }
  30. else
  31. {
  32. bInitOk = true;
  33. }
  34. }
  35. sPlugin()
  36. {
  37. nModuleID = -1; //模块编号
  38. nFileDll = NULL; //库的句柄
  39. nCreatePlug = NULL; //创建模块的函数指针
  40. nFreePlug = NULL; //释放模块的函数指针
  41. bInitOk = false; //是否初始化成功
  42. Str_ModuleName = ""; //模块名称
  43. }
  44. };
  45. typedef map<int, sPlugin> Map_Plugin;
  46. typedef map<std::string, CBaseDispatch*> DISTASKMAP;
  47. class LogCtrl :public CFrameTool_I
  48. {
  49. public:
  50. virtual BOOL Add_Log(int nLevel, LPCSTR pszFmt, ...);
  51. private:
  52. };
  53. class TaskMNG
  54. {
  55. /*
  56. ===============================================单例=====================================================
  57. */
  58. public:
  59. //初始化获取
  60. static TaskMNG* instance();
  61. //释放结束
  62. static void destroyInstance();
  63. enum TaskStatus
  64. {
  65. Status_Error=-1,
  66. Status_Null = 0,
  67. Status_Init = 1,
  68. Status_Run = 2,
  69. Status_Pass = 3,
  70. Status_Stop = 4,
  71. };
  72. private:
  73. TaskMNG();
  74. ~TaskMNG();
  75. TaskMNG(const TaskMNG& pData);
  76. //const TaskMNG& operator=(const TaskMNG& pData)=0;
  77. static TaskMNG* g_GlobalSingle;
  78. static std::mutex m_Mutex;
  79. public:
  80. void InitDB(string strIP,int nType,string strDBname,string strUser,string strPwd);
  81. bool CreateDispatchTask(int courseid, int systype, int trainid
  82. , int runlineid, int parm1, int parm2, InitCourInfo* curseinfo);
  83. bool DeleteDispatchTask(int courseid, int systype, int trainid);
  84. bool StopDispatchTask(int courseid, int systype, int trainid);
  85. bool PauseDispatchTask(int courseid, int systype, int trainid);
  86. bool ResumeDispatchTask(int courseid, int systype, int trainid);
  87. bool RunDispatchTask(int courseid, int systype, int trainid);
  88. bool NetComand_Receive(OCCCOMMAND& command);
  89. void NetComand_Send(LPBASENETPACKET pnetmsg, int dessystype, OCCCOMMAND::CmdType cmdtype, int trianid, int nDesID = -1);
  90. //获取列表
  91. CBaseDispatch* CreateNewTaskType(int systype);
  92. //日志模块
  93. void AddLogItem(string str1, string str2, int nLevel);
  94. string GetCurTime_ms();
  95. CBaseDispatch* pGetEleVOC();
  96. TaskMNG::TaskStatus getTaskStatus();
  97. std::string getTaskText();
  98. protected:
  99. DISTASKMAP m_DispatchTasksMap;
  100. public:
  101. CommandQueue m_pSendList;
  102. CommandQueue m_pRecvList;
  103. CommandQueue m_pSendGroupList;
  104. CommandQueue m_pGetGroupList;
  105. CommandQueue m_pGetRealList;
  106. CommandQueue m_pSendRealList;
  107. YD_DBOperator* m_pdb;
  108. int m_NetServerID;
  109. public:
  110. Map_Plugin m_PluginMap;
  111. string m_strSeverIP;
  112. string m_strDBName;
  113. string m_strUserID;
  114. string m_strPassWord;
  115. int m_nDBType;
  116. LogCtrl pLogCtrl;
  117. TaskStatus nTaskStatus;
  118. string m_strLog;
  119. };