@@ -561,20 +561,21 @@ impl Manager {
561561 /// Create a [CompositeDevice] from the given configuration
562562 async fn create_composite_device_from_config (
563563 & mut self ,
564+ path : PathBuf ,
564565 config : & CompositeDeviceConfig ,
565566 device : DeviceInfo ,
566567 ) -> Result < CompositeDevice , Box < dyn Error > > {
567568 // Lookup the capability map associated with this config if it exists
568569 let capability_map = if let Some ( map_id) = config. capability_map_id . clone ( ) {
569- log:: debug!( "Found capability mapping in config: {}" , map_id ) ;
570+ log:: debug!( "Found capability mapping in config: {map_id}" ) ;
570571 let capability_map = load_capability_mappings ( ) ;
571572 capability_map. get ( & map_id) . cloned ( )
572573 } else {
573574 None
574575 } ;
575576
576577 // Create a composite device to manage these devices
577- log:: info!( "Found matching source device for: { :?}" , config . name ) ;
578+ log:: info!( "Found matching source device for config {path :?}" ) ;
578579 let config = config. clone ( ) ;
579580 let device = CompositeDevice :: new (
580581 self . dbus . clone ( ) ,
@@ -973,6 +974,12 @@ impl Manager {
973974 id : String ,
974975 device : DeviceInfo ,
975976 ) -> Result < ( ) , Box < dyn Error > > {
977+ // Ignore the device if it's already in use.
978+ if let Some ( device_path) = self . source_devices_used . get ( & id) {
979+ log:: debug!( "Source device {id} already in use by {device_path}. Skipping." ) ;
980+ return Ok ( ( ) ) ;
981+ }
982+
976983 // Check all existing composite devices to see if this device is part of
977984 // their config
978985 ' start: for composite_device in self . composite_devices . keys ( ) {
@@ -1082,8 +1089,8 @@ impl Manager {
10821089 // a match that will automatically create a CompositeDevice.
10831090 let configs = self . load_device_configs ( ) . await ;
10841091 log:: debug!( "Checking unused configs" ) ;
1085- for config in configs {
1086- log:: trace!( "Checking config {:?} for device" , config . name ) ;
1092+ for ( path , config) in configs {
1093+ log:: trace!( "Checking if config {path :?} matches device" , ) ;
10871094
10881095 // Check to see if 'auto_manage' is enabled for this config.
10891096 let auto_manage = config
@@ -1093,15 +1100,14 @@ impl Manager {
10931100 . unwrap_or ( false ) ;
10941101 if !self . manage_all_devices && !auto_manage {
10951102 log:: trace!(
1096- "Config {:?} does not have 'auto_manage' option enabled. Skipping." ,
1097- config. name
1103+ "Config {path:?} does not have 'auto_manage' option enabled. Skipping." ,
10981104 ) ;
10991105 continue ;
11001106 }
11011107
11021108 // Check to see if this configuration matches the system
11031109 if !config. has_valid_matches ( & self . dmi_data , & self . cpu_info ) {
1104- log:: trace!( "Configuration does not match system" ) ;
1110+ log:: trace!( "Configuration {path:?} does not match system" ) ;
11051111 continue ;
11061112 }
11071113
@@ -1114,11 +1120,11 @@ impl Manager {
11141120 }
11151121 }
11161122 log:: info!(
1117- "Found a matching {} device {id}, creating CompositeDevice" ,
1123+ "Found a matching {} device {id} in config {path:?} , creating CompositeDevice" ,
11181124 device. kind( )
11191125 ) ;
11201126 let dev = self
1121- . create_composite_device_from_config ( & config, device)
1127+ . create_composite_device_from_config ( path , & config, device)
11221128 . await ?;
11231129
11241130 // Get the target input devices from the config
@@ -1759,10 +1765,10 @@ impl Manager {
17591765 /// Looks in all default locations for [CompositeDeviceConfig] definitions and
17601766 /// load/parse them. Returns an array of these configs which can be used
17611767 /// to automatically create a [CompositeDevice].
1762- pub async fn load_device_configs ( & self ) -> Vec < CompositeDeviceConfig > {
1768+ pub async fn load_device_configs ( & self ) -> Vec < ( PathBuf , CompositeDeviceConfig ) > {
17631769 let task = task:: spawn_blocking ( move || {
17641770 log:: trace!( "Loading device configurations" ) ;
1765- let mut devices: Vec < CompositeDeviceConfig > = Vec :: new ( ) ;
1771+ let mut devices: Vec < ( PathBuf , CompositeDeviceConfig ) > = Vec :: new ( ) ;
17661772 let paths = get_devices_paths ( ) ;
17671773 let files = get_multidir_sorted_files ( paths. as_slice ( ) , |entry| {
17681774 entry. path ( ) . extension ( ) . unwrap_or_default ( ) == "yaml"
@@ -1782,7 +1788,7 @@ impl Manager {
17821788 continue ;
17831789 }
17841790 let device = device. unwrap ( ) ;
1785- devices. push ( device) ;
1791+ devices. push ( ( file , device) ) ;
17861792 }
17871793
17881794 devices
0 commit comments