123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695 |
- #include "GlobalInfo.h"
- #include <QSettings>
- #include "spdlog/spdlog.h"
- /* ====================================================================================
- * ******************************* 全局变量定义 **********************************
- * ====================================================================================*/
- int g_eventTimeVaild = 600; /* 事件时间有效性,单位秒,超过这个时间就认为是无效数据 */
- ActionList g_actionList; /* 全局算法列表 */
- /* ====================================================================================
- * *************************** DeviceInfo成员函数 *******************************
- * ====================================================================================*/
- /* 对比是否相等 */
- bool DeviceInfo::operator==(const DeviceInfo& other)
- {
- if(DeviceID != other.DeviceID) {
- return false;
- }
- else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
- return false;
- }
- else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
- return false;
- }
- else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
- return false;
- }
- return true;
- }
- /* 对比设备关联的算法信息是否相等 */
- bool DeviceInfo::isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other)
- {
- /* 算法数目不相等,直接返回false */
- if(vecAlgorithmInfo.size() != other.size()) {
- return false;
- }else {
- /* 算法数目相等,进一步对比算法信息 */
- bool isEquality = true;
- /* 逐步对比算法信息 */
- for(const auto& it0 : vecAlgorithmInfo) {
- bool isEq2 = true;
- for(const auto& it1 : other) {
- if(it0 == it1) {
- continue;
- }else {
- isEq2 = false;
- break;
- }
- }
- if(!isEq2) {
- isEquality = false;
- break;
- }
- }
- if(!isEquality) {
- return false;
- }
- }
- return true;
- }
- /* ====================================================================================
- * ************************** AlarmInfo成员函数 ****************************
- * ====================================================================================*/
- AlarmInfo::AlarmInfo()
- {
- Is_Alarm = false;
- AlarmID = 0;
- DeviceID = 0;
- RoomID = 0;
- ChannelID = 0;
- State = 0;
- OnWork = 0;
- StartTime = "";
- EndTime = "";
- EventTime = "";
- PicUrl = "";
- ImageInfo = "";
- AppID = "";
- ActionID = "";
- ActionDes = "";
- FaceIDList = "";
- FaceNameList = "";
- BboxList = "";
- }
- AlarmInfo& AlarmInfo::operator=(AlarmInfo& other)
- {
- if(this != &other)
- {
- Is_Alarm = other.Is_Alarm;
- AlarmID = other.AlarmID;
- DeviceID = other.DeviceID;
- RoomID = other.RoomID;
- ChannelID = other.ChannelID;
- State = other.State;
- OnWork = other.OnWork;
- StartTime = other.StartTime;
- EndTime = other.EndTime;
- EventTime = other.EventTime;
- PicUrl = other.PicUrl;
- ImageInfo = other.ImageInfo;
- AppID = other.AppID;
- ActionID = other.ActionID;
- ActionDes = other.ActionDes;
- FaceIDList = other.FaceIDList;
- FaceNameList = other.FaceNameList;
- BboxList = other.BboxList;
- vecPersonInfo = other.vecPersonInfo;
- }
- return *this;
- }
- /* 清空内容 */
- void AlarmInfo::reInit()
- {
- Is_Alarm = false;
- AlarmID = 0;
- DeviceID = 0;
- RoomID = 0;
- ChannelID = 0;
- State = 0;
- OnWork = 0;
- StartTime = "";
- EndTime = "";
- EventTime = "";
- PicUrl = "";
- ImageInfo = "";
- AppID = "";
- ActionID = "";
- ActionDes = "";
- FaceIDList = "";
- FaceNameList = "";
- BboxList = "";
- }
- AlarmRuleInfo::AlarmRuleInfo()
- {
- LiveMinEnable = false;
- LiveMaxEnable = false;
- DicMinEnable = false;
- DicMaxEnable = false;
- LiveDicMinEnable = false;
- LiveDicMaxEnable = false;
- LiveMin = 0;
- LiveMax = 0;
- DicMin = 0;
- DicMax = 0;
- LiveDicMin = 0;
- LiveDicMax = 0;
- RuleName = "";
- }
- AlarmRuleInfo& AlarmRuleInfo::operator=(AlarmRuleInfo& other)
- {
- if(this != &other)
- {
- LiveMinEnable = other.LiveMinEnable;
- LiveMaxEnable = other.LiveMaxEnable;
- DicMinEnable = other.DicMinEnable;
- DicMaxEnable = other.DicMaxEnable;
- LiveDicMinEnable = other.LiveDicMinEnable;
- LiveDicMaxEnable = other.LiveDicMaxEnable;
- LiveMin = other.LiveMin;
- LiveMax = other.LiveMax;
- DicMin = other.DicMin;
- DicMax = other.DicMax;
- LiveDicMin = other.LiveDicMin;
- LiveDicMax = other.LiveDicMax;
- RuleName = other.RuleName;
- }
- return *this;
- }
- /* ====================================================================================
- * ************************** ListActionInfo成员函数 ****************************
- * ====================================================================================*/
- ActionInfo::ActionInfo()
- {
- RunState = RunTimeState::RUN_STATE_INIT;
- ChannelID = -1;
- RoomID = -1;
- CameraID = -1;
- RoomType = -1;
- ActionID = "";
- strRoomName = "";
- strActionName = "";
- }
- ActionInfo& ActionInfo::operator=(const ActionInfo& other)
- {
- if (this != &other)
- {
- ChannelID = other.ChannelID;
- RoomID = other.RoomID;
- CameraID = other.CameraID;
- ActionID = other.ActionID;
- strRoomName = other.strRoomName;
- RoomType = other.RoomType;
- }
- return *this;
- }
- bool ActionInfo::operator==(const ActionInfo& other)
- {
- if(ChannelID != other.ChannelID) {
- return false;
- }
- if(RoomID != other.RoomID) {
- return false;
- }
- if(CameraID != other.CameraID) {
- return false;
- }
- if(ActionID != other.ActionID) {
- return false;
- }
- if(RoomType != other.RoomType) {
- return false;
- }
- return true;
- }
- /* 对比除摄像机外的基础信息是否相等 */
- bool ActionInfo::isEqualBaseInfo(const ActionInfo& other)
- {
- if(ChannelID != other.ChannelID) {
- return false;
- }
- if(RoomID != other.RoomID) {
- return false;
- }
- if(ActionID != other.ActionID) {
- return false;
- }
- if(RoomType != other.RoomType) {
- return false;
- }
- return true;
- }
- /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
- bool ListActionInfo::insertActionInfo(ActionInfo* info)
- {
- /* 先判断是否已经在列表中了 */
- if(findActionInList(info) == nullptr)
- {
- ActionInfo* pActionInfo = new ActionInfo;
- *pActionInfo = *info;
- listActionInfo.push_back(pActionInfo);
- }
- return true;
-
- }
- /* 删除信息 */
- bool ListActionInfo::deleteActionInfo(ActionInfo* info)
- {
- if(info == nullptr)
- {
- return false;
- }
- if(findActionInList(info) != nullptr)
- {
- listActionInfo.remove(info);
- delete info;
- info = nullptr;
- }
- return true;
- }
- /* 给算法添加摄像机,原有的会被替换掉 */
- bool ListActionInfo::addActionCamera(ActionInfo* pInfo)
- {
- auto pActionInfo = findActionIDInListNoCamera(pInfo);
- if(pActionInfo != nullptr)
- {
- pActionInfo->CameraID = pInfo->CameraID;
- }
- return true;
- }
- /* 清空算法中的摄像机信息 */
- void ListActionInfo::clearCameraList()
- {
- for(auto& it0 : listActionInfo)
- {
- it0->CameraID = -1;
- }
- }
- /* 清空设置成STOP或ERROR的Action */
- void ListActionInfo::clearStopAction()
- {
- for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();)
- {
- if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
- {
- delete *it0;
- it0 = listActionInfo.erase(it0);
- }else {
- ++it0;
- }
- }
- }
- /* 查找算法ID是否已在列表中 */
- ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
- {
- for(const auto& it0 : listActionInfo)
- {
- if(*it0 == *pInfo)
- {
- return it0;
- }
- }
- return nullptr;
- }
- /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
- ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo)
- {
- for(const auto& it0 : listActionInfo)
- {
- if(it0->isEqualBaseInfo(*pInfo))
- {
- return it0;
- }
- }
- return nullptr;
- }
- /* 清空容器 */
- void ListActionInfo::clear()
- {
- for(auto& it0 : listActionInfo)
- {
- delete it0;
- it0 = nullptr;
- }
- listActionInfo.clear();
- }
- /* ====================================================================================
- * *********************** ListRoomActionInfo成员函数 ***************************
- * ====================================================================================*/
- /* 对比频道信息、房间信息、算法ID是否相等 */
- bool RoomActionInfo::isEqualBaseInfo(const RoomActionInfo& other)
- {
- if(ChannelID != other.ChannelID) {
- return false;
- }
- if(RoomID != other.RoomID) {
- return false;
- }
- if(ActionID != other.ActionID) {
- return false;
- }
- if(RoomType != other.RoomType) {
- return false;
- }
- return true;
- }
- /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
- bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
- {
- /* 先判断是否已经在列表中了 */
- if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr)
- {
- RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
- *pRoomActionInfo = info;
- listRoomActionInfo.push_back(pRoomActionInfo);
- }
- return true;
- }
- /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
- bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID)
- {
- /* 先判断是否已经在列表中了 */
- if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr)
- {
- RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
- pRoomActionInfo->RoomID = RoomID;
- pRoomActionInfo->ActionID = strActionID;
- listRoomActionInfo.push_back(pRoomActionInfo);
- }
- return true;
- }
- /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
- bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo)
- {
- if(pInfo == nullptr)
- {
- return false;
- }
- for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0)
- {
- if(*it0 == pInfo)
- {
- listRoomActionInfo.erase(it0);
- delete pInfo;
- pInfo = nullptr;
- return true;
- }
- }
- return false;
- }
- /* 清空容器 */
- void ListRoomActionInfo::clear()
- {
- for(auto& it0 : listRoomActionInfo)
- {
- delete it0;
- it0 = nullptr;
- }
- listRoomActionInfo.clear();
- }
- /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
- void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
- {
- auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
- if(pRAInfo != nullptr)
- {
- pRAInfo->listCameraID.push_back(info.CameraID);
- }else {
- RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
- pRoomActionInfo->ChannelID = info.ChannelID;
- pRoomActionInfo->RoomID = info.RoomID;
- pRoomActionInfo->ActionID = info.ActionID;
- pRoomActionInfo->RoomType = info.RoomType;
- pRoomActionInfo->strRoomName = info.strRoomName;
- pRoomActionInfo->listCameraID.push_back(info.CameraID);
- listRoomActionInfo.push_back(pRoomActionInfo);
- }
- }
- /* 清空算法对应的摄像机列表 */
- void ListRoomActionInfo::clearCameraList()
- {
- for(auto& it0 : listRoomActionInfo)
- {
- it0->listCameraID.clear();
- }
- }
- /* 清理设置为STOP或者ERROR的RoomAction */
- void ListRoomActionInfo::clearStopRoomAction()
- {
- for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();)
- {
- if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
- {
- delete *it0;
- it0 = listRoomActionInfo.erase(it0);
- }else {
- ++it0;
- }
- }
- }
- /* 查找算法ID是否已在列表中 */
- RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
- {
- for(const auto& it0 : listRoomActionInfo)
- {
- if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
- {
- return it0;
- }
- }
- return nullptr;
- }
- FuncActionInfo::FuncActionInfo()
- {
- ChannelID = -1;
- appFunction = AppFunction::APP_NONE;
- RunState = RunTimeState::RUN_STATE_NONE;
- strFunctionName = "";
- StartTime = std::chrono::system_clock::now();
- EndTime = std::chrono::system_clock::now();
- listRoomCamActInfo.clear();
- }
- FuncActionInfo& FuncActionInfo::operator=(FuncActionInfo& other)
- {
- if(this != &other)
- {
- ChannelID = other.ChannelID;
- appFunction = other.appFunction;
- RunState = other.RunState;
- strFunctionName = other.strFunctionName;
- StartTime = other.StartTime;
- EndTime = other.EndTime;
- listRoomCamActInfo = other.listRoomCamActInfo;
- }
- return *this;
- }
- /* 添加算法信息 */
- bool FuncActionInfo::addActionInfo(const ActionInfo& info)
- {
- /* 根据此类的功能,添加算法信息 */
- if(appFunction == AppFunction::APP_NONE)
- {
- return false;
- }
- /* 将其添加到对应的房间 */
- bool isFind = false;
- for(auto& it0 : listRoomCamActInfo)
- {
- if((it0.RoomID == info.RoomID) && (it0.RoomType == info.RoomType))
- {
- isFind = true;
- it0.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
- }
- }
- /* 没找到这个房间,就创建 */
- if(!isFind)
- {
- RoomCamActInfo roomCamActInfo;
- roomCamActInfo.RoomID = info.RoomID;
- roomCamActInfo.RoomType = info.RoomType;
- roomCamActInfo.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
- listRoomCamActInfo.push_back(roomCamActInfo);
- }
- return true;
- }
- /**
- * @brief 添加功能信息,一个应用功能在一个频道内只有一个实例
- *
- * @param func 应用功能
- * @return true 添加成功,或者已有这个应用功能
- * @return false
- */
- bool ListFuncActInfo::addFuncActionInfo(AppFunction func)
- {
- if(func == AppFunction::APP_NONE)
- {
- return false;
- }
- /* 先查找有没有这个应用信息 */
- if(findAppFunction(func))
- {
- return true;
- }
- FuncActionInfo* pFuncActionInfo = new FuncActionInfo;
- pFuncActionInfo->appFunction = func;
- listFuncActionInfo.push_back(pFuncActionInfo);
- return true;
- }
- /**
- * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
- *
- * @param info
- * @return true
- * @return false
- */
- bool ListFuncActInfo::addActionInfo(const ActionInfo& info)
- {
- if(info.ActionID.empty())
- {
- return false;
- }
- /* 人脸识别算法 */
- if(info.ActionID == g_actionList.ActFace)
- {
-
- }
- return true;
- }
- /* 查找应用信息 */
- bool ListFuncActInfo::findAppFunction(const AppFunction func)
- {
- for(const auto& it0 : listFuncActionInfo)
- {
- if(it0->appFunction == func)
- {
- return true;
- }
- }
- return false;
- }
- /* 根据频率和功能查找实例 */
- FuncActionInfo* ListFuncActInfo::findAppFunction(const int ChannelID, const AppFunction func)
- {
- for(const auto& it0 : listFuncActionInfo)
- {
- if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
- {
- return it0;
- }
- }
- return nullptr;
- }
- /* ====================================================================================
- * ************************** GlobalConfig成员函数 ******************************
- * ====================================================================================*/
- /* 创建实例 */
- GlobalConfig g_config;
- GlobalConfig::GlobalConfig()
- {
- ThreadSleepMS = 300;
- }
- /* 读取配置文件 */
- bool GlobalConfig::readConfig(const QString& strConfigFile)
- {
- if(strConfigFile.isEmpty())
- {
- SPDLOG_ERROR("读取配置文件失败! 配置文件名为空");
- return false;
- }
- SPDLOG_DEBUG("读取配置文件: {}", strConfigFile.toStdString());
- QSettings settings(strConfigFile, QSettings::IniFormat);
- settings.setIniCodec("UTF-8");
- settings.beginGroup("System");
- AppPeopleOnWork = settings.value("APPPEPOLEONWORK", 300).toInt(); /* 离岗时间 */
- Contraband = settings.value("APPBADTHING", 50).toInt(); /* 违禁物品出现的时间 */
- AppBadMan = settings.value("APPBADMAN", 50).toInt(); /* 非法入侵 */
- AppTired = settings.value("APPTIRED", 50).toInt(); /* 疲劳检测时间 */
- AppPeopleCont = settings.value("APPPEPOLECONT", 50).toInt(); /* 人员聚集时间 */
- AppPlayPhone = settings.value("APPPLAYPHONE", 50).toInt(); /* 玩手机识别 */
- AppMouse = settings.value("APPMOUSE", 50).toInt(); /* 手势识别 */
- AppMask = settings.value("APPMASK", 5).toInt(); /* 戴口罩识别 */
- CheckSet = settings.value("CHECKSET", 300).toInt(); /* 服务端多久检测一次配置 */
- EventTimeValid = settings.value("EventTimeValid", 300).toInt(); /* 事件时间有效期 */
- Key = settings.value("Key").toString().toStdString(); /* Key */
- Secret = settings.value("Secret").toString().toStdString(); /* Secret */
- settings.endGroup();
- if(Key.empty() || Secret.empty())
- {
- SPDLOG_ERROR("读取配置文件失败! Key或Secret为空");
- return false;
- }
- return true;
- }
- /* 打印读取到的值 */
- void GlobalConfig::printValue()
- {
- SPDLOG_INFO("APPPEPOLEONWORK: {}", AppPeopleOnWork);
- SPDLOG_INFO("APPBADTHING: {}", Contraband);
- SPDLOG_INFO("APPBADMAN: {}", AppBadMan);
- SPDLOG_INFO("APPTIRED: {}", AppTired);
- SPDLOG_INFO("APPPEOPLECONT: {}", AppPeopleCont);
- SPDLOG_INFO("APPPLAYPHONE: {}", AppPlayPhone);
- SPDLOG_INFO("APPMOUSE: {}", AppMouse);
- SPDLOG_INFO("APPMASK: {}", AppMask);
- SPDLOG_INFO("CHECKSET: {}", CheckSet);
- SPDLOG_INFO("EventTimeValid: {}", EventTimeValid);
- }
|