BasicConfig.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-03-28 09:03:02
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-09-28 14:18:59
  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. std::string payServerIP = "10.81.160.141";
  45. int filterLevel = 2;
  46. int vpn = 0;
  47. int InferChecker = 0;
  48. std::string InferCheckerIP = "192.168.31.219";
  49. int InferCheckerPort = 8860;
  50. public:
  51. BasicConfig(){}
  52. ~BasicConfig(){}
  53. /**
  54. * @description: json转换为object
  55. * @param {string&} json
  56. * @return {*}
  57. */
  58. bool JsonToObject(std::string& json){
  59. rapidjson::Document doc;
  60. doc.Parse(json.c_str());
  61. if(!doc.IsObject()){
  62. return false;
  63. }
  64. // get members
  65. const auto end = doc.MemberEnd();
  66. // json_type
  67. if(end == doc.FindMember("usr") || !doc["usr"].IsString()) {
  68. return false;
  69. }else{
  70. usr = doc["usr"].GetString();
  71. }
  72. if(end == doc.FindMember("pwd") || !doc["pwd"].IsString()) {
  73. return false;
  74. }else{
  75. pwd = doc["pwd"].GetString();
  76. }
  77. if(end == doc.FindMember("NettyIP") || !doc["NettyIP"].IsString()) {
  78. return false;
  79. }else{
  80. NettyIP = doc["NettyIP"].GetString();
  81. }
  82. if(end == doc.FindMember("NettyPort") || !doc["NettyPort"].IsString()) {
  83. return false;
  84. }else{
  85. NettyPort = std::atoi(doc["NettyPort"].GetString());
  86. }
  87. if(end == doc.FindMember("DiskUsageThreshold") || !doc["DiskUsageThreshold"].IsString()) {
  88. return false;
  89. }else{
  90. DiskUsageThreshold = std::atof(doc["DiskUsageThreshold"].GetString());
  91. }
  92. if(end == doc.FindMember("HardDiskCleanupTime") || !doc["HardDiskCleanupTime"].IsString()) {
  93. return false;
  94. }else{
  95. HardDiskCleanupTime = std::atoi(doc["HardDiskCleanupTime"].GetString());
  96. }
  97. if(end == doc.FindMember("InferDataRetentionTime") || !doc["InferDataRetentionTime"].IsString()) {
  98. return false;
  99. }else{
  100. InferDataRetentionTime = std::atoi(doc["InferDataRetentionTime"].GetString());
  101. }
  102. if(end == doc.FindMember("interval") || !doc["interval"].IsString()) {
  103. return false;
  104. }else{
  105. interval = std::atoi(doc["interval"].GetString());
  106. }
  107. if(end == doc.FindMember("sensitivity") || !doc["sensitivity"].IsString()) {
  108. return false;
  109. }else{
  110. sensitivity = std::atoi(doc["sensitivity"].GetString());
  111. }
  112. if(end == doc.FindMember("TimeOut") || !doc["TimeOut"].IsString()) {
  113. return false;
  114. }else{
  115. TimeOut = std::atoi(doc["TimeOut"].GetString());
  116. }
  117. if(end == doc.FindMember("mysql_IP") || !doc["mysql_IP"].IsString()) {
  118. return false;
  119. }else{
  120. mysql_IP = doc["mysql_IP"].GetString();
  121. }
  122. if(end == doc.FindMember("mysql_port") || !doc["mysql_port"].IsString()) {
  123. return false;
  124. }else{
  125. mysql_port = std::atoi(doc["mysql_port"].GetString());
  126. }
  127. if(end != doc.FindMember("com_port") && doc["com_port"].IsString()) {
  128. com_port = doc["com_port"].GetString();
  129. }
  130. if(end != doc.FindMember("Debug") && doc["Debug"].IsString()) {
  131. debug = std::atoi(doc["Debug"].GetString());
  132. }
  133. if(end != doc.FindMember("getHistoryVideoFlag") && doc["getHistoryVideoFlag"].IsString()) {
  134. getHistoryVideoFlag = std::atoi(doc["getHistoryVideoFlag"].GetString());
  135. }
  136. if(end != doc.FindMember("ClearPastRecords") && doc["ClearPastRecords"].IsString()) {
  137. ClearPastRecords = std::atoi(doc["ClearPastRecords"].GetString());
  138. }
  139. if(end != doc.FindMember("bboxSize") && doc["bboxSize"].IsString()) {
  140. bboxSize = std::atof(doc["bboxSize"].GetString());
  141. }
  142. if(end != doc.FindMember("ExpelInterval") && doc["ExpelInterval"].IsString()) {
  143. ExpelInterval = std::atoi(doc["ExpelInterval"].GetString());
  144. }
  145. if(end != doc.FindMember("LowVersion") && doc["LowVersion"].IsString()){
  146. LowVersion = std::atoi(doc["LowVersion"].GetString());
  147. }
  148. if(end != doc.FindMember("ExpelPort") && doc["ExpelPort"].IsString()){
  149. ExpelPort = std::atoi(doc["ExpelPort"].GetString());
  150. }
  151. if(end != doc.FindMember("InferInterval") && doc["InferInterval"].IsString()){
  152. InferInterval = std::atoi(doc["InferInterval"].GetString());
  153. }
  154. if(end != doc.FindMember("payServerIP") && doc["payServerIP"].IsString()){
  155. payServerIP = doc["payServerIP"].GetString();
  156. }
  157. if(end != doc.FindMember("filterLevel") && doc["filterLevel"].IsString()){
  158. filterLevel = std::atoi(doc["filterLevel"].GetString());
  159. }
  160. if(end != doc.FindMember("vpn") && doc["vpn"].IsString()){
  161. vpn = std::atoi(doc["vpn"].GetString());
  162. }
  163. if(end != doc.FindMember("InferChecker") && doc["InferChecker"].IsString()){
  164. InferChecker = std::atoi(doc["InferChecker"].GetString());
  165. }
  166. if(end != doc.FindMember("InferCheckerIP") && doc["InferCheckerIP"].IsString()){
  167. InferCheckerIP = doc["InferCheckerIP"].GetString();
  168. }
  169. if(end != doc.FindMember("InferCheckerPort") && doc["InferCheckerPort"].IsString()){
  170. InferCheckerPort = std::atoi(doc["InferCheckerPort"].GetString());
  171. }
  172. return true;
  173. }
  174. };
  175. #endif