void Init() { s_devnode_name_map.clear(); // During initialization we use udev to iterate over all /dev/input/event* devices. // Note: the Linux kernel is currently limited to just 32 event devices. If this ever // changes, hopefully udev will take care of this. udev* udev = udev_new(); _assert_msg_(PAD, udev != nullptr, "Couldn't initialize libudev."); // List all input devices udev_enumerate* enumerate = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(enumerate, "input"); udev_enumerate_scan_devices(enumerate); udev_list_entry* devices = udev_enumerate_get_list_entry(enumerate); // Iterate over all input devices udev_list_entry* dev_list_entry; udev_list_entry_foreach(dev_list_entry, devices) { const char* path = udev_list_entry_get_name(dev_list_entry); udev_device* dev = udev_device_new_from_syspath(udev, path); const char* devnode = udev_device_get_devnode(dev); // We only care about devices which we have read/write access to. if (devnode && access(devnode, W_OK) == 0) { // 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<evdevDevice>(devnode); if (input->IsInteresting()) { g_controller_interface.AddDevice(std::move(input)); s_devnode_name_map.insert(std::pair<std::string, std::string>(devnode, name)); } } udev_device_unref(dev); } udev_enumerate_unref(enumerate); udev_unref(udev); StartHotplugThread(); }
void Init() { s_devnode_name_map.clear(); StartHotplugThread(); }
void Init() { s_devnode_name_map.clear(); PopulateDevices(); StartHotplugThread(); }