SPAServer.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef SPASERVER_H
  2. #define SPASERVER_H
  3. #include "FromSuperBrain.h"
  4. #include "FromRedis.h"
  5. #include "ToEQMDataBase.h"
  6. /**
  7. * 安播辅助提示系统服务类
  8. * 写入EQM数据库的报警逻辑
  9. *
  10. */
  11. class SPAServer
  12. {
  13. public:
  14. SPAServer();
  15. ~SPAServer();
  16. /* 启动服务 */
  17. void startServer();
  18. private:
  19. /* 从基础平台获取算法信息和设备信息的线程函数 */
  20. void threadFromSuperBrain();
  21. /* 处理算法信息,返回值为true,说明有改变,需要重新读取 */
  22. bool processAlgorithmInfo(std::vector<AlgorithmInfo> vecNewAlgInfo);
  23. /* 处理设备信息,传入新获取到的值,返回true需要更新本地数据缓存 */
  24. bool processDeviceInfo(std::vector<DeviceInfo> vecNewDevInfo);
  25. /* 对比算法信息现有的数据和新获取到的数据,取出要删除和添加的数据 */
  26. void compareAlgorithmInfo(const std::vector<AlgorithmInfo>& vecNewInfo, std::vector<AlgorithmInfo>& vecAlgUpdate, std::vector<AlgorithmInfo>& vecAlgDelete);
  27. /* 对比设备和算法关联表是否需要更新 */
  28. void compareDeviceAlgorithmInfo(const std::vector<DeviceInfo>& vecNewInfo, std::vector<DeviceInfo>& vecDevUpdate);
  29. /* 从Redis获取数据线程函数,这个是摄像机线程 */
  30. void threadFromRedis(const CameraThreadInfo& info);
  31. /* 解析Redis基础数据 */
  32. void parseRedisData(const std::string& strData, AlarmInfo& alarmInfo);
  33. /* 解析Redis的基础通用数据,不包含bBoxes数组数据 */
  34. void parseRedisBaseData(const std::string& strData, AlarmInfo& alarmInfo);
  35. /* 解析Redis的bBoxes数据, */
  36. void parseRedisBBoxesData(const std::string& strData, AlarmInfo& alarmInfo);
  37. /* 判断时间是否长时间没有更新 */
  38. bool isEventTimeVaild(const std::string& strTime);
  39. /* 分派任务的线程 */
  40. void threadRoomCamera();
  41. /* 将该算法对应的摄像机放入摄像机列表 */
  42. bool insertCameraToAction(RoomActionInfo* pRAInfo, std::list<RoomCameraInfo>& listRC, std::multimap<int, std::string>& mapCameraActionID);
  43. /* 更新房间、算法需要的摄像机个数 */
  44. bool updateRoomActionCameraCount(std::shared_ptr<RoomActionInfo> pRAInfo);
  45. /* 更新算法的摄像机ID */
  46. bool updateActionCameraID(std::shared_ptr<ActionInfo> pInfo);
  47. /* 设置线程状态 */
  48. void setThreadState(std::shared_ptr<ActionInfo> pInfo, RunTimeState state);
  49. /* 人员在岗识别线程,应该是人脸识别线程,这个需要房间内多个摄像机共同识别 */
  50. void threadActPersonWork(RoomActionInfo* RAInfo);
  51. /* 区域人员检测,检测这个区域内的人数,不能少于多少人,不能多余多少人 */
  52. void threadActPersonNumber(RoomActionInfo* RAInfo);
  53. /* 违禁物品识别 */
  54. void threadActContraband(ActionInfo* info);
  55. /* 非法入侵检测 */
  56. void threadActIllegalInvasion(ActionInfo* info);
  57. private:
  58. std::shared_ptr<spdlog::logger> m_logger = nullptr;
  59. bool m_threadRunning = true; /* 线程正在运行 */
  60. FromSuperBrain m_fromSuperBrain;
  61. ToEQMDataBase m_toEQMDataBase;
  62. std::string m_keyContraband; /* 违禁品检测的Key,这个Key后面可能随时会变动 */
  63. std::string m_KeyFace; /* 人脸检测的Key */
  64. std::mutex m_mutexActionID; /* 算法ID的互斥锁 */
  65. std::string ActPersonWork; /* 人员在岗识别 */
  66. std::string ActPersonNumber; /* 区域人员检测 */
  67. std::string ActContraband; /* 违禁品检测 */
  68. std::string ActIllegalInvasion; /* 非法入侵检测 */
  69. std::string ActFatigueDetection; /* 疲劳检测 */
  70. /* 算法信息,这个就是tAction在内存中的数据,方便后续对比,程序启动的时候会先获取一份 */
  71. std::vector<AlgorithmInfo> m_vecEqmAlgInfo;
  72. /* 设备信息,这个是tActionCamer的信息 */
  73. std::vector<DeviceInfo> m_vecEqmDevInfo;
  74. /* 算法信息列表,每个算法所在的频率、房间、摄像机 */
  75. std::mutex m_mutexActionInfo;
  76. ListActionInfo m_listActionInfo;
  77. /* 设备和算法关联信息,这里存储着已经删除的设备对应的算法信息,将在这一轮循环中删除 */
  78. std::list<int> m_listDevIDDelete;
  79. /* 房间和算法关联的信息,包含所需要的摄像机ID */
  80. std::mutex m_mutexRunRAI;
  81. ListRoomActionInfo m_runListRoomActionInfo;
  82. /* 运行时的算法信息列表,这个容器存储的是不需要摄像机融合的算法 */
  83. std::mutex m_mutexRunActionInfo;
  84. ListActionInfo m_runListActionInfo;
  85. };
  86. #endif /* SPASERVER_H */