mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-26 22:38:34 +00:00
ControllerInterface: Switch to std::shared_ptr
Small cleanup by using std::shared_ptr and getting rid of ciface.Devices() which just returned the m_devices (which defeats the point of making m_devices protected). Incidentally, this should make the code safer when we have different threads accessing devices in the future (for hotplug?). A lot of code use Device references directly so there is no easy way to remove FindDevice() and make those unique_ptrs.
This commit is contained in:
parent
afa202738e
commit
8678133e87
18 changed files with 80 additions and 60 deletions
|
@ -144,17 +144,45 @@ bool DeviceQualifier::operator==(const DeviceQualifier& devq) const
|
|||
return false;
|
||||
}
|
||||
|
||||
Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const
|
||||
std::shared_ptr<Device> DeviceContainer::FindDevice(const DeviceQualifier& devq) const
|
||||
{
|
||||
for (Device* d : m_devices)
|
||||
std::lock_guard<std::mutex> lk(m_devices_mutex);
|
||||
for (const auto& d : m_devices)
|
||||
{
|
||||
if (devq == d)
|
||||
if (devq == d.get())
|
||||
return d;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> DeviceContainer::GetAllDeviceStrings() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(m_devices_mutex);
|
||||
|
||||
std::vector<std::string> device_strings;
|
||||
DeviceQualifier device_qualifier;
|
||||
|
||||
for (const auto& d : m_devices)
|
||||
{
|
||||
device_qualifier.FromDevice(d.get());
|
||||
device_strings.emplace_back(device_qualifier.ToString());
|
||||
}
|
||||
|
||||
return device_strings;
|
||||
}
|
||||
|
||||
std::string DeviceContainer::GetDefaultDeviceString() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(m_devices_mutex);
|
||||
if (m_devices.empty())
|
||||
return "";
|
||||
|
||||
DeviceQualifier device_qualifier;
|
||||
device_qualifier.FromDevice(m_devices[0].get());
|
||||
return device_qualifier.ToString();
|
||||
}
|
||||
|
||||
Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const
|
||||
{
|
||||
if (def_dev)
|
||||
|
@ -164,7 +192,8 @@ Device::Input* DeviceContainer::FindInput(const std::string& name, const Device*
|
|||
return inp;
|
||||
}
|
||||
|
||||
for (Device* d : m_devices)
|
||||
std::lock_guard<std::mutex> lk(m_devices_mutex);
|
||||
for (const auto& d : m_devices)
|
||||
{
|
||||
Device::Input* const i = d->FindInput(name);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue