GlobalConfig.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #ifndef GLOBALCONFIG_H
  2. #define GLOBALCONFIG_H
  3. #include <QString>
  4. #include <QReadWriteLock>
  5. #include <map>
  6. #include <QDateTime>
  7. #define GVariable GlobalVariable::getInstance()
  8. /**
  9. * @brief 全局应用使用到的变量
  10. *
  11. */
  12. class GlobalVariable
  13. {
  14. friend class GlobalConfig;
  15. GlobalVariable();
  16. GlobalVariable(const GlobalVariable& other) = delete;
  17. GlobalVariable& operator=(const GlobalVariable& other) = delete;
  18. public:
  19. ~GlobalVariable() {}
  20. static GlobalVariable& getInstance()
  21. {
  22. static GlobalVariable gv;
  23. return gv;
  24. }
  25. int AppUpdateOnWorkTimeInterval_Time; /* 更新在岗信息的时间间隔 */
  26. int AppLeaveOnWork_Time; /* 离岗报警时间 */
  27. int AppContraband_Time; /* 违禁物品出现的时间 */
  28. int AppIllInvasion_Time; /* 非法入侵超时时间 */
  29. int AppTired_Time; /* 疲劳检测时间 */
  30. int AppPeopleCount_LessTime; /* 区域人员统计少于多长时间会取消报警 */
  31. int AppPlayPhone; /* 玩手机识别 */
  32. int AppMouse; /* 老鼠识别 */
  33. int AppMask; /* 戴口罩识别 */
  34. int CheckAppSet; /* 服务端多久检测一次配置 */
  35. int EventTimeValid; /* 事件时间有效期 */
  36. const int CheckDeviceTime = 60; /* 从超脑平台检测设备的时间间隔,单位是秒 */
  37. QReadWriteLock mutexRW; /* 读写锁 */
  38. /* 任务线程休眠时间,单位是ms */
  39. int ThreadSleepMS() { return m_threadSleepMS; }
  40. /* 人脸识别算法ID */
  41. std::string ActFaceIdentify() { return m_actFaceIdentify; }
  42. /* 人员统计算法ID */
  43. std::string ActPersonCount() { return m_actPersonCount; }
  44. /* 违禁品算法ID */
  45. std::string ActContraband() { return m_actContraband; }
  46. /* 玩手机算法ID */
  47. std::string ActPlayPhone() { return m_actPlayPhone; }
  48. /* 疲劳检测算法ID */
  49. std::string ActFatigueDetection() { return m_actFatigueDetection; }
  50. /* 睡岗识别算法ID */
  51. std::string ActSleep() { return m_actSleep; }
  52. /* 老鼠检测 */
  53. std::string ActMouseDetect() { return m_actMouseDetect; }
  54. /* 未戴口罩识别 */
  55. std::string ActNoMask() { return m_actNoMask; }
  56. /* 摔倒识别 */
  57. std::string ActAllDown() { return m_actAllDown; }
  58. /* 动物识别 */
  59. std::string ActAnimalDetect() { return m_actAnimalDetect; }
  60. std::string getActionName(const std::string& actionID);
  61. /* 设置算法名称和算法ID对应关系,没有算法不会添加 */
  62. void setActionName(const std::map<std::string, std::string>& mapAction);
  63. /* 通过不带后缀的算法ID获取完整的算法ID,后缀通过“-”连接 */
  64. // std::string getFullActionID(const std::string& actionID);
  65. /* 设置一个空时间,设置这个时间,在数据库里都是空 */
  66. const std::string nullTimeStr = "2000-01-01 00:00:00";
  67. const QDateTime nullTime = QDateTime::fromString(nullTimeStr.c_str(), "yyyy-MM-dd hh:mm:ss");
  68. private:
  69. int m_threadSleepMS = 1000; /* 线程休眠时间,单位是ms */
  70. int m_logDetail = 0; /* 详细日志级别,打印Debug日志,0表示不打印,1表示打印 */
  71. /* 算法ID,通过这个识别从超脑平台获取到的算法,这个算法ID是全的,带有后缀的 */
  72. /* 人脸识别算法ID */
  73. std::string m_actFaceIdentify;
  74. /* 人员统计算法ID */
  75. std::string m_actPersonCount;
  76. /* 违禁品算法ID */
  77. std::string m_actContraband;
  78. /* 玩手机算法ID */
  79. std::string m_actPlayPhone;
  80. /* 疲劳检测算法ID */
  81. std::string m_actFatigueDetection;
  82. /* 睡岗识别算法ID */
  83. std::string m_actSleep;
  84. /* 老鼠检测 */
  85. std::string m_actMouseDetect;
  86. /* 未戴口罩识别 */
  87. std::string m_actNoMask;
  88. /* 摔倒识别 */
  89. std::string m_actAllDown;
  90. /* 动物识别 */
  91. std::string m_actAnimalDetect;
  92. private:
  93. std::map<std::string, std::string> m_mapAction; /* 算法ID和算法名称的对应关系,目前是从配置文件中读取的 */
  94. };
  95. /* ====================================================================================
  96. * ***************************** GlobalConfig ***********************************
  97. * ====================================================================================*/
  98. #define GConfig GlobalConfig::getInstance()
  99. /**
  100. * @brief 配置文件信息
  101. *
  102. */
  103. class GlobalConfig
  104. {
  105. GlobalConfig();
  106. ~GlobalConfig() = default;
  107. GlobalConfig(const GlobalConfig& other) = delete;
  108. GlobalConfig& operator=(const GlobalConfig& other) = delete;
  109. public:
  110. static GlobalConfig& getInstance()
  111. {
  112. static GlobalConfig gc;
  113. return gc;
  114. }
  115. /* 初始化服务 */
  116. void initService();
  117. /* 读取基础配置文件 */
  118. bool readBaseConfig(const QString& strConfigFile);
  119. /* 打印基础配置文件 */
  120. void printBaseConfig();
  121. /* 读取算法配置文件 */
  122. bool readAlgorithmConfig(const QString& strConfigFile);
  123. /* 打印算法配置文件 */
  124. void printAlgorithmConfig();
  125. /* 读取应用配置文件 */
  126. bool readAppConfig(const QString& strConfigFile);
  127. /* 打印读取到的值 */
  128. void printAppConfig();
  129. /* 获取webapi信息 */
  130. QString webapiUrl() { return m_webAPIUrl; }
  131. QString webapiKey() { return m_webAPIKey; }
  132. QString webapiAppType() { return m_webAPIAppType; }
  133. /* 获取Redis信息 */
  134. std::string redisIP() { return m_redisIP; }
  135. int redisPort() { return m_redisPort; }
  136. std::string redisPWD() { return m_redisPWD; }
  137. /* 获取超脑信息 */
  138. std::string superBrainUrl() { return m_superBrainUrl; }
  139. std::string superBrainAppKey() { return m_superBrainAppKey; }
  140. std::string superBrainAppSecret() { return m_superBrainAppSecret; }
  141. /* 获取TCP监听端口 */
  142. int listenPort() { return m_listenPort; }
  143. public:
  144. /* 添加通道信息 */
  145. void setChannelInfo(std::map<int, std::string> mapChannelName);
  146. /* 清空通道信息 */
  147. void clearChannelInfo();
  148. /* 获取通道名称 */
  149. std::string getChannelName(int ChannelID);
  150. /* 获取通道信息 */
  151. std::map<int, std::string> getChannelInfoMap();
  152. /* 添加摄像机信息 */
  153. void setCameraInfo(std::map<int, std::string> mapCameraName);
  154. /* 获取摄像机名称 */
  155. std::string getCameraName(int CameraID);
  156. /* 获取摄像机信息列表 */
  157. std::map<int, std::string> getCameraInfoMap() { return m_mapCameraName; }
  158. private:
  159. QReadWriteLock m_rwLockChnInfo; /* 读写锁 */
  160. std::map<int, std::string> m_mapChannelName; /* 通道名称 */
  161. /* 摄像机名称 */
  162. QReadWriteLock m_rwLockCamInfo; /* 读写锁 */
  163. std::map<int, std::string> m_mapCameraName; /* 摄像机名称 */
  164. QString m_webAPIUrl; /* WebAPI的URL */
  165. QString m_webAPIKey; /* WebAPI的Key */
  166. const QString m_webAPIAppType = "SPSS"; /* WebAPI的Secret */
  167. std::string m_redisIP; /* Redis的IP */
  168. int m_redisPort; /* Redis的端口 */
  169. std::string m_redisPWD; /* Redis的密码 */
  170. std::string m_superBrainUrl; /* 超脑的URL */
  171. std::string m_superBrainAppKey; /* 超脑的AppKey */
  172. std::string m_superBrainAppSecret; /* 超脑的AppSecret */
  173. int m_listenPort; /* TCP监听端口 */
  174. };
  175. #endif /* GLOBALCONFIG_H */