From f8ee70fd137592022200577dbff65330b0f75b11 Mon Sep 17 00:00:00 2001 From: fritsch Date: Sun, 12 Jan 2020 12:02:53 +0100 Subject: [PATCH 1/3] PeripheralBusUSBLibUdev: Filter on USB only --- .../platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp b/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp index 07c45a3e96fda..96c8529c74f2a 100644 --- a/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp +++ b/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp @@ -81,6 +81,13 @@ CPeripheralBusUSB::CPeripheralBusUSB(CPeripherals& manager) : /* 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", NULL) < 0) + { + CLog::Log(LOGERROR, "Could not limit filter on USB only"); + } + udev_monitor_enable_receiving(m_udevMon); CLog::Log(LOGDEBUG, "%s - initialised udev monitor", __FUNCTION__); From 139a7dc95f0f5f284b55af989ce2e37d924f886a Mon Sep 17 00:00:00 2001 From: fritsch Date: Sun, 12 Jan 2020 16:24:28 +0100 Subject: [PATCH 2/3] PeripheralUSB: Create udev contexts in their thread --- .../peripherals/PeripheralBusUSBLibUdev.cpp | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp b/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp index 96c8529c74f2a..b68fce347f923 100644 --- a/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp +++ b/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp @@ -72,36 +72,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"); - - /* filter to only receive usb events */ - if (udev_monitor_filter_add_match_subsystem_devtype(m_udevMon, "usb", NULL) < 0) - { - CLog::Log(LOGERROR, "Could not limit filter on USB only"); - } - - 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); @@ -195,6 +177,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) @@ -203,6 +203,8 @@ void CPeripheralBusUSB::Process(void) if (bUpdated && !m_bStop) ScanForDevices(); } + udev_monitor_unref(m_udevMon); + udev_unref(m_udev); } void CPeripheralBusUSB::Clear(void) From bac79990a897b7ddcea2781610328ea137636a0f Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 15 Jan 2020 09:48:09 -0500 Subject: [PATCH 3/3] Add missing cassert include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this include, ‘assert’ was not declared in this scope errors occur. --- xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp b/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp index b68fce347f923..7baf6900c06ec 100644 --- a/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp +++ b/xbmc/platform/linux/peripherals/PeripheralBusUSBLibUdev.cpp @@ -11,6 +11,7 @@ extern "C" { #include } +#include #include #include "utils/log.h"