linux版本中间件

Config.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include "Config.h"
  2. CConfig::CConfig()
  3. {
  4. }
  5. CConfig::~CConfig()
  6. {
  7. }
  8. bool CConfig::load()
  9. {
  10. //Json::Value root;
  11. std::ifstream ifs;
  12. ifs.open(CFGPATH);
  13. Json::CharReaderBuilder builder;
  14. builder["collectComments"] = true;
  15. JSONCPP_STRING errs;
  16. if (!parseFromStream(builder, ifs, &root, &errs)) {
  17. std::cout << errs << std::endl;
  18. return false;
  19. }
  20. if (ifs.is_open())
  21. ifs.close();
  22. return true;
  23. }
  24. bool CConfig::write()
  25. {
  26. //Json::Value root;
  27. Json::StreamWriterBuilder builder;
  28. root["fsAddr"] = "192.168.8.6";
  29. root["fsPort"] = 8021;
  30. root["fsPwd"] = "123456";
  31. root["wsPort"] = 9002;
  32. root["dbAddr"] = "tcp://192.168.8.4:3306";
  33. root["dbUser"] = "root";
  34. root["dbPwd"] = "123456";
  35. root["dbDatabase"] = "freeswitch";
  36. root["trunkCount"] = 10;
  37. root["extContext"] = "ForEXten";
  38. root["meetingContext"] = "ExtenMeeting";
  39. root["ttsPath"] = ".";
  40. root["recordPath"] = ".";
  41. root["gateWayPrefix"] = "9";
  42. root["gateWayCaller"] = "58558810";
  43. root["gateWayAccount"] = "hykj";
  44. root["autoRecord"] = true;
  45. root["postProcessTime"] = 20;
  46. const std::string json_file = Json::writeString(builder, root);
  47. std::ofstream ofs;
  48. ofs.open(CFGPATH);
  49. ofs.write(json_file.c_str(),json_file.length());
  50. ofs.close();
  51. return true;
  52. }
  53. std::string CConfig::fsAddr()
  54. {
  55. //return "192.168.8.6";
  56. return root["fsAddr"].asString();
  57. }
  58. short int CConfig::fsPort()
  59. {
  60. //return 8021;
  61. return (int16_t)root["fsPort"].asInt();
  62. }
  63. std::string CConfig::fsPwd()
  64. {
  65. //return "123456";
  66. return root["fsPwd"].asString();
  67. }
  68. uint16_t CConfig::wsPort()
  69. {
  70. //return 9002;
  71. return (uint16_t)root["wsPort"].asUInt();
  72. }
  73. std::string CConfig::dbAddr()
  74. {
  75. //return "tcp://192.168.8.4:3306";
  76. return root["dbAddr"].asString();
  77. }
  78. std::string CConfig::dbUser()
  79. {
  80. //return "root";
  81. return root["dbUser"].asString();
  82. }
  83. std::string CConfig::dbPwd()
  84. {
  85. //return "123456";
  86. return root["dbPwd"].asString();
  87. }
  88. std::string CConfig::dbDatabase()
  89. {
  90. //return "freeswitch";
  91. return root["dbDatabase"].asString();
  92. }
  93. int CConfig::trunkCount()
  94. {
  95. //return 10;
  96. return root["trunkCount"].asInt();
  97. }
  98. std::string CConfig::extContext()
  99. {
  100. //return "ForEXten";
  101. return root["extContext"].asString();
  102. }
  103. std::string CConfig::meetingContext()
  104. {
  105. //return "ExtenMeeting";
  106. return root["meetingContext"].asString();
  107. }
  108. std::string CConfig::ttsPath()
  109. {
  110. //return ".";
  111. return root["ttsPath"].asString();
  112. }
  113. std::string CConfig::recordPath()
  114. {
  115. //return ".";
  116. return root["recordPath"].asString();
  117. }
  118. std::string CConfig::gateWayPrefix()
  119. {
  120. //return "9";
  121. return root["gateWayPrefix"].asString();
  122. }
  123. std::string CConfig::gateWayCaller()
  124. {
  125. //return "58558810";
  126. return root["gateWayCaller"].asString();
  127. }
  128. std::string CConfig::gateWayAccount()
  129. {
  130. //return "hykj";
  131. return root["gateWayAccount"].asString();
  132. }
  133. bool CConfig::isAutoRecord()
  134. {
  135. return root["autoRecord"].asBool();
  136. }
  137. int CConfig::postProcessTime()
  138. {
  139. return root["postProcessTime"].asInt();
  140. }
  141. CConfig CConfig::cfg;