Skip to content

Commit dca6f72

Browse files
committed
Add Plugin::HasDevice()
1 parent 7ba948f commit dca6f72

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/aspl/Plugin.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class Plugin : public Object
101101
//! Returns nullptr if there is no such device.
102102
std::shared_ptr<Device> GetDeviceByID(AudioObjectID deviceID) const;
103103

104+
//! Check if device is already added.
105+
bool HasDevice(std::shared_ptr<Device> device) const;
106+
104107
//! Add device to the plugin.
105108
//! Adds device to the owned object list.
106109
void AddDevice(std::shared_ptr<Device> device);

src/Plugin.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ std::shared_ptr<Device> Plugin::GetDeviceByID(AudioObjectID deviceID) const
7878
return deviceByID.at(deviceID);
7979
}
8080

81+
bool Plugin::HasDevice(std::shared_ptr<Device> device) const
82+
{
83+
auto readLock = deviceByID_.GetReadLock();
84+
85+
const auto& deviceByID = readLock.GetReference();
86+
87+
return deviceByID.count(device->GetID());
88+
}
89+
8190
void Plugin::AddDevice(std::shared_ptr<Device> device)
8291
{
8392
std::lock_guard writeLock(writeMutex_);

0 commit comments

Comments
 (0)