blob: 4eb52901f3cf10c5bbbb9aef1922203b9d03414a [file] [log] [blame]
honghaiz023f3ef2015-10-19 09:39:32 -07001/*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#include "rtc_base/network_monitor.h"
honghaiz023f3ef2015-10-19 09:39:32 -070012
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stdint.h>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/checks.h"
Yves Gerey988cc082018-10-23 12:03:01 +020016#include "rtc_base/location.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020017#include "rtc_base/logging.h"
honghaiz023f3ef2015-10-19 09:39:32 -070018
19namespace {
20const uint32_t UPDATE_NETWORKS_MESSAGE = 1;
21
22// This is set by NetworkMonitorFactory::SetFactory and the caller of
23// NetworkMonitorFactory::SetFactory must be responsible for calling
24// ReleaseFactory to destroy the factory.
25rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
26} // namespace
27
28namespace rtc {
29NetworkMonitorInterface::NetworkMonitorInterface() {}
30
31NetworkMonitorInterface::~NetworkMonitorInterface() {}
32
honghaizcec0a082016-01-15 14:49:09 -080033NetworkMonitorBase::NetworkMonitorBase() : worker_thread_(Thread::Current()) {}
honghaiz023f3ef2015-10-19 09:39:32 -070034NetworkMonitorBase::~NetworkMonitorBase() {}
35
36void NetworkMonitorBase::OnNetworksChanged() {
Mirko Bonadei675513b2017-11-09 11:09:25 +010037 RTC_LOG(LS_VERBOSE) << "Network change is received at the network monitor";
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -070038 worker_thread_->Post(RTC_FROM_HERE, this, UPDATE_NETWORKS_MESSAGE);
honghaiz023f3ef2015-10-19 09:39:32 -070039}
40
41void NetworkMonitorBase::OnMessage(Message* msg) {
nisseede5da42017-01-12 05:15:36 -080042 RTC_DCHECK(msg->message_id == UPDATE_NETWORKS_MESSAGE);
honghaiz023f3ef2015-10-19 09:39:32 -070043 SignalNetworksChanged();
44}
45
Qingsi Wangde2ed7d2018-04-27 14:25:37 -070046AdapterType NetworkMonitorBase::GetVpnUnderlyingAdapterType(
47 const std::string& interface_name) {
48 return ADAPTER_TYPE_UNKNOWN;
49}
50
honghaiz023f3ef2015-10-19 09:39:32 -070051NetworkMonitorFactory::NetworkMonitorFactory() {}
52NetworkMonitorFactory::~NetworkMonitorFactory() {}
53
54void NetworkMonitorFactory::SetFactory(NetworkMonitorFactory* factory) {
55 if (network_monitor_factory != nullptr) {
56 delete network_monitor_factory;
57 }
58 network_monitor_factory = factory;
59}
60
61void NetworkMonitorFactory::ReleaseFactory(NetworkMonitorFactory* factory) {
62 if (factory == network_monitor_factory) {
63 SetFactory(nullptr);
64 }
65}
66
67NetworkMonitorFactory* NetworkMonitorFactory::GetFactory() {
68 return network_monitor_factory;
69}
70
71} // namespace rtc