GlobalConfig.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 AppPeopleOnWork_Time; /* 离岗时间 */
  27. int AppContraband_Time; /* 违禁物品出现的时间 */
  28. int AppBadMan_Time; /* 非法入侵超时时间 */
  29. int AppTired_Time; /* 疲劳检测时间 */
  30. int AppPeopleCount_LessTime; /* 区域人员统计少于多长时间会取消报警 */
  31. int AppPlayPhone; /* 玩手机识别 */
  32. int AppMouse; /* 老鼠识别 */
  33. int AppMask; /* 戴口罩识别 */
  34. int CheckSet; /* 服务端多久检测一次配置 */
  35. int EventTimeValid; /* 事件时间有效期 */
  36. const int CheckDeviceTime = 20; /* 从超脑平台检测设备的时间间隔,单位是秒 */
  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 QDateTime nullTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
  67. private:
  68. int m_threadSleepMS = 1000; /* 线程休眠时间,单位是ms */
  69. /* 算法ID,通过这个识别从超脑平台获取到的算法,这个算法ID是全的,带有后缀的 */
  70. /* 人脸识别算法ID */
  71. std::string m_actFaceIdentify;
  72. /* 人员统计算法ID */
  73. std::string m_actPersonCount;
  74. /* 违禁品算法ID */
  75. std::string m_actContraband;
  76. /* 玩手机算法ID */
  77. std::string m_actPlayPhone;
  78. /* 疲劳检测算法ID */
  79. std::string m_actFatigueDetection;
  80. /* 睡岗识别算法ID */
  81. std::string m_actSleep;
  82. /* 老鼠检测 */
  83. std::string m_actMouseDetect;
  84. /* 未戴口罩识别 */
  85. std::string m_actNoMask;
  86. /* 摔倒识别 */
  87. std::string m_actAllDown;
  88. /* 动物识别 */
  89. std::string m_actAnimalDetect;
  90. private:
  91. std::map<std::string, std::string> m_mapAction; /* 算法ID和算法名称的对应关系,目前是从配置文件中读取的 */
  92. };
  93. /* ====================================================================================
  94. * ***************************** GlobalConfig ***********************************
  95. * ====================================================================================*/
  96. #define GConfig GlobalConfig::getInstance()
  97. /**
  98. * @brief 配置文件信息
  99. *
  100. */
  101. class GlobalConfig
  102. {
  103. GlobalConfig();
  104. ~GlobalConfig() = default;
  105. GlobalConfig(const GlobalConfig& other) = delete;
  106. GlobalConfig& operator=(const GlobalConfig& other) = delete;
  107. public:
  108. static GlobalConfig& getInstance()
  109. {
  110. static GlobalConfig gc;
  111. return gc;
  112. }
  113. /* 初始化服务 */
  114. void initService();
  115. /* 读取基础配置文件 */
  116. bool readBaseConfig(const QString& strConfigFile);
  117. /* 打印基础配置文件 */
  118. void printBaseConfig();
  119. /* 读取算法配置文件 */
  120. bool readAlgorithmConfig(const QString& strConfigFile);
  121. /* 打印算法配置文件 */
  122. void printAlgorithmConfig();
  123. /* 读取应用配置文件 */
  124. bool readAppConfig(const QString& strConfigFile);
  125. /* 打印读取到的值 */
  126. void printAppConfig();
  127. /* 获取webapi信息 */
  128. QString webapiUrl() { return m_webAPIUrl; }
  129. QString webapiKey() { return m_webAPIKey; }
  130. QString webapiAppType() { return m_webAPIAppType; }
  131. /* 获取Redis信息 */
  132. std::string redisIP() { return m_redisIP; }
  133. int redisPort() { return m_redisPort; }
  134. std::string redisPWD() { return m_redisPWD; }
  135. /* 获取超脑信息 */
  136. std::string superBrainUrl() { return m_superBrainUrl; }
  137. std::string superBrainAppKey() { return m_superBrainAppKey; }
  138. std::string superBrainAppSecret() { return m_superBrainAppSecret; }
  139. public:
  140. /* 添加通道信息 */
  141. void setChannelInfo(std::map<int, std::string> mapChannelName);
  142. /* 清空通道信息 */
  143. void clearChannelInfo();
  144. /* 获取通道名称 */
  145. std::string getChannelName(int ChannelID);
  146. /* 获取通道信息 */
  147. std::map<int, std::string> getChannelInfoMap();
  148. /* 添加摄像机信息 */
  149. void setCameraInfo(std::map<int, std::string> mapCameraName);
  150. /* 获取摄像机名称 */
  151. std::string getCameraName(int CameraID);
  152. /* 获取摄像机信息列表 */
  153. std::map<int, std::string> getCameraInfoMap() { return m_mapCameraName; }
  154. private:
  155. QReadWriteLock m_rwLockChnInfo; /* 读写锁 */
  156. std::map<int, std::string> m_mapChannelName; /* 通道名称 */
  157. /* 摄像机名称 */
  158. QReadWriteLock m_rwLockCamInfo; /* 读写锁 */
  159. std::map<int, std::string> m_mapCameraName; /* 摄像机名称 */
  160. QString m_webAPIUrl; /* WebAPI的URL */
  161. QString m_webAPIKey; /* WebAPI的Key */
  162. const QString m_webAPIAppType = "SPSS"; /* WebAPI的Secret */
  163. std::string m_redisIP; /* Redis的IP */
  164. int m_redisPort; /* Redis的端口 */
  165. std::string m_redisPWD; /* Redis的密码 */
  166. std::string m_superBrainUrl; /* 超脑的URL */
  167. std::string m_superBrainAppKey; /* 超脑的AppKey */
  168. std::string m_superBrainAppSecret; /* 超脑的AppSecret */
  169. };
  170. #endif /* GLOBALCONFIG_H */