GlobalConfig.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef GLOBALCONFIG_H
  2. #define GLOBALCONFIG_H
  3. #include <QString>
  4. #include "GlobalVariable.h"
  5. /* ====================================================================================
  6. * ***************************** GlobalConfig ***********************************
  7. * ====================================================================================*/
  8. #define GConfig GlobalConfig::getInstance()
  9. /**
  10. * @brief 配置文件信息
  11. *
  12. */
  13. class GlobalConfig
  14. {
  15. GlobalConfig();
  16. ~GlobalConfig() = default;
  17. GlobalConfig(const GlobalConfig& other) = delete;
  18. GlobalConfig& operator=(const GlobalConfig& other) = delete;
  19. public:
  20. static GlobalConfig& getInstance()
  21. {
  22. static GlobalConfig gc;
  23. return gc;
  24. }
  25. const int liveRoomType = 1; /* 直播间类型 */
  26. const int dicRoomType = 2; /* 导播间类型 */
  27. /* 读取配置文件 */
  28. bool readConfig(const QString& strConfigFile);
  29. /* 打印读取到的值 */
  30. void printValue();
  31. int AppUpdateOnWorkTimeInterval_Time; /* 更新在岗信息的时间间隔 */
  32. int AppPeopleOnWork_Time; /* 离岗时间 */
  33. int AppContraband_Time; /* 违禁物品出现的时间 */
  34. int AppBadMan_Time; /* 非法入侵超时时间 */
  35. int AppTired_Time; /* 疲劳检测时间 */
  36. int AppPeopleCont; /* 区域人员统计 */
  37. int AppPlayPhone; /* 玩手机识别 */
  38. int AppMouse; /* 老鼠识别 */
  39. int AppMask; /* 戴口罩识别 */
  40. int CheckSet; /* 服务端多久检测一次配置 */
  41. int EventTimeValid; /* 事件时间有效期 */
  42. int ThreadSleepMS; /* 任务线程休眠时间,单位是ms */
  43. std::string Key; /* Key */
  44. std::string Secret; /* Secret */
  45. public:
  46. /* 添加通道信息 */
  47. void setChannelInfo(std::map<int, std::string> mapChannelName);
  48. /* 清空通道信息 */
  49. void clearChannelInfo();
  50. /* 获取通道名称 */
  51. std::string getChannelName(int ChannelID);
  52. /* 添加摄像机信息 */
  53. void setCameraInfo(std::map<int, std::string> mapCameraName);
  54. /* 获取摄像机名称 */
  55. std::string getCameraName(int CameraID);
  56. private:
  57. QReadWriteLock m_rwLockChnInfo; /* 读写锁 */
  58. std::map<int, std::string> m_mapChannelName; /* 通道名称 */
  59. /* 摄像机名称 */
  60. QReadWriteLock m_rwLockCamInfo; /* 读写锁 */
  61. std::map<int, std::string> m_mapCameraName; /* 摄像机名称 */
  62. };
  63. /* ====================================================================================
  64. * ************************ GlobalThreadInfo成员函数 ****************************
  65. * ====================================================================================*/
  66. #define GThreadInfo GlobalThreadInfo::getInstance()
  67. /**
  68. * @brief 线程信息,也是应用功能块列表,每个频率下的每个功能就是一个线程
  69. *
  70. */
  71. class GlobalThreadInfo
  72. {
  73. GlobalThreadInfo() {}
  74. ~GlobalThreadInfo() {}
  75. GlobalThreadInfo(const GlobalThreadInfo& other) = delete;
  76. GlobalThreadInfo& operator=(const GlobalThreadInfo& other) = delete;
  77. public:
  78. static GlobalThreadInfo& getInstance()
  79. {
  80. static GlobalThreadInfo instance;
  81. return instance;
  82. }
  83. /* 获取线程运行标志位 */
  84. bool getRunning() const;
  85. /* 设置线程运行标志位 */
  86. void setRunning(bool bRunning);
  87. /* 手动给功能块列表加锁 */
  88. void lockRunFAI();
  89. /* 手动解锁 */
  90. void unlockRunFAI();
  91. /* 添加功能信息 */
  92. bool addFuncActionInfo(const AppAndTimeInfo& func);
  93. /* 添加算法信息 */
  94. bool addActionInfo(const ActionInfo& info);
  95. /* 清空无用的功能信息 */
  96. void clearNoneFuncActionInfo();
  97. /* 清空房间和算法列表 */
  98. void clearActionList();
  99. /* 设置没有配置摄像机的功能退出 */
  100. void setNoneCameraFuncStop();
  101. /* 获取容器 */
  102. std::list<FuncActionInfo*>& getList() {
  103. return m_listFuncActionInfo;
  104. }
  105. /* 查找应用信息 */
  106. bool findAppFunction(const AppFunction func);
  107. FuncActionInfo* findAppFunction(const int ChannelID, const AppFunction func);
  108. FuncActionInfo* findAppFunction(const FuncActionInfo& func);
  109. /* 设置线程状态 */
  110. void setThreadState(FuncActionInfo* pInfo, RunTimeState state);
  111. void setThreadState(FuncActionInfo& pInfo, RunTimeState state);
  112. /* 更新算法的摄像机ID */
  113. bool updateFuncInfo(FuncActionInfo* pInfo);
  114. bool updateFuncInfo(FuncActionInfo& pInfo);
  115. private:
  116. std::atomic_bool m_bRunning; /* 线程运行状态 */
  117. /* 运行时应用线程功能相关信息 */
  118. std::mutex m_mutexRunFAI;
  119. std::list<FuncActionInfo*> m_listFuncActionInfo; /* 功能信息列表 */
  120. };
  121. #endif /* GLOBALCONFIG_H */