AppService.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #pragma once
  2. #include "LNBuffer.h"
  3. #include "LNHandle.h"
  4. #include "LNAcceptor.h"
  5. #include <ProactorTask.h>
  6. #include <thread>
  7. #include <chrono>
  8. #include <Simplelog.h>
  9. #include <map>
  10. #include <time.h>
  11. #include <UDPSocket.h>
  12. #include <ace/Init_ACE.h>
  13. //#include "LWSServer.h"
  14. #include <httplib.h>
  15. #include "MGWSServer.h"
  16. #include "SuperManager.h"
  17. #include <RWLockImpl.h>
  18. class C315ClientManager;
  19. extern bool g_bLog;
  20. extern time_t g_stStart;
  21. extern string g_strExepath; //程序目录
  22. extern string g_strVersion; //程序版本
  23. extern C315ClientManager* g_p315ClientManager;
  24. extern uint32_t g_tReminderInterval;
  25. extern string g_strMoMp;
  26. extern CMyRWLock g_lockSync;
  27. extern bool g_bDataCompression;
  28. typedef struct tagFileData
  29. {
  30. char* data = nullptr;
  31. uint32_t len = 0;
  32. uint32_t crc = 0;
  33. time_t ctime = 0;
  34. public:
  35. tagFileData()
  36. {
  37. ctime = time(NULL);
  38. }
  39. void Join();
  40. private:
  41. ~tagFileData()
  42. {
  43. delete[] data;
  44. len = 0;
  45. crc = 0;
  46. ctime = 0;
  47. }
  48. }UPGRADE_FILE_DATA, *LPUPGRADE_FILE_DATA;
  49. class CAppService
  50. {
  51. public:
  52. CAppService();
  53. virtual ~CAppService();
  54. public:
  55. static CAppService* Instance() { return &obj; };
  56. bool Start();
  57. void Stop();
  58. CLNHandle* GetHandle() { return m_pHandle; };
  59. CLNAcceptor* GetAcceptor() { return m_pAcceptor; };
  60. CUDPSocket* GetUdpSocket() { return m_pUdpSocket; };
  61. //inline CLWSServer* GetLwsServer() { return m_lwsServer; };
  62. inline CMGWSServer* GetMgServer() { return m_mgServer; }
  63. //type filedata
  64. std::map<CString, LPUPGRADE_FILE_DATA> m_mapTypeData;
  65. //临时
  66. std::map<CString, LPUPGRADE_FILE_DATA> m_mapTempTypeData;
  67. static BOOL FileDataConvertCharData(const uint8_t* filedata, const int filelen, char* strData);
  68. BOOL m_bHaveDeviceUpgrade = FALSE;
  69. time_t m_tDeviceUpgrade = 0;
  70. inline uint32_t GetPackNo()
  71. {
  72. return m_packno++;
  73. }
  74. void SetSycnSuperTime()
  75. {
  76. m_tmLastSyncSuper = 0;
  77. m_index = 0;
  78. }
  79. private:
  80. static void ThreadProc(DWORD_PTR);
  81. static void ThreadProcForHTTP10088(DWORD_PTR);
  82. static void ThreadProcForHTTP10087(DWORD_PTR);
  83. static void ThreadProcCreateTable(DWORD_PTR);
  84. static uint32_t GeneralMovePack(uint8_t** pack, int* len);
  85. private:
  86. CString m_strIniPath;
  87. static CAppService obj;
  88. bool m_bRun = false;
  89. CLNHandle* m_pHandle = nullptr;
  90. CLNAcceptor* m_pAcceptor = nullptr;
  91. CUDPSocket* m_pUdpSocket = nullptr;
  92. //CLWSServer* m_lwsServer = nullptr;
  93. CMGWSServer* m_mgServer = nullptr;
  94. CProactorTask *m_pProactorTask = nullptr;
  95. std::thread *m_pThreadClearConn = nullptr;
  96. std::thread *m_pCreateTableThread = nullptr;
  97. bool m_bWork = false;
  98. std::thread *m_pHttpThread = nullptr;
  99. std::thread* m_pHttpThread2 = nullptr;
  100. static httplib::Server m_svr10088;
  101. static httplib::Server m_svr10087;
  102. uint32_t m_packno = 1;
  103. //磁盘告警
  104. static void ThreadProcForSpace(DWORD_PTR);
  105. std::thread* m_pThreadSpace = nullptr;
  106. int m_nInterval = 3600; //间隔一个小时执行一次磁盘判断
  107. time_t m_tmLastSpaceTime = 0;
  108. //下发设备同步时间
  109. static void ThreadProcForTime(DWORD_PTR);
  110. std::thread* m_pThreadTime = nullptr;
  111. time_t m_tmLastSyncTime = 0;
  112. //同步到上级
  113. static void ThreadProcSync(DWORD_PTR);
  114. int m_nIntervalSync = 1800; //间隔半个小时执行一次同步
  115. std::thread* m_pThreadSync = nullptr;
  116. time_t m_tmLastSyncSuper = 0;
  117. uint64_t m_index = 0;
  118. };