Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: webrtc/base/networkmonitor.h

Issue 1556743002: Bind a socket to a network if the network handle is set. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix a compiling issue for Windows Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 typedef uint32_t NetworkHandle;
pthatcher1 2016/01/14 20:07:24 Is this ever used?
honghaiz3 2016/01/15 01:00:38 Good catch. Move this androidnetworkmonitor_jni.h
22
23 class IPAddress;
24
25 // Error values are negative.
26 enum NetworkBindingResults {
27 OK = 0, // No error
28 ERR_FAILED = -1, // Generic error
29 ERR_NOT_IMPLEMENTED = -2,
30 ERR_ADDRESS_NOT_FOUND = -3,
31 ERR_NETWORK_CHANGED = -4
32 };
33
34 class NetworkBinderInterface {
35 public:
36 // Binds a socket to the network that is attached to |address| so that all
37 // packets on the socket |socket_fd| will be sent via that network.
pthatcher1 2016/01/14 20:07:24 Can you explain why we need this (because some ope
honghaiz3 2016/01/15 01:00:38 Done.
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
30 * the worker thread. 51 * the worker thread.
31 * 52 *
32 * Memory consideration: 53 * Memory consideration:
33 * NetworkMonitor is owned by the caller (NetworkManager). The global network 54 * 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 55 * monitor factory is owned by the factory itself but needs to be released from
35 * the factory creator. 56 * the factory creator.
36 */ 57 */
37 // Generic network monitor interface. It starts and stops monitoring network 58 // Generic network monitor interface. It starts and stops monitoring network
38 // changes, and fires the SignalNetworksChanged event when networks change. 59 // changes, and fires the SignalNetworksChanged event when networks change.
39 class NetworkMonitorInterface { 60 class NetworkMonitorInterface : public NetworkBinderInterface {
40 public: 61 public:
41 NetworkMonitorInterface(); 62 NetworkMonitorInterface();
42 virtual ~NetworkMonitorInterface(); 63 virtual ~NetworkMonitorInterface();
43 64
44 sigslot::signal0<> SignalNetworksChanged; 65 sigslot::signal0<> SignalNetworksChanged;
45 66
46 virtual void Start() = 0; 67 virtual void Start() = 0;
47 virtual void Stop() = 0; 68 virtual void Stop() = 0;
48 69
49 // Implementations should call this method on the base when networks change, 70 // Implementations should call this method on the base when networks change,
50 // and the base will fire SignalNetworksChanged on the right thread. 71 // and the base will fire SignalNetworksChanged on the right thread.
51 virtual void OnNetworksChanged() = 0; 72 virtual void OnNetworksChanged() = 0;
52 }; 73 };
53 74
54 class NetworkMonitorBase : public NetworkMonitorInterface, 75 class NetworkMonitorBase : public NetworkMonitorInterface,
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
82 void Start() override;
61 void OnNetworksChanged() override; 83 void OnNetworksChanged() override;
62 84
63 void OnMessage(Message* msg) override; 85 void OnMessage(Message* msg) override;
64 86
65 private: 87 private:
66 Thread* thread_; 88 Thread* thread_;
67 }; 89 };
68 90
69 /* 91 /*
70 * NetworkMonitorFactory creates NetworkMonitors. 92 * NetworkMonitorFactory creates NetworkMonitors.
71 */ 93 */
72 class NetworkMonitorFactory { 94 class NetworkMonitorFactory {
73 public: 95 public:
74 // This is not thread-safe; it should be called once (or once per audio/video 96 // This is not thread-safe; it should be called once (or once per audio/video
75 // call) during the call initialization. 97 // call) during the call initialization.
76 static void SetFactory(NetworkMonitorFactory* factory); 98 static void SetFactory(NetworkMonitorFactory* factory);
77 99
78 static void ReleaseFactory(NetworkMonitorFactory* factory); 100 static void ReleaseFactory(NetworkMonitorFactory* factory);
79 static NetworkMonitorFactory* GetFactory(); 101 static NetworkMonitorFactory* GetFactory();
80 102
81 virtual NetworkMonitorInterface* CreateNetworkMonitor() = 0; 103 virtual NetworkMonitorInterface* GetOrCreateNetworkMonitor() = 0;
82 104
83 virtual ~NetworkMonitorFactory(); 105 virtual ~NetworkMonitorFactory();
84 106
85 protected: 107 protected:
86 NetworkMonitorFactory(); 108 NetworkMonitorFactory();
87 }; 109 };
88 110
89 } // namespace rtc 111 } // namespace rtc
90 112
91 #endif // WEBRTC_BASE_NETWORKMONITOR_H_ 113 #endif // WEBRTC_BASE_NETWORKMONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698