Artem Titov | e5cc85b | 2019-03-28 12:11:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 | |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 11 | #ifndef TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_ |
| 12 | #define TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_ |
Artem Titov | e5cc85b | 2019-03-28 12:11:09 +0100 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
| 17 | #include "api/test/network_emulation_manager.h" |
| 18 | #include "rtc_base/critical_section.h" |
| 19 | #include "rtc_base/ip_address.h" |
| 20 | #include "rtc_base/network.h" |
| 21 | #include "rtc_base/socket_server.h" |
| 22 | #include "rtc_base/thread.h" |
| 23 | #include "rtc_base/thread_checker.h" |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 24 | #include "test/network/fake_network_socket_server.h" |
| 25 | #include "test/network/network_emulation.h" |
Artem Titov | e5cc85b | 2019-03-28 12:11:09 +0100 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | namespace test { |
| 29 | |
| 30 | // Framework assumes that rtc::NetworkManager is called from network thread. |
| 31 | class EmulatedNetworkManager : public rtc::NetworkManagerBase, |
| 32 | public sigslot::has_slots<>, |
| 33 | public EmulatedNetworkManagerInterface { |
| 34 | public: |
Artem Titov | 806299e | 2019-04-12 12:17:19 +0200 | [diff] [blame] | 35 | EmulatedNetworkManager(Clock* clock, |
| 36 | TaskQueueForTest* task_queue, |
| 37 | EndpointsContainer* endpoints_container); |
Artem Titov | e5cc85b | 2019-03-28 12:11:09 +0100 | [diff] [blame] | 38 | |
| 39 | void EnableEndpoint(EmulatedEndpoint* endpoint); |
| 40 | void DisableEndpoint(EmulatedEndpoint* endpoint); |
| 41 | |
| 42 | // NetworkManager interface. All these methods are supposed to be called from |
| 43 | // the same thread. |
| 44 | void StartUpdating() override; |
| 45 | void StopUpdating() override; |
| 46 | |
| 47 | // EmulatedNetworkManagerInterface API |
| 48 | rtc::Thread* network_thread() override { return &network_thread_; } |
| 49 | rtc::NetworkManager* network_manager() override { return this; } |
Artem Titov | 806299e | 2019-04-12 12:17:19 +0200 | [diff] [blame] | 50 | void GetStats( |
| 51 | std::function<void(EmulatedNetworkStats)> stats_callback) const override; |
Artem Titov | e5cc85b | 2019-03-28 12:11:09 +0100 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | void UpdateNetworksOnce(); |
| 55 | void MaybeSignalNetworksChanged(); |
| 56 | |
Artem Titov | 806299e | 2019-04-12 12:17:19 +0200 | [diff] [blame] | 57 | TaskQueueForTest* const task_queue_; |
Artem Titov | bdecb3c | 2019-03-29 15:20:23 +0100 | [diff] [blame] | 58 | EndpointsContainer* const endpoints_container_; |
Artem Titov | e5cc85b | 2019-03-28 12:11:09 +0100 | [diff] [blame] | 59 | FakeNetworkSocketServer socket_server_; |
| 60 | rtc::Thread network_thread_; |
| 61 | |
| 62 | bool sent_first_update_ RTC_GUARDED_BY(network_thread_); |
| 63 | int start_count_ RTC_GUARDED_BY(network_thread_); |
| 64 | }; |
| 65 | |
| 66 | } // namespace test |
| 67 | } // namespace webrtc |
| 68 | |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 69 | #endif // TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_ |