| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- #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;
- root["postProcessTime"] = 20;
- 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 (int16_t)root["fsPort"].asInt();
- }
- std::string CConfig::fsPwd()
- {
- //return "123456";
- return root["fsPwd"].asString();
- }
- uint16_t CConfig::wsPort()
- {
- //return 9002;
- return (uint16_t)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();
- }
- int CConfig::postProcessTime()
- {
- return root["postProcessTime"].asInt();
- }
- CConfig CConfig::cfg;
|