AppService.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. extern bool g_bExternalData; //是否启用外部数据
  29. extern CString g_strIniPath;
  30. typedef struct tagFileData
  31. {
  32. char* data = nullptr;
  33. uint32_t len = 0;
  34. uint32_t crc = 0;
  35. time_t ctime = 0;
  36. public:
  37. tagFileData()
  38. {
  39. ctime = time(NULL);
  40. }
  41. void Join();
  42. private:
  43. ~tagFileData()
  44. {
  45. delete[] data;
  46. len = 0;
  47. crc = 0;
  48. ctime = 0;
  49. }
  50. }UPGRADE_FILE_DATA, *LPUPGRADE_FILE_DATA;
  51. class CAppService
  52. {
  53. public:
  54. CAppService();
  55. virtual ~CAppService();
  56. public:
  57. static CAppService* Instance() { return &obj; };
  58. bool Start();
  59. void Stop();
  60. CLNHandle* GetHandle() { return m_pHandle; };
  61. CLNAcceptor* GetAcceptor() { return m_pAcceptor; };
  62. CUDPSocket* GetUdpSocket() { return m_pUdpSocket; };
  63. //inline CLWSServer* GetLwsServer() { return m_lwsServer; };
  64. inline CMGWSServer* GetMgServer() { return m_mgServer; }
  65. //type filedata
  66. std::map<CString, LPUPGRADE_FILE_DATA> m_mapTypeData;
  67. //临时
  68. std::map<CString, LPUPGRADE_FILE_DATA> m_mapTempTypeData;
  69. static BOOL FileDataConvertCharData(const uint8_t* filedata, const int filelen, char* strData);
  70. BOOL m_bHaveDeviceUpgrade = FALSE;
  71. time_t m_tDeviceUpgrade = 0;
  72. inline uint32_t GetPackNo()
  73. {
  74. return m_packno++;
  75. }
  76. void SetSycnSuperTime()
  77. {
  78. m_tmLastSyncSuper = 0;
  79. m_index = 0;
  80. }
  81. private:
  82. static void ThreadProc(DWORD_PTR);
  83. static void ThreadProcForHTTP10088(DWORD_PTR);
  84. static void ThreadProcForHTTP10087(DWORD_PTR);
  85. static void ThreadProcCreateTable(DWORD_PTR);
  86. static uint32_t GeneralMovePack(uint8_t** pack, int* len);
  87. private:
  88. CString m_strIniPath;
  89. static CAppService obj;
  90. bool m_bRun = false;
  91. CLNHandle* m_pHandle = nullptr;
  92. CLNAcceptor* m_pAcceptor = nullptr;
  93. CUDPSocket* m_pUdpSocket = nullptr;
  94. //CLWSServer* m_lwsServer = nullptr;
  95. CMGWSServer* m_mgServer = nullptr;
  96. CProactorTask *m_pProactorTask = nullptr;
  97. std::thread *m_pThreadClearConn = nullptr;
  98. std::thread *m_pCreateTableThread = nullptr;
  99. bool m_bWork = false;
  100. std::thread *m_pHttpThread = nullptr;
  101. std::thread* m_pHttpThread2 = nullptr;
  102. static httplib::Server m_svr10088;
  103. static httplib::Server m_svr10087;
  104. uint32_t m_packno = 1;
  105. //磁盘告警
  106. static void ThreadProcForSpace(DWORD_PTR);
  107. std::thread* m_pThreadSpace = nullptr;
  108. int m_nInterval = 3600; //间隔一个小时执行一次磁盘判断
  109. time_t m_tmLastSpaceTime = 0;
  110. //下发设备同步时间
  111. static void ThreadProcForTime(DWORD_PTR);
  112. std::thread* m_pThreadTime = nullptr;
  113. time_t m_tmLastSyncTime = 0;
  114. //同步到上级
  115. static void ThreadProcSync(DWORD_PTR);
  116. int m_nIntervalSync = 1800; //间隔半个小时执行一次同步
  117. std::thread* m_pThreadSync = nullptr;
  118. time_t m_tmLastSyncSuper = 0;
  119. uint64_t m_index = 0;
  120. };