Loading system/gd/rust/linux/client/src/dbus_iface.rs +10 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,10 @@ use std::sync::{Arc, Mutex}; use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust}; fn make_object_path(idx: i32, name: &str) -> dbus::Path { dbus::Path::new(format!("/org/chromium/bluetooth/hci{}/{}", idx, name)).unwrap() } impl_dbus_arg_enum!(BluetoothTransport); impl_dbus_arg_enum!(BtSspVariant); Loading Loading @@ -115,14 +119,17 @@ pub(crate) struct BluetoothDBus { } impl BluetoothDBus { pub(crate) fn new(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>) -> BluetoothDBus { // TODO: Adapter client should dynamically accept hci # and be initialized pub(crate) fn new( conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>, index: i32, ) -> BluetoothDBus { BluetoothDBus { client_proxy: ClientDBusProxy { conn: conn.clone(), cr: cr, bus_name: String::from("org.chromium.bluetooth"), objpath: dbus::Path::new("/org/chromium/bluetooth/adapter0").unwrap(), objpath: make_object_path(index, "adapter"), interface: String::from("org.chromium.bluetooth.Bluetooth"), }, } Loading system/gd/rust/linux/client/src/main.rs +7 −3 Original line number Diff line number Diff line Loading @@ -50,11 +50,13 @@ struct API { } // This creates the API implementations over D-Bus. fn create_api_dbus(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>) -> API { let bluetooth = Arc::new(Mutex::new(Box::new(BluetoothDBus::new(conn.clone(), cr.clone())))); fn create_api_dbus(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>, idx: i32) -> API { let bluetooth_manager = Arc::new(Mutex::new(Box::new(BluetoothManagerDBus::new(conn.clone(), cr.clone())))); let bluetooth = Arc::new(Mutex::new(Box::new(BluetoothDBus::new(conn.clone(), cr.clone(), idx)))); API { bluetooth_manager, bluetooth } } Loading Loading @@ -90,7 +92,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { }), ); let api = create_api_dbus(conn, cr); // We only need hci index 0 for now. // TODO: Have a mechanism (e.g. CLI argument or btclient command) to select the hci index. let api = create_api_dbus(conn, cr, 0); // TODO: Registering the callback should be done when btmanagerd is ready (detect with // ObjectManager). Loading system/gd/rust/linux/service/src/main.rs +7 −6 Original line number Diff line number Diff line Loading @@ -27,9 +27,6 @@ mod iface_bluetooth_gatt; mod iface_bluetooth_media; const DBUS_SERVICE_NAME: &str = "org.chromium.bluetooth"; 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. Loading @@ -46,6 +43,10 @@ fn get_adapter_index(args: &Vec<String>) -> i32 { 0 } fn make_object_name(idx: i32, name: &str) -> String { String::from(format!("/org/chromium/bluetooth/hci{}/{}", idx, name)) } /// Runs the Bluetooth daemon serving D-Bus IPC. fn main() -> Result<(), Box<dyn Error>> { let (tx, rx) = Stack::create_channel(); Loading Loading @@ -103,7 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> { // Register D-Bus method handlers of IBluetooth. iface_bluetooth::export_bluetooth_dbus_obj( String::from(format!("{}{}", OBJECT_BLUETOOTH, adapter_index)), make_object_name(adapter_index, "adapter"), conn.clone(), &mut cr, bluetooth, Loading @@ -111,7 +112,7 @@ fn main() -> Result<(), Box<dyn Error>> { ); // Register D-Bus method handlers of IBluetoothGatt. iface_bluetooth_gatt::export_bluetooth_gatt_dbus_obj( String::from(format!("{}{}", OBJECT_BLUETOOTH_GATT, adapter_index)), make_object_name(adapter_index, "gatt"), conn.clone(), &mut cr, bluetooth_gatt, Loading @@ -119,7 +120,7 @@ fn main() -> Result<(), Box<dyn Error>> { ); iface_bluetooth_media::export_bluetooth_media_dbus_obj( String::from(format!("{}{}", OBJECT_BLUETOOTH_MEDIA, adapter_index)), make_object_name(adapter_index, "media"), conn.clone(), &mut cr, bluetooth_media, Loading Loading
system/gd/rust/linux/client/src/dbus_iface.rs +10 −3 Original line number Diff line number Diff line Loading @@ -21,6 +21,10 @@ use std::sync::{Arc, Mutex}; use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust}; fn make_object_path(idx: i32, name: &str) -> dbus::Path { dbus::Path::new(format!("/org/chromium/bluetooth/hci{}/{}", idx, name)).unwrap() } impl_dbus_arg_enum!(BluetoothTransport); impl_dbus_arg_enum!(BtSspVariant); Loading Loading @@ -115,14 +119,17 @@ pub(crate) struct BluetoothDBus { } impl BluetoothDBus { pub(crate) fn new(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>) -> BluetoothDBus { // TODO: Adapter client should dynamically accept hci # and be initialized pub(crate) fn new( conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>, index: i32, ) -> BluetoothDBus { BluetoothDBus { client_proxy: ClientDBusProxy { conn: conn.clone(), cr: cr, bus_name: String::from("org.chromium.bluetooth"), objpath: dbus::Path::new("/org/chromium/bluetooth/adapter0").unwrap(), objpath: make_object_path(index, "adapter"), interface: String::from("org.chromium.bluetooth.Bluetooth"), }, } Loading
system/gd/rust/linux/client/src/main.rs +7 −3 Original line number Diff line number Diff line Loading @@ -50,11 +50,13 @@ struct API { } // This creates the API implementations over D-Bus. fn create_api_dbus(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>) -> API { let bluetooth = Arc::new(Mutex::new(Box::new(BluetoothDBus::new(conn.clone(), cr.clone())))); fn create_api_dbus(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>, idx: i32) -> API { let bluetooth_manager = Arc::new(Mutex::new(Box::new(BluetoothManagerDBus::new(conn.clone(), cr.clone())))); let bluetooth = Arc::new(Mutex::new(Box::new(BluetoothDBus::new(conn.clone(), cr.clone(), idx)))); API { bluetooth_manager, bluetooth } } Loading Loading @@ -90,7 +92,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { }), ); let api = create_api_dbus(conn, cr); // We only need hci index 0 for now. // TODO: Have a mechanism (e.g. CLI argument or btclient command) to select the hci index. let api = create_api_dbus(conn, cr, 0); // TODO: Registering the callback should be done when btmanagerd is ready (detect with // ObjectManager). Loading
system/gd/rust/linux/service/src/main.rs +7 −6 Original line number Diff line number Diff line Loading @@ -27,9 +27,6 @@ mod iface_bluetooth_gatt; mod iface_bluetooth_media; const DBUS_SERVICE_NAME: &str = "org.chromium.bluetooth"; 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. Loading @@ -46,6 +43,10 @@ fn get_adapter_index(args: &Vec<String>) -> i32 { 0 } fn make_object_name(idx: i32, name: &str) -> String { String::from(format!("/org/chromium/bluetooth/hci{}/{}", idx, name)) } /// Runs the Bluetooth daemon serving D-Bus IPC. fn main() -> Result<(), Box<dyn Error>> { let (tx, rx) = Stack::create_channel(); Loading Loading @@ -103,7 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> { // Register D-Bus method handlers of IBluetooth. iface_bluetooth::export_bluetooth_dbus_obj( String::from(format!("{}{}", OBJECT_BLUETOOTH, adapter_index)), make_object_name(adapter_index, "adapter"), conn.clone(), &mut cr, bluetooth, Loading @@ -111,7 +112,7 @@ fn main() -> Result<(), Box<dyn Error>> { ); // Register D-Bus method handlers of IBluetoothGatt. iface_bluetooth_gatt::export_bluetooth_gatt_dbus_obj( String::from(format!("{}{}", OBJECT_BLUETOOTH_GATT, adapter_index)), make_object_name(adapter_index, "gatt"), conn.clone(), &mut cr, bluetooth_gatt, Loading @@ -119,7 +120,7 @@ fn main() -> Result<(), Box<dyn Error>> { ); iface_bluetooth_media::export_bluetooth_media_dbus_obj( String::from(format!("{}{}", OBJECT_BLUETOOTH_MEDIA, adapter_index)), make_object_name(adapter_index, "media"), conn.clone(), &mut cr, bluetooth_media, Loading