Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +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 | |
| 11 | #ifndef TEST_PC_E2E_STATS_POLLER_H_ |
| 12 | #define TEST_PC_E2E_STATS_POLLER_H_ |
| 13 | |
| 14 | #include <map> |
| 15 | #include <string> |
| 16 | #include <utility> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "api/peer_connection_interface.h" |
Artem Titov | d57628f | 2019-03-22 12:34:25 +0100 | [diff] [blame] | 20 | #include "api/test/stats_observer_interface.h" |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 21 | #include "test/pc/e2e/test_peer.h" |
| 22 | |
| 23 | namespace webrtc { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 24 | namespace webrtc_pc_e2e { |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 25 | |
| 26 | // Helper class that will notify all the webrtc::test::StatsObserverInterface |
| 27 | // objects subscribed. |
| 28 | class InternalStatsObserver : public StatsObserver { |
| 29 | public: |
| 30 | InternalStatsObserver(std::string pc_label, |
| 31 | TestPeer* peer, |
| 32 | std::vector<StatsObserverInterface*> observers) |
| 33 | : pc_label_(std::move(pc_label)), |
| 34 | peer_(peer), |
| 35 | observers_(std::move(observers)) {} |
| 36 | |
| 37 | void PollStats(); |
| 38 | |
| 39 | void OnComplete(const StatsReports& reports) override; |
| 40 | |
| 41 | private: |
| 42 | std::string pc_label_; |
| 43 | TestPeer* peer_; |
| 44 | std::vector<StatsObserverInterface*> observers_; |
| 45 | }; |
| 46 | |
| 47 | // Helper class to invoke GetStats on a PeerConnection by passing a |
| 48 | // webrtc::StatsObserver that will notify all the |
| 49 | // webrtc::test::StatsObserverInterface subscribed. |
| 50 | class StatsPoller { |
| 51 | public: |
| 52 | StatsPoller(std::vector<StatsObserverInterface*> observers, |
| 53 | std::map<std::string, TestPeer*> peers_to_observe); |
| 54 | |
| 55 | void PollStatsAndNotifyObservers(); |
| 56 | |
| 57 | private: |
| 58 | std::vector<rtc::scoped_refptr<InternalStatsObserver>> pollers_; |
| 59 | }; |
| 60 | |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 61 | } // namespace webrtc_pc_e2e |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 62 | } // namespace webrtc |
| 63 | |
| 64 | #endif // TEST_PC_E2E_STATS_POLLER_H_ |