Skip to content
Permalink
Browse files
Merge pull request #8840 from Techjar/evdev-combining-phys
ControllerInterface: Combine evdev devices with the same physical location in addition to unique ID
  • Loading branch information
jordan-woyak committed Sep 20, 2020
2 parents c9a1134 + 8423f84 commit 50b5224
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
@@ -204,19 +204,24 @@ static int s_wakeup_eventfd;
// sysfs is not stable, so this is probably the easiest way to get a name for a node.
static std::map<std::string, std::weak_ptr<evdevDevice>> s_devnode_objects;

static std::shared_ptr<evdevDevice> FindDeviceWithUniqueID(const char* unique_id)
static std::shared_ptr<evdevDevice>
FindDeviceWithUniqueIDAndPhysicalLocation(const char* unique_id, const char* physical_location)
{
if (!unique_id)
if (!unique_id || !physical_location)
return nullptr;

for (auto& [node, dev] : s_devnode_objects)
{
if (const auto device = dev.lock())
{
const auto* dev_uniq = device->GetUniqueID();
const auto* dev_phys = device->GetPhysicalLocation();

if (dev_uniq && std::strcmp(dev_uniq, unique_id) == 0)
if (dev_uniq && dev_phys && std::strcmp(dev_uniq, unique_id) == 0 &&
std::strcmp(dev_phys, physical_location) == 0)
{
return device;
}
}
}

@@ -244,10 +249,12 @@ static void AddDeviceNode(const char* devnode)
}

const auto uniq = libevdev_get_uniq(dev);
auto evdev_device = FindDeviceWithUniqueID(uniq);
const auto phys = libevdev_get_phys(dev);
auto evdev_device = FindDeviceWithUniqueIDAndPhysicalLocation(uniq, phys);
if (evdev_device)
{
NOTICE_LOG(SERIALINTERFACE, "evdev combining devices with unique id: %s", uniq);
NOTICE_LOG(SERIALINTERFACE, "evdev combining devices with unique id: %s, physical location: %s",
uniq, phys);

evdev_device->AddNode(devnode, fd, dev);

@@ -589,6 +596,14 @@ const char* evdevDevice::GetUniqueID() const
return uniq;
}

const char* evdevDevice::GetPhysicalLocation() const
{
if (m_nodes.empty())
return nullptr;

return libevdev_get_phys(m_nodes.front().device);
}

evdevDevice::~evdevDevice()
{
for (auto& node : m_nodes)
@@ -82,6 +82,7 @@ class evdevDevice : public Core::Device
bool AddNode(std::string devnode, int fd, libevdev* dev);

const char* GetUniqueID() const;
const char* GetPhysicalLocation() const;

std::string GetName() const override { return m_name; }
std::string GetSource() const override { return "evdev"; }

0 comments on commit 50b5224

Please sign in to comment.