diff options
author | Peter Frühberger <Peter.Fruehberger@gmail.com> | 2020-01-25 16:59:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-25 16:59:48 +0100 |
commit | 32f9a30095190f31b886affb525689d64b9faa29 (patch) | |
tree | 640c7ef0f64f375bd7a53412782291e0b970aa65 | |
parent | 7fdfc88158f71a20fe2c6d1efba362d3f2ef5bd5 (diff) | |
parent | bac79990a897b7ddcea2781610328ea137636a0f (diff) |
Merge pull request #17189 from fritsch/periphleia
Backport: PeripheralBusUSB Fixes
-rw-r--r-- | xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp b/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp index 07c45a3e96..7baf6900c0 100644 --- a/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp +++ b/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp @@ -11,6 +11,7 @@ extern "C" { #include <libudev.h> } +#include <cassert> #include <poll.h> #include "utils/log.h" @@ -72,29 +73,18 @@ CPeripheralBusUSB::CPeripheralBusUSB(CPeripherals& manager) : m_udev = NULL; m_udevMon = NULL; - - if (!(m_udev = udev_new())) - { - CLog::Log(LOGERROR, "%s - failed to allocate udev context", __FUNCTION__); - return; - } - - /* set up a devices monitor that listen for any device change */ - m_udevMon = udev_monitor_new_from_netlink(m_udev, "udev"); - udev_monitor_enable_receiving(m_udevMon); - - CLog::Log(LOGDEBUG, "%s - initialised udev monitor", __FUNCTION__); } CPeripheralBusUSB::~CPeripheralBusUSB(void) { StopThread(true); - udev_monitor_unref(m_udevMon); - udev_unref(m_udev); } bool CPeripheralBusUSB::PerformDeviceScan(PeripheralScanResults &results) { + // We don't want this one to be called from outside world + assert(IsCurrentThread()); + struct udev_enumerate *enumerate; struct udev_list_entry *devices, *dev_list_entry; struct udev_device *dev(NULL), *parent(NULL); @@ -188,6 +178,24 @@ PeripheralType CPeripheralBusUSB::GetType(int iDeviceClass) void CPeripheralBusUSB::Process(void) { + if (!(m_udev = udev_new())) + { + CLog::Log(LOGERROR, "%s - failed to allocate udev context", __FUNCTION__); + return; + } + + /* set up a devices monitor that listen for any device change */ + m_udevMon = udev_monitor_new_from_netlink(m_udev, "udev"); + + /* filter to only receive usb events */ + if (udev_monitor_filter_add_match_subsystem_devtype(m_udevMon, "usb", nullptr) < 0) + { + CLog::Log(LOGERROR, "Could not limit filter on USB only"); + } + + CLog::Log(LOGDEBUG, "%s - initialised udev monitor", __FUNCTION__); + + udev_monitor_enable_receiving(m_udevMon); bool bUpdated(false); ScanForDevices(); while (!m_bStop) @@ -196,6 +204,8 @@ void CPeripheralBusUSB::Process(void) if (bUpdated && !m_bStop) ScanForDevices(); } + udev_monitor_unref(m_udevMon); + udev_unref(m_udev); } void CPeripheralBusUSB::Clear(void) |