GlobalFuncThread.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. /* 根据房间ID查找房间信息 */
  28. RoomCamActInfo findRoomInfo(const int RoomID);
  29. /* 获取摄像机名称 */
  30. std::string getCameraName(int CameraID);
  31. };
  32. /**
  33. * @brief 线程功能块
  34. *
  35. */
  36. struct ListFuncActInfo
  37. {
  38. ListFuncActInfo() = default;
  39. // /* 添加功能信息 */
  40. // bool addFuncThreadInfo(const AppAndTimeInfo& func);
  41. /* 添加算法信息 */
  42. bool addActionInfo(const ActionInfo& info);
  43. /* 清空无用的功能信息 */
  44. void clearNoneFuncThreadInfo();
  45. /* 清空房间和算法列表 */
  46. void clearActionList();
  47. /* 获取容器 */
  48. std::list<FuncThreadInfo*>& getData() {
  49. return listFuncThreadInfo;
  50. }
  51. /* 查找应用信息 */
  52. bool findAppFunction(const AppFunction func);
  53. FuncThreadInfo* findAppFunction(const int ChannelID, const AppFunction func);
  54. FuncThreadInfo* findAppFunction(const FuncThreadInfo& func);
  55. std::list<FuncThreadInfo*> listFuncThreadInfo; /* 功能信息列表 */
  56. };
  57. /* ====================================================================================
  58. * ************************ GlobalThreadInfo成员函数 ****************************
  59. * ====================================================================================*/
  60. #define GThreadInfo GlobalThreadInfo::getInstance()
  61. /**
  62. * @brief 线程信息,也是应用功能块列表,每个频率下的每个功能就是一个线程
  63. *
  64. */
  65. class GlobalThreadInfo
  66. {
  67. GlobalThreadInfo() {}
  68. ~GlobalThreadInfo() {}
  69. GlobalThreadInfo(const GlobalThreadInfo& other) = delete;
  70. GlobalThreadInfo& operator=(const GlobalThreadInfo& other) = delete;
  71. public:
  72. static GlobalThreadInfo& getInstance()
  73. {
  74. static GlobalThreadInfo instance;
  75. return instance;
  76. }
  77. /* 获取线程运行标志位 */
  78. bool getRunning() const;
  79. /* 设置线程运行标志位 */
  80. void setRunning(bool bRunning);
  81. /* 手动给功能块列表加锁 */
  82. void lockRunFAI();
  83. /* 手动解锁 */
  84. void unlockRunFAI();
  85. /* 添加功能信息 */
  86. bool addFuncThreadInfo(const ChannelAppInfo& func);
  87. /* 添加算法信息 */
  88. bool addActionInfo(const ActionInfo& info);
  89. /* 清空无用的功能信息 */
  90. void clearNoneFuncThreadInfo();
  91. /* 清空房间和算法列表 */
  92. void clearActionList();
  93. /* 设置没有配置摄像机的功能退出 */
  94. void setNoneCameraFuncStop();
  95. /* 获取容器 */
  96. std::list<FuncThreadInfo*>& getList() {
  97. return m_listFuncThreadInfo;
  98. }
  99. /* 查找应用信息 */
  100. bool findAppFunction(const AppFunction func);
  101. FuncThreadInfo* findAppFunction(const int ChannelID, const AppFunction func);
  102. FuncThreadInfo* findAppFunction(const FuncThreadInfo& func);
  103. /* 设置应用信息 */
  104. inline void setAppFunction(const ActionInfo& info, const AppFunction func);
  105. /* 设置线程状态 */
  106. void setThreadState(FuncThreadInfo* pInfo, RunTimeState state);
  107. void setThreadState(FuncThreadInfo& pInfo, RunTimeState state);
  108. /* 更新算法的摄像机ID */
  109. bool updateFuncInfo(FuncThreadInfo* pInfo);
  110. bool updateFuncInfo(FuncThreadInfo& pInfo);
  111. /* 更新频率信息 */
  112. // void setChannelInfo(std::map<int, std::string> mapChannelName);
  113. /* 设置摄像机信息 */
  114. void setCameraInfo(std::map<int, std::string> mapCameraName);
  115. private:
  116. std::atomic_bool m_bRunning; /* 线程运行状态 */
  117. /* 运行时应用线程功能相关信息 */
  118. std::mutex m_mutexRunFAI;
  119. std::list<FuncThreadInfo*> m_listFuncThreadInfo; /* 功能信息列表 */
  120. };
  121. #endif // GLOBALFUNCTHREAD_H