diff options
| author | Léo Lam <leo@leolam.fr> | 2019-01-16 21:00:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-16 21:00:48 +0100 |
| commit | a8bc6f9899630591f616c4b2ed9fca560038e203 (patch) | |
| tree | f61b53fd10762763dceab5f380d57a3d176c5fc7 /Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | |
| parent | b2de98cad168dee08a5299bd1220d88a0a6c09eb (diff) | |
| parent | b425f86121c8c9f3b4a510e522d03e432677dcea (diff) | |
Merge pull request #7693 from jordan-woyak/hotplug-callback-fix
ControllerInterface: Hotplug callback fixes.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 318b288434..3da92e8b75 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -249,10 +249,20 @@ void ControllerInterface::UpdateInput() // Register a callback to be called when a device is added or removed (as from the input backends' // hotplug thread), or when devices are refreshed -void ControllerInterface::RegisterDevicesChangedCallback(std::function<void()> callback) +// Returns a handle for later removing the callback. +ControllerInterface::HotplugCallbackHandle +ControllerInterface::RegisterDevicesChangedCallback(std::function<void()> callback) { std::lock_guard<std::mutex> lk(m_callbacks_mutex); m_devices_changed_callbacks.emplace_back(std::move(callback)); + return std::prev(m_devices_changed_callbacks.end()); +} + +// Unregister a device callback. +void ControllerInterface::UnregisterDevicesChangedCallback(const HotplugCallbackHandle& handle) +{ + std::lock_guard<std::mutex> lk(m_callbacks_mutex); + m_devices_changed_callbacks.erase(handle); } // Invoke all callbacks that were registered |
