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

Commit 7e886f34 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "topshim: Add A2dp Sink Callback Dispatcher"

parents c687f792 37d54977
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
//! Media service facade

use bt_topshim::btif::BluetoothInterface;
use bt_topshim::profiles::a2dp::{A2dp, A2dpCallbacksDispatcher, A2dpSink};
use bt_topshim::profiles::a2dp::{
    A2dp, A2dpCallbacksDispatcher, A2dpSink, A2dpSinkCallbacksDispatcher,
};
use bt_topshim::profiles::avrcp::{Avrcp, AvrcpCallbacksDispatcher};
use bt_topshim_facade_protobuf::facade::{
    A2dpSourceConnectRequest, A2dpSourceConnectResponse, StartA2dpRequest, StartA2dpResponse,
@@ -17,6 +19,10 @@ fn get_a2dp_dispatcher() -> A2dpCallbacksDispatcher {
    A2dpCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) }
}

fn get_a2dp_sink_dispatcher() -> A2dpSinkCallbacksDispatcher {
    A2dpSinkCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) }
}

fn get_avrcp_dispatcher() -> AvrcpCallbacksDispatcher {
    AvrcpCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) }
}
@@ -60,7 +66,7 @@ impl MediaService for MediaServiceImpl {
                sink.success(StartA2dpResponse::default()).await.unwrap();
            })
        } else if req.start_a2dp_sink {
            self.btif_a2dp_sink.lock().unwrap().initialize();
            self.btif_a2dp_sink.lock().unwrap().initialize(get_a2dp_sink_dispatcher());
            ctx.spawn(async move {
                sink.success(StartA2dpResponse::default()).await.unwrap();
            })
+15 −1
Original line number Diff line number Diff line
@@ -335,6 +335,17 @@ impl A2dp {
    }
}

#[derive(Debug)]
pub enum A2dpSinkCallbacks {
    ConnectionState(RawAddress, BtavConnectionState),
}

pub struct A2dpSinkCallbacksDispatcher {
    pub dispatch: Box<dyn Fn(A2dpSinkCallbacks) + Send>,
}

type A2dpSinkCb = Arc<Mutex<A2dpSinkCallbacksDispatcher>>;

pub struct A2dpSink {
    internal: cxx::UniquePtr<ffi::A2dpSinkIntf>,
    _is_init: bool,
@@ -353,7 +364,10 @@ impl A2dpSink {
        A2dpSink { internal: a2dp_sink, _is_init: false }
    }

    pub fn initialize(&mut self) -> bool {
    pub fn initialize(&mut self, callbacks: A2dpSinkCallbacksDispatcher) -> bool {
        if get_dispatchers().lock().unwrap().set::<A2dpSinkCb>(Arc::new(Mutex::new(callbacks))) {
            panic!("Tried to set dispatcher for A2dp Sink Callbacks while it already exists");
        }
        self.internal.pin_mut().init();
        true
    }