diff --git a/rtc_base/network.cc b/rtc_base/network.cc index f4a349bae0..a22d8ffbe4 100644 --- a/rtc_base/network.cc +++ b/rtc_base/network.cc @@ -863,8 +863,8 @@ void BasicNetworkManager::StartNetworkMonitor() { if (!network_monitor_) { return; } - network_monitor_->SignalNetworksChanged.connect( - this, &BasicNetworkManager::OnNetworksChanged); + network_monitor_->SetNetworksChangedCallback( + [this]() { OnNetworksChanged(); }); } if (network_monitor_->SupportsBindSocketToNetwork()) { diff --git a/rtc_base/network_monitor.h b/rtc_base/network_monitor.h index dddc2f60f4..1e150fe861 100644 --- a/rtc_base/network_monitor.h +++ b/rtc_base/network_monitor.h @@ -11,8 +11,10 @@ #ifndef RTC_BASE_NETWORK_MONITOR_H_ #define RTC_BASE_NETWORK_MONITOR_H_ +#include +#include + #include "rtc_base/network_constants.h" -#include "rtc_base/third_party/sigslot/sigslot.h" namespace rtc { @@ -73,8 +75,6 @@ class NetworkMonitorInterface { NetworkMonitorInterface(); virtual ~NetworkMonitorInterface(); - sigslot::signal0<> SignalNetworksChanged; - virtual void Start() = 0; virtual void Stop() = 0; @@ -110,6 +110,20 @@ class NetworkMonitorInterface { virtual bool IsAdapterAvailable(const std::string& interface_name) { return true; } + + void SetNetworksChangedCallback(std::function callback) { + networks_changed_callback_ = std::move(callback); + } + + protected: + void InvokeNetworksChangedCallback() { + if (networks_changed_callback_) { + networks_changed_callback_(); + } + } + + private: + std::function networks_changed_callback_; }; } // namespace rtc diff --git a/rtc_base/network_unittest.cc b/rtc_base/network_unittest.cc index 75856634ab..01e18af7f8 100644 --- a/rtc_base/network_unittest.cc +++ b/rtc_base/network_unittest.cc @@ -100,6 +100,10 @@ class FakeNetworkMonitor : public NetworkMonitorInterface { void set_adapters(std::vector adapters) { adapters_ = adapters; } + void InovkeNetworksChangedCallbackForTesting() { + InvokeNetworksChangedCallback(); + } + private: bool started_ = false; std::vector adapters_; @@ -1128,7 +1132,7 @@ TEST_F(NetworkTest, TestNetworkMonitoring) { ClearNetworks(manager); // Network manager is started, so the callback is called when the network // monitor fires the network-change event. - network_monitor->SignalNetworksChanged(); + network_monitor->InovkeNetworksChangedCallbackForTesting(); EXPECT_TRUE_WAIT(callback_called_, 1000); // Network manager is stopped. diff --git a/sdk/android/src/jni/android_network_monitor.cc b/sdk/android/src/jni/android_network_monitor.cc index 088ca47f41..08b77fe099 100644 --- a/sdk/android/src/jni/android_network_monitor.cc +++ b/sdk/android/src/jni/android_network_monitor.cc @@ -267,8 +267,8 @@ void AndroidNetworkMonitor::Stop() { started_ = false; find_network_handle_without_ipv6_temporary_part_ = false; - // Cancel any pending tasks. We should not call SignalNetworksChanged when the - // monitor is stopped. + // Cancel any pending tasks. We should not call + // `InvokeNetworksChangedCallback()` when the monitor is stopped. safety_flag_->SetNotAlive(); JNIEnv* env = AttachCurrentThreadIfNeeded(); @@ -411,7 +411,7 @@ void AndroidNetworkMonitor::OnNetworkConnected_n( for (const rtc::IPAddress& address : network_info.ip_addresses) { network_handle_by_address_[address] = network_info.handle; } - SignalNetworksChanged(); + InvokeNetworksChangedCallback(); } absl::optional @@ -479,7 +479,7 @@ void AndroidNetworkMonitor::OnNetworkPreference_n( << rtc::NetworkPreferenceToString(preference); auto adapter_type = AdapterTypeFromNetworkType(type, surface_cellular_types_); network_preference_by_adapter_type_[adapter_type] = preference; - SignalNetworksChanged(); + InvokeNetworksChangedCallback(); } void AndroidNetworkMonitor::SetNetworkInfos( @@ -586,7 +586,7 @@ void AndroidNetworkMonitor::NotifyConnectionTypeChanged( network_thread_->PostTask(ToQueuedTask(safety_flag_, [this] { RTC_LOG(LS_INFO) << "Android network monitor detected connection type change."; - SignalNetworksChanged(); + InvokeNetworksChangedCallback(); })); } diff --git a/sdk/objc/native/src/objc_network_monitor.mm b/sdk/objc/native/src/objc_network_monitor.mm index e85bb8b6a4..2fc84dfa51 100644 --- a/sdk/objc/native/src/objc_network_monitor.mm +++ b/sdk/objc/native/src/objc_network_monitor.mm @@ -87,7 +87,7 @@ void ObjCNetworkMonitor::OnPathUpdate( thread_->PostTask(ToQueuedTask(safety_flag_, [this, adapter_type_by_name] { RTC_DCHECK_RUN_ON(thread_); adapter_type_by_name_ = adapter_type_by_name; - SignalNetworksChanged(); + InvokeNetworksChangedCallback(); })); }