Instance: add method FindOutput()

Move code from handle_moveoutput().
This commit is contained in:
Max Kellermann
2022-07-13 14:52:13 +02:00
parent 370df37596
commit 8db14c9cb3
3 changed files with 45 additions and 22 deletions

View File

@@ -145,29 +145,24 @@ handle_moveoutput(Client &client, Request request, Response &response)
/* find the partition which owns this output currently */
auto &instance = client.GetInstance();
for (auto &partition : instance.partitions) {
if (&partition == &dest_partition)
continue;
auto *output = partition.outputs.FindByName(output_name);
if (output == nullptr || output->IsDummy())
continue;
const bool was_enabled = output->IsEnabled();
if (existing_output != nullptr)
/* move the output back where it once was */
existing_output->ReplaceDummy(output->Steal(),
was_enabled);
else
/* copy the AudioOutputControl and add it to the output list */
dest_partition.outputs.AddMoveFrom(std::move(*output),
was_enabled);
instance.EmitIdle(IDLE_OUTPUT);
return CommandResult::OK;
auto *output = instance.FindOutput(output_name, dest_partition);
if (output == nullptr) {
response.Error(ACK_ERROR_NO_EXIST, "No such output");
return CommandResult::ERROR;
}
response.Error(ACK_ERROR_NO_EXIST, "No such output");
return CommandResult::ERROR;
const bool was_enabled = output->IsEnabled();
if (existing_output != nullptr)
/* move the output back where it once was */
existing_output->ReplaceDummy(output->Steal(),
was_enabled);
else
/* copy the AudioOutputControl and add it to the output list */
dest_partition.outputs.AddMoveFrom(std::move(*output),
was_enabled);
instance.EmitIdle(IDLE_OUTPUT);
return CommandResult::OK;
}