Switch example peerconnection server to ABSL_FLAG.
TBR=kwiberg@webrtc.org
Bug: webrtc:10616
Change-Id: I611f6f67c5473b7f7ef623fa788e5403e7a8001a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/143790
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28373}
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index eed9222..fdff31a 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -727,6 +727,8 @@
"../rtc_tools:command_line_parser",
"../system_wrappers:field_trial",
"../test:field_trial",
+ "//third_party/abseil-cpp/absl/flags:flag",
+ "//third_party/abseil-cpp/absl/flags:parse",
]
}
rtc_executable("relayserver") {
diff --git a/examples/DEPS b/examples/DEPS
index 114cda3..1604a6a 100644
--- a/examples/DEPS
+++ b/examples/DEPS
@@ -10,4 +10,7 @@
"+sdk/objc",
"+system_wrappers/include",
"+third_party/libyuv",
+
+ # Abseil flags are allowed in tests and tools.
+ "+absl/flags",
]
diff --git a/examples/peerconnection/server/main.cc b/examples/peerconnection/server/main.cc
index 79b2c2c..9be7685 100644
--- a/examples/peerconnection/server/main.cc
+++ b/examples/peerconnection/server/main.cc
@@ -19,14 +19,15 @@
#include <string>
#include <vector>
+#include "absl/flags/flag.h"
+#include "absl/flags/parse.h"
#include "examples/peerconnection/server/data_socket.h"
#include "examples/peerconnection/server/peer_channel.h"
-#include "rtc_base/flags.h"
-#include "rtc_tools/simple_command_line_parser.h"
#include "system_wrappers/include/field_trial.h"
#include "test/field_trial.h"
-WEBRTC_DEFINE_string(
+ABSL_FLAG(
+ std::string,
force_fieldtrials,
"",
"Field trials control experimental features. This flag specifies the field "
@@ -34,6 +35,7 @@
"--force_fieldtrials=WebRTC-FooFeature/Enabled/ "
"will assign the group Enabled to field trial WebRTC-FooFeature. Multiple "
"trials are separated by \"/\"");
+ABSL_FLAG(int, port, 8888, "default: 8888");
static const size_t kMaxConnections = (FD_SETSIZE - 2);
@@ -63,25 +65,17 @@
}
int main(int argc, char* argv[]) {
- std::string program_name = argv[0];
- std::string usage = "Example usage: " + program_name + " --port=8888";
- webrtc::test::CommandLineParser parser;
- parser.Init(argc, argv);
- parser.SetUsageMessage(usage);
- parser.SetFlag("port", "8888");
- parser.SetFlag("help", "false");
- parser.ProcessFlags();
-
- if (parser.GetFlag("help") == "true") {
- parser.PrintUsageMessage();
- return 0;
- }
+ absl::ParseCommandLine(argc, argv);
+ // TODO(bugs.webrtc.org/10616): Add program usage message when Abseil
+ // flags supports it.
+ // std::string usage = "Example usage: " + program_name + " --port=8888";
// InitFieldTrialsFromString stores the char*, so the char array must outlive
// the application.
- webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
+ webrtc::field_trial::InitFieldTrialsFromString(
+ absl::GetFlag(FLAGS_force_fieldtrials).c_str());
- int port = strtol((parser.GetFlag("port")).c_str(), NULL, 10);
+ int port = absl::GetFlag(FLAGS_port);
// Abort if the user specifies a port that is outside the allowed
// range [1, 65535].