mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-30 09:26:15 +02:00
config getServerStatus
This commit is contained in:
parent
5ba3301a4d
commit
ad568f1076
3 changed files with 71 additions and 58 deletions
|
@ -52,17 +52,12 @@ Config::Config()
|
|||
if (j.count("ConfigVersion"))
|
||||
{
|
||||
json jClient = j["Client"];
|
||||
for (json::iterator it = jClient.begin(); it != jClient.end(); ++it)
|
||||
for (auto it = jClient.begin(); it != jClient.end(); ++it)
|
||||
{
|
||||
ClientInfoPtr client = make_shared<ClientInfo>();
|
||||
client->fromJson(*it);
|
||||
if (client->host.mac.empty())
|
||||
if (client->clientId.empty() || getClientInfo(client->clientId))
|
||||
continue;
|
||||
for (const auto& c: clients)
|
||||
{
|
||||
if (c->host.mac == client->host.mac)
|
||||
continue;
|
||||
}
|
||||
|
||||
client->connected = false;
|
||||
clients.push_back(client);
|
||||
|
@ -77,6 +72,12 @@ Config::Config()
|
|||
}
|
||||
|
||||
|
||||
Config::~Config()
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
void Config::save()
|
||||
{
|
||||
std::ofstream ofs(filename_.c_str(), std::ofstream::out|std::ofstream::trunc);
|
||||
|
@ -89,7 +90,7 @@ void Config::save()
|
|||
}
|
||||
|
||||
|
||||
ClientInfoPtr Config::getClientInfo(const std::string& clientId, bool add)
|
||||
ClientInfoPtr Config::getClientInfo(const std::string& clientId) const
|
||||
{
|
||||
if (clientId.empty())
|
||||
return nullptr;
|
||||
|
@ -100,16 +101,52 @@ ClientInfoPtr Config::getClientInfo(const std::string& clientId, bool add)
|
|||
return client;
|
||||
}
|
||||
|
||||
if (!add)
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ClientInfoPtr client = make_shared<ClientInfo>(clientId);
|
||||
clients.push_back(client);
|
||||
|
||||
ClientInfoPtr Config::addClientInfo(const std::string& clientId)
|
||||
{
|
||||
ClientInfoPtr client = getClientInfo(clientId);
|
||||
if (!client)
|
||||
{
|
||||
client = make_shared<ClientInfo>(clientId);
|
||||
clients.push_back(client);
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
|
||||
json Config::getServerStatus(const std::string& clientId, const json& streams) const
|
||||
{
|
||||
json jClient = json::array();
|
||||
if (clientId != "")
|
||||
{
|
||||
ClientInfoPtr client = getClientInfo(clientId);
|
||||
if (client)
|
||||
jClient += client->toJson();
|
||||
}
|
||||
else
|
||||
jClient = getClientInfos();
|
||||
|
||||
Host host;
|
||||
host.update();
|
||||
//TODO: Set MAC and IP
|
||||
Snapserver snapserver("Snapserver", VERSION);
|
||||
json serverStatus = {
|
||||
{"server", {
|
||||
{"host", host.toJson()},//getHostName()},
|
||||
{"snapserver", snapserver.toJson()}
|
||||
}},
|
||||
{"clients", jClient},
|
||||
{"streams", streams}
|
||||
};
|
||||
|
||||
return serverStatus;
|
||||
}
|
||||
|
||||
|
||||
json Config::getClientInfos() const
|
||||
{
|
||||
json result = json::array();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue