aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-11-03 18:01:02 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-11-03 18:01:02 +0000
commit064935a69293d3cb076bf5ed81c6d0ae074a8ffe (patch)
treeb111f1d4fb8ac6881cb4ab064d30cabe808bb02b
parentb1beb83e93ebd1b753bac26e1fea6a4b8fc4955e (diff)
parent3086e25b1a7eec1e262901a3df13c7684259a9f2 (diff)
downloadbt-064935a69293d3cb076bf5ed81c6d0ae074a8ffe.tar.gz
Merge changes I6c755e4a,I648aead5
* changes: topshim: Add A2dp Sink Disconnect topshim: Add A2dp Sink Connect and Set Active
-rw-r--r--gd/rust/topshim/btav_sink/btav_sink_shim.cc24
-rw-r--r--gd/rust/topshim/btav_sink/btav_sink_shim.h12
-rw-r--r--gd/rust/topshim/src/profiles/a2dp.rs21
3 files changed, 50 insertions, 7 deletions
diff --git a/gd/rust/topshim/btav_sink/btav_sink_shim.cc b/gd/rust/topshim/btav_sink/btav_sink_shim.cc
index f0816df71..53d943a5c 100644
--- a/gd/rust/topshim/btav_sink/btav_sink_shim.cc
+++ b/gd/rust/topshim/btav_sink/btav_sink_shim.cc
@@ -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,23 @@ 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::disconnect(RustRawAddress bt_addr) const {
+ return intf_->disconnect(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.
}
diff --git a/gd/rust/topshim/btav_sink/btav_sink_shim.h b/gd/rust/topshim/btav_sink/btav_sink_shim.h
index 2306ee14b..785c15043 100644
--- a/gd/rust/topshim/btav_sink/btav_sink_shim.h
+++ b/gd/rust/topshim/btav_sink/btav_sink_shim.h
@@ -18,20 +18,28 @@
#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 disconnect(RustRawAddress bt_addr) const;
+ int set_active_device(RustRawAddress bt_addr) const;
+ void cleanup() const;
private:
const btav_sink_interface_t* intf_;
diff --git a/gd/rust/topshim/src/profiles/a2dp.rs b/gd/rust/topshim/src/profiles/a2dp.rs
index 72bb79d25..380ebdd33 100644
--- a/gd/rust/topshim/src/profiles/a2dp.rs
+++ b/gd/rust/topshim/src/profiles/a2dp.rs
@@ -182,8 +182,11 @@ 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 disconnect(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 +371,22 @@ 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 disconnect(&mut self, bt_addr: RawAddress) {
+ self.internal.disconnect(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) {}
}