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

Commit 810e44b4 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Initial commit for topshim avrcp

Add cxx binding for basic functions.

Test: avrcp cxx code is generated.
Test: avrcp needs to be initialized when using a2dp.
Tag: #floss
Bug: 190730870
Change-Id: Ib0af0e3e18275239a1858b0d6488eb05bd175d74
parent aabcfbb3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@ config("rust_topshim_config") {
cxxbridge_header("btif_bridge_header") {
  sources = [
    "src/btif.rs",
    "src/profiles/a2dp.rs"
    "src/profiles/a2dp.rs",
    "src/profiles/avrcp.rs"
  ]
  all_dependent_configs = [ ":rust_topshim_config" ]
  deps = [":cxxlibheader"]
@@ -34,7 +35,8 @@ cxxbridge_header("btif_bridge_header") {
cxxbridge_cc("btif_bridge_code") {
  sources = [
    "src/btif.rs",
    "src/profiles/a2dp.rs"
    "src/profiles/a2dp.rs",
    "src/profiles/avrcp.rs"
  ]
  deps = [":btif_bridge_header"]
  configs = [ "//bt/gd:gd_defaults" ]
+2 −0
Original line number Diff line number Diff line
@@ -228,6 +228,8 @@ std::unique_ptr<AvrcpIntf> GetAvrcpProfile(const unsigned char* btif) {
  return avrcpif;
}

AvrcpIntf::~AvrcpIntf() {}

void AvrcpIntf::init() {
  intf_->Init(&mAvrcpInterface, &mVolumeInterface);
}
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ std::unique_ptr<A2dpIntf> GetA2dpProfile(const unsigned char* btif);
class AvrcpIntf {
 public:
  AvrcpIntf(bluetooth::avrcp::ServiceInterface* intf) : intf_(intf) {}
  ~AvrcpIntf();

  void init();
  void cleanup();
  int connect(RustRawAddress bt_addr);
+46 −0
Original line number Diff line number Diff line
use crate::btif::BluetoothInterface;

#[cxx::bridge(namespace = bluetooth::topshim::rust)]
pub mod ffi {
    unsafe extern "C++" {
        include!("btav/btav_shim.h");

        type AvrcpIntf;

        unsafe fn GetAvrcpProfile(btif: *const u8) -> UniquePtr<AvrcpIntf>;

        fn init(self: Pin<&mut AvrcpIntf>);
        fn cleanup(self: Pin<&mut AvrcpIntf>);

    }
    extern "Rust" {}
}

pub struct Avrcp {
    internal: cxx::UniquePtr<ffi::AvrcpIntf>,
    _is_init: bool,
}

// For *const u8 opaque btif
unsafe impl Send for Avrcp {}

impl Avrcp {
    pub fn new(intf: &BluetoothInterface) -> Avrcp {
        let avrcpif: cxx::UniquePtr<ffi::AvrcpIntf>;
        unsafe {
            avrcpif = ffi::GetAvrcpProfile(intf.as_raw_ptr());
        }

        Avrcp { internal: avrcpif, _is_init: false }
    }

    pub fn initialize(&mut self) -> bool {
        self.internal.pin_mut().init();
        true
    }

    pub fn cleanup(&mut self) -> bool {
        self.internal.pin_mut().cleanup();
        true
    }
}
+1 −0
Original line number Diff line number Diff line
pub mod a2dp;
pub mod avrcp;
pub mod hid_host;