diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 00:12:27 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 00:12:27 +0000 |
commit | f12b14ebaef0065e903f25fddf851bc7abde3e8c (patch) | |
tree | cfc4a344ac89c32c6ce5987d1ee002372e6e26e2 /remoting | |
parent | 11883849004bdead3af9e2e51ea3f40d5f985169 (diff) | |
download | chromium_src-f12b14ebaef0065e903f25fddf851bc7abde3e8c.zip chromium_src-f12b14ebaef0065e903f25fddf851bc7abde3e8c.tar.gz chromium_src-f12b14ebaef0065e903f25fddf851bc7abde3e8c.tar.bz2 |
Skeleton of the Chromoting service for Windows.
Review URL: http://codereview.chromium.org/9337006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120871 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/remoting_host_service_win.cc | 146 | ||||
-rw-r--r-- | remoting/remoting.gyp | 15 |
2 files changed, 161 insertions, 0 deletions
diff --git a/remoting/host/remoting_host_service_win.cc b/remoting/host/remoting_host_service_win.cc new file mode 100644 index 0000000..50a5fa8 --- /dev/null +++ b/remoting/host/remoting_host_service_win.cc @@ -0,0 +1,146 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// This file implements the Windows service controlling Me2Me host processes +// running within user sessions. + +#include <windows.h> +#include <stdio.h> + +#include "base/command_line.h" +#include "base/logging.h" + +namespace { + +// Command line actions and switches: +// "run" sumply runs the service as usual. +const wchar_t kRunActionName[] = L"run"; + +// "install" requests the service to be installed. +const wchar_t kInstallActionName[] = L"install"; + +// "remove" uninstalls the service. +const wchar_t kRemoveActionName[] = L"remove"; + +// "--console" runs the service interactively for debugging purposes. +const char kConsoleSwitchName[] = "console"; + +// "--help" or "--?" prints the usage message. +const char kHelpSwitchName[] = "help"; +const char kQuestionSwitchName[] = "?"; + +const char kUsageMessage[] = + "\n" + "Usage: %s [action] [options]\n" + "\n" + "Actions:\n" + " run - Run the service. If no action specified 'run' is assumed.\n" + " install - Install the service.\n" + " remove - Uninstall the service.\n" + "\n" + "Options:\n" + " --console - Run the service interactively for debugging purposes.\n" + " --help, --? - Print this message.\n"; + +// Exit codes: +const int kSuccessExitCode = 0; +const int kUsageExitCode = 1; + +void usage(const char* program_name) { + fprintf(stderr, kUsageMessage, program_name); +} + +} // namespace + +namespace remoting { + +class HostService { + public: + HostService(): + run_routine_(&HostService::RunAsService) { + } + + ~HostService() { + } + + // This function parses the command line and selects the action routine. + bool InitWithCommandLine(const CommandLine* command_line) { + CommandLine::StringVector args = command_line->GetArgs(); + + // Choose the action to perform. + if (!args.empty()) { + if (args.size() > 1) { + LOG(ERROR) << "Invalid command line: more than one action requested."; + return false; + } + if (args[0] == kInstallActionName) { + run_routine_ = &HostService::Install; + } else if (args[0] == kRemoveActionName) { + run_routine_ = &HostService::Remove; + } else if (args[0] != kRunActionName) { + LOG(ERROR) << "Invalid command line: invalid action specified: " + << args[0]; + return false; + } + } + + // Run interactively if needed. + if (run_routine_ == &HostService::RunAsService && + command_line->HasSwitch(kConsoleSwitchName)) { + run_routine_ = &HostService::RunInConsole; + } + + return true; + } + + // Invoke the choosen action routine. + int Run() { + return (this->*run_routine_)(); + } + + private: + int Install() { + NOTIMPLEMENTED(); + return 0; + } + + int Remove() { + NOTIMPLEMENTED(); + return 0; + } + + int RunAsService() { + NOTIMPLEMENTED(); + return 0; + } + + int RunInConsole() { + NOTIMPLEMENTED(); + return 0; + } + + int (HostService::*run_routine_)(); +}; + +} // namespace remoting + +int main(int argc, char** argv) { + CommandLine::Init(argc, argv); + + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + + if (command_line->HasSwitch(kHelpSwitchName) || + command_line->HasSwitch(kQuestionSwitchName)) { + usage(argv[0]); + return kSuccessExitCode; + } + + remoting::HostService service; + if (!service.InitWithCommandLine(command_line)) { + usage(argv[0]); + return kUsageExitCode; + } + + return service.Run(); +} diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 4b86ba2..50be11a 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -227,6 +227,21 @@ ], # end of 'targets' }], # 'OS=="linux"' + ['OS=="win"', { + 'targets': [ + { + 'target_name': 'remoting_service', + 'type': 'executable', + 'variables': { 'enable_wexit_time_destructors': 1, }, + 'dependencies': [ + '../base/base.gyp:base_i18n', + ], + 'sources': [ + 'host/remoting_host_service_win.cc', + ], + }, # end of target 'remoting_service' + ], + }], # 'OS=="win"' ], # end of 'conditions' 'targets': [ |