OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // This is an application of a minimal host process in a Chromoting |
| 6 // system. It serves the purpose of gluing different pieces together |
| 7 // to make a functional host process for testing. |
| 8 // |
| 9 // It peforms the following functionality: |
| 10 // 1. Connect to the GTalk network and register the machine as a host. |
| 11 // 2. Accepts connection through libjingle. |
| 12 // 3. Receive mouse / keyboard events through libjingle. |
| 13 // 4. Sends screen capture through libjingle. |
| 14 |
| 15 #include <iostream> |
| 16 #include <string> |
| 17 |
| 18 #include "build/build_config.h" |
| 19 |
| 20 #if defined(OS_POSIX) |
| 21 #include <termios.h> |
| 22 #endif // defined (OS_POSIX) |
| 23 |
| 24 #include "base/at_exit.h" |
| 25 #include "remoting/host/capturer_fake.h" |
| 26 #include "remoting/host/encoder_verbatim.h" |
| 27 #include "remoting/host/simple_host.h" |
| 28 |
| 29 #if defined(OS_WIN) |
| 30 #include "remoting/host/capturer_gdi.h" |
| 31 #include "remoting/host/event_executor_win.h" |
| 32 #elif defined(OS_LINUX) |
| 33 #include "remoting/host/capturer_linux.h" |
| 34 #include "remoting/host/event_executor_linux.h" |
| 35 #elif defined(OS_MAC) |
| 36 #include "remoting/host/capturer_mac.h" |
| 37 #include "remoting/host/event_executor_mac.h" |
| 38 #endif |
| 39 |
| 40 void SetConsoleEcho(bool on) { |
| 41 #if defined(OS_WIN) |
| 42 HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); |
| 43 if ((hIn == INVALID_HANDLE_VALUE) || (hIn == NULL)) |
| 44 return; |
| 45 |
| 46 DWORD mode; |
| 47 if (!GetConsoleMode(hIn, &mode)) |
| 48 return; |
| 49 |
| 50 if (on) { |
| 51 mode = mode | ENABLE_ECHO_INPUT; |
| 52 } else { |
| 53 mode = mode & ~ENABLE_ECHO_INPUT; |
| 54 } |
| 55 |
| 56 SetConsoleMode(hIn, mode); |
| 57 #elif defined(OS_POSIX) |
| 58 struct termios settings; |
| 59 tcgetattr(STDIN_FILENO, &settings); |
| 60 if (on) { |
| 61 settings.c_lflag |= ECHO; |
| 62 } else { |
| 63 settings.c_lflag &= ~ECHO; |
| 64 } |
| 65 tcsetattr(STDIN_FILENO, TCSANOW, &settings); |
| 66 #endif // defined(OS_WIN) |
| 67 } |
| 68 |
| 69 int main(int argc, char** argv) { |
| 70 base::AtExitManager exit_manager; |
| 71 |
| 72 // Check the argument to see if we should use a fake capturer and encoder. |
| 73 bool fake = false; |
| 74 if (argc > 1 && std::string(argv[1]) == "--fake") { |
| 75 fake = true; |
| 76 } |
| 77 |
| 78 // Prompt user for username and password. |
| 79 std::string username; |
| 80 std::cout << "JID: "; |
| 81 std::cin >> username; |
| 82 std::string password; |
| 83 SetConsoleEcho(false); |
| 84 std::cout << "Password: "; |
| 85 std::cin >> password; |
| 86 SetConsoleEcho(true); |
| 87 std::cout << std::endl; |
| 88 |
| 89 scoped_ptr<remoting::Capturer> capturer; |
| 90 scoped_ptr<remoting::Encoder> encoder; |
| 91 scoped_ptr<remoting::EventExecutor> executor; |
| 92 #if defined(OS_WIN) |
| 93 capturer.reset(new remoting::CapturerGdi()); |
| 94 executor.reset(new remoting::EventExecutorWin()); |
| 95 #elif defined(OS_LINUX) |
| 96 capturer.reset(new remoting::CapturerLinux()); |
| 97 executor.reset(new remoting::EventExecutorLinux()); |
| 98 #elif defined(OS_MAC) |
| 99 capturer.reset(new remoting::CapturerMac()); |
| 100 executor.reset(new remoting::EventExecutorMac()); |
| 101 #endif |
| 102 encoder.reset(new remoting::EncoderVerbatim()); |
| 103 |
| 104 if (fake) { |
| 105 // Inject a fake capturer. |
| 106 capturer.reset(new remoting::CapturerFake()); |
| 107 } |
| 108 |
| 109 // Construct a simple host with username and password. |
| 110 // TODO(hclam): Allow the host to load saved credentials. |
| 111 scoped_refptr<remoting::SimpleHost> host |
| 112 = new remoting::SimpleHost(username, password, |
| 113 capturer.release(), |
| 114 encoder.release(), |
| 115 executor.release()); |
| 116 host->Run(); |
| 117 return 0; |
| 118 } |
OLD | NEW |