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

Commit c0220dd2 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Remove embedded stack from command line client

We do not need embedded stack in command line client anymore since D-Bus
mode is now usable. This patch also adds a missing dependency in a
BUILD.gn.

Bug: 188718349
Tag: #floss
Test: manual - Build floss on Linux

Change-Id: I14b341147e8305143f34b535715ff815e94070d1
parent 380a28e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ static_library("device") {

  deps = [
    "//bt/gd/rust/shim:init_flags_bridge_header",
    "//bt/gd/rust/shim:libbluetooth_rust_interop",
    "//bt/gd/rust/shim:message_loop_thread_bridge_header",
  ]
}
+0 −2
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ edition = "2018"
[dependencies]
rustyline = "8.0"
bt_topshim = { path = "../../topshim" }
bt_shim = { path = "../../shim" }
btstack = { path = "../stack" }

dbus = "0.9.2"
@@ -26,4 +25,3 @@ pkg-config = "0.3.19"
[[bin]]
name = "btclient"
path = "src/main.rs"
build = "build.rs"
+0 −27
Original line number Diff line number Diff line
use pkg_config::Config;

fn main() {
    let target_dir = std::env::var_os("CARGO_TARGET_DIR").unwrap();

    // The main linking point with c++ code is the libbluetooth-static.a
    // These includes all the symbols built via C++ but doesn't include other
    // links (i.e. pkg-config)
    println!("cargo:rustc-link-lib=static=bluetooth-static");
    println!("cargo:rustc-link-search=native={}", target_dir.into_string().unwrap());

    // A few dynamic links
    println!("cargo:rustc-link-lib=dylib=flatbuffers");
    println!("cargo:rustc-link-lib=dylib=protobuf");
    println!("cargo:rustc-link-lib=dylib=resolv");

    // Clang requires -lc++ instead of -lstdc++
    println!("cargo:rustc-link-lib=c++");

    // A few more dependencies from pkg-config. These aren't included as part of
    // the libbluetooth-static.a
    Config::new().probe("libchrome").unwrap();
    Config::new().probe("libmodp_b64").unwrap();
    Config::new().probe("tinyxml2").unwrap();

    println!("cargo:rerun-if-changed=build.rs");
}
+3 −42
Original line number Diff line number Diff line
extern crate bt_shim;

use bt_topshim::btif::get_btinterface;
use bt_topshim::topstack;
use btstack::bluetooth::{
    get_bt_dispatcher, Bluetooth, BluetoothDevice, IBluetooth, IBluetoothCallback,
};

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

use dbus::channel::MatchingReceiver;

@@ -29,7 +24,6 @@ mod dbus_iface;
mod editor;

struct BtCallback {
    disconnect_callbacks: Arc<Mutex<Vec<Box<dyn Fn() + Send>>>>,
    objpath: String,
}

@@ -52,9 +46,7 @@ impl IBluetoothCallback for BtCallback {
}

impl RPCProxy for BtCallback {
    fn register_disconnect(&mut self, f: Box<dyn Fn() + Send>) {
        self.disconnect_callbacks.lock().unwrap().push(f);
    }
    fn register_disconnect(&mut self, _f: Box<dyn Fn() + Send>) {}

    fn get_object_id(&self) -> String {
        self.objpath.clone()
@@ -65,25 +57,6 @@ struct API<T: IBluetooth> {
    bluetooth: Arc<Mutex<Box<T>>>,
}

// This creates the API implementations directly embedded to this client.
// TODO: Remove when D-Bus client is completed since this is only useful while D-Bus client is
// under development.
#[allow(dead_code)]
fn create_api_embedded() -> API<Bluetooth> {
    let (tx, rx) = Stack::create_channel();

    let intf = Arc::new(Mutex::new(get_btinterface().unwrap()));
    let bluetooth = Arc::new(Mutex::new(Box::new(Bluetooth::new(tx.clone(), intf.clone()))));

    intf.lock().unwrap().initialize(get_bt_dispatcher(tx), vec![]);

    bluetooth.lock().unwrap().init_profiles();

    topstack::get_runtime().spawn(Stack::dispatch(rx, bluetooth.clone()));

    API { bluetooth }
}

// This creates the API implementations over D-Bus.
fn create_api_dbus(conn: Arc<SyncConnection>, cr: Arc<Mutex<Crossroads>>) -> API<BluetoothDBus> {
    let bluetooth = Arc::new(Mutex::new(Box::new(BluetoothDBus::new(conn.clone(), cr))));
@@ -125,20 +98,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

        let api = create_api_dbus(conn, cr);

        let dc_callbacks = Arc::new(Mutex::new(vec![]));
        api.bluetooth.lock().unwrap().register_callback(Box::new(BtCallback {
            disconnect_callbacks: dc_callbacks.clone(),
            objpath: String::from("/org/chromium/bluetooth/client/bluetooth_callback"),
        }));

        let handler = CommandHandler::<BluetoothDBus>::new(api.bluetooth.clone());

        let simulate_disconnect = move |_cmd| {
            for callback in &*dc_callbacks.lock().unwrap() {
                callback();
            }
        };

        let handle_cmd = move |cmd: String| match cmd.split(' ').collect::<Vec<&str>>()[0] {
            "enable" => handler.cmd_enable(cmd),
            "disable" => handler.cmd_disable(cmd),
@@ -147,10 +112,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
            "cancel_discovery" => handler.cmd_cancel_discovery(cmd),
            "create_bond" => handler.cmd_create_bond(cmd),

            // Simulate client disconnection. Only useful in embedded mode. In D-Bus mode there is
            // real D-Bus disconnection.
            "simulate_disconnect" => simulate_disconnect(cmd),

            // Ignore empty commands.
            "" => {}