@@ -1195,28 +1195,52 @@ impl Manager {
11951195
11961196 // Get the device id
11971197 let id = device. get_id ( ) ;
1198- if self . source_device_dbus_paths . contains_key ( & id) {
1199- log:: debug!(
1200- "Device already exists with id {id}: {dev_name} ({dev_sysname}): {dev_path}"
1201- ) ;
1202- return Ok ( ( ) ) ;
1203- }
12041198
1205- // Get the DBus path based on the device subsystem
1206- let path = match subsystem. as_str ( ) {
1207- "input" => evdev:: get_dbus_path ( sys_name) ,
1208- "hidraw" => hidraw:: get_dbus_path ( sys_name) ,
1209- "iio" => iio:: get_dbus_path ( sys_name) ,
1210- "leds" => led:: get_dbus_path ( sys_name) ,
1211- _ => return Err ( format ! ( "Device subsystem not supported: {subsystem:?}" ) . into ( ) ) ,
1212- } ;
1199+ // Create a DBus interface manager for the source device if one does not exist
1200+ if !self . source_device_dbus_paths . contains_key ( & id) {
1201+ // Get the DBus path based on the device subsystem
1202+ let path = match subsystem. as_str ( ) {
1203+ "input" => evdev:: get_dbus_path ( sys_name) ,
1204+ "hidraw" => hidraw:: get_dbus_path ( sys_name) ,
1205+ "iio" => iio:: get_dbus_path ( sys_name) ,
1206+ "leds" => led:: get_dbus_path ( sys_name) ,
1207+ _ => return Err ( format ! ( "Device subsystem not supported: {subsystem:?}" ) . into ( ) ) ,
1208+ } ;
1209+ let conn = self . dbus . connection ( ) . clone ( ) ;
1210+ let mut dbus = DBusInterfaceManager :: new ( conn, path) ?;
1211+
1212+ // Register subsystem-specific DBus interfaces
1213+ match subsystem. as_str ( ) {
1214+ "input" => {
1215+ let evdev_iface = SourceEventDeviceInterface :: new ( dev) ;
1216+ dbus. register ( evdev_iface) ;
1217+ }
1218+ "hidraw" => {
1219+ let hidraw_iface = SourceHIDRawInterface :: new ( dev) ;
1220+ dbus. register ( hidraw_iface) ;
1221+ }
1222+ "iio" => {
1223+ let iio_iface = SourceIioImuInterface :: new ( dev) ;
1224+ dbus. register ( iio_iface) ;
1225+ }
1226+ "leds" => {
1227+ let led_iface = SourceLedInterface :: new ( dev) ;
1228+ dbus. register ( led_iface) ;
1229+ }
1230+ _ => ( ) ,
1231+ }
12131232
1214- // Create a DBus interface manager for the source device
1215- let conn = self . dbus . connection ( ) . clone ( ) ;
1216- let mut dbus = DBusInterfaceManager :: new ( conn, path) ?;
1233+ // Register the generic udev dbus interface for the device. The
1234+ // [DBusInterfaceManager] will unregister all interfaces automatically
1235+ // if it goes out of scope.
1236+ let udev_iface = SourceUdevDeviceInterface :: new ( device. clone ( ) ) ;
1237+ dbus. register ( udev_iface) ;
1238+
1239+ // Track the lifetime of the source device to keep the dbus interface(s) up
1240+ self . source_device_dbus_paths . insert ( id. clone ( ) , dbus) ;
1241+ }
12171242
1218- // Register subsystem-specific DBus interfaces and check to see if the
1219- // device should be managed by inputplumber or not.
1243+ // Check to see if the device should be managed by inputplumber or not.
12201244 let mut notify_device_added = true ;
12211245 match subsystem. as_str ( ) {
12221246 "input" => {
@@ -1227,10 +1251,6 @@ impl Manager {
12271251
12281252 log:: debug!( "event device added: {dev_name} ({dev_sysname})" ) ;
12291253
1230- // Register the evdev dbus interface
1231- let evdev_iface = SourceEventDeviceInterface :: new ( dev) ;
1232- dbus. register ( evdev_iface) ;
1233-
12341254 // Check to see if the device should be managed or not
12351255 ' check_manage: {
12361256 if !device. is_virtual ( ) {
@@ -1281,10 +1301,6 @@ impl Manager {
12811301
12821302 log:: debug!( "hidraw device added: {dev_name} ({dev_sysname})" ) ;
12831303
1284- // Register the hidraw dbus interface
1285- let hidraw_iface = SourceHIDRawInterface :: new ( dev) ;
1286- dbus. register ( hidraw_iface) ;
1287-
12881304 // Check to see if the device should be managed or not
12891305 ' check_manage: {
12901306 if !device. is_virtual ( ) {
@@ -1358,10 +1374,6 @@ impl Manager {
13581374
13591375 log:: debug!( "iio device added: {} ({})" , device. name( ) , device. sysname( ) ) ;
13601376
1361- // Register the iio dbus interface
1362- let iio_iface = SourceIioImuInterface :: new ( dev) ;
1363- dbus. register ( iio_iface) ;
1364-
13651377 // Check to see if the device is virtual
13661378 if device. is_virtual ( ) {
13671379 log:: debug!( "{dev_name} ({dev_sysname}) is virtual, skipping consideration for {dev_path}" ) ;
@@ -1374,25 +1386,20 @@ impl Manager {
13741386 "leds" => {
13751387 log:: debug!( "LED device added: {} ({})" , device. name( ) , device. sysname( ) ) ;
13761388
1377- // Register the led dbus interface
1378- let led_iface = SourceLedInterface :: new ( dev) ;
1379- dbus. register ( led_iface) ;
1389+ // Check to see if the device is virtual
1390+ if device. is_virtual ( ) {
1391+ log:: debug!( "{dev_name} ({dev_sysname}) is virtual, skipping consideration for {dev_path}" ) ;
1392+ notify_device_added = false ;
1393+ } else {
1394+ log:: trace!( "Device {dev_name} ({dev_sysname}) is real - {dev_path}" ) ;
1395+ }
13801396 }
13811397
13821398 _ => {
13831399 return Err ( format ! ( "Device subsystem not supported: {subsystem:?}" ) . into ( ) ) ;
13841400 }
13851401 } ;
13861402
1387- // Register the generic udev dbus interface for the device. The
1388- // [DBusInterfaceManager] will unregister all interfaces automatically
1389- // if it goes out of scope.
1390- let udev_iface = SourceUdevDeviceInterface :: new ( device. clone ( ) ) ;
1391- dbus. register ( udev_iface) ;
1392-
1393- // Track the lifetime of the source device to keep the dbus interface(s) up
1394- self . source_device_dbus_paths . insert ( id. clone ( ) , dbus) ;
1395-
13961403 // Signal that a source device was added
13971404 if notify_device_added {
13981405 log:: debug!( "Spawning task to add source device: {id}" ) ;
0 commit comments