diff --git a/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc b/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc index 9d4550ce0..32c3a36fc 100644 --- a/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc +++ b/pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc @@ -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; - if constexpr (std::is_same_v) { - 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; diff --git a/pw_bluetooth_sapphire/host/sco/sco_connection_manager.cc b/pw_bluetooth_sapphire/host/sco/sco_connection_manager.cc index 4f09a22b4..de43e9ec6 100644 --- a/pw_bluetooth_sapphire/host/sco/sco_connection_manager.cc +++ b/pw_bluetooth_sapphire/host/sco/sco_connection_manager.cc @@ -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; - if constexpr (std::is_same_v) { - 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; diff --git a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/bredr_connection_manager.h b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/bredr_connection_manager.h index 2255ef664..c30adc7e7 100644 --- a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/bredr_connection_manager.h +++ b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/gap/bredr_connection_manager.h @@ -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. diff --git a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/sco/sco_connection_manager.h b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/sco/sco_connection_manager.h index 3cb3b8009..526eb0fc9 100644 --- a/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/sco/sco_connection_manager.h +++ b/pw_bluetooth_sapphire/public/pw_bluetooth_sapphire/internal/host/sco/sco_connection_manager.h @@ -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(