OLD | NEW |
---|---|
(Empty) | |
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 */ | |
10 #include "webrtc/tools/network_tester/config_reader.h" | |
11 | |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 #include "webrtc/base/ignore_wundef.h" | |
16 #include "webrtc/base/logging.h" | |
17 | |
18 #ifdef WEBRTC_NETWORK_TESTER_PROTO | |
19 RTC_PUSH_IGNORING_WUNDEF() | |
20 #include "webrtc/tools/network_tester/network_tester_config.pb.h" | |
21 RTC_POP_IGNORING_WUNDEF() | |
22 #endif // WEBRTC_NETWORK_TESTER_PROTO | |
23 | |
24 namespace webrtc { | |
25 | |
26 namespace { | |
27 rtc::Optional<int> ParseMessageSize(std::istream& config_stream) { | |
28 int byte = config_stream.get(); | |
29 if (config_stream.eof()) { | |
30 return rtc::Optional<int>(); | |
31 } | |
32 RTC_DCHECK(0 <= byte && byte <= 255); | |
minyue-webrtc
2017/04/03 08:05:19
nit
RTC_DCHECK_LE
RTC_DCHECK_GE
for better error m
michaelt
2017/04/03 13:05:39
Done.
| |
33 return rtc::Optional<int>(byte); | |
34 } | |
35 } | |
36 | |
37 ConfigReader::ConfigReader(const std::string& config_file_path) | |
38 : config_stream_(config_file_path, | |
39 std::ios_base::in | std::ios_base::binary) { | |
40 RTC_DCHECK(config_stream_.is_open()); | |
41 RTC_DCHECK(config_stream_.good()); | |
42 } | |
43 | |
44 ConfigReader::~ConfigReader() = default; | |
45 | |
46 rtc::Optional<ConfigReader::Config> ConfigReader::GetNextConfig() { | |
47 #ifdef WEBRTC_NETWORK_TESTER_PROTO | |
48 auto message_size = ParseMessageSize(config_stream_); | |
49 if (!message_size) | |
50 return rtc::Optional<Config>(); | |
51 constexpr size_t kMaxEventSize = (1u << 16) - 1; | |
52 std::vector<char> message_buffer(kMaxEventSize); | |
53 config_stream_.read(message_buffer.data(), *message_size); | |
54 RTC_DCHECK_EQ(config_stream_.gcount(), *message_size); | |
55 webrtc::network_tester::config::NetworkTesterConfig proto_config; | |
56 if (!proto_config.ParseFromArray(message_buffer.data(), *message_size)) | |
57 return rtc::Optional<Config>(); | |
58 RTC_DCHECK(proto_config.has_packet_send_interval_ms()); | |
59 RTC_DCHECK(proto_config.has_packet_size()); | |
60 RTC_DCHECK(proto_config.has_execution_time_ms()); | |
61 Config config; | |
62 config.packet_send_interval_ms = proto_config.packet_send_interval_ms(); | |
63 config.packet_size = proto_config.packet_size(); | |
64 config.execution_time_ms = proto_config.execution_time_ms(); | |
65 return rtc::Optional<Config>(config); | |
66 #else | |
67 return rtc::Optional<Config>(); | |
68 #endif // WEBRTC_NETWORK_TESTER_PROTO | |
69 } | |
70 | |
71 } // namespace webrtc | |
OLD | NEW |