minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "rtc_tools/network_tester/config_reader.h" |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 11 | |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
Danil Chapovalov | 6e9d895 | 2018-04-09 20:30:51 +0200 | [diff] [blame] | 15 | #include "rtc_base/checks.h" |
| 16 | |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
| 19 | ConfigReader::ConfigReader(const std::string& config_file_path) |
| 20 | : proto_config_index_(0) { |
| 21 | std::ifstream config_stream(config_file_path, |
| 22 | std::ios_base::in | std::ios_base::binary); |
| 23 | RTC_DCHECK(config_stream.is_open()); |
| 24 | RTC_DCHECK(config_stream.good()); |
| 25 | std::string config_data((std::istreambuf_iterator<char>(config_stream)), |
| 26 | (std::istreambuf_iterator<char>())); |
| 27 | if (config_data.size() > 0) { |
| 28 | proto_all_configs_.ParseFromString(config_data); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | ConfigReader::~ConfigReader() = default; |
| 33 | |
| 34 | rtc::Optional<ConfigReader::Config> ConfigReader::GetNextConfig() { |
| 35 | #ifdef WEBRTC_NETWORK_TESTER_PROTO |
| 36 | if (proto_config_index_ >= proto_all_configs_.configs_size()) |
Oskar Sundbom | 59dd482 | 2017-11-16 10:55:27 +0100 | [diff] [blame] | 37 | return rtc::nullopt; |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 38 | auto proto_config = proto_all_configs_.configs(proto_config_index_++); |
| 39 | RTC_DCHECK(proto_config.has_packet_send_interval_ms()); |
| 40 | RTC_DCHECK(proto_config.has_packet_size()); |
| 41 | RTC_DCHECK(proto_config.has_execution_time_ms()); |
| 42 | Config config; |
| 43 | config.packet_send_interval_ms = proto_config.packet_send_interval_ms(); |
| 44 | config.packet_size = proto_config.packet_size(); |
| 45 | config.execution_time_ms = proto_config.execution_time_ms(); |
Oskar Sundbom | 59dd482 | 2017-11-16 10:55:27 +0100 | [diff] [blame] | 46 | return config; |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 47 | #else |
Oskar Sundbom | 59dd482 | 2017-11-16 10:55:27 +0100 | [diff] [blame] | 48 | return rtc::nullopt; |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 49 | #endif // WEBRTC_NETWORK_TESTER_PROTO |
| 50 | } |
| 51 | |
| 52 | } // namespace webrtc |