AppService.h 3.6 KB

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