#include "config.hpp" #include #include #include #include using namespace std; using namespace nlohmann; using namespace iflytop; void MQTTConfig::initialize(string file_name) { std::ifstream jfile(file_name); jfile >> m_mqttConfigJson; jfile.close(); try { m_address = m_mqttConfigJson["address"]; m_username = m_mqttConfigJson["username"]; m_password = m_mqttConfigJson["password"]; m_clientid = m_mqttConfigJson["clientid"]; m_qos = m_mqttConfigJson["qos"]; m_topic = m_mqttConfigJson["topic"]; m_timeout = m_mqttConfigJson["timeout"]; } catch (const std::exception& e) { std::cerr << "mqtt_config_read error: " << e.what() << '\n'; } } string MQTTConfig::dump() { stringstream ret; ret << "==========================mqtt_config_dump_start===========================" << endl; ret << "address = " << getAddress() << endl; ret << "username = " << getUsername() << endl; ret << "password = " << getPassword() << endl; ret << "clientid = " << getClientid() << endl; ret << "qos = " << getQos() << endl; ret << "topic = " << getTopic() << endl; ret << "timeout = " << getTimeout() << endl; ret << "===========================mqtt_config_dump_end============================" << endl; return ret.str(); } const string& MQTTConfig::getAddress() { return m_address; } const string& MQTTConfig::getUsername() { return m_username; } const string& MQTTConfig::getPassword() { return m_password; } const string& MQTTConfig::getClientid() { return m_clientid; } int MQTTConfig::getQos() { return m_qos; } const string& MQTTConfig::getTopic() { return m_topic; } int MQTTConfig::getTimeout() { return m_timeout; }