GlobalConfig.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. int ThreadSleepMS; /* 任务线程休眠时间,单位是ms */
  37. const int CheckDeviceTime = 20; /* 从超脑平台检测设备的时间间隔,单位是秒 */
  38. QReadWriteLock mutexRW; /* 读写锁 */
  39. /* 人脸识别算法ID */
  40. std::string ActFaceIdentify() { return m_actFaceIdentify; }
  41. /* 人员统计算法ID */
  42. std::string ActPersonCount() { return m_actPersonCount; }
  43. /* 违禁品算法ID */
  44. std::string ActContraband() { return m_actContraband; }
  45. /* 玩手机算法ID */
  46. std::string ActPlayPhone() { return m_actPlayPhone; }
  47. /* 疲劳检测算法ID */
  48. std::string ActFatigueDetection() { return m_actFatigueDetection; }
  49. /* 睡岗识别算法ID */
  50. std::string ActSleep() { return m_actSleep; }
  51. /* 老鼠检测 */
  52. std::string ActMouseDetect() { return m_actMouseDetect; }
  53. /* 未戴口罩识别 */
  54. std::string ActNoMask() { return m_actNoMask; }
  55. /* 摔倒识别 */
  56. std::string ActAllDown() { return m_actAllDown; }
  57. /* 动物识别 */
  58. std::string ActAnimalDetect() { return m_actAnimalDetect; }
  59. std::string getActionName(const std::string& actionID);
  60. /* 设置算法名称和算法ID对应关系,没有算法不会添加 */
  61. void setActionName(const std::map<std::string, std::string>& mapAction);
  62. /* 通过不带后缀的算法ID获取完整的算法ID,后缀通过“-”连接 */
  63. // std::string getFullActionID(const std::string& actionID);
  64. /* 设置一个空时间,设置这个时间,在数据库里都是空 */
  65. const QDateTime nullTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss");
  66. private:
  67. /* 算法ID,通过这个识别从超脑平台获取到的算法,这个算法ID是全的,带有后缀的 */
  68. /* 人脸识别算法ID */
  69. std::string m_actFaceIdentify;
  70. /* 人员统计算法ID */
  71. std::string m_actPersonCount;
  72. /* 违禁品算法ID */
  73. std::string m_actContraband;
  74. /* 玩手机算法ID */
  75. std::string m_actPlayPhone;
  76. /* 疲劳检测算法ID */
  77. std::string m_actFatigueDetection;
  78. /* 睡岗识别算法ID */
  79. std::string m_actSleep;
  80. /* 老鼠检测 */
  81. std::string m_actMouseDetect;
  82. /* 未戴口罩识别 */
  83. std::string m_actNoMask;
  84. /* 摔倒识别 */
  85. std::string m_actAllDown;
  86. /* 动物识别 */
  87. std::string m_actAnimalDetect;
  88. private:
  89. std::map<std::string, std::string> m_mapAction; /* 算法ID和算法名称的对应关系,目前是从配置文件中读取的 */
  90. };
  91. /* ====================================================================================
  92. * ***************************** GlobalConfig ***********************************
  93. * ====================================================================================*/
  94. #define GConfig GlobalConfig::getInstance()
  95. /**
  96. * @brief 配置文件信息
  97. *
  98. */
  99. class GlobalConfig
  100. {
  101. GlobalConfig();
  102. ~GlobalConfig() = default;
  103. GlobalConfig(const GlobalConfig& other) = delete;
  104. GlobalConfig& operator=(const GlobalConfig& other) = delete;
  105. public:
  106. static GlobalConfig& getInstance()
  107. {
  108. static GlobalConfig gc;
  109. return gc;
  110. }
  111. /* 初始化服务 */
  112. void initService();
  113. /* 读取基础配置文件 */
  114. bool readBaseConfig(const QString& strConfigFile);
  115. /* 打印基础配置文件 */
  116. void printBaseConfig();
  117. /* 读取算法配置文件 */
  118. bool readAlgorithmConfig(const QString& strConfigFile);
  119. /* 打印算法配置文件 */
  120. void printAlgorithmConfig();
  121. /* 读取应用配置文件 */
  122. bool readAppConfig(const QString& strConfigFile);
  123. /* 打印读取到的值 */
  124. void printAppConfig();
  125. /* 获取webapi信息 */
  126. QString webapiUrl() { return m_webAPIUrl; }
  127. QString webapiKey() { return m_webAPIKey; }
  128. QString webapiAppType() { return m_webAPIAppType; }
  129. /* 获取Redis信息 */
  130. std::string redisIP() { return m_redisIP; }
  131. int redisPort() { return m_redisPort; }
  132. std::string redisPWD() { return m_redisPWD; }
  133. /* 获取超脑信息 */
  134. std::string superBrainUrl() { return m_superBrainUrl; }
  135. std::string superBrainAppKey() { return m_superBrainAppKey; }
  136. std::string superBrainAppSecret() { return m_superBrainAppSecret; }
  137. public:
  138. /* 添加通道信息 */
  139. void setChannelInfo(std::map<int, std::string> mapChannelName);
  140. /* 清空通道信息 */
  141. void clearChannelInfo();
  142. /* 获取通道名称 */
  143. std::string getChannelName(int ChannelID);
  144. /* 获取通道信息 */
  145. std::map<int, std::string> getChannelInfoMap();
  146. /* 添加摄像机信息 */
  147. void setCameraInfo(std::map<int, std::string> mapCameraName);
  148. /* 获取摄像机名称 */
  149. std::string getCameraName(int CameraID);
  150. /* 获取摄像机信息列表 */
  151. std::map<int, std::string> getCameraInfoMap() { return m_mapCameraName; }
  152. private:
  153. QReadWriteLock m_rwLockChnInfo; /* 读写锁 */
  154. std::map<int, std::string> m_mapChannelName; /* 通道名称 */
  155. /* 摄像机名称 */
  156. QReadWriteLock m_rwLockCamInfo; /* 读写锁 */
  157. std::map<int, std::string> m_mapCameraName; /* 摄像机名称 */
  158. QString m_webAPIUrl; /* WebAPI的URL */
  159. QString m_webAPIKey; /* WebAPI的Key */
  160. const QString m_webAPIAppType = "SPSS"; /* WebAPI的Secret */
  161. std::string m_redisIP; /* Redis的IP */
  162. int m_redisPort; /* Redis的端口 */
  163. std::string m_redisPWD; /* Redis的密码 */
  164. std::string m_superBrainUrl; /* 超脑的URL */
  165. std::string m_superBrainAppKey; /* 超脑的AppKey */
  166. std::string m_superBrainAppSecret; /* 超脑的AppSecret */
  167. };
  168. #endif /* GLOBALCONFIG_H */