command/partition: add command "delpartition"
This commit is contained in:
@@ -103,6 +103,7 @@ static constexpr struct command commands[] = {
|
||||
{ "decoders", PERMISSION_READ, 0, 0, handle_decoders },
|
||||
{ "delete", PERMISSION_CONTROL, 1, 1, handle_delete },
|
||||
{ "deleteid", PERMISSION_CONTROL, 1, 1, handle_deleteid },
|
||||
{ "delpartition", PERMISSION_ADMIN, 1, 1, handle_delpartition },
|
||||
{ "disableoutput", PERMISSION_ADMIN, 1, 1, handle_disableoutput },
|
||||
{ "enableoutput", PERMISSION_ADMIN, 1, 1, handle_enableoutput },
|
||||
#ifdef ENABLE_DATABASE
|
||||
|
@@ -112,6 +112,48 @@ handle_newpartition(Client &client, Request request, Response &response)
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
CommandResult
|
||||
handle_delpartition(Client &client, Request request, Response &response)
|
||||
{
|
||||
const char *name = request.front();
|
||||
if (!IsValidPartitionName(name)) {
|
||||
response.Error(ACK_ERROR_ARG, "bad name");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
auto &instance = client.GetInstance();
|
||||
auto *partition = instance.FindPartition(name);
|
||||
if (partition == nullptr) {
|
||||
response.Error(ACK_ERROR_NO_EXIST, "no such partition");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
if (partition == &instance.partitions.front()) {
|
||||
response.Error(ACK_ERROR_UNKNOWN,
|
||||
"cannot delete the default partition");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
if (!partition->clients.empty()) {
|
||||
response.Error(ACK_ERROR_UNKNOWN,
|
||||
"partition still has clients");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
if (!partition->outputs.IsDummy()) {
|
||||
response.Error(ACK_ERROR_UNKNOWN,
|
||||
"partition still has outputs");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
partition->BeginShutdown();
|
||||
instance.DeletePartition(*partition);
|
||||
|
||||
instance.EmitIdle(IDLE_PARTITION);
|
||||
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
CommandResult
|
||||
handle_moveoutput(Client &client, Request request, Response &response)
|
||||
{
|
||||
|
@@ -35,6 +35,9 @@ handle_listpartitions(Client &client, Request request, Response &response);
|
||||
CommandResult
|
||||
handle_newpartition(Client &client, Request request, Response &response);
|
||||
|
||||
CommandResult
|
||||
handle_delpartition(Client &client, Request request, Response &response);
|
||||
|
||||
CommandResult
|
||||
handle_moveoutput(Client &client, Request request, Response &response);
|
||||
|
||||
|
Reference in New Issue
Block a user