blob: ed76a3fcf79ff107aa5c975bba6ff13b0773e291 [file] [log] [blame]
minyue939df962017-04-19 01:58:38 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020010#include "rtc_tools/network_tester/config_reader.h"
minyue939df962017-04-19 01:58:38 -070011
Yves Gerey3e707812018-11-28 16:47:49 +010012#include <fstream>
13#include <iterator>
minyue939df962017-04-19 01:58:38 -070014#include <string>
minyue939df962017-04-19 01:58:38 -070015
Danil Chapovalov6e9d8952018-04-09 20:30:51 +020016#include "rtc_base/checks.h"
17
minyue939df962017-04-19 01:58:38 -070018namespace webrtc {
19
20ConfigReader::ConfigReader(const std::string& config_file_path)
21 : proto_config_index_(0) {
22 std::ifstream config_stream(config_file_path,
23 std::ios_base::in | std::ios_base::binary);
24 RTC_DCHECK(config_stream.is_open());
25 RTC_DCHECK(config_stream.good());
26 std::string config_data((std::istreambuf_iterator<char>(config_stream)),
27 (std::istreambuf_iterator<char>()));
28 if (config_data.size() > 0) {
29 proto_all_configs_.ParseFromString(config_data);
30 }
31}
32
33ConfigReader::~ConfigReader() = default;
34
Danil Chapovalov431abd92018-06-18 12:54:17 +020035absl::optional<ConfigReader::Config> ConfigReader::GetNextConfig() {
minyue939df962017-04-19 01:58:38 -070036#ifdef WEBRTC_NETWORK_TESTER_PROTO
37 if (proto_config_index_ >= proto_all_configs_.configs_size())
Danil Chapovalov431abd92018-06-18 12:54:17 +020038 return absl::nullopt;
minyue939df962017-04-19 01:58:38 -070039 auto proto_config = proto_all_configs_.configs(proto_config_index_++);
40 RTC_DCHECK(proto_config.has_packet_send_interval_ms());
41 RTC_DCHECK(proto_config.has_packet_size());
42 RTC_DCHECK(proto_config.has_execution_time_ms());
43 Config config;
44 config.packet_send_interval_ms = proto_config.packet_send_interval_ms();
45 config.packet_size = proto_config.packet_size();
46 config.execution_time_ms = proto_config.execution_time_ms();
Oskar Sundbom59dd4822017-11-16 10:55:27 +010047 return config;
minyue939df962017-04-19 01:58:38 -070048#else
Danil Chapovalov431abd92018-06-18 12:54:17 +020049 return absl::nullopt;
minyue939df962017-04-19 01:58:38 -070050#endif // WEBRTC_NETWORK_TESTER_PROTO
51}
52
53} // namespace webrtc