BasicConfig.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-03-28 09:03:02
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-07-25 11:17:07
  8. */
  9. #ifndef __BASICECONFIG_H_
  10. #define __BASICECONFIG_H_
  11. #include <iostream>
  12. #include <vector>
  13. #include <rapidjson/document.h>
  14. #include <rapidjson/rapidjson.h>
  15. #include <rapidjson/stringbuffer.h>
  16. #include <rapidjson/writer.h>
  17. using namespace std;
  18. class BasicConfig
  19. {
  20. public:
  21. // usr
  22. std::string usr;
  23. std::string pwd;
  24. // NettyIp;
  25. std::string NettyIP;
  26. int NettyPort;
  27. std::string mysql_IP;
  28. int mysql_port;
  29. double DiskUsageThreshold;
  30. int HardDiskCleanupTime;
  31. int InferDataRetentionTime;
  32. int interval;
  33. int sensitivity;
  34. int TimeOut;
  35. int debug;
  36. int getHistoryVideoFlag;
  37. int ClearPastRecords;
  38. int LowVersion = 0;
  39. double bboxSize = 0.0;
  40. int ExpelInterval = 0;
  41. std::string com_port = "";
  42. int ExpelPort = 19002;
  43. int InferInterval = 2000;
  44. public:
  45. BasicConfig(){}
  46. ~BasicConfig(){}
  47. /**
  48. * @description: json转换为object
  49. * @param {string&} json
  50. * @return {*}
  51. */
  52. bool JsonToObject(std::string& json){
  53. rapidjson::Document doc;
  54. if (doc.Parse<rapidjson::kParseCommentsFlag>(json.c_str()).HasParseError()) {
  55. return false;
  56. }
  57. // get members
  58. const auto end = doc.MemberEnd();
  59. // json_type
  60. if(end == doc.FindMember("usr") || !doc["usr"].IsString()) {
  61. return false;
  62. }else{
  63. usr = doc["usr"].GetString();
  64. }
  65. if(end == doc.FindMember("pwd") || !doc["pwd"].IsString()) {
  66. return false;
  67. }else{
  68. pwd = doc["pwd"].GetString();
  69. }
  70. if(end == doc.FindMember("NettyIP") || !doc["NettyIP"].IsString()) {
  71. return false;
  72. }else{
  73. NettyIP = doc["NettyIP"].GetString();
  74. }
  75. if(end == doc.FindMember("NettyPort") || !doc["NettyPort"].IsString()) {
  76. return false;
  77. }else{
  78. NettyPort = std::atoi(doc["NettyPort"].GetString());
  79. }
  80. if(end == doc.FindMember("DiskUsageThreshold") || !doc["DiskUsageThreshold"].IsString()) {
  81. return false;
  82. }else{
  83. DiskUsageThreshold = std::atof(doc["DiskUsageThreshold"].GetString());
  84. }
  85. if(end == doc.FindMember("HardDiskCleanupTime") || !doc["HardDiskCleanupTime"].IsString()) {
  86. return false;
  87. }else{
  88. HardDiskCleanupTime = std::atoi(doc["HardDiskCleanupTime"].GetString());
  89. }
  90. if(end == doc.FindMember("InferDataRetentionTime") || !doc["InferDataRetentionTime"].IsString()) {
  91. return false;
  92. }else{
  93. InferDataRetentionTime = std::atoi(doc["InferDataRetentionTime"].GetString());
  94. }
  95. if(end == doc.FindMember("interval") || !doc["interval"].IsString()) {
  96. return false;
  97. }else{
  98. interval = std::atoi(doc["interval"].GetString());
  99. }
  100. if(end == doc.FindMember("sensitivity") || !doc["sensitivity"].IsString()) {
  101. return false;
  102. }else{
  103. sensitivity = std::atoi(doc["sensitivity"].GetString());
  104. }
  105. if(end == doc.FindMember("TimeOut") || !doc["TimeOut"].IsString()) {
  106. return false;
  107. }else{
  108. TimeOut = std::atoi(doc["TimeOut"].GetString());
  109. }
  110. if(end == doc.FindMember("mysql_IP") || !doc["mysql_IP"].IsString()) {
  111. return false;
  112. }else{
  113. mysql_IP = doc["mysql_IP"].GetString();
  114. }
  115. if(end == doc.FindMember("mysql_port") || !doc["mysql_port"].IsString()) {
  116. return false;
  117. }else{
  118. mysql_port = std::atoi(doc["mysql_port"].GetString());
  119. }
  120. if(end != doc.FindMember("com_port") && doc["com_port"].IsString()) {
  121. com_port = doc["com_port"].GetString();
  122. }
  123. if(end != doc.FindMember("Debug") && doc["Debug"].IsString()) {
  124. debug = std::atoi(doc["Debug"].GetString());
  125. }
  126. if(end != doc.FindMember("getHistoryVideoFlag") && doc["getHistoryVideoFlag"].IsString()) {
  127. getHistoryVideoFlag = std::atoi(doc["getHistoryVideoFlag"].GetString());
  128. }
  129. if(end != doc.FindMember("ClearPastRecords") && doc["ClearPastRecords"].IsString()) {
  130. ClearPastRecords = std::atoi(doc["ClearPastRecords"].GetString());
  131. }
  132. if(end != doc.FindMember("bboxSize") && doc["bboxSize"].IsString()) {
  133. bboxSize = std::atof(doc["bboxSize"].GetString());
  134. }
  135. if(end != doc.FindMember("ExpelInterval") && doc["ExpelInterval"].IsString()) {
  136. ExpelInterval = std::atoi(doc["ExpelInterval"].GetString());
  137. }
  138. if(end != doc.FindMember("LowVersion") && doc["LowVersion"].IsString()){
  139. LowVersion = std::atoi(doc["LowVersion"].GetString());
  140. }
  141. if(end != doc.FindMember("ExpelPort") && doc["ExpelPort"].IsString()){
  142. ExpelPort = std::atoi(doc["ExpelPort"].GetString());
  143. }
  144. if(end != doc.FindMember("InferInterval") && doc["InferInterval"].IsString()){
  145. InferInterval = std::atoi(doc["InferInterval"].GetString());
  146. }
  147. return true;
  148. }
  149. };
  150. #endif