mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 15:46:42 +02:00
update jsonrpc++ to v1.2.0
This commit is contained in:
parent
49bec47576
commit
e7e529c818
8 changed files with 1554 additions and 1519 deletions
|
@ -2,7 +2,6 @@ set(SERVER_SOURCES
|
|||
config.cpp
|
||||
controlServer.cpp
|
||||
controlSession.cpp
|
||||
jsonrp.cpp
|
||||
snapServer.cpp
|
||||
streamServer.cpp
|
||||
streamSession.cpp
|
||||
|
|
|
@ -36,7 +36,7 @@ DEBUG=-O3
|
|||
|
||||
CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function $(DEBUG) -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -isystem ../externals/asio/asio/include -I../externals/popl/include -I../externals/aixlog/include -I../externals -I../common
|
||||
LDFLAGS = $(ADD_LDFLAGS) -lvorbis -lvorbisenc -logg -lFLAC
|
||||
OBJ = snapServer.o config.o controlServer.o controlSession.o jsonrp.o streamServer.o streamSession.o streamreader/streamUri.o streamreader/base64.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o streamreader/processStream.o streamreader/airplayStream.o streamreader/spotifyStream.o streamreader/watchdog.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o ../common/sampleFormat.o
|
||||
OBJ = snapServer.o config.o controlServer.o controlSession.o streamServer.o streamSession.o streamreader/streamUri.o streamreader/base64.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o streamreader/processStream.o streamreader/airplayStream.o streamreader/spotifyStream.o streamreader/watchdog.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o ../common/sampleFormat.o
|
||||
|
||||
ifneq (,$(TARGET))
|
||||
CXXFLAGS += -D$(TARGET)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "jsonrp.hpp"
|
||||
#include "jsonrpcpp.hpp"
|
||||
#include "controlServer.h"
|
||||
#include "message/time.h"
|
||||
#include "aixlog.hpp"
|
||||
|
|
1017
server/jsonrp.cpp
1017
server/jsonrp.cpp
File diff suppressed because it is too large
Load diff
|
@ -1,457 +0,0 @@
|
|||
/***
|
||||
__ ____ __ __ _ ____ ____ ___ _ _
|
||||
_( )/ ___) / \ ( ( \( _ \( _ \ / __)( ) ( )
|
||||
/ \) \\___ \( O )/ / ) / ) __/( (__(_ _)(_ _)
|
||||
\____/(____/ \__/ \_)__)(__\_)(__) \___)(_) (_)
|
||||
version 1.1.0
|
||||
https://github.com/badaix/jsonrpcpp
|
||||
|
||||
This file is part of jsonrpc++
|
||||
Copyright (C) 2017 Johannes Pohl
|
||||
|
||||
This software may be modified and distributed under the terms
|
||||
of the MIT license. See the LICENSE file for details.
|
||||
***/
|
||||
|
||||
/// http://patorjk.com/software/taag/#p=display&f=Graceful&t=JSONRPC%2B%2B
|
||||
|
||||
#ifndef JSON_RPC_H
|
||||
#define JSON_RPC_H
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
#include "common/json.hpp"
|
||||
|
||||
|
||||
using Json = nlohmann::json;
|
||||
|
||||
namespace jsonrpcpp
|
||||
{
|
||||
|
||||
|
||||
class Entity;
|
||||
class Request;
|
||||
class Notification;
|
||||
class Parameter;
|
||||
class Response;
|
||||
class Error;
|
||||
class Batch;
|
||||
|
||||
|
||||
typedef std::shared_ptr<Entity> entity_ptr;
|
||||
typedef std::shared_ptr<Request> request_ptr;
|
||||
typedef std::shared_ptr<Notification> notification_ptr;
|
||||
typedef std::shared_ptr<Parameter> parameter_ptr;
|
||||
typedef std::shared_ptr<Response> response_ptr;
|
||||
typedef std::shared_ptr<Error> error_ptr;
|
||||
typedef std::shared_ptr<Batch> batch_ptr;
|
||||
|
||||
|
||||
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
enum class entity_t : uint8_t
|
||||
{
|
||||
unknown,
|
||||
exception,
|
||||
id,
|
||||
error,
|
||||
response,
|
||||
request,
|
||||
notification,
|
||||
batch
|
||||
};
|
||||
|
||||
Entity(entity_t type);
|
||||
virtual ~Entity();
|
||||
|
||||
bool is_exception();
|
||||
bool is_id();
|
||||
bool is_error();
|
||||
bool is_response();
|
||||
bool is_request();
|
||||
bool is_notification();
|
||||
bool is_batch();
|
||||
|
||||
virtual std::string type_str() const;
|
||||
|
||||
virtual Json to_json() const = 0;
|
||||
virtual void parse_json(const Json& json) = 0;
|
||||
|
||||
virtual void parse(const std::string& json_str);
|
||||
virtual void parse(const char* json_str);
|
||||
|
||||
protected:
|
||||
entity_t entity;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class NullableEntity : public Entity
|
||||
{
|
||||
public:
|
||||
NullableEntity(entity_t type);
|
||||
NullableEntity(entity_t type, std::nullptr_t);
|
||||
virtual ~NullableEntity();
|
||||
virtual explicit operator bool() const
|
||||
{
|
||||
return !isNull;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool isNull;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Id : public Entity
|
||||
{
|
||||
public:
|
||||
enum class value_t : uint8_t
|
||||
{
|
||||
null,
|
||||
string,
|
||||
integer
|
||||
};
|
||||
|
||||
Id();
|
||||
Id(int id);
|
||||
Id(const char* id);
|
||||
Id(const std::string& id);
|
||||
Id(const Json& json_id);
|
||||
|
||||
virtual Json to_json() const;
|
||||
virtual void parse_json(const Json& json);
|
||||
|
||||
friend std::ostream& operator<< (std::ostream &out, const Id &id)
|
||||
{
|
||||
out << id.to_json();
|
||||
return out;
|
||||
}
|
||||
|
||||
value_t type;
|
||||
int int_id;
|
||||
std::string string_id;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Parameter : public NullableEntity
|
||||
{
|
||||
public:
|
||||
enum class value_t : uint8_t
|
||||
{
|
||||
null,
|
||||
array,
|
||||
map
|
||||
};
|
||||
|
||||
Parameter(std::nullptr_t);
|
||||
Parameter(const Json& json = nullptr);
|
||||
Parameter(const std::string& key1, const Json& value1,
|
||||
const std::string& key2 = "", const Json& value2 = nullptr,
|
||||
const std::string& key3 = "", const Json& value3 = nullptr,
|
||||
const std::string& key4 = "", const Json& value4 = nullptr);
|
||||
|
||||
virtual Json to_json() const;
|
||||
virtual void parse_json(const Json& json);
|
||||
|
||||
bool is_array() const;
|
||||
bool is_map() const;
|
||||
bool is_null() const;
|
||||
|
||||
Json get(const std::string& key) const;
|
||||
Json get(size_t idx) const;
|
||||
bool has(const std::string& key) const;
|
||||
bool has(size_t idx) const;
|
||||
|
||||
template<typename T>
|
||||
T get(const std::string& key) const
|
||||
{
|
||||
return get(key).get<T>();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T get(size_t idx) const
|
||||
{
|
||||
return get(idx).get<T>();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T get(const std::string& key, const T& default_value) const
|
||||
{
|
||||
if (!has(key))
|
||||
return default_value;
|
||||
else
|
||||
return get<T>(key);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T get(size_t idx, const T& default_value) const
|
||||
{
|
||||
if (!has(idx))
|
||||
return default_value;
|
||||
else
|
||||
return get<T>(idx);
|
||||
}
|
||||
|
||||
value_t type;
|
||||
std::vector<Json> param_array;
|
||||
std::map<std::string, Json> param_map;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Error : public NullableEntity
|
||||
{
|
||||
public:
|
||||
Error(const Json& json = nullptr);
|
||||
Error(std::nullptr_t);
|
||||
Error(const std::string& message, int code, const Json& data = nullptr);
|
||||
|
||||
virtual Json to_json() const;
|
||||
virtual void parse_json(const Json& json);
|
||||
|
||||
int code;
|
||||
std::string message;
|
||||
Json data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// JSON-RPC 2.0 request
|
||||
/**
|
||||
* Simple jsonrpc 2.0 parser with getters
|
||||
* Currently no named parameters are supported, but only array parameters
|
||||
*/
|
||||
class Request : public Entity
|
||||
{
|
||||
public:
|
||||
Request(const Json& json = nullptr);
|
||||
Request(const Id& id, const std::string& method, const Parameter& params = nullptr);
|
||||
|
||||
virtual Json to_json() const;
|
||||
virtual void parse_json(const Json& json);
|
||||
|
||||
std::string method;
|
||||
Parameter params;
|
||||
Id id;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class RpcException : public std::exception
|
||||
{
|
||||
char* text_;
|
||||
public:
|
||||
RpcException(const char* text);
|
||||
RpcException(const std::string& text);
|
||||
RpcException(const RpcException& e);
|
||||
|
||||
virtual ~RpcException() throw();
|
||||
virtual const char* what() const noexcept;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ParseErrorException : public RpcException, public Entity
|
||||
{
|
||||
public:
|
||||
Error error;
|
||||
|
||||
ParseErrorException(const Error& error);
|
||||
ParseErrorException(const ParseErrorException& e);
|
||||
ParseErrorException(const std::string& data);
|
||||
virtual Json to_json() const;
|
||||
|
||||
protected:
|
||||
virtual void parse_json(const Json& json);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// -32600 Invalid Request The JSON sent is not a valid Request object.
|
||||
// -32601 Method not found The method does not exist / is not available.
|
||||
// -32602 Invalid params Invalid method parameter(s).
|
||||
// -32603 Internal error Internal JSON-RPC error.
|
||||
|
||||
class RequestException : public RpcException, public Entity
|
||||
{
|
||||
public:
|
||||
Error error;
|
||||
Id id;
|
||||
|
||||
RequestException(const Error& error, const Id& requestId = Id());
|
||||
RequestException(const RequestException& e);
|
||||
virtual Json to_json() const;
|
||||
|
||||
protected:
|
||||
virtual void parse_json(const Json& json);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class InvalidRequestException : public RequestException
|
||||
{
|
||||
public:
|
||||
InvalidRequestException(const Id& requestId = Id());
|
||||
InvalidRequestException(const Request& request);
|
||||
InvalidRequestException(const char* data, const Id& requestId = Id());
|
||||
InvalidRequestException(const std::string& data, const Id& requestId = Id());
|
||||
};
|
||||
|
||||
|
||||
|
||||
class MethodNotFoundException : public RequestException
|
||||
{
|
||||
public:
|
||||
MethodNotFoundException(const Id& requestId = Id());
|
||||
MethodNotFoundException(const Request& request);
|
||||
MethodNotFoundException(const char* data, const Id& requestId = Id());
|
||||
MethodNotFoundException(const std::string& data, const Id& requestId = Id());
|
||||
};
|
||||
|
||||
|
||||
|
||||
class InvalidParamsException : public RequestException
|
||||
{
|
||||
public:
|
||||
InvalidParamsException(const Id& requestId = Id());
|
||||
InvalidParamsException(const Request& request);
|
||||
InvalidParamsException(const char* data, const Id& requestId = Id());
|
||||
InvalidParamsException(const std::string& data, const Id& requestId = Id());
|
||||
};
|
||||
|
||||
|
||||
|
||||
class InternalErrorException : public RequestException
|
||||
{
|
||||
public:
|
||||
InternalErrorException(const Id& requestId = Id());
|
||||
InternalErrorException(const Request& request);
|
||||
InternalErrorException(const char* data, const Id& requestId = Id());
|
||||
InternalErrorException(const std::string& data, const Id& requestId = Id());
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Response : public Entity
|
||||
{
|
||||
public:
|
||||
Id id;
|
||||
Json result;
|
||||
Error error;
|
||||
|
||||
Response(const Json& json = nullptr);
|
||||
Response(const Id& id, const Json& result);
|
||||
Response(const Id& id, const Error& error);
|
||||
Response(const Request& request, const Json& result);
|
||||
Response(const Request& request, const Error& error);
|
||||
Response(const RequestException& exception);
|
||||
|
||||
virtual Json to_json() const;
|
||||
virtual void parse_json(const Json& json);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Notification : public Entity
|
||||
{
|
||||
public:
|
||||
std::string method;
|
||||
Parameter params;
|
||||
Notification(const Json& json = nullptr);
|
||||
Notification(const char* method, const Parameter& params = nullptr);
|
||||
Notification(const std::string& method, const Parameter& params);
|
||||
|
||||
virtual Json to_json() const;
|
||||
virtual void parse_json(const Json& json);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
typedef std::function<void(const Parameter& params)> notification_callback;
|
||||
typedef std::function<jsonrpcpp::response_ptr(const Id& id, const Parameter& params)> request_callback;
|
||||
|
||||
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
Parser();
|
||||
virtual ~Parser();
|
||||
|
||||
entity_ptr parse(const std::string& json_str);
|
||||
entity_ptr parse_json(const Json& json);
|
||||
|
||||
void register_notification_callback(const std::string& notification, notification_callback callback);
|
||||
void register_request_callback(const std::string& request, request_callback callback);
|
||||
|
||||
static entity_ptr do_parse(const std::string& json_str);
|
||||
static entity_ptr do_parse_json(const Json& json);
|
||||
static bool is_request(const std::string& json_str);
|
||||
static bool is_request(const Json& json);
|
||||
static bool is_notification(const std::string& json_str);
|
||||
static bool is_notification(const Json& json);
|
||||
static bool is_response(const std::string& json_str);
|
||||
static bool is_response(const Json& json);
|
||||
static bool is_batch(const std::string& json_str);
|
||||
static bool is_batch(const Json& json);
|
||||
|
||||
private:
|
||||
std::map<std::string, notification_callback> notification_callbacks_;
|
||||
std::map<std::string, request_callback> request_callbacks_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Batch : public Entity
|
||||
{
|
||||
public:
|
||||
std::vector<entity_ptr> entities;
|
||||
|
||||
Batch(const Json& json = nullptr);
|
||||
|
||||
virtual Json to_json() const;
|
||||
virtual void parse_json(const Json& json);
|
||||
|
||||
template<typename T>
|
||||
void add(const T& entity)
|
||||
{
|
||||
entities.push_back(std::make_shared<T>(entity));
|
||||
}
|
||||
|
||||
void add_ptr(const entity_ptr& entity)
|
||||
{
|
||||
entities.push_back(entity);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
} //namespace jsonrpc
|
||||
|
||||
|
||||
|
||||
#endif
|
1510
server/jsonrpcpp.hpp
Normal file
1510
server/jsonrpcpp.hpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -151,36 +151,36 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
{
|
||||
try
|
||||
{
|
||||
////LOG(INFO) << "StreamServer::ProcessRequest method: " << request->method << ", " << "id: " << request->id << "\n";
|
||||
////LOG(INFO) << "StreamServer::ProcessRequest method: " << request->method << ", " << "id: " << request->id() << "\n";
|
||||
Json result;
|
||||
|
||||
if (request->method.find("Client.") == 0)
|
||||
if (request->method().find("Client.") == 0)
|
||||
{
|
||||
ClientInfoPtr clientInfo = Config::instance().getClientInfo(request->params.get("id"));
|
||||
ClientInfoPtr clientInfo = Config::instance().getClientInfo(request->params().get("id"));
|
||||
if (clientInfo == nullptr)
|
||||
throw jsonrpcpp::InternalErrorException("Client not found", request->id);
|
||||
throw jsonrpcpp::InternalErrorException("Client not found", request->id());
|
||||
|
||||
if (request->method == "Client.GetStatus")
|
||||
if (request->method() == "Client.GetStatus")
|
||||
{
|
||||
/// Request: {"id":8,"jsonrpc":"2.0","method":"Client.GetStatus","params":{"id":"00:21:6a:7d:74:fc"}}
|
||||
/// Response: {"id":8,"jsonrpc":"2.0","result":{"client":{"config":{"instance":1,"latency":0,"name":"","volume":{"muted":false,"percent":74}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc","lastSeen":{"sec":1488026416,"usec":135973},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}}}}
|
||||
result["client"] = clientInfo->toJson();
|
||||
}
|
||||
else if (request->method == "Client.SetVolume")
|
||||
else if (request->method() == "Client.SetVolume")
|
||||
{
|
||||
/// Request: {"id":8,"jsonrpc":"2.0","method":"Client.SetVolume","params":{"id":"00:21:6a:7d:74:fc","volume":{"muted":false,"percent":74}}}
|
||||
/// Response: {"id":8,"jsonrpc":"2.0","result":{"volume":{"muted":false,"percent":74}}}
|
||||
/// Notification: {"jsonrpc":"2.0","method":"Client.OnVolumeChanged","params":{"id":"00:21:6a:7d:74:fc","volume":{"muted":false,"percent":74}}}
|
||||
clientInfo->config.volume.fromJson(request->params.get("volume"));
|
||||
clientInfo->config.volume.fromJson(request->params().get("volume"));
|
||||
result["volume"] = clientInfo->config.volume.toJson();
|
||||
notification.reset(new jsonrpcpp::Notification("Client.OnVolumeChanged", jsonrpcpp::Parameter("id", clientInfo->id, "volume", clientInfo->config.volume.toJson())));
|
||||
}
|
||||
else if (request->method == "Client.SetLatency")
|
||||
else if (request->method() == "Client.SetLatency")
|
||||
{
|
||||
/// Request: {"id":7,"jsonrpc":"2.0","method":"Client.SetLatency","params":{"id":"00:21:6a:7d:74:fc#2","latency":10}}
|
||||
/// Response: {"id":7,"jsonrpc":"2.0","result":{"latency":10}}
|
||||
/// Notification: {"jsonrpc":"2.0","method":"Client.OnLatencyChanged","params":{"id":"00:21:6a:7d:74:fc#2","latency":10}}
|
||||
int latency = request->params.get("latency");
|
||||
int latency = request->params().get("latency");
|
||||
if (latency < -10000)
|
||||
latency = -10000;
|
||||
else if (latency > settings_.bufferMs)
|
||||
|
@ -189,20 +189,20 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
result["latency"] = clientInfo->config.latency;
|
||||
notification.reset(new jsonrpcpp::Notification("Client.OnLatencyChanged", jsonrpcpp::Parameter("id", clientInfo->id, "latency", clientInfo->config.latency)));
|
||||
}
|
||||
else if (request->method == "Client.SetName")
|
||||
else if (request->method() == "Client.SetName")
|
||||
{
|
||||
/// Request: {"id":6,"jsonrpc":"2.0","method":"Client.SetName","params":{"id":"00:21:6a:7d:74:fc#2","name":"Laptop"}}
|
||||
/// Response: {"id":6,"jsonrpc":"2.0","result":{"name":"Laptop"}}
|
||||
/// Notification: {"jsonrpc":"2.0","method":"Client.OnNameChanged","params":{"id":"00:21:6a:7d:74:fc#2","name":"Laptop"}}
|
||||
clientInfo->config.name = request->params.get("name");
|
||||
clientInfo->config.name = request->params().get("name");
|
||||
result["name"] = clientInfo->config.name;
|
||||
notification.reset(new jsonrpcpp::Notification("Client.OnNameChanged", jsonrpcpp::Parameter("id", clientInfo->id, "name", clientInfo->config.name)));
|
||||
}
|
||||
else
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id);
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id());
|
||||
|
||||
|
||||
if (request->method.find("Client.Set") == 0)
|
||||
if (request->method().find("Client.Set") == 0)
|
||||
{
|
||||
/// Update client
|
||||
session_ptr session = getStreamSession(clientInfo->id);
|
||||
|
@ -218,24 +218,24 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (request->method.find("Group.") == 0)
|
||||
else if (request->method().find("Group.") == 0)
|
||||
{
|
||||
GroupPtr group = Config::instance().getGroup(request->params.get("id"));
|
||||
GroupPtr group = Config::instance().getGroup(request->params().get("id"));
|
||||
if (group == nullptr)
|
||||
throw jsonrpcpp::InternalErrorException("Group not found", request->id);
|
||||
throw jsonrpcpp::InternalErrorException("Group not found", request->id());
|
||||
|
||||
if (request->method == "Group.GetStatus")
|
||||
if (request->method() == "Group.GetStatus")
|
||||
{
|
||||
/// Request: {"id":5,"jsonrpc":"2.0","method":"Group.GetStatus","params":{"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1"}}
|
||||
/// Response: {"id":5,"jsonrpc":"2.0","result":{"group":{"clients":[{"config":{"instance":2,"latency":10,"name":"Laptop","volume":{"muted":false,"percent":48}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc#2","lastSeen":{"sec":1488026485,"usec":644997},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}},{"config":{"instance":1,"latency":0,"name":"","volume":{"muted":false,"percent":74}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc","lastSeen":{"sec":1488026481,"usec":223747},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}}],"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","muted":true,"name":"","stream_id":"stream 1"}}}
|
||||
result["group"] = group->toJson();
|
||||
}
|
||||
else if (request->method == "Group.SetMute")
|
||||
else if (request->method() == "Group.SetMute")
|
||||
{
|
||||
/// Request: {"id":5,"jsonrpc":"2.0","method":"Group.SetMute","params":{"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","mute":true}}
|
||||
/// Response: {"id":5,"jsonrpc":"2.0","result":{"mute":true}}
|
||||
/// Notification: {"jsonrpc":"2.0","method":"Group.OnMute","params":{"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","mute":true}}
|
||||
bool muted = request->params.get<bool>("mute");
|
||||
bool muted = request->params().get<bool>("mute");
|
||||
group->muted = muted;
|
||||
|
||||
/// Update clients
|
||||
|
@ -257,15 +257,15 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
result["mute"] = group->muted;
|
||||
notification.reset(new jsonrpcpp::Notification("Group.OnMute", jsonrpcpp::Parameter("id", group->id, "mute", group->muted)));
|
||||
}
|
||||
else if (request->method == "Group.SetStream")
|
||||
else if (request->method() == "Group.SetStream")
|
||||
{
|
||||
/// Request: {"id":4,"jsonrpc":"2.0","method":"Group.SetStream","params":{"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","stream_id":"stream 1"}}
|
||||
/// Response: {"id":4,"jsonrpc":"2.0","result":{"stream_id":"stream 1"}}
|
||||
/// Notification: {"jsonrpc":"2.0","method":"Group.OnStreamChanged","params":{"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","stream_id":"stream 1"}}
|
||||
string streamId = request->params.get("stream_id");
|
||||
string streamId = request->params().get("stream_id");
|
||||
PcmStreamPtr stream = streamManager_->getStream(streamId);
|
||||
if (stream == nullptr)
|
||||
throw jsonrpcpp::InternalErrorException("Stream not found", request->id);
|
||||
throw jsonrpcpp::InternalErrorException("Stream not found", request->id());
|
||||
|
||||
group->streamId = streamId;
|
||||
|
||||
|
@ -285,12 +285,12 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
result["stream_id"] = group->streamId;
|
||||
notification.reset(new jsonrpcpp::Notification("Group.OnStreamChanged", jsonrpcpp::Parameter("id", group->id, "stream_id", group->streamId)));
|
||||
}
|
||||
else if (request->method == "Group.SetClients")
|
||||
else if (request->method() == "Group.SetClients")
|
||||
{
|
||||
/// Request: {"id":3,"jsonrpc":"2.0","method":"Group.SetClients","params":{"clients":["00:21:6a:7d:74:fc#2","00:21:6a:7d:74:fc"],"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1"}}
|
||||
/// Response: {"id":3,"jsonrpc":"2.0","result":{"server":{"groups":[{"clients":[{"config":{"instance":2,"latency":6,"name":"123 456","volume":{"muted":false,"percent":48}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc#2","lastSeen":{"sec":1488025901,"usec":864472},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}},{"config":{"instance":1,"latency":0,"name":"","volume":{"muted":false,"percent":100}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc","lastSeen":{"sec":1488025905,"usec":45238},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}}],"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","muted":false,"name":"","stream_id":"stream 2"}],"server":{"host":{"arch":"x86_64","ip":"","mac":"","name":"T400","os":"Linux Mint 17.3 Rosa"},"snapserver":{"controlProtocolVersion":1,"name":"Snapserver","protocolVersion":1,"version":"0.10.0"}},"streams":[{"id":"stream 1","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 1","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 1","scheme":"pipe"}},{"id":"stream 2","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 2","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 2","scheme":"pipe"}}]}}}
|
||||
/// Notification: {"jsonrpc":"2.0","method":"Server.OnUpdate","params":{"server":{"groups":[{"clients":[{"config":{"instance":2,"latency":6,"name":"123 456","volume":{"muted":false,"percent":48}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc#2","lastSeen":{"sec":1488025901,"usec":864472},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}},{"config":{"instance":1,"latency":0,"name":"","volume":{"muted":false,"percent":100}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc","lastSeen":{"sec":1488025905,"usec":45238},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}}],"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","muted":false,"name":"","stream_id":"stream 2"}],"server":{"host":{"arch":"x86_64","ip":"","mac":"","name":"T400","os":"Linux Mint 17.3 Rosa"},"snapserver":{"controlProtocolVersion":1,"name":"Snapserver","protocolVersion":1,"version":"0.10.0"}},"streams":[{"id":"stream 1","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 1","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 1","scheme":"pipe"}},{"id":"stream 2","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 2","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 2","scheme":"pipe"}}]}}}
|
||||
vector<string> clients = request->params.get("clients");
|
||||
vector<string> clients = request->params().get("clients");
|
||||
/// Remove clients from group
|
||||
for (auto iter = group->clients.begin(); iter != group->clients.end();)
|
||||
{
|
||||
|
@ -344,11 +344,11 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
notification.reset(new jsonrpcpp::Notification("Server.OnUpdate", jsonrpcpp::Parameter("server", server)));
|
||||
}
|
||||
else
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id);
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id());
|
||||
}
|
||||
else if (request->method.find("Server.") == 0)
|
||||
else if (request->method().find("Server.") == 0)
|
||||
{
|
||||
if (request->method.find("Server.GetRPCVersion") == 0)
|
||||
if (request->method().find("Server.GetRPCVersion") == 0)
|
||||
{
|
||||
/// Request: {"id":8,"jsonrpc":"2.0","method":"Server.GetRPCVersion"}
|
||||
/// Response: {"id":8,"jsonrpc":"2.0","result":{"major":2,"minor":0,"patch":0}}
|
||||
|
@ -359,20 +359,20 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
// <patch>: bugfix release
|
||||
result["patch"] = 0;
|
||||
}
|
||||
else if (request->method == "Server.GetStatus")
|
||||
else if (request->method() == "Server.GetStatus")
|
||||
{
|
||||
/// Request: {"id":1,"jsonrpc":"2.0","method":"Server.GetStatus"}
|
||||
/// Response: {"id":1,"jsonrpc":"2.0","result":{"server":{"groups":[{"clients":[{"config":{"instance":2,"latency":6,"name":"123 456","volume":{"muted":false,"percent":48}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc#2","lastSeen":{"sec":1488025696,"usec":578142},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}},{"config":{"instance":1,"latency":0,"name":"","volume":{"muted":false,"percent":81}},"connected":true,"host":{"arch":"x86_64","ip":"192.168.0.54","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc","lastSeen":{"sec":1488025696,"usec":611255},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}}],"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","muted":false,"name":"","stream_id":"stream 2"}],"server":{"host":{"arch":"x86_64","ip":"","mac":"","name":"T400","os":"Linux Mint 17.3 Rosa"},"snapserver":{"controlProtocolVersion":1,"name":"Snapserver","protocolVersion":1,"version":"0.10.0"}},"streams":[{"id":"stream 1","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 1","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 1","scheme":"pipe"}},{"id":"stream 2","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 2","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 2","scheme":"pipe"}}]}}}
|
||||
result["server"] = Config::instance().getServerStatus(streamManager_->toJson());
|
||||
}
|
||||
else if (request->method == "Server.DeleteClient")
|
||||
else if (request->method() == "Server.DeleteClient")
|
||||
{
|
||||
/// Request: {"id":2,"jsonrpc":"2.0","method":"Server.DeleteClient","params":{"id":"00:21:6a:7d:74:fc"}}
|
||||
/// Response: {"id":2,"jsonrpc":"2.0","result":{"server":{"groups":[{"clients":[{"config":{"instance":2,"latency":6,"name":"123 456","volume":{"muted":false,"percent":48}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc#2","lastSeen":{"sec":1488025751,"usec":654777},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}}],"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","muted":false,"name":"","stream_id":"stream 2"}],"server":{"host":{"arch":"x86_64","ip":"","mac":"","name":"T400","os":"Linux Mint 17.3 Rosa"},"snapserver":{"controlProtocolVersion":1,"name":"Snapserver","protocolVersion":1,"version":"0.10.0"}},"streams":[{"id":"stream 1","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 1","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 1","scheme":"pipe"}},{"id":"stream 2","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 2","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 2","scheme":"pipe"}}]}}}
|
||||
/// Notification: {"jsonrpc":"2.0","method":"Server.OnUpdate","params":{"server":{"groups":[{"clients":[{"config":{"instance":2,"latency":6,"name":"123 456","volume":{"muted":false,"percent":48}},"connected":true,"host":{"arch":"x86_64","ip":"127.0.0.1","mac":"00:21:6a:7d:74:fc","name":"T400","os":"Linux Mint 17.3 Rosa"},"id":"00:21:6a:7d:74:fc#2","lastSeen":{"sec":1488025751,"usec":654777},"snapclient":{"name":"Snapclient","protocolVersion":2,"version":"0.10.0"}}],"id":"4dcc4e3b-c699-a04b-7f0c-8260d23c43e1","muted":false,"name":"","stream_id":"stream 2"}],"server":{"host":{"arch":"x86_64","ip":"","mac":"","name":"T400","os":"Linux Mint 17.3 Rosa"},"snapserver":{"controlProtocolVersion":1,"name":"Snapserver","protocolVersion":1,"version":"0.10.0"}},"streams":[{"id":"stream 1","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 1","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 1","scheme":"pipe"}},{"id":"stream 2","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"buffer_ms":"20","codec":"flac","name":"stream 2","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 2","scheme":"pipe"}}]}}}
|
||||
ClientInfoPtr clientInfo = Config::instance().getClientInfo(request->params.get("id"));
|
||||
ClientInfoPtr clientInfo = Config::instance().getClientInfo(request->params().get("id"));
|
||||
if (clientInfo == nullptr)
|
||||
throw jsonrpcpp::InternalErrorException("Client not found", request->id);
|
||||
throw jsonrpcpp::InternalErrorException("Client not found", request->id());
|
||||
|
||||
Config::instance().remove(clientInfo);
|
||||
|
||||
|
@ -383,11 +383,11 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
notification.reset(new jsonrpcpp::Notification("Server.OnUpdate", jsonrpcpp::Parameter("server", server)));
|
||||
}
|
||||
else
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id);
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id());
|
||||
}
|
||||
else if (request->method.find("Stream.") == 0)
|
||||
else if (request->method().find("Stream.") == 0)
|
||||
{
|
||||
if (request->method.find("Stream.SetMeta") == 0)
|
||||
if (request->method().find("Stream.SetMeta") == 0)
|
||||
{
|
||||
/// Request: {"id":4,"jsonrpc":"2.0","method":"Stream.SetMeta","params":{"id":"Spotify",
|
||||
/// "meta": {"album": "some album", "artist": "some artist", "track": "some track"...}}}
|
||||
|
@ -395,25 +395,25 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
/// Response: {"id":4,"jsonrpc":"2.0","result":{"stream_id":"Spotify"}}
|
||||
/// Call onMetaChanged(const PcmStream* pcmStream) for updates and notifications
|
||||
|
||||
LOG(INFO) << "Stream.SetMeta(" << request->params.get("id") << ")" << request->params.get("meta") <<"\n";
|
||||
LOG(INFO) << "Stream.SetMeta(" << request->params().get("id") << ")" << request->params().get("meta") <<"\n";
|
||||
|
||||
// Find stream
|
||||
string streamId = request->params.get("id");
|
||||
string streamId = request->params().get("id");
|
||||
PcmStreamPtr stream = streamManager_->getStream(streamId);
|
||||
if (stream == nullptr)
|
||||
throw jsonrpcpp::InternalErrorException("Stream not found", request->id);
|
||||
throw jsonrpcpp::InternalErrorException("Stream not found", request->id());
|
||||
|
||||
// Set metadata from request
|
||||
stream->setMeta(request->params.get("meta"));
|
||||
stream->setMeta(request->params().get("meta"));
|
||||
|
||||
// Setup response
|
||||
result["id"] = streamId;
|
||||
}
|
||||
else
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id);
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id());
|
||||
}
|
||||
else
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id);
|
||||
throw jsonrpcpp::MethodNotFoundException(request->id());
|
||||
|
||||
Config::instance().save();
|
||||
response.reset(new jsonrpcpp::Response(*request, result));
|
||||
|
@ -426,7 +426,7 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
catch (const exception& e)
|
||||
{
|
||||
LOG(ERROR) << "StreamServer::onMessageReceived exception: " << e.what() << ", message: " << request->to_json().dump() << "\n";
|
||||
response.reset(new jsonrpcpp::InternalErrorException(e.what(), request->id));
|
||||
response.reset(new jsonrpcpp::InternalErrorException(e.what(), request->id()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <sstream>
|
||||
#include <mutex>
|
||||
|
||||
#include "jsonrp.hpp"
|
||||
#include "jsonrpcpp.hpp"
|
||||
#include "streamSession.h"
|
||||
#include "streamreader/streamManager.h"
|
||||
#include "common/queue.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue