blob: 4e50e662dad86986bfa0b62bd32c486088825e3d [file] [log] [blame]
Artem Titove5cc85b2019-03-28 12:11:09 +01001/*
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 Titov386802e2019-07-05 10:48:17 +020011#ifndef TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_
12#define TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_
Artem Titove5cc85b2019-03-28 12:11:09 +010013
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 Titov386802e2019-07-05 10:48:17 +020024#include "test/network/fake_network_socket_server.h"
25#include "test/network/network_emulation.h"
Artem Titove5cc85b2019-03-28 12:11:09 +010026
27namespace webrtc {
28namespace test {
29
30// Framework assumes that rtc::NetworkManager is called from network thread.
31class EmulatedNetworkManager : public rtc::NetworkManagerBase,
32 public sigslot::has_slots<>,
33 public EmulatedNetworkManagerInterface {
34 public:
Artem Titov806299e2019-04-12 12:17:19 +020035 EmulatedNetworkManager(Clock* clock,
36 TaskQueueForTest* task_queue,
37 EndpointsContainer* endpoints_container);
Artem Titove5cc85b2019-03-28 12:11:09 +010038
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 Titov806299e2019-04-12 12:17:19 +020050 void GetStats(
51 std::function<void(EmulatedNetworkStats)> stats_callback) const override;
Artem Titove5cc85b2019-03-28 12:11:09 +010052
53 private:
54 void UpdateNetworksOnce();
55 void MaybeSignalNetworksChanged();
56
Artem Titov806299e2019-04-12 12:17:19 +020057 TaskQueueForTest* const task_queue_;
Artem Titovbdecb3c2019-03-29 15:20:23 +010058 EndpointsContainer* const endpoints_container_;
Artem Titove5cc85b2019-03-28 12:11:09 +010059 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 Titov386802e2019-07-05 10:48:17 +020069#endif // TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_