| 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 | 18 |
| 19 namespace rtc { | 19 namespace rtc { |
| 20 |
| 21 class IPAddress; |
| 22 |
| 23 // Error values are negative. |
| 24 enum NetworkBindingResults { |
| 25 NETWORK_BIND_SUCCESS = 0, // No error |
| 26 NETWORK_BIND_FAILURE = -1, // Generic error |
| 27 NETWORK_BIND_NOT_IMPLEMENTED = -2, |
| 28 NETWORK_BIND_ADDRESS_NOT_FOUND = -3, |
| 29 NETWORK_BIND_NETWORK_CHANGED = -4 |
| 30 }; |
| 31 |
| 32 class NetworkBinderInterface { |
| 33 public: |
| 34 // Binds a socket to the network that is attached to |address| so that all |
| 35 // packets on the socket |socket_fd| will be sent via that network. |
| 36 // This is needed because some operating systems (like Android) require a |
| 37 // special bind call to put packets on a non-default network interface. |
| 38 virtual int BindSocketToNetwork(int socket_fd, const IPAddress& address) = 0; |
| 39 }; |
| 40 |
| 20 /* | 41 /* |
| 21 * Receives network-change events via |OnNetworksChanged| and signals the | 42 * Receives network-change events via |OnNetworksChanged| and signals the |
| 22 * networks changed event. | 43 * networks changed event. |
| 23 * | 44 * |
| 24 * Threading consideration: | 45 * Threading consideration: |
| 25 * It is expected that all upstream operations (from native to Java) are | 46 * It is expected that all upstream operations (from native to Java) are |
| 26 * performed from the worker thread. This includes creating, starting and | 47 * performed from the worker thread. This includes creating, starting and |
| 27 * stopping the monitor. This avoids the potential race condition when creating | 48 * stopping the monitor. This avoids the potential race condition when creating |
| 28 * the singleton Java NetworkMonitor class. Downstream operations can be from | 49 * the singleton Java NetworkMonitor class. Downstream operations can be from |
| 29 * any thread, but this class will forward all the downstream operations onto | 50 * any thread, but this class will forward all the downstream operations onto |
| (...skipping 25 matching lines...) Expand all Loading... |
| 55 public MessageHandler, | 76 public MessageHandler, |
| 56 public sigslot::has_slots<> { | 77 public sigslot::has_slots<> { |
| 57 public: | 78 public: |
| 58 NetworkMonitorBase(); | 79 NetworkMonitorBase(); |
| 59 ~NetworkMonitorBase() override; | 80 ~NetworkMonitorBase() override; |
| 60 | 81 |
| 61 void OnNetworksChanged() override; | 82 void OnNetworksChanged() override; |
| 62 | 83 |
| 63 void OnMessage(Message* msg) override; | 84 void OnMessage(Message* msg) override; |
| 64 | 85 |
| 86 protected: |
| 87 Thread* worker_thread() { return worker_thread_; } |
| 88 |
| 65 private: | 89 private: |
| 66 Thread* thread_; | 90 Thread* worker_thread_; |
| 67 }; | 91 }; |
| 68 | 92 |
| 69 /* | 93 /* |
| 70 * NetworkMonitorFactory creates NetworkMonitors. | 94 * NetworkMonitorFactory creates NetworkMonitors. |
| 71 */ | 95 */ |
| 72 class NetworkMonitorFactory { | 96 class NetworkMonitorFactory { |
| 73 public: | 97 public: |
| 74 // This is not thread-safe; it should be called once (or once per audio/video | 98 // This is not thread-safe; it should be called once (or once per audio/video |
| 75 // call) during the call initialization. | 99 // call) during the call initialization. |
| 76 static void SetFactory(NetworkMonitorFactory* factory); | 100 static void SetFactory(NetworkMonitorFactory* factory); |
| 77 | 101 |
| 78 static void ReleaseFactory(NetworkMonitorFactory* factory); | 102 static void ReleaseFactory(NetworkMonitorFactory* factory); |
| 79 static NetworkMonitorFactory* GetFactory(); | 103 static NetworkMonitorFactory* GetFactory(); |
| 80 | 104 |
| 81 virtual NetworkMonitorInterface* CreateNetworkMonitor() = 0; | 105 virtual NetworkMonitorInterface* CreateNetworkMonitor() = 0; |
| 82 | 106 |
| 83 virtual ~NetworkMonitorFactory(); | 107 virtual ~NetworkMonitorFactory(); |
| 84 | 108 |
| 85 protected: | 109 protected: |
| 86 NetworkMonitorFactory(); | 110 NetworkMonitorFactory(); |
| 87 }; | 111 }; |
| 88 | 112 |
| 89 } // namespace rtc | 113 } // namespace rtc |
| 90 | 114 |
| 91 #endif // WEBRTC_BASE_NETWORKMONITOR_H_ | 115 #endif // WEBRTC_BASE_NETWORKMONITOR_H_ |
| OLD | NEW |