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.