From b22cabcf768c20ef8784392ce0310a2775272247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Terelius?= Date: Thu, 2 Jun 2022 10:51:59 +0200 Subject: [PATCH] Add AbslParse functions for TimeMode enum. (This allows creation of TimeMode ABSL_FLAGs.) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:14145 Change-Id: Id79c4411ba4443a3ee8a0da3990c36955cc9aa35 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264821 Commit-Queue: Björn Terelius Auto-Submit: Björn Terelius Reviewed-by: Mirko Bonadei Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#37090} --- api/BUILD.gn | 1 + api/test/network_emulation_manager.cc | 29 ++++++++++++++++++++++++++- api/test/network_emulation_manager.h | 10 +++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/api/BUILD.gn b/api/BUILD.gn index 107e57db5a..2f46c6931b 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -693,6 +693,7 @@ rtc_source_set("network_emulation_manager_api") { ":time_controller", "../call:simulated_network", "../rtc_base", + "../rtc_base:checks", "../rtc_base:network_constants", "../rtc_base:threading", "test/network_emulation", diff --git a/api/test/network_emulation_manager.cc b/api/test/network_emulation_manager.cc index 9c148a069b..6956094aa4 100644 --- a/api/test/network_emulation_manager.cc +++ b/api/test/network_emulation_manager.cc @@ -7,13 +7,40 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include "api/test/network_emulation_manager.h" + #include -#include "api/test/network_emulation_manager.h" #include "call/simulated_network.h" +#include "rtc_base/checks.h" namespace webrtc { +bool AbslParseFlag(absl::string_view text, TimeMode* mode, std::string* error) { + if (text == "realtime") { + *mode = TimeMode::kRealTime; + return true; + } + if (text == "simulated") { + *mode = TimeMode::kSimulated; + return true; + } + *error = + "Unknown value for TimeMode enum. Options are 'realtime' or 'simulated'"; + return false; +} + +std::string AbslUnparseFlag(TimeMode mode) { + switch (mode) { + case TimeMode::kRealTime: + return "realtime"; + case TimeMode::kSimulated: + return "simulated"; + } + RTC_CHECK_NOTREACHED(); + return "unknown"; +} + NetworkEmulationManager::SimulatedNetworkNode::Builder& NetworkEmulationManager::SimulatedNetworkNode::Builder::config( BuiltInNetworkBehaviorConfig config) { diff --git a/api/test/network_emulation_manager.h b/api/test/network_emulation_manager.h index b5c68af5f3..fcf33d947b 100644 --- a/api/test/network_emulation_manager.h +++ b/api/test/network_emulation_manager.h @@ -148,6 +148,16 @@ class EmulatedNetworkManagerInterface { enum class TimeMode { kRealTime, kSimulated }; +// Called implicitly when parsing an ABSL_FLAG of type TimeMode. +// from the command line flag value `text`. +// Returns `true` and sets `*mode` on success; +// returns `false` and sets `*error` on failure. +bool AbslParseFlag(absl::string_view text, TimeMode* mode, std::string* error); + +// AbslUnparseFlag returns a textual flag value corresponding to the TimeMode +// `mode`. +std::string AbslUnparseFlag(TimeMode mode); + // Provides an API for creating and configuring emulated network layer. // All objects returned by this API are owned by NetworkEmulationManager itself // and will be deleted when manager will be deleted.