@@ -53,7 +53,7 @@ pub(crate) struct WindowsDevice {
5353impl WindowsDevice {
5454 pub ( crate ) fn from_device_info (
5555 d : & DeviceInfo ,
56- ) -> impl MaybeFuture < Output = Result < crate :: Device , Error > > {
56+ ) -> impl MaybeFuture < Output = Result < Arc < WindowsDevice > , Error > > {
5757 let instance_id = d. instance_id . clone ( ) ;
5858 let devinst = d. devinst ;
5959 Blocking :: new ( move || {
@@ -85,14 +85,14 @@ impl WindowsDevice {
8585 } )
8686 . collect ( ) ;
8787
88- Ok ( crate :: Device :: wrap ( Arc :: new ( WindowsDevice {
88+ Ok ( Arc :: new ( WindowsDevice {
8989 device_descriptor,
9090 config_descriptors,
9191 speed : connection_info. speed ,
9292 active_config : connection_info. active_config ,
9393 devinst : devinst,
9494 handles : Mutex :: new ( BTreeMap :: new ( ) ) ,
95- } ) ) )
95+ } ) )
9696 } )
9797 }
9898
@@ -145,63 +145,55 @@ impl WindowsDevice {
145145 pub ( crate ) fn claim_interface (
146146 self : Arc < Self > ,
147147 interface_number : u8 ,
148- ) -> impl MaybeFuture < Output = Result < crate :: Interface , Error > > {
148+ ) -> impl MaybeFuture < Output = Result < Arc < WindowsInterface > , Error > > {
149149 Blocking :: new ( move || {
150- self . claim_interface_blocking ( interface_number)
151- . map ( crate :: Interface :: wrap)
152- } )
153- }
154-
155- fn claim_interface_blocking (
156- self : & Arc < Self > ,
157- interface_number : u8 ,
158- ) -> Result < Arc < WindowsInterface > , Error > {
159- let driver = get_driver_name ( self . devinst ) ;
160-
161- let mut handles = self . handles . lock ( ) . unwrap ( ) ;
162-
163- if driver. eq_ignore_ascii_case ( "winusb" ) {
164- match handles. entry ( 0 ) {
165- Entry :: Occupied ( mut e) => e. get_mut ( ) . claim_interface ( self , interface_number) ,
166- Entry :: Vacant ( e) => {
167- let path = get_winusb_device_path ( self . devinst ) ?;
168- let mut handle = WinusbFileHandle :: new ( & path, 0 ) ?;
169- let intf = handle. claim_interface ( self , interface_number) ?;
170- e. insert ( handle) ;
171- Ok ( intf)
150+ let driver = get_driver_name ( self . devinst ) ;
151+
152+ let mut handles = self . handles . lock ( ) . unwrap ( ) ;
153+
154+ if driver. eq_ignore_ascii_case ( "winusb" ) {
155+ match handles. entry ( 0 ) {
156+ Entry :: Occupied ( mut e) => e. get_mut ( ) . claim_interface ( & self , interface_number) ,
157+ Entry :: Vacant ( e) => {
158+ let path = get_winusb_device_path ( self . devinst ) ?;
159+ let mut handle = WinusbFileHandle :: new ( & path, 0 ) ?;
160+ let intf = handle. claim_interface ( & self , interface_number) ?;
161+ e. insert ( handle) ;
162+ Ok ( intf)
163+ }
172164 }
173- }
174- } else if driver. eq_ignore_ascii_case ( "usbccgp" ) {
175- let ( first_interface, child_dev) =
176- find_usbccgp_child ( self . devinst , interface_number)
177- . ok_or_else ( || Error :: new ( ErrorKind :: NotFound , "Interface not found" ) ) ?;
165+ } else if driver. eq_ignore_ascii_case ( "usbccgp" ) {
166+ let ( first_interface, child_dev) =
167+ find_usbccgp_child ( self . devinst , interface_number)
168+ . ok_or_else ( || Error :: new ( ErrorKind :: NotFound , "Interface not found" ) ) ?;
178169
179- if first_interface != interface_number {
180- debug ! ( "Guessing that interface {interface_number} is an associated interface of {first_interface}" ) ;
181- }
170+ if first_interface != interface_number {
171+ debug ! ( "Guessing that interface {interface_number} is an associated interface of {first_interface}" ) ;
172+ }
182173
183- match handles. entry ( first_interface) {
184- Entry :: Occupied ( mut e) => e. get_mut ( ) . claim_interface ( self , interface_number) ,
185- Entry :: Vacant ( e) => {
186- let path = get_usbccgp_winusb_device_path ( child_dev) ?;
187- let mut handle = WinusbFileHandle :: new ( & path, first_interface) ?;
188- let intf = handle. claim_interface ( self , interface_number) ?;
189- e. insert ( handle) ;
190- Ok ( intf)
174+ match handles. entry ( first_interface) {
175+ Entry :: Occupied ( mut e) => e. get_mut ( ) . claim_interface ( & self , interface_number) ,
176+ Entry :: Vacant ( e) => {
177+ let path = get_usbccgp_winusb_device_path ( child_dev) ?;
178+ let mut handle = WinusbFileHandle :: new ( & path, first_interface) ?;
179+ let intf = handle. claim_interface ( & self , interface_number) ?;
180+ e. insert ( handle) ;
181+ Ok ( intf)
182+ }
191183 }
184+ } else {
185+ Err ( Error :: new (
186+ ErrorKind :: Unsupported ,
187+ format ! ( "Device driver is {driver:?}, not WinUSB or USBCCGP" ) ,
188+ ) )
192189 }
193- } else {
194- Err ( Error :: new (
195- ErrorKind :: Unsupported ,
196- format ! ( "Device driver is {driver:?}, not WinUSB or USBCCGP" ) ,
197- ) )
198- }
190+ } )
199191 }
200192
201193 pub ( crate ) fn detach_and_claim_interface (
202194 self : Arc < Self > ,
203195 interface : u8 ,
204- ) -> impl MaybeFuture < Output = Result < crate :: Interface , Error > > {
196+ ) -> impl MaybeFuture < Output = Result < Arc < WindowsInterface > , Error > > {
205197 self . claim_interface ( interface)
206198 }
207199}
0 commit comments