Implement command line flags for peerconnection client example on Windows

Adding the flags and functionality for 'autoconnect', 'autocall', 'server',
'port', and 'help' like in the linux example.

BUG=3459
R=tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/13609004

Patch from Vicken Simonian <vsimon@gmail.com>.

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6573 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kjellander@webrtc.org 2014-07-01 16:28:13 +00:00
parent 9138eb649b
commit 0402515d35
4 changed files with 52 additions and 6 deletions

View File

@ -14,6 +14,7 @@ Paul Kapustin <pkapustin@gmail.com>
Rafael Lopez Diez <rafalopezdiez@gmail.com>
Robert Nagy
Silviu Caragea <silviu.cpp@gmail.com>
Vicken Simonian <vsimon@gmail.com>
Victor Costan <costan@gmail.com>
Google Inc.

View File

@ -26,6 +26,7 @@
*/
#include "talk/examples/peerconnection/client/conductor.h"
#include "talk/examples/peerconnection/client/flagdefs.h"
#include "talk/examples/peerconnection/client/main_wnd.h"
#include "talk/examples/peerconnection/client/peer_connection_client.h"
#include "talk/base/ssladapter.h"
@ -39,7 +40,24 @@ int PASCAL wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
talk_base::Win32Thread w32_thread;
talk_base::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
MainWnd wnd;
WindowsCommandLineArguments win_args;
int argc = win_args.argc();
char **argv = win_args.argv();
FlagList::SetFlagsFromCommandLine(&argc, argv, true);
if (FLAG_help) {
FlagList::Print(NULL, false);
return 0;
}
// Abort if the user specifies a port that is outside the allowed
// range [1, 65535].
if ((FLAG_port < 1) || (FLAG_port > 65535)) {
printf("Error: %i is not a valid port.\n", FLAG_port);
return -1;
}
MainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall);
if (!wnd.Create()) {
ASSERT(false);
return -1;

View File

@ -36,6 +36,8 @@
ATOM MainWnd::wnd_class_ = 0;
const wchar_t MainWnd::kClassName[] = L"WebRTC_MainWnd";
using talk_base::sprintfn;
namespace {
const char kConnecting[] = "Connecting... ";
@ -79,10 +81,15 @@ void AddListBoxItem(HWND listbox, const std::string& str, LPARAM item_data) {
} // namespace
MainWnd::MainWnd()
MainWnd::MainWnd(const char* server, int port, bool auto_connect,
bool auto_call)
: ui_(CONNECT_TO_SERVER), wnd_(NULL), edit1_(NULL), edit2_(NULL),
label1_(NULL), label2_(NULL), button_(NULL), listbox_(NULL),
destroyed_(false), callback_(NULL), nested_msg_(NULL) {
destroyed_(false), callback_(NULL), nested_msg_(NULL),
server_(server), auto_connect_(auto_connect), auto_call_(auto_call) {
char buffer[10] = {0};
sprintfn(buffer, sizeof(buffer), "%i", port);
port_ = buffer;
}
MainWnd::~MainWnd() {
@ -158,6 +165,9 @@ void MainWnd::SwitchToConnectUI() {
ui_ = CONNECT_TO_SERVER;
LayoutConnectUI(true);
::SetFocus(edit1_);
if (auto_connect_)
::PostMessage(button_, BM_CLICK, 0, 0);
}
void MainWnd::SwitchToPeerList(const Peers& peers) {
@ -173,6 +183,19 @@ void MainWnd::SwitchToPeerList(const Peers& peers) {
ui_ = LIST_PEERS;
LayoutPeerListUI(true);
::SetFocus(listbox_);
if (auto_call_ && peers.begin() != peers.end()) {
// Get the number of items in the list
LRESULT count = ::SendMessage(listbox_, LB_GETCOUNT, 0, 0);
if (count != LB_ERR) {
// Select the last item in the list
LRESULT selection = ::SendMessage(listbox_, LB_SETCURSEL , count - 1, 0);
if (selection != LB_ERR)
::PostMessage(wnd_, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(listbox_),
LBN_DBLCLK),
reinterpret_cast<LPARAM>(listbox_));
}
}
}
void MainWnd::SwitchToStreamingUI() {
@ -465,8 +488,8 @@ void MainWnd::CreateChildWindows() {
CreateChildWindow(&listbox_, LISTBOX_ID, L"ListBox",
LBS_HASSTRINGS | LBS_NOTIFY, WS_EX_CLIENTEDGE);
::SetWindowTextA(edit1_, GetDefaultServerName().c_str());
::SetWindowTextA(edit2_, "8888");
::SetWindowTextA(edit1_, server_.c_str());
::SetWindowTextA(edit2_, port_.c_str());
}
void MainWnd::LayoutConnectUI(bool show) {

View File

@ -93,7 +93,7 @@ class MainWnd : public MainWindow {
UI_THREAD_CALLBACK = WM_APP + 1,
};
MainWnd();
MainWnd(const char* server, int port, bool auto_connect, bool auto_call);
~MainWnd();
bool Create();
@ -207,6 +207,10 @@ class MainWnd : public MainWindow {
void* nested_msg_;
MainWndCallback* callback_;
static ATOM wnd_class_;
std::string server_;
std::string port_;
bool auto_connect_;
bool auto_call_;
};
#endif // WIN32