Add AbslParse functions for TimeMode enum. (This allows creation of TimeMode ABSL_FLAGs.)
Bug: webrtc:14145
Change-Id: Id79c4411ba4443a3ee8a0da3990c36955cc9aa35
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264821
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Auto-Submit: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37090}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 107e57d..2f46c69 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -693,6 +693,7 @@
":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 9c148a0..6956094 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 <utility>
-#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 b5c68af..fcf33d9 100644
--- a/api/test/network_emulation_manager.h
+++ b/api/test/network_emulation_manager.h
@@ -148,6 +148,16 @@
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.