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

Commit 8b8987f6 authored by Charlie Boutier's avatar Charlie Boutier Committed by David Duarte
Browse files

topshim: Add A2dp Sink Connect and Set Active

Test: m bt_topshim_facade
Change-Id: I648aead5ab379e53a9e98d4293b77f6185810c8b
parent 37d54977
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
#include <memory>

#include "include/hardware/bluetooth.h"
#include "rust/cxx.h"
#include "src/profiles/a2dp.rs.h"
#include "types/raw_address.h"

namespace bluetooth {
@@ -37,6 +39,12 @@ btav_sink_callbacks_t g_a2dp_sink_callbacks = {
    audio_state_cb,
    audio_config_cb,
};

static RawAddress from_rust_address(const RustRawAddress& raddr) {
  RawAddress addr;
  addr.FromOctets(raddr.address.data());
  return addr;
}
}  // namespace internal

A2dpSinkIntf::~A2dpSinkIntf() {
@@ -54,11 +62,19 @@ std::unique_ptr<A2dpSinkIntf> GetA2dpSinkProfile(const unsigned char* btif) {
  return a2dp_sink;
}

int A2dpSinkIntf::init() {
int A2dpSinkIntf::init() const {
  return intf_->init(&internal::g_a2dp_sink_callbacks, 1);
}

void A2dpSinkIntf::cleanup() {
int A2dpSinkIntf::connect(RustRawAddress bt_addr) const {
  return intf_->connect(internal::from_rust_address(bt_addr));
}

int A2dpSinkIntf::set_active_device(RustRawAddress bt_addr) const {
  return intf_->set_active_device(internal::from_rust_address(bt_addr));
}

void A2dpSinkIntf::cleanup() const {
  // TODO: Implement.
}

+9 −2
Original line number Diff line number Diff line
@@ -18,20 +18,27 @@

#include <memory>

#include "gd/rust/topshim/btav_sink/btav_sink_shim.h"
#include "include/hardware/bt_av.h"
#include "rust/cxx.h"
#include "types/raw_address.h"

namespace bluetooth {
namespace topshim {
namespace rust {

struct RustRawAddress;

class A2dpSinkIntf {
 public:
  A2dpSinkIntf(const btav_sink_interface_t* intf) : intf_(intf){};
  ~A2dpSinkIntf();

  // interface for Settings
  int init();
  void cleanup();
  int init() const;
  int connect(RustRawAddress bt_addr) const;
  int set_active_device(RustRawAddress bt_addr) const;
  void cleanup() const;

 private:
  const btav_sink_interface_t* intf_;
+13 −3
Original line number Diff line number Diff line
@@ -182,8 +182,10 @@ pub mod ffi {

        unsafe fn GetA2dpSinkProfile(btif: *const u8) -> UniquePtr<A2dpSinkIntf>;

        fn init(self: Pin<&mut A2dpSinkIntf>) -> i32;
        fn cleanup(self: Pin<&mut A2dpSinkIntf>);
        fn init(self: &A2dpSinkIntf) -> i32;
        fn connect(self: &A2dpSinkIntf, bt_addr: RustRawAddress) -> i32;
        fn set_active_device(self: &A2dpSinkIntf, bt_addr: RustRawAddress) -> i32;
        fn cleanup(self: &A2dpSinkIntf);
    }
    extern "Rust" {
        fn connection_state_callback(addr: RustRawAddress, state: u32);
@@ -368,10 +370,18 @@ impl A2dpSink {
        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();
        self.internal.init();
        true
    }

    pub fn connect(&mut self, bt_addr: RawAddress) {
        self.internal.connect(bt_addr.into());
    }

    pub fn set_active_device(&mut self, bt_addr: RawAddress) {
        self.internal.set_active_device(bt_addr.into());
    }

    pub fn cleanup(&mut self) {}
}