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; |
+} |