From e9e853b19ab8989c639e7f431ede7a377a427579 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 Feb 2017 12:37:14 +0100 Subject: [PATCH] command/Partition: add command "partition" to switch to another partition --- doc/protocol.xml | 14 ++++++++++++++ src/command/AllCommands.cxx | 1 + src/command/PartitionCommands.cxx | 15 +++++++++++++++ src/command/PartitionCommands.hxx | 3 +++ 4 files changed, 33 insertions(+) diff --git a/doc/protocol.xml b/doc/protocol.xml index 1c0730eb3..6819a2abc 100644 --- a/doc/protocol.xml +++ b/doc/protocol.xml @@ -2368,6 +2368,20 @@ OK + + + + partition + NAME + + + + + Switch the client to a different partition. + + + + diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index 43dbaa691..ef4d34ded 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -137,6 +137,7 @@ static constexpr struct command commands[] = { { "next", PERMISSION_CONTROL, 0, 0, handle_next }, { "notcommands", PERMISSION_NONE, 0, 0, handle_not_commands }, { "outputs", PERMISSION_READ, 0, 0, handle_devices }, + { "partition", PERMISSION_READ, 1, 1, handle_partition }, { "password", PERMISSION_NONE, 1, 1, handle_password }, { "pause", PERMISSION_CONTROL, 0, 1, handle_pause }, { "ping", PERMISSION_NONE, 0, 0, handle_ping }, diff --git a/src/command/PartitionCommands.cxx b/src/command/PartitionCommands.cxx index 5953437d2..7929b5998 100644 --- a/src/command/PartitionCommands.cxx +++ b/src/command/PartitionCommands.cxx @@ -28,6 +28,21 @@ #include "player/Thread.hxx" #include "util/CharUtil.hxx" +CommandResult +handle_partition(Client &client, Request request, Response &response) +{ + const char *name = request.front(); + auto &instance = client.GetInstance(); + auto *partition = instance.FindPartition(name); + if (partition == nullptr) { + response.Error(ACK_ERROR_NO_EXIST, "partition does not exist"); + return CommandResult::ERROR; + } + + client.SetPartition(*partition); + return CommandResult::OK; +} + CommandResult handle_listpartitions(Client &client, Request, Response &r) { diff --git a/src/command/PartitionCommands.hxx b/src/command/PartitionCommands.hxx index 6c51beeb4..7a370a523 100644 --- a/src/command/PartitionCommands.hxx +++ b/src/command/PartitionCommands.hxx @@ -26,6 +26,9 @@ class Client; class Request; class Response; +CommandResult +handle_partition(Client &client, Request request, Response &response); + CommandResult handle_listpartitions(Client &client, Request request, Response &response);