Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c515f1fd authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Gerrit Code Review
Browse files

Merge "floss: Change object path naming"

parents 8f47f483 ae99c24e
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -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);

@@ -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"),
            },
        }
+7 −3
Original line number Diff line number Diff line
@@ -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 }
}

@@ -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).
+7 −6
Original line number Diff line number Diff line
@@ -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.
@@ -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();
@@ -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,
@@ -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,
@@ -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,