#include "Config.h" CConfig::CConfig() { } CConfig::~CConfig() { } bool CConfig::load() { //Json::Value root; std::ifstream ifs; ifs.open(CFGPATH); Json::CharReaderBuilder builder; builder["collectComments"] = true; JSONCPP_STRING errs; if (!parseFromStream(builder, ifs, &root, &errs)) { std::cout << errs << std::endl; return false; } if (ifs.is_open()) ifs.close(); return true; } bool CConfig::write() { //Json::Value root; Json::StreamWriterBuilder builder; root["fsAddr"] = "192.168.8.6"; root["fsPort"] = 8021; root["fsPwd"] = "123456"; root["wsPort"] = 9002; root["dbAddr"] = "tcp://192.168.8.4:3306"; root["dbUser"] = "root"; root["dbPwd"] = "123456"; root["dbDatabase"] = "freeswitch"; root["trunkCount"] = 10; root["extContext"] = "ForEXten"; root["meetingContext"] = "ExtenMeeting"; root["ttsPath"] = "."; root["recordPath"] = "."; root["gateWayPrefix"] = "9"; root["gateWayCaller"] = "58558810"; root["gateWayAccount"] = "hykj"; root["autoRecord"] = true; const std::string json_file = Json::writeString(builder, root); std::ofstream ofs; ofs.open(CFGPATH); ofs.write(json_file.c_str(),json_file.length()); ofs.close(); return true; } std::string CConfig::fsAddr() { //return "192.168.8.6"; return root["fsAddr"].asString(); } short int CConfig::fsPort() { //return 8021; return root["fsPort"].asInt(); } std::string CConfig::fsPwd() { //return "123456"; return root["fsPwd"].asString(); } uint16_t CConfig::wsPort() { //return 9002; return root["wsPort"].asUInt(); } std::string CConfig::dbAddr() { //return "tcp://192.168.8.4:3306"; return root["dbAddr"].asString(); } std::string CConfig::dbUser() { //return "root"; return root["dbUser"].asString(); } std::string CConfig::dbPwd() { //return "123456"; return root["dbPwd"].asString(); } std::string CConfig::dbDatabase() { //return "freeswitch"; return root["dbDatabase"].asString(); } int CConfig::trunkCount() { //return 10; return root["trunkCount"].asInt(); } std::string CConfig::extContext() { //return "ForEXten"; return root["extContext"].asString(); } std::string CConfig::meetingContext() { //return "ExtenMeeting"; return root["meetingContext"].asString(); } std::string CConfig::ttsPath() { //return "."; return root["ttsPath"].asString(); } std::string CConfig::recordPath() { //return "."; return root["recordPath"].asString(); } std::string CConfig::gateWayPrefix() { //return "9"; return root["gateWayPrefix"].asString(); } std::string CConfig::gateWayCaller() { //return "58558810"; return root["gateWayCaller"].asString(); } std::string CConfig::gateWayAccount() { //return "hykj"; return root["gateWayAccount"].asString(); } bool CConfig::isAutoRecord() { return root["autoRecord"].asBool(); } CConfig CConfig::cfg;