| Index: cloud_print/gcp20/prototype/gcp20_device.cc
|
| diff --git a/cloud_print/gcp20/prototype/gcp20_device.cc b/cloud_print/gcp20/prototype/gcp20_device.cc
|
| index f210063a7baab93a729d4ef4317f771c5843ff7c..88d50db98ed8f70e1d30c85af503feb67ae42a04 100644
|
| --- a/cloud_print/gcp20/prototype/gcp20_device.cc
|
| +++ b/cloud_print/gcp20/prototype/gcp20_device.cc
|
| @@ -2,12 +2,40 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include <stdio.h>
|
| +#include <signal.h>
|
|
|
| +#include "base/at_exit.h"
|
| +#include "base/bind.h"
|
| #include "base/command_line.h"
|
| #include "base/logging.h"
|
| +#include "base/message_loop.h"
|
| +#include "base/run_loop.h"
|
| #include "base/threading/platform_thread.h"
|
| -#include "cloud_print/gcp20/prototype/dns_sd_server.h"
|
| +#include "base/time.h"
|
| +#include "cloud_print/gcp20/prototype/printer.h"
|
| +
|
| +namespace {
|
| +
|
| +Printer printer;
|
| +base::AtExitManager at_exit;
|
| +
|
| +void StopPrinter() {
|
| + printer.Stop();
|
| +}
|
| +
|
| +void StartPrinter() {
|
| + bool success = printer.Start();
|
| + DCHECK(success);
|
| +
|
| + at_exit.RegisterTask(base::Bind(&StopPrinter));
|
| +}
|
| +
|
| +void OnAbort(int val) {
|
| + StopPrinter();
|
| + base::MessageLoop::current()->Quit();
|
| +}
|
| +
|
| +} // namespace
|
|
|
| int main(int argc, char* argv[]) {
|
| CommandLine::Init(argc, argv);
|
| @@ -18,11 +46,12 @@ int main(int argc, char* argv[]) {
|
| logging::APPEND_TO_OLD_LOG_FILE,
|
| logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
|
|
|
| - DnsSdServer dns_sd_server;
|
| - dns_sd_server.Start();
|
| - base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2));
|
| - dns_sd_server.Shutdown();
|
| + signal(SIGINT, OnAbort); // Handle Ctrl+C signal.
|
| +
|
| + base::MessageLoop loop(base::MessageLoop::TYPE_IO);
|
| + base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&StartPrinter));
|
| + base::RunLoop runner;
|
| + runner.Run();
|
|
|
| return 0;
|
| }
|
| -
|
|
|