delete client

This commit is contained in:
badaix 2016-01-15 23:54:39 +01:00
parent 3e8842b941
commit 252cda188a
3 changed files with 18 additions and 0 deletions

View file

@ -91,3 +91,8 @@ json Config::getClientInfos() const
} }
void Config::remove(ClientInfoPtr client)
{
clients.erase(std::remove(clients.begin(), clients.end(), client), clients.end());
}

View file

@ -129,6 +129,7 @@ public:
} }
ClientInfoPtr getClientInfo(const std::string& mac, bool add = true); ClientInfoPtr getClientInfo(const std::string& mac, bool add = true);
void remove(ClientInfoPtr client);
std::vector<ClientInfoPtr> clients; std::vector<ClientInfoPtr> clients;
json getClientInfos() const; json getClientInfos() const;

View file

@ -161,6 +161,18 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std::
{"clients", jClient} {"clients", jClient}
}; };
} }
else if (request.method == "System.DeleteClient")
{
clientInfo = Config::instance().getClientInfo(request.getParam("client").get<string>(), false);
if (clientInfo == nullptr)
throw JsonInternalErrorException("Client not found", request.id);
response = clientInfo->macAddress;
Config::instance().remove(clientInfo);
Config::instance().save();
json notification = JsonNotification::getJson("Client.OnDelete", clientInfo->toJson());
controlServer_->send(notification.dump(), controlSession);
clientInfo = nullptr;
}
else if (request.method == "Client.SetVolume") else if (request.method == "Client.SetVolume")
{ {
clientInfo->volume.percent = request.getParam<uint16_t>("volume", 0, 100); clientInfo->volume.percent = request.getParam<uint16_t>("volume", 0, 100);