Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Remove uses of EventCallbackVariant
Browse files Browse the repository at this point in the history
Remove EventCallbackVariant uses in ScoConnectionManager and
BrEdrConnectionManager now that they are only used in conjunction
with EmbossEventCallbacks.

Bug: b/42167863
Test: pw presubmit --step gn_chre_googletest_nanopb_sapphire_build
Change-Id: I1c6e06e8987de462a3466f364b505cb1b7230ea2
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/246312
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Ben Lawson <[email protected]>
Docs-Not-Needed: Josh Conner <[email protected]>
Commit-Queue: Josh Conner <[email protected]>
  • Loading branch information
josh-conner authored and CQ Bot Account committed Nov 1, 2024
1 parent 19e98dd commit ef86a47
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 59 deletions.
38 changes: 9 additions & 29 deletions pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,38 +139,18 @@ void SetPageScanEnabled(bool enabled,

hci::CommandChannel::EventHandlerId BrEdrConnectionManager::AddEventHandler(
const hci_spec::EventCode& code,
hci::CommandChannel::EventCallbackVariant cb) {
hci::CommandChannel::EmbossEventCallback cb) {
auto self = weak_self_.GetWeakPtr();
hci::CommandChannel::EventHandlerId event_id = 0;
event_id = std::visit(
[hci = hci_, &self, code](
auto&& callback) -> hci::CommandChannel::EventHandlerId {
using T = std::decay_t<decltype(callback)>;
if constexpr (std::is_same_v<T, hci::CommandChannel::EventCallback>) {
return hci->command_channel()->AddEventHandler(
code,
[self,
event_cb = std::move(callback)](const hci::EventPacket& event) {
if (!self.is_alive()) {
return hci::CommandChannel::EventCallbackResult::kRemove;
}
return event_cb(event);
});
} else if constexpr (std::is_same_v<
T,
hci::CommandChannel::EmbossEventCallback>) {
return hci->command_channel()->AddEventHandler(
code,
[self, emboss_event_cb = std::move(callback)](
const hci::EmbossEventPacket& event) {
if (!self.is_alive()) {
return hci::CommandChannel::EventCallbackResult::kRemove;
}
return emboss_event_cb(event);
});
event_id = hci_->command_channel()->AddEventHandler(
code,
[self,
emboss_event_cb = std::move(cb)](const hci::EmbossEventPacket& event) {
if (!self.is_alive()) {
return hci::CommandChannel::EventCallbackResult::kRemove;
}
},
std::move(cb));
return emboss_event_cb(event);
});
PW_DCHECK(event_id);
event_handler_ids_.push_back(event_id);
return event_id;
Expand Down
36 changes: 8 additions & 28 deletions pw_bluetooth_sapphire/host/sco/sco_connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,37 +129,17 @@ ScoConnectionManager::RequestHandle ScoConnectionManager::AcceptConnection(

hci::CommandChannel::EventHandlerId ScoConnectionManager::AddEventHandler(
const hci_spec::EventCode& code,
hci::CommandChannel::EventCallbackVariant event_cb_variant) {
hci::CommandChannel::EmbossEventCallback event_cb) {
auto self = weak_ptr_factory_.GetWeakPtr();
hci::CommandChannel::EventHandlerId event_id = 0;
event_id = std::visit(
[this, &self, code](
auto&& event_cb) -> hci::CommandChannel::EventHandlerId {
using T = std::decay_t<decltype(event_cb)>;
if constexpr (std::is_same_v<T, hci::CommandChannel::EventCallback>) {
return transport_->command_channel()->AddEventHandler(
code,
[self, cb = std::move(event_cb)](const hci::EventPacket& event) {
if (!self.is_alive()) {
return hci::CommandChannel::EventCallbackResult::kRemove;
}
return cb(event);
});
} else if constexpr (std::is_same_v<
T,
hci::CommandChannel::EmbossEventCallback>) {
return transport_->command_channel()->AddEventHandler(
code,
[self,
cb = std::move(event_cb)](const hci::EmbossEventPacket& event) {
if (!self.is_alive()) {
return hci::CommandChannel::EventCallbackResult::kRemove;
}
return cb(event);
});
event_id = transport_->command_channel()->AddEventHandler(
code,
[self, cb = std::move(event_cb)](const hci::EmbossEventPacket& event) {
if (!self.is_alive()) {
return hci::CommandChannel::EventCallbackResult::kRemove;
}
},
std::move(event_cb_variant));
return cb(event);
});
PW_CHECK(event_id);
event_handler_ids_.push_back(event_id);
return event_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class BrEdrConnectionManager final {
// Helper to register an event handler to run.
hci::CommandChannel::EventHandlerId AddEventHandler(
const hci_spec::EventCode& code,
hci::CommandChannel::EventCallbackVariant cb);
hci::CommandChannel::EmbossEventCallback cb);

// Find the outstanding connection request object for a connection request
// to/from |peer_id|. Returns nullopt if no request for |peer_id| exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ScoConnectionManager final {

hci::CommandChannel::EventHandlerId AddEventHandler(
const hci_spec::EventCode& code,
hci::CommandChannel::EventCallbackVariant event_callback_variant);
hci::CommandChannel::EmbossEventCallback event_callback);

// Event handlers:
hci::CommandChannel::EventCallbackResult OnSynchronousConnectionComplete(
Expand Down

0 comments on commit ef86a47

Please sign in to comment.