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

Commit 0192f70c authored by Michael Sun's avatar Michael Sun
Browse files

topshim: handle the new btav error struct

Handle the btav error struct by propagating it through the C++/Rust layer.

BUG: 240781725
Tag: #floss
Test: ./build.py
Test: emerge-${BOARD} floss
Change-Id: I8aa9a46b8e4e8c1008a8a5e8255005cfd529d052
parent e427b84b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ impl BluetoothMedia {

    pub fn dispatch_a2dp_callbacks(&mut self, cb: A2dpCallbacks) {
        match cb {
            A2dpCallbacks::ConnectionState(addr, state) => {
            A2dpCallbacks::ConnectionState(addr, state, _error) => {
                if !self.a2dp_states.get(&addr).is_none()
                    && state == *self.a2dp_states.get(&addr).unwrap()
                {
+12 −3
Original line number Diff line number Diff line
@@ -152,10 +152,19 @@ static ::rust::Vec<A2dpCodecConfig> to_rust_codec_config_vec(const std::vector<b
  return rconfigs;
}

static void connection_state_cb(
    const RawAddress& bd_addr, btav_connection_state_t state, [[maybe_unused]] const btav_error_t& error) {
static A2dpError to_rust_error(const btav_error_t& error) {
  A2dpError a2dp_error = {
      .status = error.status,
      .error_code = error.error_code,
      .error_msg = error.error_msg.value_or(""),
  };
  return a2dp_error;
}

static void connection_state_cb(const RawAddress& bd_addr, btav_connection_state_t state, const btav_error_t& error) {
  RustRawAddress addr = rusty::CopyToRustAddress(bd_addr);
  rusty::connection_state_callback(addr, state);
  A2dpError a2dp_error = to_rust_error(error);
  rusty::connection_state_callback(addr, state, a2dp_error);
}
static void audio_state_cb(const RawAddress& bd_addr, btav_audio_state_t state) {
  RustRawAddress addr = rusty::CopyToRustAddress(bd_addr);
+34 −4
Original line number Diff line number Diff line
use crate::btif::{BluetoothInterface, RawAddress};
use crate::btif::{BluetoothInterface, BtStatus, RawAddress};
use crate::topstack::get_dispatchers;

use num_traits::cast::FromPrimitive;
@@ -77,6 +77,18 @@ impl From<i32> for A2dpCodecPriority {
    }
}

#[derive(Debug)]
pub struct A2dpError {
    /// Standard BT status come from a function return or the cloest approximation to the real
    /// error.
    pub status: BtStatus,
    /// An additional value to help explain the error. In the A2Dp context, this is often referring
    /// to the BTA_AV_XXX status.
    pub error: i32,
    /// An optional error message that the lower layer wants to deliver.
    pub error_message: Option<String>,
}

bitflags! {
    pub struct A2dpCodecSampleRate: i32 {
        const RATE_NONE = 0x0;
@@ -154,6 +166,13 @@ pub mod ffi {
        data_position_nsec: i32,
    }

    #[derive(Debug, Default)]
    pub struct A2dpError {
        status: u32,
        error_code: u8,
        error_msg: String,
    }

    unsafe extern "C++" {
        include!("btav/btav_shim.h");
        include!("btav_sink/btav_sink_shim.h");
@@ -189,7 +208,7 @@ pub mod ffi {
        fn cleanup(self: &A2dpSinkIntf);
    }
    extern "Rust" {
        fn connection_state_callback(addr: RustRawAddress, state: u32);
        fn connection_state_callback(addr: RustRawAddress, state: u32, error: A2dpError);
        fn audio_state_callback(addr: RustRawAddress, state: u32);
        fn audio_config_callback(
            addr: RustRawAddress,
@@ -204,6 +223,7 @@ pub mod ffi {
pub type FfiAddress = ffi::RustRawAddress;
pub type A2dpCodecConfig = ffi::A2dpCodecConfig;
pub type PresentationPosition = ffi::RustPresentationPosition;
pub type FfiA2dpError = ffi::A2dpError;

impl From<RawAddress> for FfiAddress {
    fn from(addr: RawAddress) -> Self {
@@ -233,9 +253,18 @@ impl Default for A2dpCodecConfig {
    }
}

impl Into<A2dpError> for FfiA2dpError {
    fn into(self) -> A2dpError {
        A2dpError {
            status: self.status.into(),
            error: self.error_code as i32,
            error_message: if self.error_msg == "" { None } else { Some(self.error_msg) },
        }
    }
}
#[derive(Debug)]
pub enum A2dpCallbacks {
    ConnectionState(RawAddress, BtavConnectionState),
    ConnectionState(RawAddress, BtavConnectionState, A2dpError),
    AudioState(RawAddress, BtavAudioState),
    AudioConfig(RawAddress, A2dpCodecConfig, Vec<A2dpCodecConfig>, Vec<A2dpCodecConfig>),
    MandatoryCodecPreferred(RawAddress),
@@ -248,8 +277,9 @@ pub struct A2dpCallbacksDispatcher {
type A2dpCb = Arc<Mutex<A2dpCallbacksDispatcher>>;

cb_variant!(A2dpCb, connection_state_callback -> A2dpCallbacks::ConnectionState,
FfiAddress -> RawAddress, u32 -> BtavConnectionState, {
FfiAddress -> RawAddress, u32 -> BtavConnectionState, FfiA2dpError -> A2dpError,{
    let _0 = _0.into();
    let _2 = _2.into();
});

cb_variant!(A2dpCb, audio_state_callback -> A2dpCallbacks::AudioState,