restore config

This commit is contained in:
badaix 2015-09-05 22:38:27 +02:00
parent 5d68e36718
commit 4c94025747
2 changed files with 21 additions and 10 deletions

View file

@ -31,6 +31,22 @@ Config::Config()
mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
filename_ = dir + "settings.json"; filename_ = dir + "settings.json";
cerr << filename_ << "\n"; cerr << filename_ << "\n";
ifstream ifs(filename_, std::ifstream::in);
if (ifs.good())
{
json j;
ifs >> j;
json jClient = j["Client"];
for (json::iterator it = jClient.begin(); it != jClient.end(); ++it)
{
ClientInfoPtr client = make_shared<ClientInfo>();
client->fromJson(*it);
clients.push_back(client);
std::cout << "Client:\n" << std::setw(4) << client->toJson() << '\n';
}
}
// fs::create_directory(filename_.parent_path()); // fs::create_directory(filename_.parent_path());
} }

View file

@ -68,7 +68,7 @@ struct Volume
struct ClientInfo struct ClientInfo
{ {
ClientInfo(const std::string& _macAddress = "") : macAddress(_macAddress), volume(100), connected(false) ClientInfo(const std::string& _macAddress = "") : macAddress(_macAddress), volume(100), connected(false), latency(0)
{ {
lastSeen.tv_sec = 0; lastSeen.tv_sec = 0;
lastSeen.tv_usec = 0; lastSeen.tv_usec = 0;
@ -85,6 +85,7 @@ struct ClientInfo
lastSeen.tv_sec = jGet<int32_t>(j["lastSeen"], "sec", 0); lastSeen.tv_sec = jGet<int32_t>(j["lastSeen"], "sec", 0);
lastSeen.tv_usec = jGet<int32_t>(j["lastSeen"], "usec", 0); lastSeen.tv_usec = jGet<int32_t>(j["lastSeen"], "usec", 0);
connected = jGet<bool>(j, "connected", true); connected = jGet<bool>(j, "connected", true);
latency = jGet<int32_t>(j, "latency", 0);
} }
json toJson() json toJson()
@ -94,22 +95,15 @@ struct ClientInfo
j["IP"] = ipAddress; j["IP"] = ipAddress;
j["host"] = hostName; j["host"] = hostName;
j["version"] = version; j["version"] = version;
j["name"] = getName(); j["name"] = name;
j["volume"] = volume.toJson(); j["volume"] = volume.toJson();
j["lastSeen"]["sec"] = lastSeen.tv_sec; j["lastSeen"]["sec"] = lastSeen.tv_sec;
j["lastSeen"]["usec"] = lastSeen.tv_usec; j["lastSeen"]["usec"] = lastSeen.tv_usec;
j["connected"] = connected; j["connected"] = connected;
j["latency"] = latency;
return j; return j;
} }
std::string getName()
{
if (name.empty())
return hostName;
else
return name;
}
std::string macAddress; std::string macAddress;
std::string ipAddress; std::string ipAddress;
std::string hostName; std::string hostName;
@ -119,6 +113,7 @@ struct ClientInfo
bool muted; bool muted;
timeval lastSeen; timeval lastSeen;
bool connected; bool connected;
int32_t latency;
}; };
typedef std::shared_ptr<ClientInfo> ClientInfoPtr; typedef std::shared_ptr<ClientInfo> ClientInfoPtr;