Loading system/gd/rust/linux/client/src/dbus_iface.rs +2 −2 Original line number Diff line number Diff line Loading @@ -116,13 +116,13 @@ pub(crate) struct BluetoothDBus { impl BluetoothDBus { pub(crate) fn new(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>) -> BluetoothDBus { // TODO: Adapter path should have hci number, e.g. /org/chromium/bluetooth/adapter/hci0. // TODO: Adapter client should dynamically accept hci # and be initialized BluetoothDBus { client_proxy: ClientDBusProxy { conn: conn.clone(), cr: cr, bus_name: String::from("org.chromium.bluetooth"), objpath: dbus::Path::new("/org/chromium/bluetooth/adapter").unwrap(), objpath: dbus::Path::new("/org/chromium/bluetooth/adapter0").unwrap(), interface: String::from("org.chromium.bluetooth.Bluetooth"), }, } Loading system/gd/rust/linux/service/src/main.rs +39 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,21 @@ const OBJECT_BLUETOOTH: &str = "/org/chromium/bluetooth/adapter"; const OBJECT_BLUETOOTH_GATT: &str = "/org/chromium/bluetooth/gatt"; const OBJECT_BLUETOOTH_MEDIA: &str = "/org/chromium/bluetooth/media"; /// Check command line arguments for target hci adapter (--hci=N). If no adapter /// is set, default to 0. fn get_adapter_index(args: &Vec<String>) -> i32 { for arg in args { if arg.starts_with("--hci=") { let num = (&arg[6..]).parse::<i32>(); if num.is_ok() { return num.unwrap(); } } } 0 } /// Runs the Bluetooth daemon serving D-Bus IPC. fn main() -> Result<(), Box<dyn Error>> { let (tx, rx) = Stack::create_channel(); Loading @@ -44,6 +59,9 @@ fn main() -> Result<(), Box<dyn Error>> { // Args don't include arg[0] which is the binary name let all_args = std::env::args().collect::<Vec<String>>(); let args = all_args[1..].to_vec(); let adapter_index = get_adapter_index(&args); intf.lock().unwrap().initialize(get_bt_dispatcher(tx), args); bluetooth.lock().unwrap().init_profiles(); Loading Loading @@ -85,7 +103,7 @@ fn main() -> Result<(), Box<dyn Error>> { // Register D-Bus method handlers of IBluetooth. iface_bluetooth::export_bluetooth_dbus_obj( String::from(OBJECT_BLUETOOTH), String::from(format!("{}{}", OBJECT_BLUETOOTH, adapter_index)), conn.clone(), &mut cr, bluetooth, Loading @@ -93,7 +111,7 @@ fn main() -> Result<(), Box<dyn Error>> { ); // Register D-Bus method handlers of IBluetoothGatt. iface_bluetooth_gatt::export_bluetooth_gatt_dbus_obj( String::from(OBJECT_BLUETOOTH_GATT), String::from(format!("{}{}", OBJECT_BLUETOOTH_GATT, adapter_index)), conn.clone(), &mut cr, bluetooth_gatt, Loading @@ -101,7 +119,7 @@ fn main() -> Result<(), Box<dyn Error>> { ); iface_bluetooth_media::export_bluetooth_media_dbus_obj( String::from(OBJECT_BLUETOOTH_MEDIA), String::from(format!("{}{}", OBJECT_BLUETOOTH_MEDIA, adapter_index)), conn.clone(), &mut cr, bluetooth_media, Loading @@ -121,3 +139,21 @@ fn main() -> Result<(), Box<dyn Error>> { unreachable!() }) } #[cfg(test)] mod tests { use crate::get_adapter_index; #[test] fn device_index_parsed() { // A few failing cases assert_eq!(get_adapter_index(&vec! {}), 0); assert_eq!(get_adapter_index(&vec! {"--bar".to_string(), "--hci".to_string()}), 0); assert_eq!(get_adapter_index(&vec! {"--hci=foo".to_string()}), 0); assert_eq!(get_adapter_index(&vec! {"--hci=12t".to_string()}), 0); // Some passing cases assert_eq!(get_adapter_index(&vec! {"--hci=12".to_string()}), 12); assert_eq!(get_adapter_index(&vec! {"--hci=1".to_string(), "--hci=2".to_string()}), 1); } } Loading
system/gd/rust/linux/client/src/dbus_iface.rs +2 −2 Original line number Diff line number Diff line Loading @@ -116,13 +116,13 @@ pub(crate) struct BluetoothDBus { impl BluetoothDBus { pub(crate) fn new(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>) -> BluetoothDBus { // TODO: Adapter path should have hci number, e.g. /org/chromium/bluetooth/adapter/hci0. // TODO: Adapter client should dynamically accept hci # and be initialized BluetoothDBus { client_proxy: ClientDBusProxy { conn: conn.clone(), cr: cr, bus_name: String::from("org.chromium.bluetooth"), objpath: dbus::Path::new("/org/chromium/bluetooth/adapter").unwrap(), objpath: dbus::Path::new("/org/chromium/bluetooth/adapter0").unwrap(), interface: String::from("org.chromium.bluetooth.Bluetooth"), }, } Loading
system/gd/rust/linux/service/src/main.rs +39 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,21 @@ const OBJECT_BLUETOOTH: &str = "/org/chromium/bluetooth/adapter"; const OBJECT_BLUETOOTH_GATT: &str = "/org/chromium/bluetooth/gatt"; const OBJECT_BLUETOOTH_MEDIA: &str = "/org/chromium/bluetooth/media"; /// Check command line arguments for target hci adapter (--hci=N). If no adapter /// is set, default to 0. fn get_adapter_index(args: &Vec<String>) -> i32 { for arg in args { if arg.starts_with("--hci=") { let num = (&arg[6..]).parse::<i32>(); if num.is_ok() { return num.unwrap(); } } } 0 } /// Runs the Bluetooth daemon serving D-Bus IPC. fn main() -> Result<(), Box<dyn Error>> { let (tx, rx) = Stack::create_channel(); Loading @@ -44,6 +59,9 @@ fn main() -> Result<(), Box<dyn Error>> { // Args don't include arg[0] which is the binary name let all_args = std::env::args().collect::<Vec<String>>(); let args = all_args[1..].to_vec(); let adapter_index = get_adapter_index(&args); intf.lock().unwrap().initialize(get_bt_dispatcher(tx), args); bluetooth.lock().unwrap().init_profiles(); Loading Loading @@ -85,7 +103,7 @@ fn main() -> Result<(), Box<dyn Error>> { // Register D-Bus method handlers of IBluetooth. iface_bluetooth::export_bluetooth_dbus_obj( String::from(OBJECT_BLUETOOTH), String::from(format!("{}{}", OBJECT_BLUETOOTH, adapter_index)), conn.clone(), &mut cr, bluetooth, Loading @@ -93,7 +111,7 @@ fn main() -> Result<(), Box<dyn Error>> { ); // Register D-Bus method handlers of IBluetoothGatt. iface_bluetooth_gatt::export_bluetooth_gatt_dbus_obj( String::from(OBJECT_BLUETOOTH_GATT), String::from(format!("{}{}", OBJECT_BLUETOOTH_GATT, adapter_index)), conn.clone(), &mut cr, bluetooth_gatt, Loading @@ -101,7 +119,7 @@ fn main() -> Result<(), Box<dyn Error>> { ); iface_bluetooth_media::export_bluetooth_media_dbus_obj( String::from(OBJECT_BLUETOOTH_MEDIA), String::from(format!("{}{}", OBJECT_BLUETOOTH_MEDIA, adapter_index)), conn.clone(), &mut cr, bluetooth_media, Loading @@ -121,3 +139,21 @@ fn main() -> Result<(), Box<dyn Error>> { unreachable!() }) } #[cfg(test)] mod tests { use crate::get_adapter_index; #[test] fn device_index_parsed() { // A few failing cases assert_eq!(get_adapter_index(&vec! {}), 0); assert_eq!(get_adapter_index(&vec! {"--bar".to_string(), "--hci".to_string()}), 0); assert_eq!(get_adapter_index(&vec! {"--hci=foo".to_string()}), 0); assert_eq!(get_adapter_index(&vec! {"--hci=12t".to_string()}), 0); // Some passing cases assert_eq!(get_adapter_index(&vec! {"--hci=12".to_string()}), 12); assert_eq!(get_adapter_index(&vec! {"--hci=1".to_string(), "--hci=2".to_string()}), 1); } }