GlobalFuncThread.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef GLOBALFUNCTHREAD_H
  2. #define GLOBALFUNCTHREAD_H
  3. #include "GlobalVariable.h"
  4. /**
  5. * @brief 按照功能分类的线程信息,一个实例就是一个功能,
  6. 比如区域入侵检测,需要多个算法多个摄像机共同配合
  7. *
  8. */
  9. struct FuncThreadInfo
  10. {
  11. int ChannelID; /* 频率ID */
  12. std::string strChannelName; /* 频率名称 */
  13. AppFunction appFunction; /* 任务功能 */
  14. RunTimeState RunState; /* 线程运行状态 */
  15. std::string strFunctionName; /* 功能名称 */
  16. QDateTime StartTime; /* 开始时间 */
  17. QDateTime EndTime; /* 结束时间 */
  18. std::list<RoomCamActInfo> listRoomCamActInfo; /* 房间内的摄像机和算法关联信息 */
  19. std::map<int, std::string> mapCameraName; /* 摄像机名称 */
  20. FuncThreadInfo();
  21. ~FuncThreadInfo();
  22. FuncThreadInfo& operator=(FuncThreadInfo& other);
  23. /* 添加算法信息 */
  24. bool addActionInfo(const ActionInfo& info);
  25. /* 清空算法信息 */
  26. void clearActionList();
  27. /* 获取摄像机名称 */
  28. std::string getCameraName(int CameraID);
  29. };
  30. /**
  31. * @brief 线程功能块
  32. *
  33. */
  34. struct ListFuncActInfo
  35. {
  36. ListFuncActInfo() = default;
  37. /* 添加功能信息 */
  38. bool addFuncThreadInfo(const AppAndTimeInfo& func);
  39. /* 添加算法信息 */
  40. bool addActionInfo(const ActionInfo& info);
  41. /* 清空无用的功能信息 */
  42. void clearNoneFuncThreadInfo();
  43. /* 清空房间和算法列表 */
  44. void clearActionList();
  45. /* 获取容器 */
  46. std::list<FuncThreadInfo*>& getData() {
  47. return listFuncThreadInfo;
  48. }
  49. /* 查找应用信息 */
  50. bool findAppFunction(const AppFunction func);
  51. FuncThreadInfo* findAppFunction(const int ChannelID, const AppFunction func);
  52. FuncThreadInfo* findAppFunction(const FuncThreadInfo& func);
  53. std::list<FuncThreadInfo*> listFuncThreadInfo; /* 功能信息列表 */
  54. };
  55. /* ====================================================================================
  56. * ************************ GlobalThreadInfo成员函数 ****************************
  57. * ====================================================================================*/
  58. #define GThreadInfo GlobalThreadInfo::getInstance()
  59. /**
  60. * @brief 线程信息,也是应用功能块列表,每个频率下的每个功能就是一个线程
  61. *
  62. */
  63. class GlobalThreadInfo
  64. {
  65. GlobalThreadInfo() {}
  66. ~GlobalThreadInfo() {}
  67. GlobalThreadInfo(const GlobalThreadInfo& other) = delete;
  68. GlobalThreadInfo& operator=(const GlobalThreadInfo& other) = delete;
  69. public:
  70. static GlobalThreadInfo& getInstance()
  71. {
  72. static GlobalThreadInfo instance;
  73. return instance;
  74. }
  75. /* 获取线程运行标志位 */
  76. bool getRunning() const;
  77. /* 设置线程运行标志位 */
  78. void setRunning(bool bRunning);
  79. /* 手动给功能块列表加锁 */
  80. void lockRunFAI();
  81. /* 手动解锁 */
  82. void unlockRunFAI();
  83. /* 添加功能信息 */
  84. bool addFuncThreadInfo(const AppAndTimeInfo& func);
  85. /* 添加算法信息 */
  86. bool addActionInfo(const ActionInfo& info);
  87. /* 清空无用的功能信息 */
  88. void clearNoneFuncThreadInfo();
  89. /* 清空房间和算法列表 */
  90. void clearActionList();
  91. /* 设置没有配置摄像机的功能退出 */
  92. void setNoneCameraFuncStop();
  93. /* 获取容器 */
  94. std::list<FuncThreadInfo*>& getList() {
  95. return m_listFuncThreadInfo;
  96. }
  97. /* 查找应用信息 */
  98. bool findAppFunction(const AppFunction func);
  99. FuncThreadInfo* findAppFunction(const int ChannelID, const AppFunction func);
  100. FuncThreadInfo* findAppFunction(const FuncThreadInfo& func);
  101. /* 设置线程状态 */
  102. void setThreadState(FuncThreadInfo* pInfo, RunTimeState state);
  103. void setThreadState(FuncThreadInfo& pInfo, RunTimeState state);
  104. /* 更新算法的摄像机ID */
  105. bool updateFuncInfo(FuncThreadInfo* pInfo);
  106. bool updateFuncInfo(FuncThreadInfo& pInfo);
  107. /* 更新频率信息 */
  108. // void setChannelInfo(std::map<int, std::string> mapChannelName);
  109. /* 设置摄像机信息 */
  110. void setCameraInfo(std::map<int, std::string> mapCameraName);
  111. private:
  112. std::atomic_bool m_bRunning; /* 线程运行状态 */
  113. /* 运行时应用线程功能相关信息 */
  114. std::mutex m_mutexRunFAI;
  115. std::list<FuncThreadInfo*> m_listFuncThreadInfo; /* 功能信息列表 */
  116. };
  117. #endif // GLOBALFUNCTHREAD_H