diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2016-06-25 21:46:39 +0200 |
|---|---|---|
| committer | Léo Lam <leo@innovatetechnologi.es> | 2016-06-25 21:46:39 +0200 |
| commit | 8678133e8746fdc20f7d012005ebf2db370ddccc (patch) | |
| tree | ccca4a186be0e8ee93c733c8d2315e5dd0c20db2 /Source/Core/InputCommon/ControllerInterface/Device.cpp | |
| parent | afa202738e54652e98e8388a5c6a1541d750e3e6 (diff) | |
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.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Device.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 7a3b8ac845..e47b04de99 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -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); |
