1 // Copyright 2013 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.
7 #include "base/at_exit.h"
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h"
13 #include "base/threading/platform_thread.h"
14 #include "base/time/time.h"
15 #include "cloud_print/gcp20/prototype/printer.h"
19 const char kHelpMessage[] =
20 "usage: gcp20_device [switches] [options]\n"
23 " --disable-confirmation disables confirmation of registration\n"
24 " --disable-method-check disables HTTP method checking (POST, GET)\n"
25 " --disable-x-token disables checking of X-Privet-Token "
27 " -h, --help prints this message\n"
28 " --no-announcement disables DNS announcements\n"
29 " --simulate-printing-errors simulates some errors for local printing\n"
30 " --unicast-respond DNS responses will be sent in unicast "
31 "instead of multicast\n"
34 " --domain-name=<name> sets, should ends with '.local'\n"
35 " --http-port=<value> sets port for HTTP server\n"
36 " --service-name=<name> sets DNS service name\n"
37 " --state-path=<path> sets path to file with registration state\n"
38 " --ttl=<value> sets TTL for DNS announcements\n"
40 "WARNING: mDNS probing is not implemented\n";
43 printf("%s", kHelpMessage);
46 void StartPrinter(Printer* printer) {
47 bool success = printer->Start();
51 base::RunLoop* g_runner = NULL;
52 Printer* g_printer = NULL;
53 base::MessageLoop* g_message_loop;
56 // Always do after printer.Stop() to make sure XMPP will
57 // be disabled fully before |Quit| will be called
58 // (XMPP disables itself via MessageLoop call).
59 g_message_loop->PostTask(FROM_HERE, g_runner->QuitClosure());
60 g_message_loop = NULL;
64 void OnAbort(int val) {
66 g_message_loop->PostTask(
68 base::Bind(&Printer::Stop, base::Unretained(g_printer)));
69 g_message_loop->PostTask(FROM_HERE, base::Bind(&StopLoop));
76 int main(int argc, char* argv[]) {
77 base::AtExitManager at_exit;
79 CommandLine::Init(argc, argv);
81 logging::LoggingSettings settings;
82 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
83 logging::InitLogging(settings);
85 if (CommandLine::ForCurrentProcess()->HasSwitch("h") ||
86 CommandLine::ForCurrentProcess()->HasSwitch("help")) {
91 signal(SIGINT, OnAbort); // Handle Ctrl+C signal.
93 base::MessageLoop loop(base::MessageLoop::TYPE_IO);
94 g_message_loop = &loop;
95 g_message_loop->PostTask(FROM_HERE, base::Bind(&StartPrinter, &printer));