diff options
author | kjellander@webrtc.org <kjellander@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2014-07-01 16:28:13 +0000 |
---|---|---|
committer | kjellander@webrtc.org <kjellander@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2014-07-01 16:28:13 +0000 |
commit | 249b3894e5fe5cd977313f0df6eb222d5010b561 (patch) | |
tree | 33bcfc2ba0dd9a130b068e2eef83d294b158a5c7 /examples | |
parent | 230295b04527a8a231f736949e897c1fea171424 (diff) | |
download | talk-249b3894e5fe5cd977313f0df6eb222d5010b561.tar.gz |
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/talk@6573 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'examples')
-rw-r--r-- | examples/peerconnection/client/main.cc | 20 | ||||
-rw-r--r-- | examples/peerconnection/client/main_wnd.cc | 31 | ||||
-rw-r--r-- | examples/peerconnection/client/main_wnd.h | 6 |
3 files changed, 51 insertions, 6 deletions
diff --git a/examples/peerconnection/client/main.cc b/examples/peerconnection/client/main.cc index e68c78e..765dfaa 100644 --- a/examples/peerconnection/client/main.cc +++ b/examples/peerconnection/client/main.cc @@ -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; diff --git a/examples/peerconnection/client/main_wnd.cc b/examples/peerconnection/client/main_wnd.cc index 6211e99..cef1da7 100644 --- a/examples/peerconnection/client/main_wnd.cc +++ b/examples/peerconnection/client/main_wnd.cc @@ -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) { diff --git a/examples/peerconnection/client/main_wnd.h b/examples/peerconnection/client/main_wnd.h index 6d2bf3e..77da9f6 100644 --- a/examples/peerconnection/client/main_wnd.h +++ b/examples/peerconnection/client/main_wnd.h @@ -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 |