本文整理汇总了C++中Host::toJson方法的典型用法代码示例。如果您正苦于以下问题:C++ Host::toJson方法的具体用法?C++ Host::toJson怎么用?C++ Host::toJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::toJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onMessageReceived
void StreamServer::onMessageReceived(ControlSession* controlSession, const std::string& message)
{
JsonRequest request;
try
{
request.parse(message);
logO << "method: " << request.method << ", " << "id: " << request.id << "\n";
json response;
ClientInfoPtr clientInfo = nullptr;
msg::ServerSettings serverSettings;
serverSettings.bufferMs = settings_.bufferMs;
if (request.method.find("Client.Set") == 0)
{
clientInfo = Config::instance().getClientInfo(request.getParam("client").get<string>(), false);
if (clientInfo == nullptr)
throw JsonInternalErrorException("Client not found", request.id);
}
if (request.method == "Server.GetStatus")
{
json jClient = json::array();
if (request.hasParam("client"))
{
ClientInfoPtr client = Config::instance().getClientInfo(request.getParam("client").get<string>(), false);
if (client)
jClient += client->toJson();
}
else
jClient = Config::instance().getClientInfos();
Host host;
//TODO: Set MAC and IP
Snapserver snapserver("Snapserver", VERSION);
response = {
{"server", {
{"host", host.toJson()},//getHostName()},
{"snapserver", snapserver.toJson()}
}},
{"clients", jClient},
{"streams", streamManager_->toJson()}
};
// cout << response.dump(4);
}
else if (request.method == "Server.DeleteClient")
{
clientInfo = Config::instance().getClientInfo(request.getParam("client").get<string>(), false);
if (clientInfo == nullptr)
throw JsonInternalErrorException("Client not found", request.id);
response = clientInfo->host.mac;
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")
{
clientInfo->config.volume.percent = request.getParam<uint16_t>("volume", 0, 100);
response = clientInfo->config.volume.percent;
}
else if (request.method == "Client.SetMute")
{
clientInfo->config.volume.muted = request.getParam<bool>("mute", false, true);
response = clientInfo->config.volume.muted;
}
else if (request.method == "Client.SetStream")
{
string streamId = request.getParam("id").get<string>();
PcmStreamPtr stream = streamManager_->getStream(streamId);
if (stream == nullptr)
throw JsonInternalErrorException("Stream not found", request.id);
clientInfo->config.streamId = streamId;
response = clientInfo->config.streamId;
StreamSession* session = getStreamSession(request.getParam("client").get<string>());
if (session != NULL)
{
session->add(stream->getHeader());
session->setPcmStream(stream);
}
}
else if (request.method == "Client.SetLatency")
{
clientInfo->config.latency = request.getParam<int>("latency", -10000, settings_.bufferMs);
response = clientInfo->config.latency;
}
else if (request.method == "Client.SetName")
{
clientInfo->config.name = request.getParam("name").get<string>();
response = clientInfo->config.name;
}
else
throw JsonMethodNotFoundException(request.id);
if (clientInfo != nullptr)
{
serverSettings.volume = clientInfo->config.volume.percent;
//.........这里部分代码省略.........