Skip to content

Commit 0402515

Browse files
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 [email protected] Review URL: https://webrtc-codereview.appspot.com/13609004 Patch from Vicken Simonian <[email protected]>. git-svn-id: http://webrtc.googlecode.com/svn/trunk@6573 4adac7df-926f-26a2-2b94-8c16560cd09d
1 parent 9138eb6 commit 0402515

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Paul Kapustin <[email protected]>
1414
Rafael Lopez Diez <[email protected]>
1515
Robert Nagy
1616
Silviu Caragea <[email protected]>
17+
Vicken Simonian <[email protected]>
1718
Victor Costan <[email protected]>
1819

1920
Google Inc.

talk/examples/peerconnection/client/main.cc

+19-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#include "talk/examples/peerconnection/client/conductor.h"
29+
#include "talk/examples/peerconnection/client/flagdefs.h"
2930
#include "talk/examples/peerconnection/client/main_wnd.h"
3031
#include "talk/examples/peerconnection/client/peer_connection_client.h"
3132
#include "talk/base/ssladapter.h"
@@ -39,7 +40,24 @@ int PASCAL wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
3940
talk_base::Win32Thread w32_thread;
4041
talk_base::ThreadManager::Instance()->SetCurrentThread(&w32_thread);
4142

42-
MainWnd wnd;
43+
WindowsCommandLineArguments win_args;
44+
int argc = win_args.argc();
45+
char **argv = win_args.argv();
46+
47+
FlagList::SetFlagsFromCommandLine(&argc, argv, true);
48+
if (FLAG_help) {
49+
FlagList::Print(NULL, false);
50+
return 0;
51+
}
52+
53+
// Abort if the user specifies a port that is outside the allowed
54+
// range [1, 65535].
55+
if ((FLAG_port < 1) || (FLAG_port > 65535)) {
56+
printf("Error: %i is not a valid port.\n", FLAG_port);
57+
return -1;
58+
}
59+
60+
MainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall);
4361
if (!wnd.Create()) {
4462
ASSERT(false);
4563
return -1;

talk/examples/peerconnection/client/main_wnd.cc

+27-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
ATOM MainWnd::wnd_class_ = 0;
3737
const wchar_t MainWnd::kClassName[] = L"WebRTC_MainWnd";
3838

39+
using talk_base::sprintfn;
40+
3941
namespace {
4042

4143
const char kConnecting[] = "Connecting... ";
@@ -79,10 +81,15 @@ void AddListBoxItem(HWND listbox, const std::string& str, LPARAM item_data) {
7981

8082
} // namespace
8183

82-
MainWnd::MainWnd()
84+
MainWnd::MainWnd(const char* server, int port, bool auto_connect,
85+
bool auto_call)
8386
: ui_(CONNECT_TO_SERVER), wnd_(NULL), edit1_(NULL), edit2_(NULL),
8487
label1_(NULL), label2_(NULL), button_(NULL), listbox_(NULL),
85-
destroyed_(false), callback_(NULL), nested_msg_(NULL) {
88+
destroyed_(false), callback_(NULL), nested_msg_(NULL),
89+
server_(server), auto_connect_(auto_connect), auto_call_(auto_call) {
90+
char buffer[10] = {0};
91+
sprintfn(buffer, sizeof(buffer), "%i", port);
92+
port_ = buffer;
8693
}
8794

8895
MainWnd::~MainWnd() {
@@ -158,6 +165,9 @@ void MainWnd::SwitchToConnectUI() {
158165
ui_ = CONNECT_TO_SERVER;
159166
LayoutConnectUI(true);
160167
::SetFocus(edit1_);
168+
169+
if (auto_connect_)
170+
::PostMessage(button_, BM_CLICK, 0, 0);
161171
}
162172

163173
void MainWnd::SwitchToPeerList(const Peers& peers) {
@@ -173,6 +183,19 @@ void MainWnd::SwitchToPeerList(const Peers& peers) {
173183
ui_ = LIST_PEERS;
174184
LayoutPeerListUI(true);
175185
::SetFocus(listbox_);
186+
187+
if (auto_call_ && peers.begin() != peers.end()) {
188+
// Get the number of items in the list
189+
LRESULT count = ::SendMessage(listbox_, LB_GETCOUNT, 0, 0);
190+
if (count != LB_ERR) {
191+
// Select the last item in the list
192+
LRESULT selection = ::SendMessage(listbox_, LB_SETCURSEL , count - 1, 0);
193+
if (selection != LB_ERR)
194+
::PostMessage(wnd_, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(listbox_),
195+
LBN_DBLCLK),
196+
reinterpret_cast<LPARAM>(listbox_));
197+
}
198+
}
176199
}
177200

178201
void MainWnd::SwitchToStreamingUI() {
@@ -465,8 +488,8 @@ void MainWnd::CreateChildWindows() {
465488
CreateChildWindow(&listbox_, LISTBOX_ID, L"ListBox",
466489
LBS_HASSTRINGS | LBS_NOTIFY, WS_EX_CLIENTEDGE);
467490

468-
::SetWindowTextA(edit1_, GetDefaultServerName().c_str());
469-
::SetWindowTextA(edit2_, "8888");
491+
::SetWindowTextA(edit1_, server_.c_str());
492+
::SetWindowTextA(edit2_, port_.c_str());
470493
}
471494

472495
void MainWnd::LayoutConnectUI(bool show) {

talk/examples/peerconnection/client/main_wnd.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class MainWnd : public MainWindow {
9393
UI_THREAD_CALLBACK = WM_APP + 1,
9494
};
9595

96-
MainWnd();
96+
MainWnd(const char* server, int port, bool auto_connect, bool auto_call);
9797
~MainWnd();
9898

9999
bool Create();
@@ -207,6 +207,10 @@ class MainWnd : public MainWindow {
207207
void* nested_msg_;
208208
MainWndCallback* callback_;
209209
static ATOM wnd_class_;
210+
std::string server_;
211+
std::string port_;
212+
bool auto_connect_;
213+
bool auto_call_;
210214
};
211215
#endif // WIN32
212216

0 commit comments

Comments
 (0)