11use std:: { sync:: Arc , time:: Duration } ;
22
33use rusb:: {
4- Device , DeviceHandle , Direction , GlobalContext , TransferType ,
4+ Context , Device , DeviceHandle , Direction , TransferType , UsbContext ,
55 constants:: LIBUSB_CLASS_VENDOR_SPEC ,
66} ;
77
@@ -25,8 +25,8 @@ struct Endpoint {
2525/// Transport running on USB
2626#[ derive( Debug , Clone ) ]
2727pub struct USBTransport {
28- device : Device < GlobalContext > ,
29- handle : Option < Arc < DeviceHandle < GlobalContext > > > ,
28+ device : Device < Context > ,
29+ handle : Option < Arc < DeviceHandle < Context > > > ,
3030 read_endpoint : Option < Endpoint > ,
3131 write_endpoint : Option < Endpoint > ,
3232}
@@ -35,7 +35,8 @@ impl USBTransport {
3535 /// Instantiate a new [`USBTransport`].
3636 /// Only the first device with given `vendor_id` and `product_id` is returned.
3737 pub fn new ( vendor_id : u16 , product_id : u16 ) -> Result < Self > {
38- for device in rusb:: devices ( ) ?. iter ( ) {
38+ let context = Context :: new ( ) ?;
39+ for device in context. devices ( ) ?. iter ( ) {
3940 if let Ok ( descriptor) = device. device_descriptor ( )
4041 && descriptor. vendor_id ( ) == vendor_id
4142 && descriptor. product_id ( ) == product_id
@@ -51,9 +52,9 @@ impl USBTransport {
5152
5253 /// Instantiate a new [`USBTransport`] from a [`rusb::Device`].
5354 ///
54- /// Devices can be enumerated using [`rusb::devices()`] and then filtered out to get desired device.
55+ /// Devices can be enumerated using [`rusb::Context:: devices()`] and then filtered out to get desired device.
5556 #[ must_use]
56- pub const fn new_from_device ( rusb_device : rusb:: Device < GlobalContext > ) -> Self {
57+ pub const fn new_from_device ( rusb_device : rusb:: Device < Context > ) -> Self {
5758 Self {
5859 device : rusb_device,
5960 handle : None ,
@@ -70,7 +71,7 @@ impl USBTransport {
7071 Ok ( self . device . device_descriptor ( ) . map ( |d| d. product_id ( ) ) ?)
7172 }
7273
73- pub ( crate ) fn get_raw_connection ( & self ) -> Result < Arc < DeviceHandle < GlobalContext > > > {
74+ pub ( crate ) fn get_raw_connection ( & self ) -> Result < Arc < DeviceHandle < Context > > > {
7475 self . handle
7576 . as_ref ( )
7677 . ok_or ( RustADBError :: IOError ( std:: io:: Error :: new (
@@ -99,7 +100,7 @@ impl USBTransport {
99100 ) ) )
100101 }
101102
102- fn configure_endpoint ( handle : & DeviceHandle < GlobalContext > , endpoint : & Endpoint ) -> Result < ( ) > {
103+ fn configure_endpoint ( handle : & DeviceHandle < Context > , endpoint : & Endpoint ) -> Result < ( ) > {
103104 match handle. claim_interface ( endpoint. iface ) {
104105 Ok ( ( ) ) => Ok ( ( ) ) ,
105106 // busy state likely indicates an ADB server is running and has taken the lock over the device
@@ -108,7 +109,7 @@ impl USBTransport {
108109 }
109110 }
110111
111- fn find_endpoints ( handle : & DeviceHandle < GlobalContext > ) -> Result < ( Endpoint , Endpoint ) > {
112+ fn find_endpoints ( handle : & DeviceHandle < Context > ) -> Result < ( Endpoint , Endpoint ) > {
112113 let mut read_endpoint: Option < Endpoint > = None ;
113114 let mut write_endpoint: Option < Endpoint > = None ;
114115
0 commit comments