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

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

Add D-Bus daemon binary

The D-Bus daemon connects the RPC-agnostic API implementations in
`btstack` crate with the `dbus_projection` to make a D-Bus projection of
the API implementation.

Bug: 186492781
Tag: #floss
Test: manual - Use dbus-send util
Change-Id: I12391f4e9739a5d1ed6167990fc016429e7280d4
parent d63cb3a8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,4 +20,5 @@ members = [
  "gd/rust/topshim",
  "gd/rust/linux/mgmt",
  "gd/rust/linux/adapter",
  "gd/rust/linux/service",
]
+26 −0
Original line number Diff line number Diff line
[package]
name = "btserv"
version = "0.1.0"
edition = "2018"

[dependencies]
bt_topshim = { path = "../../topshim" }
bt_shim = { path = "../../shim" }
btstack = { path = "../stack" }
dbus_projection = { path = "../dbus_projection" }
dbus_macros = { path = "../dbus_projection/dbus_macros" }

dbus = "0.9.2"
dbus-crossroads = "0.3.0"
dbus-tokio = "0.7.3"
futures = "0.3.13"
num-traits = "*"
tokio = { version = "1", features = ['bytes', 'fs', 'io-util', 'libc', 'macros', 'memchr', 'mio', 'net', 'num_cpus', 'rt', 'rt-multi-thread', 'sync', 'time', 'tokio-macros'] }

[build-dependencies]
pkg-config = "0.3.19"

[[bin]]
name = "btserv"
path = "src/main.rs"
build = "build.rs"
+27 −0
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 −0
Original line number Diff line number Diff line
use dbus_macros::generate_dbus_arg;

generate_dbus_arg!();
+51 −0
Original line number Diff line number Diff line
extern crate bt_shim;

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

use dbus::nonblock::SyncConnection;
use dbus::strings::{BusName, Path};

use dbus_macros::{dbus_method, dbus_proxy_obj, generate_dbus_exporter};

use dbus_projection::DisconnectWatcher;

use std::error::Error;
use std::sync::Arc;
use std::sync::Mutex;

use crate::dbus_arg::DBusArg;

#[allow(dead_code)]
struct BluetoothCallbackDBus {}

#[dbus_proxy_obj(BluetoothCallback, "org.chromium.bluetooth.BluetoothCallback")]
impl IBluetoothCallback for BluetoothCallbackDBus {
    #[dbus_method("OnBluetoothStateChange")]
    fn on_bluetooth_state_changed(&self, prev_state: u32, new_state: u32) {}
    #[dbus_method("OnBluetoothAddressChanged")]
    fn on_bluetooth_address_changed(&self, addr: String) {}
}

#[allow(dead_code)]
struct IBluetoothDBus {}

#[generate_dbus_exporter(export_bluetooth_dbus_obj, "org.chromium.bluetooth.Bluetooth")]
impl IBluetooth for IBluetoothDBus {
    #[dbus_method("RegisterCallback")]
    fn register_callback(&mut self, callback: Box<dyn IBluetoothCallback + Send>) {}

    #[dbus_method("Enable")]
    fn enable(&mut self) -> bool {
        false
    }
    #[dbus_method("Disable")]
    fn disable(&mut self) -> bool {
        false
    }

    #[dbus_method("GetAddress")]
    fn get_address(&self) -> String {
        String::from("")
    }
}
Loading