summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-10 01:34:09 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-10 01:34:09 +0000
commit717651a584ce0566c2a0282b56007bda78c67e75 (patch)
tree6b77c3a7ab4b3b1cb8230b042b0e48c6b77ad1c6 /remoting
parentcb0d6bd52ea9b586f51efb97e4bcd47a458e8da8 (diff)
downloadchromium_src-717651a584ce0566c2a0282b56007bda78c67e75.zip
chromium_src-717651a584ce0566c2a0282b56007bda78c67e75.tar.gz
chromium_src-717651a584ce0566c2a0282b56007bda78c67e75.tar.bz2
Me2Mom support in simple_host.
BUG=None TEST=None Review URL: http://codereview.chromium.org/6931001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/simple_host_process.cc201
1 files changed, 131 insertions, 70 deletions
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index 1e188d5..ffd53ce 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -19,6 +19,7 @@
#include "build/build_config.h"
#include "base/at_exit.h"
+#include "base/callback.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/file_path.h"
@@ -38,6 +39,7 @@
#include "remoting/host/event_executor.h"
#include "remoting/host/heartbeat_sender.h"
#include "remoting/host/json_host_config.h"
+#include "remoting/host/register_support_host_request.h"
#include "remoting/proto/video.pb.h"
#if defined(TOOLKIT_USES_GTK)
@@ -67,6 +69,7 @@ void ShutdownTask(MessageLoop* message_loop) {
}
const char kFakeSwitchName[] = "fake";
+const char kMe2MomSwitchName[] = "me2mom";
const char kConfigSwitchName[] = "config";
const char kVideoSwitchName[] = "video";
@@ -75,72 +78,149 @@ const char kVideoSwitchValueZip[] = "zip";
const char kVideoSwitchValueVp8[] = "vp8";
const char kVideoSwitchValueVp8Rtp[] = "vp8rtp";
+class SimpleHost {
+ public:
+ SimpleHost()
+ : fake_(false),
+ me2mom_(false) {
+ }
-int main(int argc, char** argv) {
- // Needed for the Mac, so we don't leak objects when threads are created.
- base::mac::ScopedNSAutoreleasePool pool;
+ int Run() {
+ MessageLoopForUI message_loop;
- CommandLine::Init(argc, argv);
- const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
+ remoting::ChromotingHostContext context(&message_loop);
+ context.Start();
- base::AtExitManager exit_manager;
- crypto::EnsureNSPRInit();
+ base::Thread file_io_thread("FileIO");
+ file_io_thread.Start();
- // Allocate a chromoting context and starts it.
-#if defined(TOOLKIT_USES_GTK)
- gfx::GtkInitFromCommandLine(*cmd_line);
-#endif
- MessageLoopForUI message_loop;
- remoting::ChromotingHostContext context(&message_loop);
- context.Start();
+ FilePath config_path = GetConfigPath();
+ scoped_refptr<remoting::JsonHostConfig> config =
+ new remoting::JsonHostConfig(
+ config_path, file_io_thread.message_loop_proxy());
+ if (!config->Read()) {
+ LOG(ERROR) << "Failed to read configuration file "
+ << config_path.value();
+ context.Stop();
+ return 1;
+ }
+
+ // Construct a chromoting host.
+ scoped_refptr<ChromotingHost> host;
+ if (fake_) {
+ remoting::Capturer* capturer =
+ new remoting::CapturerFake();
+ remoting::EventExecutor* event_executor =
+ remoting::EventExecutor::Create(context.ui_message_loop(), capturer);
+ remoting::Curtain* curtain = remoting::Curtain::Create();
+ host = ChromotingHost::Create(
+ &context, config,
+ new DesktopEnvironment(capturer, event_executor, curtain));
+ } else {
+ host = ChromotingHost::Create(&context, config);
+ }
+
+ if (protocol_config_.get()) {
+ host->set_protocol_config(protocol_config_.release());
+ }
+
+ if (me2mom_) {
+ scoped_refptr<remoting::RegisterSupportHostRequest> register_request =
+ new remoting::RegisterSupportHostRequest();
+ if (!register_request->Init(
+ config, NewCallback(this, &SimpleHost::OnMe2MomHostRegistered))) {
+ return 1;
+ }
+ host->AddStatusObserver(register_request);
+ } else {
+ // Initialize HeartbeatSender.
+ scoped_refptr<remoting::HeartbeatSender> heartbeat_sender =
+ new remoting::HeartbeatSender(context.network_message_loop(), config);
+ if (!heartbeat_sender->Init())
+ return 1;
+ host->AddStatusObserver(heartbeat_sender);
+ }
+
+ // Let the chromoting host run until the shutdown task is executed.
+ host->Start(NewRunnableFunction(&ShutdownTask, &message_loop));
+ message_loop.MessageLoop::Run();
+
+ // And then stop the chromoting context.
+ context.Stop();
+ file_io_thread.Stop();
+
+ return 0;
+ }
+
+ void set_config_path(const FilePath& config_path) {
+ config_path_ = config_path;
+ }
+ void set_fake(bool fake) { fake_ = fake; }
+ void set_me2mom(bool me2mom) { me2mom_ = me2mom; }
+ void set_protocol_config(CandidateSessionConfig* protocol_config) {
+ protocol_config_.reset(protocol_config);
+ }
+ private:
+ FilePath GetConfigPath() {
+ if (!config_path_.empty())
+ return config_path_;
#if defined(OS_WIN)
- wstring home_path = GetEnvironmentVar(kHomeDrive);
- home_path += GetEnvironmentVar(kHomePath);
+ wstring home_path = GetEnvironmentVar(kHomeDrive);
+ home_path += GetEnvironmentVar(kHomePath);
#else
- string home_path = GetEnvironmentVar(base::env_vars::kHome);
+ string home_path = GetEnvironmentVar(base::env_vars::kHome);
#endif
- FilePath config_path(home_path);
- config_path = config_path.Append(kDefaultConfigPath);
- if (cmd_line->HasSwitch(kConfigSwitchName)) {
- config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName);
+ return FilePath(home_path).Append(kDefaultConfigPath);
}
- base::Thread file_io_thread("FileIO");
- file_io_thread.Start();
+ void OnMe2MomHostRegistered(bool successful, const std::string& support_id) {
+ if (successful) {
+ std::cout << "Support host registered with SupportID: "
+ << support_id << std::endl;
+ } else {
+ LOG(ERROR) << "Failed to register support host";
+ }
+ }
- scoped_refptr<remoting::JsonHostConfig> config(
- new remoting::JsonHostConfig(
- config_path, file_io_thread.message_loop_proxy()));
+ FilePath config_path_;
+ bool fake_;
+ bool me2mom_;
+ scoped_ptr<CandidateSessionConfig> protocol_config_;
+};
- if (!config->Read()) {
- LOG(ERROR) << "Failed to read configuration file " << config_path.value();
- context.Stop();
- return 1;
- }
+int main(int argc, char** argv) {
+ // Needed for the Mac, so we don't leak objects when threads are created.
+ base::mac::ScopedNSAutoreleasePool pool;
+
+ CommandLine::Init(argc, argv);
+ const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
+
+ base::AtExitManager exit_manager;
+ crypto::EnsureNSPRInit();
- FilePath module_path;
- PathService::Get(base::DIR_MODULE, &module_path);
- CHECK(media::InitializeMediaLibrary(module_path))
+ FilePath media_module_path;
+ PathService::Get(base::DIR_MODULE, &media_module_path);
+ CHECK(media::InitializeMediaLibrary(media_module_path))
<< "Cannot load media library";
- // Construct a chromoting host.
- scoped_refptr<ChromotingHost> host;
-
- bool fake = cmd_line->HasSwitch(kFakeSwitchName);
- if (fake) {
- remoting::Capturer* capturer =
- new remoting::CapturerFake();
- remoting::EventExecutor* event_executor =
- remoting::EventExecutor::Create(context.ui_message_loop(), capturer);
- remoting::Curtain* curtain = remoting::Curtain::Create();
- host = ChromotingHost::Create(
- &context, config,
- new DesktopEnvironment(capturer, event_executor, curtain));
- } else {
- host = ChromotingHost::Create(&context, config);
+#if defined(TOOLKIT_USES_GTK)
+ gfx::GtkInitFromCommandLine(*cmd_line);
+#endif // TOOLKIT_USES_GTK
+
+#if defined(OS_MACOSX)
+ mock_cr_app::RegisterMockCrApp();
+#endif // OS_MACOSX
+
+ SimpleHost simple_host;
+
+ if (cmd_line->HasSwitch(kConfigSwitchName)) {
+ simple_host.set_config_path(
+ cmd_line->GetSwitchValuePath(kConfigSwitchName));
}
+ simple_host.set_fake(cmd_line->HasSwitch(kFakeSwitchName));
+ simple_host.set_me2mom(cmd_line->HasSwitch(kMe2MomSwitchName));
if (cmd_line->HasSwitch(kVideoSwitchName)) {
string video_codec = cmd_line->GetSwitchValueASCII(kVideoSwitchName);
@@ -161,31 +241,12 @@ int main(int argc, char** argv) {
codec = ChannelConfig::CODEC_VP8;
} else {
LOG(ERROR) << "Unknown video codec: " << video_codec;
- context.Stop();
return 1;
}
config->mutable_video_configs()->push_back(ChannelConfig(
transport, remoting::protocol::kDefaultStreamVersion, codec));
- host->set_protocol_config(config.release());
+ simple_host.set_protocol_config(config.release());
}
-#if defined(OS_MACOSX)
- mock_cr_app::RegisterMockCrApp();
-#endif // OS_MACOSX
-
- // Initialize HeartbeatSender.
- scoped_refptr<remoting::HeartbeatSender> heartbeat_sender =
- new remoting::HeartbeatSender(context.network_message_loop(), config);
- if (!heartbeat_sender->Init())
- return 1;
- host->AddStatusObserver(heartbeat_sender);
-
- // Let the chromoting host run until the shutdown task is executed.
- host->Start(NewRunnableFunction(&ShutdownTask, &message_loop));
- message_loop.MessageLoop::Run();
-
- // And then stop the chromoting context.
- context.Stop();
- file_io_thread.Stop();
- return 0;
+ return simple_host.Run();
}