From 788e19f54d86ba45cdc83d39c0488b17aa1d00dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 14 Jul 2016 10:25:52 +0200 Subject: ControllerInterface: Make the ID assigning code common This makes the device ID assigning code common to all backends, by moving it to AddDevice() instead of copy-pasting or replicating the logic in the backends. Also, to prepare for hotplugging, instead of relying on a name usage count, the new ID assigning system always starts from ID 0 and tries to assign the first ID that is not used. --- Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp | 11 ++--------- Source/Core/InputCommon/ControllerInterface/evdev/evdev.h | 4 +--- 2 files changed, 3 insertions(+), 12 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/evdev') diff --git a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp index 49827369f6..16d0d108b2 100644 --- a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp +++ b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp @@ -36,12 +36,6 @@ static std::string GetName(const std::string& devnode) void Init() { - // this is used to number the joysticks - // multiple joysticks with the same name shall get unique ids starting at 0 - std::map name_counts; - - int num_controllers = 0; - // We use Udev to find any devices. In the future this will allow for hotplugging. // But for now it is essentially iterating over /dev/input/event0 to event31. However if the // naming scheme is ever updated in the future, this *should* be forwards compatable. @@ -70,12 +64,11 @@ void Init() // Unfortunately udev gives us no way to filter out the non event device interfaces. // So we open it and see if it works with evdev ioctls or not. std::string name = GetName(devnode); - auto input = std::make_shared(devnode, name_counts[name]++); + auto input = std::make_shared(devnode); if (input->IsInteresting()) { g_controller_interface.AddDevice(std::move(input)); - num_controllers++; } } udev_device_unref(dev); @@ -84,7 +77,7 @@ void Init() udev_unref(udev); } -evdevDevice::evdevDevice(const std::string& devnode, int id) : m_devfile(devnode), m_id(id) +evdevDevice::evdevDevice(const std::string& devnode) : m_devfile(devnode) { // The device file will be read on one of the main threads, so we open in non-blocking mode. m_fd = open(devnode.c_str(), O_RDWR | O_NONBLOCK); diff --git a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.h b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.h index 36c25cb42b..081913fa8e 100644 --- a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.h +++ b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.h @@ -63,11 +63,10 @@ private: public: void UpdateInput() override; - evdevDevice(const std::string& devnode, int id); + evdevDevice(const std::string& devnode); ~evdevDevice(); std::string GetName() const override { return m_name; } - int GetId() const override { return m_id; } std::string GetSource() const override { return "evdev"; } bool IsInteresting() const { return m_initialized && m_interesting; } private: @@ -75,7 +74,6 @@ private: int m_fd; libevdev* m_dev; std::string m_name; - const int m_id; bool m_initialized; bool m_interesting; }; -- cgit v1.2.3