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

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

Merge changes Ided764f4,Ic79c2972,If87bd8bd

* changes:
  Use tokio::spawn instead of choosing the runtime explicitly
  Add unit tests for BDAddr conversions
  Clean up compiler warnings for a2dp
parents 037cf136 b4edb49b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

        // The `resource` is a task that should be spawned onto a tokio compatible
        // reactor ASAP. If the resource ever finishes, we lost connection to D-Bus.
        topstack::get_runtime().spawn(async {
        tokio::spawn(async {
            let err = resource.await;
            panic!("Lost connection to D-Bus: {}", err);
        });
@@ -106,7 +106,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
        cr.lock().unwrap().set_async_support(Some((
            conn.clone(),
            Box::new(|x| {
                topstack::get_runtime().spawn(x);
                tokio::spawn(x);
            }),
        )));
        let cr_clone = cr.clone();
+1 −1
Original line number Diff line number Diff line
@@ -402,7 +402,7 @@ pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {
                    let remote__ = self.remote.clone();
                    let objpath__ = self.objpath.clone();
                    let conn__ = self.conn.clone();
                    bt_topshim::topstack::get_runtime().spawn(async move {
                    tokio::spawn(async move {
                        let proxy = dbus::nonblock::Proxy::new(
                            remote__,
                            objpath__,
+3 −3
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ fn main() -> Result<(), Box<dyn Error>> {

        // The `resource` is a task that should be spawned onto a tokio compatible
        // reactor ASAP. If the resource ever finishes, we lost connection to D-Bus.
        topstack::get_runtime().spawn(async {
        tokio::spawn(async {
            let err = resource.await;
            panic!("Lost connection to D-Bus: {}", err);
        });
@@ -63,12 +63,12 @@ fn main() -> Result<(), Box<dyn Error>> {
        cr.set_async_support(Some((
            conn.clone(),
            Box::new(|x| {
                topstack::get_runtime().spawn(x);
                tokio::spawn(x);
            }),
        )));

        // Run the stack main dispatch loop.
        topstack::get_runtime().spawn(Stack::dispatch(rx, bluetooth.clone()));
        tokio::spawn(Stack::dispatch(rx, bluetooth.clone()));

        // Set up the disconnect watcher to monitor client disconnects.
        let disconnect_watcher = Arc::new(Mutex::new(DisconnectWatcher::new()));
+1 −1
Original line number Diff line number Diff line
@@ -296,7 +296,7 @@ impl IBluetooth for Bluetooth {

        callback.register_disconnect(Box::new(move || {
            let tx = tx.clone();
            topstack::get_runtime().spawn(async move {
            tokio::spawn(async move {
                let _result = tx.send(Message::BluetoothCallbackDisconnected(id)).await;
            });
        }));
+8 −3
Original line number Diff line number Diff line
@@ -53,15 +53,16 @@ impl ToString for BDAddr {

impl BDAddr {
    /// Constructs a BDAddr from a vector of 6 bytes.
    fn from_byte_vec(raw_addr: &Vec<u8>) -> Option<BDAddr> {
    pub fn from_byte_vec(raw_addr: &Vec<u8>) -> Option<BDAddr> {
        if let Ok(val) = raw_addr.clone().try_into() {
            return Some(BDAddr { val });
        }
        None
    }

    fn from_string(addr_str: String) -> Option<BDAddr> {
        let s = addr_str.split(':').collect::<Vec<&str>>();
    pub fn from_string<S: Into<String>>(addr: S) -> Option<BDAddr> {
        let addr: String = addr.into();
        let s = addr.split(':').collect::<Vec<&str>>();

        if s.len() != 6 {
            return None;
@@ -79,6 +80,10 @@ impl BDAddr {

        Some(BDAddr { val: raw })
    }

    pub fn to_byte_arr(&self) -> [u8; 6] {
        self.val.clone()
    }
}

/// Message types that are sent to the stack main dispatch loop.
Loading