Instance: add method FindOutput()
Move code from handle_moveoutput().
This commit is contained in:
parent
370df37596
commit
8db14c9cb3
|
@ -90,6 +90,22 @@ Instance::DeletePartition(Partition &partition) noexcept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioOutputControl *
|
||||||
|
Instance::FindOutput(std::string_view name,
|
||||||
|
Partition &excluding_partition) noexcept
|
||||||
|
{
|
||||||
|
for (auto &partition : partitions) {
|
||||||
|
if (&partition == &excluding_partition)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto *output = partition.outputs.FindByName(name);
|
||||||
|
if (output != nullptr && !output->IsDummy())
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
|
|
||||||
const Database &
|
const Database &
|
||||||
|
|
|
@ -38,6 +38,7 @@ class InotifyUpdate;
|
||||||
|
|
||||||
class ClientList;
|
class ClientList;
|
||||||
struct Partition;
|
struct Partition;
|
||||||
|
class AudioOutputControl;
|
||||||
class StateFile;
|
class StateFile;
|
||||||
class RemoteTagCache;
|
class RemoteTagCache;
|
||||||
class StickerDatabase;
|
class StickerDatabase;
|
||||||
|
@ -171,6 +172,17 @@ struct Instance final
|
||||||
|
|
||||||
void BeginShutdownPartitions() noexcept;
|
void BeginShutdownPartitions() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the (non-dummy) audio output device with the
|
||||||
|
* specified name. Returns nullptr if the name does not
|
||||||
|
* exist.
|
||||||
|
*
|
||||||
|
* @param excluding_partition ignore this partition
|
||||||
|
*/
|
||||||
|
[[gnu::pure]]
|
||||||
|
AudioOutputControl *FindOutput(std::string_view name,
|
||||||
|
Partition &excluding_partition) noexcept;
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
/**
|
/**
|
||||||
* Returns the global #Database instance. May return nullptr
|
* Returns the global #Database instance. May return nullptr
|
||||||
|
|
|
@ -145,13 +145,12 @@ handle_moveoutput(Client &client, Request request, Response &response)
|
||||||
|
|
||||||
/* find the partition which owns this output currently */
|
/* find the partition which owns this output currently */
|
||||||
auto &instance = client.GetInstance();
|
auto &instance = client.GetInstance();
|
||||||
for (auto &partition : instance.partitions) {
|
|
||||||
if (&partition == &dest_partition)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto *output = partition.outputs.FindByName(output_name);
|
auto *output = instance.FindOutput(output_name, dest_partition);
|
||||||
if (output == nullptr || output->IsDummy())
|
if (output == nullptr) {
|
||||||
continue;
|
response.Error(ACK_ERROR_NO_EXIST, "No such output");
|
||||||
|
return CommandResult::ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
const bool was_enabled = output->IsEnabled();
|
const bool was_enabled = output->IsEnabled();
|
||||||
|
|
||||||
|
@ -166,8 +165,4 @@ handle_moveoutput(Client &client, Request request, Response &response)
|
||||||
|
|
||||||
instance.EmitIdle(IDLE_OUTPUT);
|
instance.EmitIdle(IDLE_OUTPUT);
|
||||||
return CommandResult::OK;
|
return CommandResult::OK;
|
||||||
}
|
|
||||||
|
|
||||||
response.Error(ACK_ERROR_NO_EXIST, "No such output");
|
|
||||||
return CommandResult::ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue