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

Unified Diff: tools/android/forwarder2/device_forwarder_main.cc

Issue 10918057: Add forwarder2 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
« no previous file with comments | « tools/android/forwarder2/device_controller.cc ('k') | tools/android/forwarder2/device_listener.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/forwarder2/device_forwarder_main.cc
diff --git a/tools/android/forwarder2/device_forwarder_main.cc b/tools/android/forwarder2/device_forwarder_main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..18c2ee4b282b9b94c2eea3254e13715aabd468f2
--- /dev/null
+++ b/tools/android/forwarder2/device_forwarder_main.cc
@@ -0,0 +1,66 @@
+// 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.
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string>
+
+#include "base/command_line.h"
+#include "base/lazy_instance.h"
+#include "base/stringprintf.h"
+#include "tools/android/common/daemon.h"
+#include "tools/android/forwarder2/device_controller.h"
+#include "tools/android/forwarder2/pipe_notifier.h"
+
+namespace {
+
+// Accessed from the signal handler.
+base::LazyInstance<forwarder::PipeNotifier>::Leaky g_notifier;
+
+// Unix domain socket name for Device Controller.
+const char kDefaultAdbSocket[] = "chrome_device_forwarder";
+
+void KillHandler(int /* unused */) {
+ if (!g_notifier.Get().Notify())
+ exit(-1);
+}
+
+} // namespace
+
+int main(int argc, char** argv) {
+ printf("Device forwarder to forward connections to the Host machine.\n");
+ printf("Like 'adb forward' but in the reverse direction\n");
+
+ CommandLine command_line(argc, argv);
+ string adb_socket_path = command_line.GetSwitchValueASCII("adb_sock");
+ if (adb_socket_path.empty()) {
+ adb_socket_path = kDefaultAdbSocket;
+ }
+ if (tools::HasHelpSwitch(command_line)) {
+ tools::ShowHelp(
+ argv[0],
+ "[--adb_sock=<adb sock>]",
+ base::StringPrintf(
+ " <adb sock> is the Abstract Unix Domain Socket path "
+ " where Adb is configured to forward from."
+ " Default is %s\n", kDefaultAdbSocket).c_str());
+ return 0;
+ }
+ if (!tools::HasNoSpawnDaemonSwitch(command_line)) {
+ tools::SpawnDaemon(0);
+ }
+
+ signal(SIGTERM, KillHandler);
+ signal(SIGINT, KillHandler);
+
+ forwarder::DeviceController controller(g_notifier.Get().receiver_fd());
+ // TODO(felipeg): We should check if the controller was correctly started
+ // before printing Ready.
+ printf("Device Forwarder Ready.\n");
+ controller.Start(adb_socket_path);
+
+ return 0;
+}
« no previous file with comments | « tools/android/forwarder2/device_controller.cc ('k') | tools/android/forwarder2/device_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698