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

Commit 67ab63c6 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

floss: Move code around without behavior change

To prepare for refactoring, this moves the code without behavior change
for clearer refactor diffs.

Bug: 199213563
Tag: #floss
Test: Run btclient on chromeos

Change-Id: I1249878d1b6eed78ebd2d2ac21d8de6321d73e54
parent 548a27a7
Loading
Loading
Loading
Loading
+8 −58
Original line number Diff line number Diff line
use bt_topshim::btif::BtSspVariant;

use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback};
use btstack::RPCProxy;
use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth};

use manager_service::iface_bluetooth_manager::IBluetoothManager;

@@ -12,60 +9,13 @@ use std::sync::{Arc, Mutex};

use crate::console_yellow;
use crate::print_info;
use crate::{BluetoothDBus, BluetoothManagerDBus};
use crate::{BluetoothDBus, BluetoothManagerDBus, BtCallback};

const INDENT_CHAR: &str = " ";
const BAR1_CHAR: &str = "=";
const BAR2_CHAR: &str = "-";
const MAX_MENU_CHAR_WIDTH: usize = 72;

struct BtCallback {
    objpath: String,
}

impl IBluetoothCallback for BtCallback {
    fn on_address_changed(&self, addr: String) {
        print_info!("Address changed to {}", addr);
    }

    fn on_device_found(&self, remote_device: BluetoothDevice) {
        print_info!("Found device: {:?}", remote_device);
    }

    fn on_discovering_changed(&self, discovering: bool) {
        print_info!("Discovering: {}", discovering);
    }

    fn on_ssp_request(
        &self,
        remote_device: BluetoothDevice,
        _cod: u32,
        variant: BtSspVariant,
        passkey: u32,
    ) {
        if variant == BtSspVariant::PasskeyNotification {
            print_info!(
                "device {}{} would like to pair, enter passkey on remote device: {:06}",
                remote_device.address.to_string(),
                if remote_device.name.len() > 0 {
                    format!(" ({})", remote_device.name)
                } else {
                    String::from("")
                },
                passkey
            );
        }
    }
}

impl RPCProxy for BtCallback {
    fn register_disconnect(&mut self, _f: Box<dyn Fn() + Send>) {}

    fn get_object_id(&self) -> String {
        self.objpath.clone()
    }
}

type CommandFunction = fn(&mut CommandHandler, &Vec<String>);

fn _noop(_handler: &mut CommandHandler, _args: &Vec<String>) {
@@ -129,10 +79,10 @@ fn build_commands() -> HashMap<String, CommandOption> {
        },
    );
    command_options.insert(
        String::from("get_address"),
        String::from("bond"),
        CommandOption {
            description: String::from("Gets the local device address."),
            function_pointer: CommandHandler::cmd_get_address,
            description: String::from("Creates a bond with a device."),
            function_pointer: CommandHandler::cmd_bond,
        },
    );
    command_options.insert(
@@ -143,10 +93,10 @@ fn build_commands() -> HashMap<String, CommandOption> {
        },
    );
    command_options.insert(
        String::from("bond"),
        String::from("get_address"),
        CommandOption {
            description: String::from("Creates a bond with a device."),
            function_pointer: CommandHandler::cmd_bond,
            description: String::from("Gets the local device address."),
            function_pointer: CommandHandler::cmd_get_address,
        },
    );
    command_options.insert(
+50 −0
Original line number Diff line number Diff line
use bt_topshim::btif::BtSspVariant;
use bt_topshim::topstack;
use btstack::bluetooth::{BluetoothDevice, IBluetoothCallback};
use btstack::RPCProxy;

use dbus::channel::MatchingReceiver;

@@ -44,6 +47,53 @@ impl manager_service::RPCProxy for BtManagerCallback {
    }
}

struct BtCallback {
    objpath: String,
}

impl IBluetoothCallback for BtCallback {
    fn on_address_changed(&self, addr: String) {
        print_info!("Address changed to {}", addr);
    }

    fn on_device_found(&self, remote_device: BluetoothDevice) {
        print_info!("Found device: {:?}", remote_device);
    }

    fn on_discovering_changed(&self, discovering: bool) {
        print_info!("Discovering: {}", discovering);
    }

    fn on_ssp_request(
        &self,
        remote_device: BluetoothDevice,
        _cod: u32,
        variant: BtSspVariant,
        passkey: u32,
    ) {
        if variant == BtSspVariant::PasskeyNotification {
            print_info!(
                "device {}{} would like to pair, enter passkey on remote device: {:06}",
                remote_device.address.to_string(),
                if remote_device.name.len() > 0 {
                    format!(" ({})", remote_device.name)
                } else {
                    String::from("")
                },
                passkey
            );
        }
    }
}

impl RPCProxy for BtCallback {
    fn register_disconnect(&mut self, _f: Box<dyn Fn() + Send>) {}

    fn get_object_id(&self) -> String {
        self.objpath.clone()
    }
}

struct API {
    bluetooth_manager: Arc<Mutex<Box<BluetoothManagerDBus>>>,
    bluetooth: Arc<Mutex<Box<BluetoothDBus>>>,