diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2016-07-29 17:43:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-29 17:43:49 +0200 |
| commit | e0cbb9d1ae6f35b4b44a8e1ed99e8a710c36a7d3 (patch) | |
| tree | 7e0fff192b12dbddbf9c39d133ee433662727fa4 /Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | |
| parent | fc85d8036f1bab0963b3a64278f8e4ea157b6dcf (diff) | |
| parent | 135641404af9c52e433ef28dba4f86fa208f4365 (diff) | |
Merge pull request #3890 from leoetlino/evdev-hotplug
evdev: Add hotplug support
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 700d390b92..f1e62e73cf 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -106,17 +106,6 @@ void ControllerInterface::Shutdown() if (!m_is_init) return; - std::lock_guard<std::mutex> lk(m_devices_mutex); - - for (const auto& d : m_devices) - { - // Set outputs to ZERO before destroying device - for (ciface::Core::Device::Output* o : d->Outputs()) - o->SetState(0); - } - - m_devices.clear(); - #ifdef CIFACE_USE_XINPUT ciface::XInput::DeInit(); #endif @@ -136,6 +125,20 @@ void ControllerInterface::Shutdown() #ifdef CIFACE_USE_ANDROID // nothing needed #endif +#ifdef CIFACE_USE_EVDEV + ciface::evdev::Shutdown(); +#endif + + std::lock_guard<std::mutex> lk(m_devices_mutex); + + for (const auto& d : m_devices) + { + // Set outputs to ZERO before destroying device + for (ciface::Core::Device::Output* o : d->Outputs()) + o->SetState(0); + } + + m_devices.clear(); m_is_init = false; } @@ -160,6 +163,14 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device m_devices.emplace_back(std::move(device)); } +void ControllerInterface::RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback) +{ + std::lock_guard<std::mutex> lk(m_devices_mutex); + m_devices.erase(std::remove_if(m_devices.begin(), m_devices.end(), + [&callback](const auto& dev) { return callback(dev.get()); }), + m_devices.end()); +} + // // UpdateInput // @@ -167,9 +178,35 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device // void ControllerInterface::UpdateInput() { - std::lock_guard<std::mutex> lk(m_devices_mutex); - for (const auto& d : m_devices) - d->UpdateInput(); + // Don't block the UI or CPU thread (to avoid a short but noticeable frame drop) + if (m_devices_mutex.try_lock()) + { + std::lock_guard<std::mutex> lk(m_devices_mutex, std::adopt_lock); + for (const auto& d : m_devices) + d->UpdateInput(); + } +} + +// +// RegisterHotplugCallback +// +// Register a callback to be called from the input backends' hotplug thread +// when there is a new device +// +void ControllerInterface::RegisterHotplugCallback(std::function<void()> callback) +{ + m_hotplug_callbacks.emplace_back(std::move(callback)); +} + +// +// InvokeHotplugCallbacks +// +// Invoke all callbacks that were registered +// +void ControllerInterface::InvokeHotplugCallbacks() const +{ + for (const auto& callback : m_hotplug_callbacks) + callback(); } // |
