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}
This commit is contained in:
Mirko Bonadei
2019-06-25 15:43:23 +02:00
committed by Commit Bot
parent f03b365875
commit 04cffe3289
3 changed files with 17 additions and 18 deletions

View File

@ -727,6 +727,8 @@ if (is_linux || is_win) {
"../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") {

View File

@ -10,4 +10,7 @@ include_rules = [
"+sdk/objc",
"+system_wrappers/include",
"+third_party/libyuv",
# Abseil flags are allowed in tests and tools.
"+absl/flags",
]

View File

@ -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 @@ WEBRTC_DEFINE_string(
"--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 @@ void HandleBrowserRequest(DataSocket* ds, bool* quit) {
}
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].