Chromium Code Reviews| 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..2485d5b589329e94c3cbbfd34f7be9812ff86d29 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/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); |
| + |
| + base::Closure callback = base::Bind(StopPrinter); |
| + at_exit.RegisterTask(callback); |
|
Vitaly Buka (NO REVIEWS)
2013/06/14 19:27:07
at_exit.RegisterTask(base::Bind(StopPrinter));
maksymb
2013/06/14 22:17:14
Done.
|
| +} |
| + |
| +void OnAbort(int val) { |
| + StopPrinter(); |
| + base::MessageLoop::current()->Quit(); |
| +} |
| + |
| +} // namespace |
| int main(int argc, char* argv[]) { |
| CommandLine::Init(argc, argv); |
| @@ -18,11 +46,13 @@ 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::Closure callback = base::Bind(StartPrinter); |
|
Vitaly Buka (NO REVIEWS)
2013/06/14 19:27:07
Same
maksymb
2013/06/14 22:17:14
Done.
|
| + base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| + base::RunLoop runner; |
| + runner.Run(); |
| return 0; |
| } |
| - |