1 /* 2 * Copyright 2020 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 11 #ifndef SDK_OBJC_NATIVE_SRC_OBJC_NETWORK_MONITOR_H_ 12 #define SDK_OBJC_NATIVE_SRC_OBJC_NETWORK_MONITOR_H_ 13 14 #include <vector> 15 16 #include "absl/strings/string_view.h" 17 #include "api/field_trials_view.h" 18 #include "api/sequence_checker.h" 19 #include "api/task_queue/pending_task_safety_flag.h" 20 #include "rtc_base/network_monitor.h" 21 #include "rtc_base/network_monitor_factory.h" 22 #include "rtc_base/string_utils.h" 23 #include "rtc_base/thread.h" 24 #include "rtc_base/thread_annotations.h" 25 #include "sdk/objc/components/network/RTCNetworkMonitor+Private.h" 26 #include "sdk/objc/native/src/network_monitor_observer.h" 27 28 namespace webrtc { 29 30 class ObjCNetworkMonitorFactory : public rtc::NetworkMonitorFactory { 31 public: 32 ObjCNetworkMonitorFactory() = default; 33 ~ObjCNetworkMonitorFactory() override = default; 34 35 rtc::NetworkMonitorInterface* CreateNetworkMonitor( 36 const FieldTrialsView& field_trials) override; 37 }; 38 39 class ObjCNetworkMonitor : public rtc::NetworkMonitorInterface, 40 public NetworkMonitorObserver { 41 public: 42 ObjCNetworkMonitor(); 43 ~ObjCNetworkMonitor() override; 44 45 void Start() override; 46 void Stop() override; 47 48 InterfaceInfo GetInterfaceInfo(absl::string_view interface_name) override; 49 50 // NetworkMonitorObserver override. 51 // Fans out updates to observers on the correct thread. 52 void OnPathUpdate( 53 std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp> 54 adapter_type_by_name) override; 55 56 private: 57 rtc::Thread* thread_ = nullptr; 58 bool started_ = false; 59 std::map<std::string, rtc::AdapterType, rtc::AbslStringViewCmp> 60 adapter_type_by_name_ RTC_GUARDED_BY(thread_); 61 rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag_; 62 RTCNetworkMonitor* network_monitor_ = nil; 63 }; 64 65 } // namespace webrtc 66 67 #endif // SDK_OBJC_NATIVE_SRC_OBJC_NETWORK_MONITOR_H_ 68