Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: cloud_print/gcp20/prototype/gcp20_device.cc

Issue 16975004: Finished DNS-SD server. Finished Privet-specified DNS-SD server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reindentation of function calls. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..719850d7e27b51d0df6a9fc4ec56b5a8ac7f9d22 100644
--- a/cloud_print/gcp20/prototype/gcp20_device.cc
+++ b/cloud_print/gcp20/prototype/gcp20_device.cc
@@ -2,12 +2,39 @@
// 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);
+
+ 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 +45,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;
}
-

Powered by Google App Engine
This is Rietveld 408576698