diff --git a/connections/implementation/base_bwu_handler.cc b/connections/implementation/base_bwu_handler.cc index c652dfbf..272e100d 100644 --- a/connections/implementation/base_bwu_handler.cc +++ b/connections/implementation/base_bwu_handler.cc @@ -23,8 +23,9 @@ namespace nearby { namespace connections { -BaseBwuHandler::BaseBwuHandler(BwuNotifications bwu_notifications) - : bwu_notifications_(std::move(bwu_notifications)) {} +BaseBwuHandler::BaseBwuHandler( + IncomingConnectionCallback incoming_connection_callback) + : incoming_connection_callback_(std::move(incoming_connection_callback)) {} ByteArray BaseBwuHandler::InitializeUpgradedMediumForEndpoint( ClientProxy* client, const std::string& service_id, @@ -78,5 +79,14 @@ void BaseBwuHandler::RevertResponderState(const std::string& service_id) { HandleRevertInitiatorStateForService(service_id); } +void BaseBwuHandler::NotifyOnIncomingConnection( + ClientProxy* client, std::unique_ptr connection) { + if (!incoming_connection_callback_) { + NEARBY_LOGS(WARNING) + << "Ignoring incoming connection, no callback registered"; + return; + } + incoming_connection_callback_(client, std::move(connection)); +} } // namespace connections } // namespace nearby diff --git a/connections/implementation/base_bwu_handler.h b/connections/implementation/base_bwu_handler.h index a6d93625..783d90e4 100644 --- a/connections/implementation/base_bwu_handler.h +++ b/connections/implementation/base_bwu_handler.h @@ -30,7 +30,8 @@ namespace connections { // of the service IDs and endpoint IDs that initiated a bandwidth upgrade. class BaseBwuHandler : public BwuHandler { public: - explicit BaseBwuHandler(BwuNotifications bwu_notifications); + explicit BaseBwuHandler( + IncomingConnectionCallback incoming_connection_callback); // BwuHandler implementation: ByteArray InitializeUpgradedMediumForEndpoint( @@ -55,9 +56,13 @@ class BaseBwuHandler : public BwuHandler { virtual void HandleRevertInitiatorStateForService( const std::string& upgrade_service_id) = 0; - BwuNotifications bwu_notifications_; + // Notifies the caller about incoming connection. + void NotifyOnIncomingConnection( + ClientProxy* client, + std::unique_ptr connection); private: + IncomingConnectionCallback incoming_connection_callback_; // Map from the (wrapped) service ID to endpoint IDs that are initiating a // bandwidth upgrade. Not used for endpoints that respond to bandwidth upgrade // requests from another device. diff --git a/connections/implementation/base_bwu_handler_test.cc b/connections/implementation/base_bwu_handler_test.cc index d04cff92..13fe331b 100644 --- a/connections/implementation/base_bwu_handler_test.cc +++ b/connections/implementation/base_bwu_handler_test.cc @@ -38,7 +38,7 @@ class BwuHandlerImpl : public BaseBwuHandler { absl::optional endpoint_id; }; - BwuHandlerImpl() : BaseBwuHandler(BwuNotifications{}) {} + BwuHandlerImpl() : BaseBwuHandler(nullptr) {} const std::vector& handle_initialize_calls() const { return handle_initialize_calls_; diff --git a/connections/implementation/bluetooth_bwu_handler.cc b/connections/implementation/bluetooth_bwu_handler.cc index 894740d0..f60d607b 100644 --- a/connections/implementation/bluetooth_bwu_handler.cc +++ b/connections/implementation/bluetooth_bwu_handler.cc @@ -28,9 +28,10 @@ namespace nearby { namespace connections { -BluetoothBwuHandler::BluetoothBwuHandler(Mediums& mediums, - BwuNotifications notifications) - : BaseBwuHandler(std::move(notifications)), mediums_(mediums) {} +BluetoothBwuHandler::BluetoothBwuHandler( + Mediums& mediums, IncomingConnectionCallback incoming_connection_callback) + : BaseBwuHandler(std::move(incoming_connection_callback)), + mediums_(mediums) {} // Called by BWU target. Retrieves a new medium info from incoming message, // and establishes connection over BT using this info. @@ -153,7 +154,7 @@ void BluetoothBwuHandler::OnIncomingBluetoothConnection( upgrade_service_id, socket), .channel = std::move(channel), }}; - bwu_notifications_.incoming_connection_cb(client, std::move(connection)); + NotifyOnIncomingConnection(client, std::move(connection)); } } // namespace connections diff --git a/connections/implementation/bluetooth_bwu_handler.h b/connections/implementation/bluetooth_bwu_handler.h index 2fa4d09b..6563eebf 100644 --- a/connections/implementation/bluetooth_bwu_handler.h +++ b/connections/implementation/bluetooth_bwu_handler.h @@ -31,8 +31,9 @@ namespace connections { // per-Medium-specific operations needed to upgrade an EndpointChannel. class BluetoothBwuHandler : public BaseBwuHandler { public: - explicit BluetoothBwuHandler(Mediums& mediums, - BwuNotifications notifications); + explicit BluetoothBwuHandler( + Mediums& mediums, + IncomingConnectionCallback incoming_connection_callback); private: class BluetoothIncomingSocket : public IncomingSocket { diff --git a/connections/implementation/bwu_handler.h b/connections/implementation/bwu_handler.h index d8ab4750..de1ee7e0 100644 --- a/connections/implementation/bwu_handler.h +++ b/connections/implementation/bwu_handler.h @@ -18,6 +18,7 @@ #include #include +#include "absl/functional/any_invocable.h" #include "connections/implementation/client_proxy.h" #include "connections/implementation/endpoint_channel.h" #include "connections/implementation/offline_frames.h" @@ -47,12 +48,9 @@ class BwuHandler { std::unique_ptr socket; std::unique_ptr channel; }; - - struct BwuNotifications { - std::function connection)> - incoming_connection_cb; - }; + using IncomingConnectionCallback = absl::AnyInvocable connection)>; virtual ~BwuHandler() = default; diff --git a/connections/implementation/bwu_manager.cc b/connections/implementation/bwu_manager.cc index 1c39963a..97f597d5 100644 --- a/connections/implementation/bwu_manager.cc +++ b/connections/implementation/bwu_manager.cc @@ -103,31 +103,40 @@ BwuManager::~BwuManager() { void BwuManager::InitBwuHandlers() { // Register the supported concrete BwuMedium implementations. - BwuHandler::BwuNotifications notifications{ - .incoming_connection_cb = - absl::bind_front(&BwuManager::OnIncomingConnection, this), - }; if (config_.allow_upgrade_to.wifi_hotspot) { handlers_.emplace( Medium::WIFI_HOTSPOT, - std::make_unique(*mediums_, notifications)); + std::make_unique( + *mediums_, + absl::bind_front(&BwuManager::OnIncomingConnection, this))); } if (config_.allow_upgrade_to.wifi_direct) { handlers_.emplace( Medium::WIFI_DIRECT, - std::make_unique(*mediums_, notifications)); + std::make_unique( + *mediums_, + absl::bind_front(&BwuManager::OnIncomingConnection, this))); } if (config_.allow_upgrade_to.wifi_lan) { - handlers_.emplace(Medium::WIFI_LAN, std::make_unique( - *mediums_, notifications)); + handlers_.emplace( + Medium::WIFI_LAN, + std::make_unique( + *mediums_, + absl::bind_front(&BwuManager::OnIncomingConnection, this))); } if (config_.allow_upgrade_to.web_rtc) { - handlers_.emplace(Medium::WEB_RTC, std::make_unique( - *mediums_, notifications)); + handlers_.emplace( + Medium::WEB_RTC, + std::make_unique( + *mediums_, + absl::bind_front(&BwuManager::OnIncomingConnection, this))); } if (config_.allow_upgrade_to.bluetooth) { - handlers_.emplace(Medium::BLUETOOTH, std::make_unique( - *mediums_, notifications)); + handlers_.emplace( + Medium::BLUETOOTH, + std::make_unique( + *mediums_, + absl::bind_front(&BwuManager::OnIncomingConnection, this))); } } diff --git a/connections/implementation/fake_bwu_handler.h b/connections/implementation/fake_bwu_handler.h index b735dc9e..78c13719 100644 --- a/connections/implementation/fake_bwu_handler.h +++ b/connections/implementation/fake_bwu_handler.h @@ -47,7 +47,7 @@ class FakeBwuHandler : public BaseBwuHandler { }; explicit FakeBwuHandler(Medium medium) - : BaseBwuHandler(BwuNotifications{}), medium_(medium) {} + : BaseBwuHandler(nullptr), medium_(medium) {} ~FakeBwuHandler() override = default; const std::vector& create_calls() const { return create_calls_; } diff --git a/connections/implementation/webrtc_bwu_handler.cc b/connections/implementation/webrtc_bwu_handler.cc index 1941abca..1fbdbb21 100644 --- a/connections/implementation/webrtc_bwu_handler.cc +++ b/connections/implementation/webrtc_bwu_handler.cc @@ -40,9 +40,10 @@ void WebrtcBwuHandler::WebrtcIncomingSocket::Close() { socket_.Close(); } std::string WebrtcBwuHandler::WebrtcIncomingSocket::ToString() { return name_; } -WebrtcBwuHandler::WebrtcBwuHandler(Mediums& mediums, - BwuNotifications notifications) - : BaseBwuHandler(std::move(notifications)), mediums_(mediums) {} +WebrtcBwuHandler::WebrtcBwuHandler( + Mediums& mediums, IncomingConnectionCallback incoming_connection_callback) + : BaseBwuHandler(std::move(incoming_connection_callback)), + mediums_(mediums) {} // Called by BWU target. Retrieves a new medium info from incoming message, // and establishes connection over WebRTC using this info. @@ -146,7 +147,7 @@ void WebrtcBwuHandler::OnIncomingWebrtcConnection( new IncomingSocketConnection{std::move(webrtc_socket), std::move(channel)}); - bwu_notifications_.incoming_connection_cb(client, std::move(connection)); + NotifyOnIncomingConnection(client, std::move(connection)); } } // namespace connections diff --git a/connections/implementation/webrtc_bwu_handler.h b/connections/implementation/webrtc_bwu_handler.h index 46faae34..c45f7946 100644 --- a/connections/implementation/webrtc_bwu_handler.h +++ b/connections/implementation/webrtc_bwu_handler.h @@ -32,7 +32,9 @@ namespace connections { // per-Medium-specific operations needed to upgrade an EndpointChannel. class WebrtcBwuHandler : public BaseBwuHandler { public: - explicit WebrtcBwuHandler(Mediums& mediums, BwuNotifications notifications); + explicit WebrtcBwuHandler( + Mediums& mediums, + IncomingConnectionCallback incoming_connection_callback); private: class WebrtcIncomingSocket : public BwuHandler::IncomingSocket { diff --git a/connections/implementation/webrtc_bwu_handler_stub.cc b/connections/implementation/webrtc_bwu_handler_stub.cc index f4590027..91f19c1f 100644 --- a/connections/implementation/webrtc_bwu_handler_stub.cc +++ b/connections/implementation/webrtc_bwu_handler_stub.cc @@ -37,9 +37,9 @@ void WebrtcBwuHandler::WebrtcIncomingSocket::Close() {} std::string WebrtcBwuHandler::WebrtcIncomingSocket::ToString() { return ""; } -WebrtcBwuHandler::WebrtcBwuHandler(Mediums& mediums, - BwuNotifications notifications) - : BaseBwuHandler(std::move(notifications)), +WebrtcBwuHandler::WebrtcBwuHandler( + Mediums& mediums, IncomingConnectionCallback incoming_connection_callback) + : BaseBwuHandler(std::move(incoming_connection_callback)), mediums_(mediums) {} // Called by BWU target. Retrieves a new medium info from incoming message, diff --git a/connections/implementation/webrtc_bwu_handler_stub.h b/connections/implementation/webrtc_bwu_handler_stub.h index f4aec1ac..de0a9ff1 100644 --- a/connections/implementation/webrtc_bwu_handler_stub.h +++ b/connections/implementation/webrtc_bwu_handler_stub.h @@ -36,7 +36,9 @@ namespace connections { // per-Medium-specific operations needed to upgrade an EndpointChannel. class WebrtcBwuHandler : public BaseBwuHandler { public: - explicit WebrtcBwuHandler(Mediums& mediums, BwuNotifications notifications); + explicit WebrtcBwuHandler( + Mediums& mediums, + IncomingConnectionCallback incoming_connection_callback); private: class WebrtcIncomingSocket : public BwuHandler::IncomingSocket { diff --git a/connections/implementation/wifi_direct_bwu_handler.cc b/connections/implementation/wifi_direct_bwu_handler.cc index c7ed4317..daa5d04b 100644 --- a/connections/implementation/wifi_direct_bwu_handler.cc +++ b/connections/implementation/wifi_direct_bwu_handler.cc @@ -28,9 +28,10 @@ namespace nearby { namespace connections { -WifiDirectBwuHandler::WifiDirectBwuHandler(Mediums& mediums, - BwuNotifications notifications) - : BaseBwuHandler(std::move(notifications)), mediums_(mediums) {} +WifiDirectBwuHandler::WifiDirectBwuHandler( + Mediums& mediums, IncomingConnectionCallback incoming_connection_callback) + : BaseBwuHandler(std::move(incoming_connection_callback)), + mediums_(mediums) {} ByteArray WifiDirectBwuHandler::HandleInitializeUpgradedMediumForEndpoint( ClientProxy* client, const std::string& upgrade_service_id, @@ -149,7 +150,7 @@ void WifiDirectBwuHandler::OnIncomingWifiDirectConnection( upgrade_service_id, socket), .channel = std::move(channel), }); - bwu_notifications_.incoming_connection_cb(client, std::move(connection)); + NotifyOnIncomingConnection(client, std::move(connection)); } } // namespace connections diff --git a/connections/implementation/wifi_direct_bwu_handler.h b/connections/implementation/wifi_direct_bwu_handler.h index 47424259..e7f159ea 100644 --- a/connections/implementation/wifi_direct_bwu_handler.h +++ b/connections/implementation/wifi_direct_bwu_handler.h @@ -29,14 +29,15 @@ namespace connections { // per-Medium-specific operations needed to upgrade an EndpointChannel. class WifiDirectBwuHandler : public BaseBwuHandler { public: - explicit WifiDirectBwuHandler(Mediums& mediums, - BwuNotifications notifications); + explicit WifiDirectBwuHandler( + Mediums& mediums, + IncomingConnectionCallback incoming_connection_callback); private: class WifiDirectIncomingSocket : public BwuHandler::IncomingSocket { public: explicit WifiDirectIncomingSocket(const std::string& name, - WifiDirectSocket socket) + WifiDirectSocket socket) : name_(name), socket_(socket) {} std::string ToString() override { return name_; } @@ -73,8 +74,8 @@ class WifiDirectBwuHandler : public BaseBwuHandler { // Accept Connection Callback. void OnIncomingWifiDirectConnection(ClientProxy* client, - const std::string& upgrade_service_id, - WifiDirectSocket socket); + const std::string& upgrade_service_id, + WifiDirectSocket socket); Mediums& mediums_; Wifi& wifi_medium_ = mediums_.GetWifi(); diff --git a/connections/implementation/wifi_direct_bwu_test.cc b/connections/implementation/wifi_direct_bwu_test.cc index 127065f2..b01d9998 100644 --- a/connections/implementation/wifi_direct_bwu_test.cc +++ b/connections/implementation/wifi_direct_bwu_test.cc @@ -38,11 +38,10 @@ class WifiDirectTest : public testing::Test { }; TEST_F(WifiDirectTest, CanCreateBwuHandler) { - BwuHandler::BwuNotifications notifications = {.incoming_connection_cb = {}}; ClientProxy client; Mediums mediums; - auto handler = std::make_unique(mediums, notifications); + auto handler = std::make_unique(mediums, nullptr); handler->InitializeUpgradedMediumForEndpoint(&client, /*service_id=*/"B", /*endpoint_id=*/"2"); @@ -56,29 +55,23 @@ TEST_F(WifiDirectTest, WFDGOBWUInit_GCCreateEndpointChannel) { CountDownLatch accept_latch(1); CountDownLatch end_latch(1); - BwuHandler::BwuNotifications notifications_1{ - .incoming_connection_cb = - [&accept_latch, &end_latch]( - ClientProxy* client, - std::unique_ptr - mutable_connection) { - NEARBY_LOGS(WARNING) << "Server socket connection accept call back"; - std::shared_ptr connection( - mutable_connection.release()); - accept_latch.CountDown(); - EXPECT_TRUE(end_latch.Await(kWaitDuration).result()); - NEARBY_LOGS(WARNING) << "Test is done. Close the socket"; - connection->channel->Close(); - connection->socket->Close(); - }, - }; - BwuHandler::BwuNotifications notifications_2 = {.incoming_connection_cb = {}}; ClientProxy wifi_direct_go, wifi_direct_gc; Mediums mediums_1, mediums_2; ExceptionOr upgrade_frame; - auto handler_1 = - std::make_unique(mediums_1, notifications_1); + auto handler_1 = std::make_unique( + mediums_1, [&](ClientProxy* client, + std::unique_ptr + mutable_connection) { + NEARBY_LOGS(WARNING) << "Server socket connection accept call back"; + std::shared_ptr connection( + mutable_connection.release()); + accept_latch.CountDown(); + EXPECT_TRUE(end_latch.Await(kWaitDuration).result()); + NEARBY_LOGS(WARNING) << "Test is done. Close the socket"; + connection->channel->Close(); + connection->socket->Close(); + }); SingleThreadExecutor server_executor; server_executor.Execute( @@ -98,10 +91,9 @@ TEST_F(WifiDirectTest, WFDGOBWUInit_GCCreateEndpointChannel) { EXPECT_TRUE(start_latch.Await(kWaitDuration).result()); EXPECT_FALSE(mediums_2.GetWifiDirect().IsConnectedToGO()); std::unique_ptr handler_2 = - std::make_unique(mediums_2, notifications_2); + std::make_unique(mediums_2, nullptr); - client_executor.Execute([&handler_2, &wifi_direct_gc, &upgrade_frame, - &accept_latch, &end_latch, &mediums_2]() { + client_executor.Execute([&]() { auto bwu_frame = upgrade_frame.result().v1().bandwidth_upgrade_negotiation(); diff --git a/connections/implementation/wifi_hotspot_bwu_handler.cc b/connections/implementation/wifi_hotspot_bwu_handler.cc index 58acf86d..4bf7f215 100644 --- a/connections/implementation/wifi_hotspot_bwu_handler.cc +++ b/connections/implementation/wifi_hotspot_bwu_handler.cc @@ -29,9 +29,10 @@ namespace nearby { namespace connections { -WifiHotspotBwuHandler::WifiHotspotBwuHandler(Mediums& mediums, - BwuNotifications notifications) - : BaseBwuHandler(std::move(notifications)), mediums_(mediums) {} +WifiHotspotBwuHandler::WifiHotspotBwuHandler( + Mediums& mediums, IncomingConnectionCallback incoming_connection_callback) + : BaseBwuHandler(std::move(incoming_connection_callback)), + mediums_(mediums) {} // Called by BWU initiator. Set up WifiHotspot upgraded medium for this // endpoint, and returns a upgrade path info (SSID, Password, Gateway used as @@ -157,7 +158,7 @@ void WifiHotspotBwuHandler::OnIncomingWifiHotspotConnection( upgrade_service_id, socket), .channel = std::move(channel), }); - bwu_notifications_.incoming_connection_cb(client, std::move(connection)); + NotifyOnIncomingConnection(client, std::move(connection)); } } // namespace connections diff --git a/connections/implementation/wifi_hotspot_bwu_handler.h b/connections/implementation/wifi_hotspot_bwu_handler.h index f7668c45..3e4fd611 100644 --- a/connections/implementation/wifi_hotspot_bwu_handler.h +++ b/connections/implementation/wifi_hotspot_bwu_handler.h @@ -29,14 +29,15 @@ namespace connections { // per-Medium-specific operations needed to upgrade an EndpointChannel. class WifiHotspotBwuHandler : public BaseBwuHandler { public: - explicit WifiHotspotBwuHandler(Mediums& mediums, - BwuNotifications notifications); + explicit WifiHotspotBwuHandler( + Mediums& mediums, + IncomingConnectionCallback incoming_connection_callback); private: class WifiHotspotIncomingSocket : public BwuHandler::IncomingSocket { public: explicit WifiHotspotIncomingSocket(const std::string& name, - WifiHotspotSocket socket) + WifiHotspotSocket socket) : name_(name), socket_(socket) {} std::string ToString() override { return name_; } @@ -64,8 +65,8 @@ class WifiHotspotBwuHandler : public BaseBwuHandler { const std::string& upgrade_service_id) final; void OnIncomingWifiHotspotConnection(ClientProxy* client, - const std::string& upgrade_service_id, - WifiHotspotSocket socket); + const std::string& upgrade_service_id, + WifiHotspotSocket socket); Mediums& mediums_; WifiHotspot& wifi_hotspot_medium_{mediums_.GetWifiHotspot()}; diff --git a/connections/implementation/wifi_hotspot_test.cc b/connections/implementation/wifi_hotspot_test.cc index c24a2988..091087c3 100644 --- a/connections/implementation/wifi_hotspot_test.cc +++ b/connections/implementation/wifi_hotspot_test.cc @@ -37,12 +37,10 @@ class WifiHotspotTest : public testing::Test { }; TEST_F(WifiHotspotTest, CanCreateBwuHandler) { - BwuHandler::BwuNotifications notifications{.incoming_connection_cb = {}}; ClientProxy client; Mediums mediums; - auto handler = - std::make_unique(mediums, notifications); + auto handler = std::make_unique(mediums, nullptr); handler->InitializeUpgradedMediumForEndpoint(&client, /*service_id=*/"B", /*endpoint_id=*/"2"); @@ -56,48 +54,40 @@ TEST_F(WifiHotspotTest, SoftAPBWUInit_STACreateEndpointChannel) { CountDownLatch accept_latch(1); CountDownLatch end_latch(1); - BwuHandler::BwuNotifications notifications_1{ - .incoming_connection_cb = - [&accept_latch, &end_latch]( - ClientProxy* client, - std::unique_ptr - mutable_connection) { - NEARBY_LOGS(WARNING) << "Server socket connection accept call back"; - accept_latch.CountDown(); - EXPECT_TRUE(end_latch.Await(kWaitDuration).result()); - }, - }; - BwuHandler::BwuNotifications notifications_2{.incoming_connection_cb = {}}; ClientProxy client_1, client_2; Mediums mediums_1, mediums_2; ExceptionOr upgrade_frame; - auto handler_1 = - std::make_unique(mediums_1, notifications_1); + auto handler_1 = std::make_unique( + mediums_1, [&](ClientProxy* client, + std::unique_ptr + mutable_connection) { + NEARBY_LOGS(WARNING) << "Server socket connection accept call back"; + accept_latch.CountDown(); + EXPECT_TRUE(end_latch.Await(kWaitDuration).result()); + }); // client_1 works as Hotspot SoftAP SingleThreadExecutor server_executor; - server_executor.Execute( - [&handler_1, &client_1, &upgrade_frame, &start_latch]() { - ByteArray upgrade_path_available_frame = - handler_1->InitializeUpgradedMediumForEndpoint(&client_1, - /*service_id=*/"A", - /*endpoint_id=*/"1"); - EXPECT_FALSE(upgrade_path_available_frame.Empty()); + server_executor.Execute([&]() { + ByteArray upgrade_path_available_frame = + handler_1->InitializeUpgradedMediumForEndpoint(&client_1, + /*service_id=*/"A", + /*endpoint_id=*/"1"); + EXPECT_FALSE(upgrade_path_available_frame.Empty()); - upgrade_frame = parser::FromBytes(upgrade_path_available_frame); - start_latch.CountDown(); - }); + upgrade_frame = parser::FromBytes(upgrade_path_available_frame); + start_latch.CountDown(); + }); // client_2 works as Hotspot STA which will connect to client_1 SingleThreadExecutor client_executor; // Wait till client_1 started as hotspot and then connect to it EXPECT_TRUE(start_latch.Await(kWaitDuration).result()); std::unique_ptr handler_2 = - std::make_unique(mediums_2, notifications_2); + std::make_unique(mediums_2, nullptr); - client_executor.Execute([&handler_2, &client_2, &upgrade_frame, &accept_latch, - &end_latch, &mediums_2]() { + client_executor.Execute([&]() { auto bwu_frame = upgrade_frame.result().v1().bandwidth_upgrade_negotiation(); diff --git a/connections/implementation/wifi_lan_bwu_handler.cc b/connections/implementation/wifi_lan_bwu_handler.cc index 3c74764d..04a0ea50 100644 --- a/connections/implementation/wifi_lan_bwu_handler.cc +++ b/connections/implementation/wifi_lan_bwu_handler.cc @@ -28,9 +28,10 @@ namespace nearby { namespace connections { -WifiLanBwuHandler::WifiLanBwuHandler(Mediums& mediums, - BwuNotifications notifications) - : BaseBwuHandler(std::move(notifications)), mediums_(mediums) {} +WifiLanBwuHandler::WifiLanBwuHandler( + Mediums& mediums, IncomingConnectionCallback incoming_connection_callback) + : BaseBwuHandler(std::move(incoming_connection_callback)), + mediums_(mediums) {} // Called by BWU target. Retrieves a new medium info from incoming message, // and establishes connection over WifiLan using this info. @@ -153,7 +154,7 @@ void WifiLanBwuHandler::OnIncomingWifiLanConnection( socket), .channel = std::move(channel), }); - bwu_notifications_.incoming_connection_cb(client, std::move(connection)); + NotifyOnIncomingConnection(client, std::move(connection)); } } // namespace connections diff --git a/connections/implementation/wifi_lan_bwu_handler.h b/connections/implementation/wifi_lan_bwu_handler.h index 13d3626b..aee1ae01 100644 --- a/connections/implementation/wifi_lan_bwu_handler.h +++ b/connections/implementation/wifi_lan_bwu_handler.h @@ -29,7 +29,9 @@ namespace connections { // per-Medium-specific operations needed to upgrade an EndpointChannel. class WifiLanBwuHandler : public BaseBwuHandler { public: - explicit WifiLanBwuHandler(Mediums& mediums, BwuNotifications notifications); + explicit WifiLanBwuHandler( + Mediums& mediums, + IncomingConnectionCallback incoming_connection_callback); private: class WifiLanIncomingSocket : public BwuHandler::IncomingSocket {