| OLD | NEW |
| 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 // This is an application of a minimal host process in a Chromoting | 5 // This is an application of a minimal host process in a Chromoting |
| 6 // system. It serves the purpose of gluing different pieces together | 6 // system. It serves the purpose of gluing different pieces together |
| 7 // to make a functional host process for testing. | 7 // to make a functional host process for testing. |
| 8 // | 8 // |
| 9 // It peforms the following functionality: | 9 // It peforms the following functionality: |
| 10 // 1. Connect to the GTalk network and register the machine as a host. | 10 // 1. Connect to the GTalk network and register the machine as a host. |
| 11 // 2. Accepts connection through libjingle. | 11 // 2. Accepts connection through libjingle. |
| 12 // 3. Receive mouse / keyboard events through libjingle. | 12 // 3. Receive mouse / keyboard events through libjingle. |
| 13 // 4. Sends screen capture through libjingle. | 13 // 4. Sends screen capture through libjingle. |
| 14 | 14 |
| 15 #include <iostream> | 15 #include <iostream> |
| 16 #include <string> | 16 #include <string> |
| 17 | 17 |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 | 19 |
| 20 #if defined(OS_POSIX) | 20 #if defined(OS_POSIX) |
| 21 #include <termios.h> | 21 #include <termios.h> |
| 22 #endif // defined (OS_POSIX) | 22 #endif // defined (OS_POSIX) |
| 23 | 23 |
| 24 #include "base/at_exit.h" | 24 #include "base/at_exit.h" |
| 25 #include "base/waitable_event.h" | 25 #include "base/waitable_event.h" |
| 26 #include "remoting/host/capturer_fake.h" | 26 #include "remoting/host/capturer_fake.h" |
| 27 #include "remoting/host/encoder_verbatim.h" | 27 #include "remoting/host/encoder_verbatim.h" |
| 28 #include "remoting/host/simple_host.h" | 28 #include "remoting/host/chromoting_host.h" |
| 29 | 29 |
| 30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 31 #include "remoting/host/capturer_gdi.h" | 31 #include "remoting/host/capturer_gdi.h" |
| 32 #include "remoting/host/event_executor_win.h" | 32 #include "remoting/host/event_executor_win.h" |
| 33 #elif defined(OS_LINUX) | 33 #elif defined(OS_LINUX) |
| 34 #include "remoting/host/capturer_linux.h" | 34 #include "remoting/host/capturer_linux.h" |
| 35 #include "remoting/host/event_executor_linux.h" | 35 #include "remoting/host/event_executor_linux.h" |
| 36 #elif defined(OS_MACOSX) | 36 #elif defined(OS_MACOSX) |
| 37 #include "remoting/host/capturer_mac.h" | 37 #include "remoting/host/capturer_mac.h" |
| 38 #include "remoting/host/event_executor_mac.h" | 38 #include "remoting/host/event_executor_mac.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 void SetConsoleEcho(bool on) { | |
| 42 #if defined(OS_WIN) | |
| 43 HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); | |
| 44 if ((hIn == INVALID_HANDLE_VALUE) || (hIn == NULL)) | |
| 45 return; | |
| 46 | |
| 47 DWORD mode; | |
| 48 if (!GetConsoleMode(hIn, &mode)) | |
| 49 return; | |
| 50 | |
| 51 if (on) { | |
| 52 mode = mode | ENABLE_ECHO_INPUT; | |
| 53 } else { | |
| 54 mode = mode & ~ENABLE_ECHO_INPUT; | |
| 55 } | |
| 56 | |
| 57 SetConsoleMode(hIn, mode); | |
| 58 #elif defined(OS_POSIX) | |
| 59 struct termios settings; | |
| 60 tcgetattr(STDIN_FILENO, &settings); | |
| 61 if (on) { | |
| 62 settings.c_lflag |= ECHO; | |
| 63 } else { | |
| 64 settings.c_lflag &= ~ECHO; | |
| 65 } | |
| 66 tcsetattr(STDIN_FILENO, TCSANOW, &settings); | |
| 67 #endif // defined(OS_WIN) | |
| 68 } | |
| 69 | |
| 70 int main(int argc, char** argv) { | 41 int main(int argc, char** argv) { |
| 71 base::AtExitManager exit_manager; | 42 base::AtExitManager exit_manager; |
| 72 | 43 |
| 73 std::string username; | 44 std::string username; |
| 74 std::string auth_token; | 45 std::string auth_token; |
| 75 | 46 |
| 76 // Check the argument to see if we should use a fake capturer and encoder. | 47 // Check the argument to see if we should use a fake capturer and encoder. |
| 77 bool fake = false; | 48 bool fake = false; |
| 78 // True if the JID was specified on the command line. | 49 // True if the JID was specified on the command line. |
| 79 bool has_jid = false; | 50 bool has_jid = false; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 capturer.reset(new remoting::CapturerMac()); | 95 capturer.reset(new remoting::CapturerMac()); |
| 125 executor.reset(new remoting::EventExecutorMac()); | 96 executor.reset(new remoting::EventExecutorMac()); |
| 126 #endif | 97 #endif |
| 127 encoder.reset(new remoting::EncoderVerbatim()); | 98 encoder.reset(new remoting::EncoderVerbatim()); |
| 128 | 99 |
| 129 if (fake) { | 100 if (fake) { |
| 130 // Inject a fake capturer. | 101 // Inject a fake capturer. |
| 131 capturer.reset(new remoting::CapturerFake()); | 102 capturer.reset(new remoting::CapturerFake()); |
| 132 } | 103 } |
| 133 | 104 |
| 134 // Construct a simple host with username and auth_token. | 105 // Construct a chromoting host with username and auth_token. |
| 135 // TODO(hclam): Allow the host to load saved credentials. | 106 // TODO(hclam): Allow the host to load saved credentials. |
| 136 base::WaitableEvent host_done(false, false); | 107 base::WaitableEvent host_done(false, false); |
| 137 scoped_refptr<remoting::SimpleHost> host | 108 scoped_refptr<remoting::ChromotingHost> host |
| 138 = new remoting::SimpleHost(username, auth_token, | 109 = new remoting::ChromotingHost(username, auth_token, |
| 139 capturer.release(), | 110 capturer.release(), |
| 140 encoder.release(), | 111 encoder.release(), |
| 141 executor.release(), | 112 executor.release(), |
| 142 &host_done); | 113 &host_done); |
| 143 host->Run(); | 114 host->Run(); |
| 144 host_done.Wait(); | 115 host_done.Wait(); |
| 145 return 0; | 116 return 0; |
| 146 } | 117 } |
| OLD | NEW |