mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-28 17:57:05 +02:00
Add RPC description
This commit is contained in:
parent
356be2eeff
commit
e2feac1d75
2 changed files with 161 additions and 0 deletions
|
@ -203,6 +203,11 @@ void ClientGetStatusRequest::execute(const jsonrpcpp::request_ptr& request, Auth
|
|||
on_response(std::move(response), nullptr);
|
||||
}
|
||||
|
||||
Request::Description ClientGetStatusRequest::description() const
|
||||
{
|
||||
return {"Get client status", {{"id", "client id"}}, "Client status, information and settings"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
ClientSetVolumeRequest::ClientSetVolumeRequest(const Server& server) : ClientRequest(server, "Client.SetVolume")
|
||||
|
@ -232,6 +237,11 @@ void ClientSetVolumeRequest::execute(const jsonrpcpp::request_ptr& request, Auth
|
|||
updateClient(request);
|
||||
}
|
||||
|
||||
Request::Description ClientSetVolumeRequest::description() const
|
||||
{
|
||||
return {"Set client volume", {{"volume", "muted [bool] and volume [percent]"}}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
ClientSetLatencyRequest::ClientSetLatencyRequest(const Server& server) : ClientRequest(server, "Client.SetLatency")
|
||||
|
@ -266,6 +276,11 @@ void ClientSetLatencyRequest::execute(const jsonrpcpp::request_ptr& request, Aut
|
|||
updateClient(request);
|
||||
}
|
||||
|
||||
Request::Description ClientSetLatencyRequest::description() const
|
||||
{
|
||||
return {"Set additional client audio latency", {{"id", "client id"}, {"latency", "value [ms]"}}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
ClientSetNameRequest::ClientSetNameRequest(const Server& server) : ClientRequest(server, "Client.SetName")
|
||||
|
@ -295,6 +310,10 @@ void ClientSetNameRequest::execute(const jsonrpcpp::request_ptr& request, AuthIn
|
|||
updateClient(request);
|
||||
}
|
||||
|
||||
Request::Description ClientSetNameRequest::description() const
|
||||
{
|
||||
return {"Set name of a client", {{"name", "new client name"}}};
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////// Group requests //////////////////////////////////////////
|
||||
|
@ -335,6 +354,12 @@ void GroupGetStatusRequest::execute(const jsonrpcpp::request_ptr& request, AuthI
|
|||
on_response(std::move(response), nullptr);
|
||||
}
|
||||
|
||||
Request::Description GroupGetStatusRequest::description() const
|
||||
{
|
||||
return {"Get status of a group", {{"id", "group id"}}, "Group status, information and settings"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
GroupSetNameRequest::GroupSetNameRequest(const Server& server) : GroupRequest(server, "Group.SetName")
|
||||
{
|
||||
|
@ -361,6 +386,12 @@ void GroupSetNameRequest::execute(const jsonrpcpp::request_ptr& request, AuthInf
|
|||
on_response(std::move(response), std::move(notification));
|
||||
}
|
||||
|
||||
Request::Description GroupSetNameRequest::description() const
|
||||
{
|
||||
return {"Set name of a group", {{"id", "group id"}, {"name", "new name of the group"}}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
GroupSetMuteRequest::GroupSetMuteRequest(const Server& server) : GroupRequest(server, "Group.SetMute")
|
||||
{
|
||||
|
@ -405,6 +436,12 @@ void GroupSetMuteRequest::execute(const jsonrpcpp::request_ptr& request, AuthInf
|
|||
on_response(std::move(response), std::move(notification));
|
||||
}
|
||||
|
||||
Request::Description GroupSetMuteRequest::description() const
|
||||
{
|
||||
return {"Mute a grouo", {{"id", "id of the group"}, {"mute", "true or false"}}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
GroupSetStreamRequest::GroupSetStreamRequest(const Server& server) : GroupRequest(server, "Group.SetStream")
|
||||
{
|
||||
|
@ -450,6 +487,12 @@ void GroupSetStreamRequest::execute(const jsonrpcpp::request_ptr& request, AuthI
|
|||
on_response(std::move(response), std::move(notification));
|
||||
}
|
||||
|
||||
Request::Description GroupSetStreamRequest::description() const
|
||||
{
|
||||
return {"Assign a stream to a group", {{"id", "id of the group"}, {"stream_id", "id of the stream"}}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
GroupSetClientsRequest::GroupSetClientsRequest(const Server& server) : GroupRequest(server, "Group.SetClients")
|
||||
{
|
||||
|
@ -525,6 +568,11 @@ void GroupSetClientsRequest::execute(const jsonrpcpp::request_ptr& request, Auth
|
|||
on_response(std::move(response), std::move(notification));
|
||||
}
|
||||
|
||||
Request::Description GroupSetClientsRequest::description() const
|
||||
{
|
||||
return {"Assign clients to a group", {{"id", "id of the group"}, {"clients", "list of client ids"}}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////// Stream requests /////////////////////////////////////////
|
||||
|
@ -552,6 +600,7 @@ std::string StreamRequest::getStreamId(const jsonrpcpp::request_ptr& request)
|
|||
}
|
||||
|
||||
|
||||
|
||||
StreamControlRequest::StreamControlRequest(const Server& server) : StreamRequest(server, "Stream.Control")
|
||||
{
|
||||
}
|
||||
|
@ -636,6 +685,12 @@ void StreamControlRequest::execute(const jsonrpcpp::request_ptr& request, AuthIn
|
|||
throw jsonrpcpp::InvalidParamsException("Command '" + command + "' not supported", request->id());
|
||||
}
|
||||
|
||||
Request::Description StreamControlRequest::description() const
|
||||
{
|
||||
return {"Control a stream (setPositiom, seek, next, previous, pause, playPause, stop, play)"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
StreamSetPropertyRequest::StreamSetPropertyRequest(const Server& server) : StreamRequest(server, "Stream.SetProperty")
|
||||
{
|
||||
|
@ -705,6 +760,12 @@ void StreamSetPropertyRequest::execute(const jsonrpcpp::request_ptr& request, Au
|
|||
throw jsonrpcpp::InvalidParamsException("Property '" + name + "' not supported", request->id());
|
||||
}
|
||||
|
||||
Request::Description StreamSetPropertyRequest::description() const
|
||||
{
|
||||
return {"Set stream property (loopStatus, shuffle, volume, mute, rate)"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
StreamAddRequest::StreamAddRequest(const Server& server) : StreamRequest(server, "Stream.AddStream")
|
||||
{
|
||||
|
@ -765,6 +826,12 @@ void StreamAddRequest::execute(const jsonrpcpp::request_ptr& request, AuthInfo&
|
|||
on_response(std::move(response), nullptr);
|
||||
}
|
||||
|
||||
Request::Description StreamAddRequest::description() const
|
||||
{
|
||||
return {"Add a stream"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
StreamRemoveRequest::StreamRemoveRequest(const Server& server) : StreamRequest(server, "Stream.RemoveStream")
|
||||
{
|
||||
|
@ -792,6 +859,11 @@ void StreamRemoveRequest::execute(const jsonrpcpp::request_ptr& request, AuthInf
|
|||
on_response(std::move(response), nullptr);
|
||||
}
|
||||
|
||||
Request::Description StreamRemoveRequest::description() const
|
||||
{
|
||||
return {"Remove a stream"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////// Server requests /////////////////////////////////////////
|
||||
|
@ -821,6 +893,11 @@ void ServerGetRpcVersionRequest::execute(const jsonrpcpp::request_ptr& request,
|
|||
on_response(std::move(response), nullptr);
|
||||
}
|
||||
|
||||
Request::Description ServerGetRpcVersionRequest::description() const
|
||||
{
|
||||
return {"Get the RPC version"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
ServerGetStatusRequest::ServerGetStatusRequest(const Server& server) : Request(server, "Server.GetStatus")
|
||||
|
@ -841,6 +918,11 @@ void ServerGetStatusRequest::execute(const jsonrpcpp::request_ptr& request, Auth
|
|||
on_response(std::move(response), nullptr);
|
||||
}
|
||||
|
||||
Request::Description ServerGetStatusRequest::description() const
|
||||
{
|
||||
return {"Get server status"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
ServerDeleteClientRequest::ServerDeleteClientRequest(const Server& server) : Request(server, "Server.DeleteClient")
|
||||
|
@ -873,6 +955,12 @@ void ServerDeleteClientRequest::execute(const jsonrpcpp::request_ptr& request, A
|
|||
on_response(std::move(response), std::move(notification));
|
||||
}
|
||||
|
||||
Request::Description ServerDeleteClientRequest::description() const
|
||||
{
|
||||
return {"Delete client"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
ServerAuthenticateRequest::ServerAuthenticateRequest(const Server& server) : Request(server, "Server.Authenticate")
|
||||
{
|
||||
|
@ -912,6 +1000,12 @@ void ServerAuthenticateRequest::execute(const jsonrpcpp::request_ptr& request, A
|
|||
on_response(std::move(response), nullptr);
|
||||
}
|
||||
|
||||
Request::Description ServerAuthenticateRequest::description() const
|
||||
{
|
||||
return {"Authenticate"};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
ServerGetTokenRequest::ServerGetTokenRequest(const Server& server) : Request(server, "Server.GetToken")
|
||||
|
@ -971,6 +1065,7 @@ void GeneralGetRpcCommands::execute(const jsonrpcpp::request_ptr& request, AuthI
|
|||
jperms["authentication"] = req->requiresAuthentication();
|
||||
jperms["authorization"] = req->requiresAuthorization();
|
||||
jreq["requires"] = jperms;
|
||||
jreq["description"] = req->description().toJson();
|
||||
commands.push_back(jreq);
|
||||
}
|
||||
Json result;
|
||||
|
@ -981,6 +1076,12 @@ void GeneralGetRpcCommands::execute(const jsonrpcpp::request_ptr& request, AuthI
|
|||
}
|
||||
|
||||
|
||||
Request::Description GeneralGetRpcCommands::description() const
|
||||
{
|
||||
return {"Get available RPC commands", {}, "List of RPC commands"};
|
||||
}
|
||||
|
||||
|
||||
void GeneralGetRpcCommands::setCommands(std::vector<std::shared_ptr<Request>> requests)
|
||||
{
|
||||
requests_ = std::move(requests);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
// standard headers
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Server;
|
||||
|
||||
|
@ -38,6 +39,44 @@ class Server;
|
|||
class Request
|
||||
{
|
||||
public:
|
||||
/// Description of the request
|
||||
struct Description
|
||||
{
|
||||
/// c'tor
|
||||
Description(std::string description, std::vector<std::pair<std::string, std::string>> parameters = {}, std::string result = "")
|
||||
: description(std::move(description)), parameters(std::move(parameters)), result(std::move(result))
|
||||
{
|
||||
}
|
||||
|
||||
/// Description
|
||||
std::string description;
|
||||
/// Parameters
|
||||
std::vector<std::pair<std::string, std::string>> parameters;
|
||||
/// Return value
|
||||
std::string result;
|
||||
|
||||
Json toJson()
|
||||
{
|
||||
Json jres;
|
||||
jres["description"] = description;
|
||||
if (!result.empty())
|
||||
jres["return"] = result;
|
||||
if (!parameters.empty())
|
||||
{
|
||||
Json jparams = Json::array();
|
||||
for (const auto& [param, desc] : parameters)
|
||||
{
|
||||
Json jparam;
|
||||
jparam["parameter"] = param;
|
||||
jparam["description"] = desc;
|
||||
jparams.push_back(std::move(jparam));
|
||||
}
|
||||
jres["parameters"] = jparams;
|
||||
}
|
||||
return jres;
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: revise handler names
|
||||
/// Response handler for json control requests, returning a @p response and/or a @p notification broadcast
|
||||
using OnResponse = std::function<void(jsonrpcpp::entity_ptr response, jsonrpcpp::notification_ptr notification)>;
|
||||
|
@ -54,6 +93,9 @@ public:
|
|||
/// Execute the Request
|
||||
virtual void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) = 0;
|
||||
|
||||
/// @return description
|
||||
virtual Description description() const = 0;
|
||||
|
||||
/// @return true if the user has the permission for the request
|
||||
virtual bool hasPermission(const AuthInfo& authinfo) const;
|
||||
|
||||
|
@ -122,6 +164,7 @@ public:
|
|||
/// c'tor
|
||||
explicit ClientGetStatusRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -132,6 +175,7 @@ public:
|
|||
/// c'tor
|
||||
explicit ClientSetVolumeRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -142,6 +186,7 @@ public:
|
|||
/// c'tor
|
||||
explicit ClientSetLatencyRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -152,6 +197,7 @@ public:
|
|||
/// c'tor
|
||||
explicit ClientSetNameRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -176,6 +222,7 @@ public:
|
|||
/// c'tor
|
||||
explicit GroupGetStatusRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -186,6 +233,7 @@ public:
|
|||
/// c'tor
|
||||
explicit GroupSetNameRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -196,6 +244,7 @@ public:
|
|||
/// c'tor
|
||||
explicit GroupSetMuteRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -206,6 +255,7 @@ public:
|
|||
/// c'tor
|
||||
explicit GroupSetStreamRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -216,6 +266,7 @@ public:
|
|||
/// c'tor
|
||||
explicit GroupSetClientsRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -242,6 +293,7 @@ public:
|
|||
/// c'tor
|
||||
explicit StreamControlRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -252,6 +304,7 @@ public:
|
|||
/// c'tor
|
||||
explicit StreamSetPropertyRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -262,6 +315,7 @@ public:
|
|||
/// c'tor
|
||||
explicit StreamAddRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -272,6 +326,7 @@ public:
|
|||
/// c'tor
|
||||
explicit StreamRemoveRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -283,6 +338,7 @@ public:
|
|||
/// c'tor
|
||||
explicit ServerGetRpcVersionRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -293,6 +349,7 @@ public:
|
|||
/// c'tor
|
||||
explicit ServerGetStatusRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -303,6 +360,7 @@ public:
|
|||
/// c'tor
|
||||
explicit ServerDeleteClientRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -313,6 +371,7 @@ public:
|
|||
/// c'tor
|
||||
explicit ServerAuthenticateRequest(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
|
||||
bool requiresAuthentication() const override
|
||||
{
|
||||
|
@ -345,6 +404,7 @@ public:
|
|||
/// c'tor
|
||||
explicit GeneralGetRpcCommands(const Server& server);
|
||||
void execute(const jsonrpcpp::request_ptr& request, AuthInfo& authinfo, const OnResponse& on_response) override;
|
||||
Description description() const override;
|
||||
|
||||
/// Set available @p requests
|
||||
void setCommands(std::vector<std::shared_ptr<Request>> requests);
|
||||
|
|
Loading…
Add table
Reference in a new issue