linux版本中间件

Config.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. const std::string json_file = Json::writeString(builder, root);
  46. std::ofstream ofs;
  47. ofs.open(CFGPATH);
  48. ofs.write(json_file.c_str(),json_file.length());
  49. ofs.close();
  50. return true;
  51. }
  52. std::string CConfig::fsAddr()
  53. {
  54. //return "192.168.8.6";
  55. return root["fsAddr"].asString();
  56. }
  57. short int CConfig::fsPort()
  58. {
  59. //return 8021;
  60. return root["fsPort"].asInt();
  61. }
  62. std::string CConfig::fsPwd()
  63. {
  64. //return "123456";
  65. return root["fsPwd"].asString();
  66. }
  67. uint16_t CConfig::wsPort()
  68. {
  69. //return 9002;
  70. return root["wsPort"].asUInt();
  71. }
  72. std::string CConfig::dbAddr()
  73. {
  74. //return "tcp://192.168.8.4:3306";
  75. return root["dbAddr"].asString();
  76. }
  77. std::string CConfig::dbUser()
  78. {
  79. //return "root";
  80. return root["dbUser"].asString();
  81. }
  82. std::string CConfig::dbPwd()
  83. {
  84. //return "123456";
  85. return root["dbPwd"].asString();
  86. }
  87. std::string CConfig::dbDatabase()
  88. {
  89. //return "freeswitch";
  90. return root["dbDatabase"].asString();
  91. }
  92. int CConfig::trunkCount()
  93. {
  94. //return 10;
  95. return root["trunkCount"].asInt();
  96. }
  97. std::string CConfig::extContext()
  98. {
  99. //return "ForEXten";
  100. return root["extContext"].asString();
  101. }
  102. std::string CConfig::meetingContext()
  103. {
  104. //return "ExtenMeeting";
  105. return root["meetingContext"].asString();
  106. }
  107. std::string CConfig::ttsPath()
  108. {
  109. //return ".";
  110. return root["ttsPath"].asString();
  111. }
  112. std::string CConfig::recordPath()
  113. {
  114. //return ".";
  115. return root["recordPath"].asString();
  116. }
  117. std::string CConfig::gateWayPrefix()
  118. {
  119. //return "9";
  120. return root["gateWayPrefix"].asString();
  121. }
  122. std::string CConfig::gateWayCaller()
  123. {
  124. //return "58558810";
  125. return root["gateWayCaller"].asString();
  126. }
  127. std::string CConfig::gateWayAccount()
  128. {
  129. //return "hykj";
  130. return root["gateWayAccount"].asString();
  131. }
  132. bool CConfig::isAutoRecord()
  133. {
  134. return root["autoRecord"].asBool();
  135. }
  136. CConfig CConfig::cfg;