#ifndef GLOBALCONFIG_H #define GLOBALCONFIG_H #include #include #include #include #define GVariable GlobalVariable::getInstance() /** * @brief 全局应用使用到的变量 * */ class GlobalVariable { friend class GlobalConfig; GlobalVariable(); GlobalVariable(const GlobalVariable& other) = delete; GlobalVariable& operator=(const GlobalVariable& other) = delete; public: ~GlobalVariable() {} static GlobalVariable& getInstance() { static GlobalVariable gv; return gv; } int AppUpdateOnWorkTimeInterval_Time; /* 更新在岗信息的时间间隔 */ int AppLeaveOnWork_Time; /* 离岗报警时间 */ int AppContraband_Time; /* 违禁物品出现的时间 */ int AppIllInvasion_Time; /* 非法入侵超时时间 */ int AppTired_Time; /* 疲劳检测时间 */ int AppPeopleCount_LessTime; /* 区域人员统计少于多长时间会取消报警 */ int AppPlayPhone; /* 玩手机识别 */ int AppMouse; /* 老鼠识别 */ int AppMask; /* 戴口罩识别 */ int CheckAppSet; /* 服务端多久检测一次配置 */ int EventTimeValid; /* 事件时间有效期 */ const int CheckDeviceTime = 60; /* 从超脑平台检测设备的时间间隔,单位是秒 */ QReadWriteLock mutexRW; /* 读写锁 */ /* 任务线程休眠时间,单位是ms */ int ThreadSleepMS() { return m_threadSleepMS; } /* 人脸识别算法ID */ std::string ActFaceIdentify() { return m_actFaceIdentify; } /* 人员统计算法ID */ std::string ActPersonCount() { return m_actPersonCount; } /* 违禁品算法ID */ std::string ActContraband() { return m_actContraband; } /* 玩手机算法ID */ std::string ActPlayPhone() { return m_actPlayPhone; } /* 疲劳检测算法ID */ std::string ActFatigueDetection() { return m_actFatigueDetection; } /* 睡岗识别算法ID */ std::string ActSleep() { return m_actSleep; } /* 老鼠检测 */ std::string ActMouseDetect() { return m_actMouseDetect; } /* 未戴口罩识别 */ std::string ActNoMask() { return m_actNoMask; } /* 摔倒识别 */ std::string ActAllDown() { return m_actAllDown; } /* 动物识别 */ std::string ActAnimalDetect() { return m_actAnimalDetect; } std::string getActionName(const std::string& actionID); /* 设置算法名称和算法ID对应关系,没有算法不会添加 */ void setActionName(const std::map& mapAction); /* 通过不带后缀的算法ID获取完整的算法ID,后缀通过“-”连接 */ // std::string getFullActionID(const std::string& actionID); /* 设置一个空时间,设置这个时间,在数据库里都是空 */ const std::string nullTimeStr = "2000-01-01 00:00:00"; const QDateTime nullTime = QDateTime::fromString(nullTimeStr.c_str(), "yyyy-MM-dd hh:mm:ss"); private: int m_threadSleepMS = 1000; /* 线程休眠时间,单位是ms */ int m_logDetail = 0; /* 详细日志级别,打印Debug日志,0表示不打印,1表示打印 */ /* 算法ID,通过这个识别从超脑平台获取到的算法,这个算法ID是全的,带有后缀的 */ /* 人脸识别算法ID */ std::string m_actFaceIdentify; /* 人员统计算法ID */ std::string m_actPersonCount; /* 违禁品算法ID */ std::string m_actContraband; /* 玩手机算法ID */ std::string m_actPlayPhone; /* 疲劳检测算法ID */ std::string m_actFatigueDetection; /* 睡岗识别算法ID */ std::string m_actSleep; /* 老鼠检测 */ std::string m_actMouseDetect; /* 未戴口罩识别 */ std::string m_actNoMask; /* 摔倒识别 */ std::string m_actAllDown; /* 动物识别 */ std::string m_actAnimalDetect; private: std::map m_mapAction; /* 算法ID和算法名称的对应关系,目前是从配置文件中读取的 */ }; /* ==================================================================================== * ***************************** GlobalConfig *********************************** * ====================================================================================*/ #define GConfig GlobalConfig::getInstance() /** * @brief 配置文件信息 * */ class GlobalConfig { GlobalConfig(); ~GlobalConfig() = default; GlobalConfig(const GlobalConfig& other) = delete; GlobalConfig& operator=(const GlobalConfig& other) = delete; public: static GlobalConfig& getInstance() { static GlobalConfig gc; return gc; } /* 初始化服务 */ void initService(); /* 读取基础配置文件 */ bool readBaseConfig(const QString& strConfigFile); /* 打印基础配置文件 */ void printBaseConfig(); /* 读取算法配置文件 */ bool readAlgorithmConfig(const QString& strConfigFile); /* 打印算法配置文件 */ void printAlgorithmConfig(); /* 读取应用配置文件 */ bool readAppConfig(const QString& strConfigFile); /* 打印读取到的值 */ void printAppConfig(); /* 获取webapi信息 */ QString webapiUrl() { return m_webAPIUrl; } QString webapiKey() { return m_webAPIKey; } QString webapiAppType() { return m_webAPIAppType; } /* 获取Redis信息 */ std::string redisIP() { return m_redisIP; } int redisPort() { return m_redisPort; } std::string redisPWD() { return m_redisPWD; } /* 获取超脑信息 */ std::string superBrainUrl() { return m_superBrainUrl; } std::string superBrainAppKey() { return m_superBrainAppKey; } std::string superBrainAppSecret() { return m_superBrainAppSecret; } /* 获取TCP监听端口 */ int listenPort() { return m_listenPort; } public: /* 添加通道信息 */ void setChannelInfo(std::map mapChannelName); /* 清空通道信息 */ void clearChannelInfo(); /* 获取通道名称 */ std::string getChannelName(int ChannelID); /* 获取通道信息 */ std::map getChannelInfoMap(); /* 添加摄像机信息 */ void setCameraInfo(std::map mapCameraName); /* 获取摄像机名称 */ std::string getCameraName(int CameraID); /* 获取摄像机信息列表 */ std::map getCameraInfoMap() { return m_mapCameraName; } private: QReadWriteLock m_rwLockChnInfo; /* 读写锁 */ std::map m_mapChannelName; /* 通道名称 */ /* 摄像机名称 */ QReadWriteLock m_rwLockCamInfo; /* 读写锁 */ std::map m_mapCameraName; /* 摄像机名称 */ QString m_webAPIUrl; /* WebAPI的URL */ QString m_webAPIKey; /* WebAPI的Key */ const QString m_webAPIAppType = "SPSS"; /* WebAPI的Secret */ std::string m_redisIP; /* Redis的IP */ int m_redisPort; /* Redis的端口 */ std::string m_redisPWD; /* Redis的密码 */ std::string m_superBrainUrl; /* 超脑的URL */ std::string m_superBrainAppKey; /* 超脑的AppKey */ std::string m_superBrainAppSecret; /* 超脑的AppSecret */ int m_listenPort; /* TCP监听端口 */ }; #endif /* GLOBALCONFIG_H */