GlobalConfig.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #ifndef GLOBALCONFIG_H
  2. #define GLOBALCONFIG_H
  3. #include <QString>
  4. #include <QReadWriteLock>
  5. #include <map>
  6. #define GVariable GlobalVariable::getInstance()
  7. /**
  8. * @brief 全局应用使用到的变量
  9. *
  10. */
  11. class GlobalVariable
  12. {
  13. friend class GlobalConfig;
  14. GlobalVariable();
  15. GlobalVariable(const GlobalVariable& other) = delete;
  16. GlobalVariable& operator=(const GlobalVariable& other) = delete;
  17. public:
  18. ~GlobalVariable() {}
  19. static GlobalVariable& getInstance()
  20. {
  21. static GlobalVariable gv;
  22. return gv;
  23. }
  24. int AppUpdateOnWorkTimeInterval_Time; /* 更新在岗信息的时间间隔 */
  25. int AppPeopleOnWork_Time; /* 离岗时间 */
  26. int AppContraband_Time; /* 违禁物品出现的时间 */
  27. int AppBadMan_Time; /* 非法入侵超时时间 */
  28. int AppTired_Time; /* 疲劳检测时间 */
  29. int AppPeopleCont; /* 区域人员统计 */
  30. int AppPlayPhone; /* 玩手机识别 */
  31. int AppMouse; /* 老鼠识别 */
  32. int AppMask; /* 戴口罩识别 */
  33. int CheckSet; /* 服务端多久检测一次配置 */
  34. int EventTimeValid; /* 事件时间有效期 */
  35. int ThreadSleepMS; /* 任务线程休眠时间,单位是ms */
  36. const int CheckDeviceTime = 20; /* 从超脑平台检测设备的时间间隔,单位是秒 */
  37. /* 算法ID,通过这个识别从超脑平台获取到的算法,这个算法ID是全的,带有后缀的 */
  38. /* 人脸识别算法ID */
  39. std::string ActFaceIdentify;
  40. /* 人员统计算法ID */
  41. std::string ActPersonCount;
  42. /* 违禁品算法ID */
  43. std::string ActContraband;
  44. /* 玩手机算法ID */
  45. std::string ActPlayPhone;
  46. /* 疲劳检测算法ID */
  47. std::string ActFatigueDetection;
  48. /* 睡岗识别算法ID */
  49. std::string ActSleep;
  50. /* 老鼠检测 */
  51. std::string ActMouseDetect;
  52. /* 未戴口罩识别 */
  53. std::string ActNoMask;
  54. /* 摔倒识别 */
  55. std::string ActAllDown;
  56. /* 动物识别 */
  57. std::string ActAnimalDetect;
  58. QReadWriteLock mutexRW; /* 读写锁 */
  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. private:
  65. std::map<std::string, std::string> m_mapAction; /* 算法ID和算法名称的对应关系,算法ID是完整的ID */
  66. };
  67. /* ====================================================================================
  68. * ***************************** GlobalConfig ***********************************
  69. * ====================================================================================*/
  70. #define GConfig GlobalConfig::getInstance()
  71. /**
  72. * @brief 配置文件信息
  73. *
  74. */
  75. class GlobalConfig
  76. {
  77. GlobalConfig();
  78. ~GlobalConfig() = default;
  79. GlobalConfig(const GlobalConfig& other) = delete;
  80. GlobalConfig& operator=(const GlobalConfig& other) = delete;
  81. public:
  82. static GlobalConfig& getInstance()
  83. {
  84. static GlobalConfig gc;
  85. return gc;
  86. }
  87. /* 初始化服务 */
  88. void initService();
  89. /* 读取基础配置文件 */
  90. bool readBaseConfig(const QString& strConfigFile);
  91. /* 打印基础配置文件 */
  92. void printBaseConfig();
  93. /* 读取算法配置文件 */
  94. bool readAlgorithmConfig(const QString& strConfigFile);
  95. /* 打印算法配置文件 */
  96. void printAlgorithmConfig();
  97. /* 读取应用配置文件 */
  98. bool readAppConfig(const QString& strConfigFile);
  99. /* 打印读取到的值 */
  100. void printAppConfig();
  101. /* 获取webapi信息 */
  102. QString webapiUrl() { return m_webAPIUrl; }
  103. QString webapiKey() { return m_webAPIKey; }
  104. QString webapiAppType() { return m_webAPIAppType; }
  105. /* 获取Redis信息 */
  106. std::string redisIP() { return m_redisIP; }
  107. int redisPort() { return m_redisPort; }
  108. std::string redisPWD() { return m_redisPWD; }
  109. /* 获取超脑信息 */
  110. std::string superBrainUrl() { return m_superBrainUrl; }
  111. std::string superBrainAppKey() { return m_superBrainAppKey; }
  112. std::string superBrainAppSecret() { return m_superBrainAppSecret; }
  113. public:
  114. /* 添加通道信息 */
  115. void setChannelInfo(std::map<int, std::string> mapChannelName);
  116. /* 清空通道信息 */
  117. void clearChannelInfo();
  118. /* 获取通道名称 */
  119. std::string getChannelName(int ChannelID);
  120. /* 获取通道信息 */
  121. std::map<int, std::string> getChannelInfoMap();
  122. /* 添加摄像机信息 */
  123. void setCameraInfo(std::map<int, std::string> mapCameraName);
  124. /* 获取摄像机名称 */
  125. std::string getCameraName(int CameraID);
  126. /* 获取摄像机信息列表 */
  127. std::map<int, std::string> getCameraInfoMap() { return m_mapCameraName; }
  128. private:
  129. QReadWriteLock m_rwLockChnInfo; /* 读写锁 */
  130. std::map<int, std::string> m_mapChannelName; /* 通道名称 */
  131. /* 摄像机名称 */
  132. QReadWriteLock m_rwLockCamInfo; /* 读写锁 */
  133. std::map<int, std::string> m_mapCameraName; /* 摄像机名称 */
  134. QString m_webAPIUrl; /* WebAPI的URL */
  135. QString m_webAPIKey; /* WebAPI的Key */
  136. const QString m_webAPIAppType = "SPSS"; /* WebAPI的Secret */
  137. std::string m_redisIP; /* Redis的IP */
  138. int m_redisPort; /* Redis的端口 */
  139. std::string m_redisPWD; /* Redis的密码 */
  140. std::string m_superBrainUrl; /* 超脑的URL */
  141. std::string m_superBrainAppKey; /* 超脑的AppKey */
  142. std::string m_superBrainAppSecret; /* 超脑的AppSecret */
  143. };
  144. #endif /* GLOBALCONFIG_H */