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 #include <stdlib.h> | 17 #include <stdlib.h> |
18 | 18 |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 | 20 |
21 #include "base/at_exit.h" | 21 #include "base/at_exit.h" |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
23 #include "base/file_path.h" | 23 #include "base/file_path.h" |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/scoped_nsautorelease_pool.h" | 25 #include "base/scoped_nsautorelease_pool.h" |
26 #include "base/thread.h" | 26 #include "base/thread.h" |
27 #include "base/waitable_event.h" | 27 #include "base/waitable_event.h" |
28 #include "remoting/host/capturer_fake.h" | 28 #include "remoting/host/capturer_fake.h" |
29 #include "remoting/host/chromoting_host.h" | 29 #include "remoting/host/chromoting_host.h" |
| 30 #include "remoting/host/chromoting_host_context.h" |
30 #include "remoting/host/encoder_verbatim.h" | 31 #include "remoting/host/encoder_verbatim.h" |
31 #include "remoting/host/json_host_config.h" | 32 #include "remoting/host/json_host_config.h" |
32 | 33 |
33 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
34 #include "remoting/host/capturer_gdi.h" | 35 #include "remoting/host/capturer_gdi.h" |
35 #include "remoting/host/event_executor_win.h" | 36 #include "remoting/host/event_executor_win.h" |
36 #elif defined(OS_LINUX) | 37 #elif defined(OS_LINUX) |
37 #include "remoting/host/capturer_linux.h" | 38 #include "remoting/host/capturer_linux.h" |
38 #include "remoting/host/event_executor_linux.h" | 39 #include "remoting/host/event_executor_linux.h" |
39 #elif defined(OS_MACOSX) | 40 #elif defined(OS_MACOSX) |
40 #include "remoting/host/capturer_mac.h" | 41 #include "remoting/host/capturer_mac.h" |
41 #include "remoting/host/event_executor_mac.h" | 42 #include "remoting/host/event_executor_mac.h" |
42 #endif | 43 #endif |
43 | 44 |
44 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
45 const std::wstring kDefaultConfigPath = L".ChromotingConfig.json"; | 46 const std::wstring kDefaultConfigPath = L".ChromotingConfig.json"; |
46 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; | 47 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; |
47 const wchar_t kHomePath[] = L"HOMEPATH"; | 48 const wchar_t kHomePath[] = L"HOMEPATH"; |
48 const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); } | 49 const wchar_t* GetEnvironmentVar(const wchar_t* x) { return _wgetenv(x); } |
49 #else | 50 #else |
50 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; | 51 const std::string kDefaultConfigPath = ".ChromotingConfig.json"; |
51 const char kHomePath[] = "HOME"; | 52 const char kHomePath[] = "HOME"; |
52 static char* GetEnvironmentVar(const char* x) { return getenv(x); } | 53 static char* GetEnvironmentVar(const char* x) { return getenv(x); } |
53 #endif | 54 #endif |
54 | 55 |
| 56 void ShutdownTask(MessageLoop* message_loop) { |
| 57 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 58 } |
| 59 |
55 const std::string kFakeSwitchName = "fake"; | 60 const std::string kFakeSwitchName = "fake"; |
56 const std::string kConfigSwitchName = "config"; | 61 const std::string kConfigSwitchName = "config"; |
57 | 62 |
58 int main(int argc, char** argv) { | 63 int main(int argc, char** argv) { |
59 // Needed for the Mac, so we don't leak objects when threads are created. | 64 // Needed for the Mac, so we don't leak objects when threads are created. |
60 base::ScopedNSAutoreleasePool pool; | 65 base::ScopedNSAutoreleasePool pool; |
61 | 66 |
62 CommandLine::Init(argc, argv); | 67 CommandLine::Init(argc, argv); |
63 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 68 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
64 | 69 |
(...skipping 24 matching lines...) Expand all Loading... |
89 std::string path = GetEnvironmentVar(kHomePath); | 94 std::string path = GetEnvironmentVar(kHomePath); |
90 #endif | 95 #endif |
91 FilePath config_path(path); | 96 FilePath config_path(path); |
92 config_path = config_path.Append(kDefaultConfigPath); | 97 config_path = config_path.Append(kDefaultConfigPath); |
93 if (cmd_line->HasSwitch(kConfigSwitchName)) { | 98 if (cmd_line->HasSwitch(kConfigSwitchName)) { |
94 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); | 99 config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName); |
95 } | 100 } |
96 | 101 |
97 if (fake) { | 102 if (fake) { |
98 // Inject a fake capturer. | 103 // Inject a fake capturer. |
| 104 LOG(INFO) << "Usage a fake capturer."; |
99 capturer.reset(new remoting::CapturerFake()); | 105 capturer.reset(new remoting::CapturerFake()); |
100 } | 106 } |
101 | 107 |
102 base::Thread file_io_thread("FileIO"); | 108 base::Thread file_io_thread("FileIO"); |
103 file_io_thread.Start(); | 109 file_io_thread.Start(); |
104 | 110 |
105 scoped_refptr<remoting::JsonHostConfig> config( | 111 scoped_refptr<remoting::JsonHostConfig> config( |
106 new remoting::JsonHostConfig( | 112 new remoting::JsonHostConfig( |
107 config_path, file_io_thread.message_loop_proxy())); | 113 config_path, file_io_thread.message_loop_proxy())); |
108 | 114 |
109 if (!config->Read()) { | 115 if (!config->Read()) { |
110 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); | 116 LOG(ERROR) << "Failed to read configuration file " << config_path.value(); |
111 return 1; | 117 return 1; |
112 } | 118 } |
113 | 119 |
114 base::WaitableEvent host_done(false, false); | 120 // Allocate a chromoting context and starts it. |
| 121 remoting::ChromotingHostContext context; |
| 122 context.Start(); |
| 123 |
| 124 // Construct a chromoting host. |
115 scoped_refptr<remoting::ChromotingHost> host = | 125 scoped_refptr<remoting::ChromotingHost> host = |
116 new remoting::ChromotingHost(config, | 126 new remoting::ChromotingHost(&context, |
| 127 config, |
117 capturer.release(), | 128 capturer.release(), |
118 encoder.release(), | 129 encoder.release(), |
119 executor.release(), | 130 executor.release()); |
120 &host_done); | |
121 host->Run(); | |
122 host_done.Wait(); | |
123 | 131 |
| 132 // Let the chromoting host runs until the shutdown task is executed. |
| 133 MessageLoop message_loop; |
| 134 host->Start(NewRunnableFunction(&ShutdownTask, &message_loop)); |
| 135 message_loop.Run(); |
| 136 |
| 137 // And then stop the chromoting context. |
| 138 context.Stop(); |
124 file_io_thread.Stop(); | 139 file_io_thread.Stop(); |
125 return 0; | 140 return 0; |
126 } | 141 } |
OLD | NEW |