mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-25 06:56:15 +02:00
restore config
This commit is contained in:
parent
5d68e36718
commit
4c94025747
2 changed files with 21 additions and 10 deletions
|
@ -31,6 +31,22 @@ Config::Config()
|
|||
mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
filename_ = dir + "settings.json";
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ struct Volume
|
|||
|
||||
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_usec = 0;
|
||||
|
@ -85,6 +85,7 @@ struct ClientInfo
|
|||
lastSeen.tv_sec = jGet<int32_t>(j["lastSeen"], "sec", 0);
|
||||
lastSeen.tv_usec = jGet<int32_t>(j["lastSeen"], "usec", 0);
|
||||
connected = jGet<bool>(j, "connected", true);
|
||||
latency = jGet<int32_t>(j, "latency", 0);
|
||||
}
|
||||
|
||||
json toJson()
|
||||
|
@ -94,22 +95,15 @@ struct ClientInfo
|
|||
j["IP"] = ipAddress;
|
||||
j["host"] = hostName;
|
||||
j["version"] = version;
|
||||
j["name"] = getName();
|
||||
j["name"] = name;
|
||||
j["volume"] = volume.toJson();
|
||||
j["lastSeen"]["sec"] = lastSeen.tv_sec;
|
||||
j["lastSeen"]["usec"] = lastSeen.tv_usec;
|
||||
j["connected"] = connected;
|
||||
j["latency"] = latency;
|
||||
return j;
|
||||
}
|
||||
|
||||
std::string getName()
|
||||
{
|
||||
if (name.empty())
|
||||
return hostName;
|
||||
else
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string macAddress;
|
||||
std::string ipAddress;
|
||||
std::string hostName;
|
||||
|
@ -119,6 +113,7 @@ struct ClientInfo
|
|||
bool muted;
|
||||
timeval lastSeen;
|
||||
bool connected;
|
||||
int32_t latency;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ClientInfo> ClientInfoPtr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue