mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
[sigslot] - Remove sigslot form NetworkMonitorInterface.
Bug: webrtc:11943 Change-Id: Iddedb2840e437dfbffcb0d6cbf71a09b0030fbab Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226869 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34573}
This commit is contained in:
parent
9b6cd191ef
commit
3707793a57
5 changed files with 30 additions and 12 deletions
|
@ -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()) {
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
#ifndef RTC_BASE_NETWORK_MONITOR_H_
|
||||
#define RTC_BASE_NETWORK_MONITOR_H_
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#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<void()> callback) {
|
||||
networks_changed_callback_ = std::move(callback);
|
||||
}
|
||||
|
||||
protected:
|
||||
void InvokeNetworksChangedCallback() {
|
||||
if (networks_changed_callback_) {
|
||||
networks_changed_callback_();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void()> networks_changed_callback_;
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
|
|
@ -100,6 +100,10 @@ class FakeNetworkMonitor : public NetworkMonitorInterface {
|
|||
|
||||
void set_adapters(std::vector<std::string> adapters) { adapters_ = adapters; }
|
||||
|
||||
void InovkeNetworksChangedCallbackForTesting() {
|
||||
InvokeNetworksChangedCallback();
|
||||
}
|
||||
|
||||
private:
|
||||
bool started_ = false;
|
||||
std::vector<std::string> 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.
|
||||
|
|
|
@ -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<NetworkHandle>
|
||||
|
@ -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();
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue