Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: remoting/client/simple_client.cc

Issue 2745006: Implement a chromoting client using X11 (Closed)
Patch Set: removed all.gyp Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/client/host_connection.cc ('k') | remoting/client/x11_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // A simple client implements a minimalize Chromoting client and shows 5 // A simple client implements a minimalize Chromoting client and shows
6 // network traffic for debugging. 6 // network traffic for debugging.
7 7
8 #include <iostream> 8 #include <iostream>
9 #include <list> 9 #include <list>
10 10
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "media/base/data_buffer.h"
15 #include "remoting/base/protocol_decoder.h" 14 #include "remoting/base/protocol_decoder.h"
15 #include "remoting/client/client_util.h"
16 #include "remoting/client/host_connection.h" 16 #include "remoting/client/host_connection.h"
17 #include "remoting/jingle_glue/jingle_channel.h"
18 #include "remoting/jingle_glue/jingle_client.h"
19 17
20 using chromotocol_pb::HostMessage; 18 using remoting::BeginUpdateStreamMessage;
21 using chromotocol_pb::InitClientMessage; 19 using remoting::EndUpdateStreamMessage;
22 using chromotocol_pb::BeginUpdateStreamMessage;
23 using chromotocol_pb::EndUpdateStreamMessage;
24 using chromotocol_pb::UpdateStreamPacketMessage;
25 using remoting::HostConnection; 20 using remoting::HostConnection;
21 using remoting::HostMessage;
26 using remoting::HostMessageList; 22 using remoting::HostMessageList;
23 using remoting::InitClientMessage;
27 using remoting::JingleClient; 24 using remoting::JingleClient;
28 using remoting::JingleChannel; 25 using remoting::JingleChannel;
29 using remoting::ProtocolDecoder; 26 using remoting::ProtocolDecoder;
30 27 using remoting::UpdateStreamPacketMessage;
31 void SetConsoleEcho(bool on) {
32 #ifdef WIN32
33 HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
34 if ((hIn == INVALID_HANDLE_VALUE) || (hIn == NULL))
35 return;
36
37 DWORD mode;
38 if (!GetConsoleMode(hIn, &mode))
39 return;
40
41 if (on) {
42 mode = mode | ENABLE_ECHO_INPUT;
43 } else {
44 mode = mode & ~ENABLE_ECHO_INPUT;
45 }
46
47 SetConsoleMode(hIn, mode);
48 #else
49 if (on)
50 system("stty echo");
51 else
52 system("stty -echo");
53 #endif
54 }
55 28
56 class SimpleHostEventHandler : public HostConnection::EventHandler { 29 class SimpleHostEventHandler : public HostConnection::EventHandler {
57 public: 30 public:
58 SimpleHostEventHandler(MessageLoop* loop) 31 SimpleHostEventHandler(MessageLoop* loop)
59 : main_loop_(loop) { 32 : main_loop_(loop) {
60 } 33 }
61 34
62 virtual void HandleMessages(HostConnection* conn, 35 virtual void HandleMessages(HostConnection* conn,
63 HostMessageList* messages) { 36 HostMessageList* messages) {
64 HostMessageList list; 37 HostMessageList list;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 103 }
131 } 104 }
132 105
133 MessageLoop* main_loop_; 106 MessageLoop* main_loop_;
134 107
135 DISALLOW_COPY_AND_ASSIGN(SimpleHostEventHandler); 108 DISALLOW_COPY_AND_ASSIGN(SimpleHostEventHandler);
136 }; 109 };
137 110
138 int main(int argc, char** argv) { 111 int main(int argc, char** argv) {
139 base::AtExitManager exit_manager; 112 base::AtExitManager exit_manager;
113 std::string host_jid, username, password;
140 114
141 if (argc > 2) { 115 if (!remoting::GetLoginInfo(host_jid, username, password)) {
142 std::cerr << "Usage: " << argv[0] << " [<host_jid>]" << std::endl; 116 std::cerr << "Cannot get valid login info." << std::endl;
143 return 1; 117 return 1;
144 } 118 }
145 119
146 // Get host JID from command line arguments, or stdin if not specified.
147 std::string host_jid;
148 if (argc == 2) {
149 host_jid = argv[1];
150 } else {
151 std::cout << "Host JID: ";
152 std::cin >> host_jid;
153 std::cin.ignore(); // Consume the leftover '\n'
154 }
155 if (host_jid.find("/chromoting") == std::string::npos) {
156 std::cerr << "Error: Expected Host JID in format: <jid>/chromoting<id>"
157 << std::endl;
158 return 1;
159 }
160
161 // Get username (JID).
162 // Extract default JID from host_jid.
163 std::string username;
164 std::string default_username;
165 size_t jid_end = host_jid.find('/');
166 if (jid_end != std::string::npos) {
167 default_username = host_jid.substr(0, jid_end);
168 }
169 std::cout << "JID [" << default_username << "]: ";
170 getline(std::cin, username);
171 if (username.length() == 0) {
172 username = default_username;
173 }
174 if (username.length() == 0) {
175 std::cerr << "Error: Expected valid JID username" << std::endl;
176 return 1;
177 }
178
179 // Get password (with console echo turned off).
180 std::string password;
181 SetConsoleEcho(false);
182 std::cout << "Password: ";
183 getline(std::cin, password);
184 SetConsoleEcho(true);
185 std::cout << std::endl;
186
187 // The message loop that everything runs on. 120 // The message loop that everything runs on.
188 MessageLoop main_loop; 121 MessageLoop main_loop;
189 SimpleHostEventHandler handler(&main_loop); 122 SimpleHostEventHandler handler(&main_loop);
190 HostConnection connection(new ProtocolDecoder(), &handler); 123 HostConnection connection(new ProtocolDecoder(), &handler);
191 connection.Connect(username, password, host_jid); 124 connection.Connect(username, password, host_jid);
192 125
193 // Run the message. 126 // Run the message.
194 main_loop.Run(); 127 main_loop.Run();
195 return 0; 128 return 0;
196 } 129 }
OLDNEW
« no previous file with comments | « remoting/client/host_connection.cc ('k') | remoting/client/x11_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698