| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_BASE_NETWORKMONITOR_H_ | 11 #ifndef WEBRTC_BASE_NETWORKMONITOR_H_ |
| 12 #define WEBRTC_BASE_NETWORKMONITOR_H_ | 12 #define WEBRTC_BASE_NETWORKMONITOR_H_ |
| 13 | 13 |
| 14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/base/scoped_ptr.h" | 15 #include "webrtc/base/scoped_ptr.h" |
| 16 #include "webrtc/base/sigslot.h" | 16 #include "webrtc/base/sigslot.h" |
| 17 #include "webrtc/base/thread.h" | 17 #include "webrtc/base/thread.h" |
| 18 //#include "webrtc/base/network.h" |
| 18 | 19 |
| 19 namespace rtc { | 20 namespace rtc { |
| 21 |
| 22 enum NetworkType { |
| 23 NETWORK_UNKNOWN, |
| 24 NETWORK_ETHERNET, |
| 25 NETWORK_WIFI, |
| 26 NETWORK_4G, |
| 27 NETWORK_3G, |
| 28 NETWORK_2G, |
| 29 NETWORK_BLUETOOTH, |
| 30 NETWORK_NONE |
| 31 }; |
| 32 |
| 33 struct NetworkInformation { |
| 34 std::string interface_name; |
| 35 uint32_t handle; |
| 36 NetworkType type; |
| 37 /* NetworkInformation(std::string& if_name, uint32_t net_handle, AdapterType |
| 38 net_type) { |
| 39 interface_name = if_name; |
| 40 handle = net_handle; |
| 41 type = net_type; |
| 42 }*/ |
| 43 }; |
| 20 /* | 44 /* |
| 21 * Receives network-change events via |OnNetworksChanged| and signals the | 45 * Receives network-change events via |OnNetworksChanged| and signals the |
| 22 * networks changed event. | 46 * networks changed event. |
| 23 * | 47 * |
| 24 * Threading consideration: | 48 * Threading consideration: |
| 25 * It is expected that all upstream operations (from native to Java) are | 49 * It is expected that all upstream operations (from native to Java) are |
| 26 * performed from the worker thread. This includes creating, starting and | 50 * performed from the worker thread. This includes creating, starting and |
| 27 * stopping the monitor. This avoids the potential race condition when creating | 51 * stopping the monitor. This avoids the potential race condition when creating |
| 28 * the singleton Java NetworkMonitor class. Downstream operations can be from | 52 * the singleton Java NetworkMonitor class. Downstream operations can be from |
| 29 * any thread, but this class will forward all the downstream operations onto | 53 * any thread, but this class will forward all the downstream operations onto |
| 30 * the worker thread. | 54 * the worker thread. |
| 31 * | 55 * |
| 32 * Memory consideration: | 56 * Memory consideration: |
| 33 * NetworkMonitor is owned by the caller (NetworkManager). The global network | 57 * NetworkMonitor is owned by the caller (NetworkManager). The global network |
| 34 * monitor factory is owned by the factory itself but needs to be released from | 58 * monitor factory is owned by the factory itself but needs to be released from |
| 35 * the factory creator. | 59 * the factory creator. |
| 36 */ | 60 */ |
| 37 // Generic network monitor interface. It starts and stops monitoring network | 61 // Generic network monitor interface. It starts and stops monitoring network |
| 38 // changes, and fires the SignalNetworksChanged event when networks change. | 62 // changes, and fires the SignalNetworksChanged event when networks change. |
| 39 class NetworkMonitorInterface { | 63 class NetworkMonitorInterface { |
| 40 public: | 64 public: |
| 41 NetworkMonitorInterface(); | 65 NetworkMonitorInterface(); |
| 42 virtual ~NetworkMonitorInterface(); | 66 virtual ~NetworkMonitorInterface(); |
| 43 | 67 |
| 44 sigslot::signal0<> SignalNetworksChanged; | 68 sigslot::signal0<> SignalNetworksChanged; |
| 69 sigslot::signal1<const NetworkInformation&> SignalNetworkAvailable; |
| 45 | 70 |
| 46 virtual void Start() = 0; | 71 virtual void Start() = 0; |
| 47 virtual void Stop() = 0; | 72 virtual void Stop() = 0; |
| 73 virtual bool GetAllNetworkInfos( |
| 74 std::vector<NetworkInformation>* net_infos) = 0; |
| 75 virtual void OnNetworkAvailable(const NetworkInformation& network_info) = 0; |
| 48 | 76 |
| 49 // Implementations should call this method on the base when networks change, | 77 // Implementations should call this method on the base when networks change, |
| 50 // and the base will fire SignalNetworksChanged on the right thread. | 78 // and the base will fire SignalNetworksChanged on the right thread. |
| 51 virtual void OnNetworksChanged() = 0; | 79 virtual void OnNetworksChanged() = 0; |
| 52 }; | 80 }; |
| 53 | 81 |
| 54 class NetworkMonitorBase : public NetworkMonitorInterface, | 82 class NetworkMonitorBase : public NetworkMonitorInterface, |
| 55 public MessageHandler, | 83 public MessageHandler, |
| 56 public sigslot::has_slots<> { | 84 public sigslot::has_slots<> { |
| 57 public: | 85 public: |
| 58 NetworkMonitorBase(); | 86 NetworkMonitorBase(); |
| 59 ~NetworkMonitorBase() override; | 87 ~NetworkMonitorBase() override; |
| 60 | 88 |
| 89 bool GetAllNetworkInfos(std::vector<NetworkInformation>* net_infos) override; |
| 90 |
| 61 void OnNetworksChanged() override; | 91 void OnNetworksChanged() override; |
| 92 void OnNetworkAvailable(const NetworkInformation& network_info) override; |
| 62 | 93 |
| 63 void OnMessage(Message* msg) override; | 94 void OnMessage(Message* msg) override; |
| 64 | 95 |
| 65 private: | 96 private: |
| 97 void OnNetworkAvailable_w(const NetworkInformation& network_info); |
| 66 Thread* thread_; | 98 Thread* thread_; |
| 67 }; | 99 }; |
| 68 | 100 |
| 69 /* | 101 /* |
| 70 * NetworkMonitorFactory creates NetworkMonitors. | 102 * NetworkMonitorFactory creates NetworkMonitors. |
| 71 */ | 103 */ |
| 72 class NetworkMonitorFactory { | 104 class NetworkMonitorFactory { |
| 73 public: | 105 public: |
| 74 // This is not thread-safe; it should be called once (or once per audio/video | 106 // This is not thread-safe; it should be called once (or once per audio/video |
| 75 // call) during the call initialization. | 107 // call) during the call initialization. |
| 76 static void SetFactory(NetworkMonitorFactory* factory); | 108 static void SetFactory(NetworkMonitorFactory* factory); |
| 77 | 109 |
| 78 static void ReleaseFactory(NetworkMonitorFactory* factory); | 110 static void ReleaseFactory(NetworkMonitorFactory* factory); |
| 79 static NetworkMonitorFactory* GetFactory(); | 111 static NetworkMonitorFactory* GetFactory(); |
| 80 | 112 |
| 81 virtual NetworkMonitorInterface* CreateNetworkMonitor() = 0; | 113 virtual NetworkMonitorInterface* CreateNetworkMonitor() = 0; |
| 82 | 114 |
| 83 virtual ~NetworkMonitorFactory(); | 115 virtual ~NetworkMonitorFactory(); |
| 84 | 116 |
| 85 protected: | 117 protected: |
| 86 NetworkMonitorFactory(); | 118 NetworkMonitorFactory(); |
| 87 }; | 119 }; |
| 88 | 120 |
| 89 } // namespace rtc | 121 } // namespace rtc |
| 90 | 122 |
| 91 #endif // WEBRTC_BASE_NETWORKMONITOR_H_ | 123 #endif // WEBRTC_BASE_NETWORKMONITOR_H_ |
| OLD | NEW |