/* * @Description: * @Version: 1.0 * @Autor: lishengyin * @Date: 2022-03-28 09:03:02 * @LastEditors: lishengyin * @LastEditTime: 2022-09-28 14:18:59 */ #ifndef __BASICECONFIG_H_ #define __BASICECONFIG_H_ #include #include #include #include #include #include using namespace std; class BasicConfig { public: // usr std::string usr; std::string pwd; // NettyIp; std::string NettyIP; int NettyPort; std::string mysql_IP; int mysql_port; double DiskUsageThreshold; int HardDiskCleanupTime; int InferDataRetentionTime; int interval; int sensitivity; int TimeOut; int debug; int getHistoryVideoFlag; int ClearPastRecords; int LowVersion = 0; double bboxSize = 0.0; int ExpelInterval = 0; std::string com_port = ""; int ExpelPort = 19002; int InferInterval = 2000; std::string payServerIP = "10.81.160.141"; int filterLevel = 2; int vpn = 0; int InferChecker = 0; std::string InferCheckerIP = "192.168.31.219"; int InferCheckerPort = 8860; public: BasicConfig(){} ~BasicConfig(){} /** * @description: json转换为object * @param {string&} json * @return {*} */ bool JsonToObject(std::string& json){ rapidjson::Document doc; doc.Parse(json.c_str()); if(!doc.IsObject()){ return false; } // get members const auto end = doc.MemberEnd(); // json_type if(end == doc.FindMember("usr") || !doc["usr"].IsString()) { return false; }else{ usr = doc["usr"].GetString(); } if(end == doc.FindMember("pwd") || !doc["pwd"].IsString()) { return false; }else{ pwd = doc["pwd"].GetString(); } if(end == doc.FindMember("NettyIP") || !doc["NettyIP"].IsString()) { return false; }else{ NettyIP = doc["NettyIP"].GetString(); } if(end == doc.FindMember("NettyPort") || !doc["NettyPort"].IsString()) { return false; }else{ NettyPort = std::atoi(doc["NettyPort"].GetString()); } if(end == doc.FindMember("DiskUsageThreshold") || !doc["DiskUsageThreshold"].IsString()) { return false; }else{ DiskUsageThreshold = std::atof(doc["DiskUsageThreshold"].GetString()); } if(end == doc.FindMember("HardDiskCleanupTime") || !doc["HardDiskCleanupTime"].IsString()) { return false; }else{ HardDiskCleanupTime = std::atoi(doc["HardDiskCleanupTime"].GetString()); } if(end == doc.FindMember("InferDataRetentionTime") || !doc["InferDataRetentionTime"].IsString()) { return false; }else{ InferDataRetentionTime = std::atoi(doc["InferDataRetentionTime"].GetString()); } if(end == doc.FindMember("interval") || !doc["interval"].IsString()) { return false; }else{ interval = std::atoi(doc["interval"].GetString()); } if(end == doc.FindMember("sensitivity") || !doc["sensitivity"].IsString()) { return false; }else{ sensitivity = std::atoi(doc["sensitivity"].GetString()); } if(end == doc.FindMember("TimeOut") || !doc["TimeOut"].IsString()) { return false; }else{ TimeOut = std::atoi(doc["TimeOut"].GetString()); } if(end == doc.FindMember("mysql_IP") || !doc["mysql_IP"].IsString()) { return false; }else{ mysql_IP = doc["mysql_IP"].GetString(); } if(end == doc.FindMember("mysql_port") || !doc["mysql_port"].IsString()) { return false; }else{ mysql_port = std::atoi(doc["mysql_port"].GetString()); } if(end != doc.FindMember("com_port") && doc["com_port"].IsString()) { com_port = doc["com_port"].GetString(); } if(end != doc.FindMember("Debug") && doc["Debug"].IsString()) { debug = std::atoi(doc["Debug"].GetString()); } if(end != doc.FindMember("getHistoryVideoFlag") && doc["getHistoryVideoFlag"].IsString()) { getHistoryVideoFlag = std::atoi(doc["getHistoryVideoFlag"].GetString()); } if(end != doc.FindMember("ClearPastRecords") && doc["ClearPastRecords"].IsString()) { ClearPastRecords = std::atoi(doc["ClearPastRecords"].GetString()); } if(end != doc.FindMember("bboxSize") && doc["bboxSize"].IsString()) { bboxSize = std::atof(doc["bboxSize"].GetString()); } if(end != doc.FindMember("ExpelInterval") && doc["ExpelInterval"].IsString()) { ExpelInterval = std::atoi(doc["ExpelInterval"].GetString()); } if(end != doc.FindMember("LowVersion") && doc["LowVersion"].IsString()){ LowVersion = std::atoi(doc["LowVersion"].GetString()); } if(end != doc.FindMember("ExpelPort") && doc["ExpelPort"].IsString()){ ExpelPort = std::atoi(doc["ExpelPort"].GetString()); } if(end != doc.FindMember("InferInterval") && doc["InferInterval"].IsString()){ InferInterval = std::atoi(doc["InferInterval"].GetString()); } if(end != doc.FindMember("payServerIP") && doc["payServerIP"].IsString()){ payServerIP = doc["payServerIP"].GetString(); } if(end != doc.FindMember("filterLevel") && doc["filterLevel"].IsString()){ filterLevel = std::atoi(doc["filterLevel"].GetString()); } if(end != doc.FindMember("vpn") && doc["vpn"].IsString()){ vpn = std::atoi(doc["vpn"].GetString()); } if(end != doc.FindMember("InferChecker") && doc["InferChecker"].IsString()){ InferChecker = std::atoi(doc["InferChecker"].GetString()); } if(end != doc.FindMember("InferCheckerIP") && doc["InferCheckerIP"].IsString()){ InferCheckerIP = doc["InferCheckerIP"].GetString(); } if(end != doc.FindMember("InferCheckerPort") && doc["InferCheckerPort"].IsString()){ InferCheckerPort = std::atoi(doc["InferCheckerPort"].GetString()); } return true; } }; #endif