• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <algorithm>
18 #include <iterator>
19 #include <limits>
20 #include <sstream>
21 #include <thread>
22 #include <vector>
23 
24 #include <android-base/logging.h>
25 #include <gflags/gflags.h>
26 
27 #include <unistd.h>
28 #include <host/commands/kernel_log_monitor/kernel_log_server.h>
29 #include <host/commands/kernel_log_monitor/utils.h>
30 
31 #include "common/libs/fs/shared_fd.h"
32 #include "host/frontend/adb_connector/adb_connection_maintainer.h"
33 #include "host/libs/config/cuttlefish_config.h"
34 #include "host/libs/config/logging.h"
35 
36 DEFINE_string(addresses, "", "Comma-separated list of addresses to "
37                              "'adb connect' to");
38 
39 namespace {
LaunchConnectionMaintainerThread(const std::string & address)40 void LaunchConnectionMaintainerThread(const std::string& address) {
41   std::thread(cuttlefish::EstablishAndMaintainConnection, address).detach();
42 }
43 
ParseAddressList(std::string ports)44 std::vector<std::string> ParseAddressList(std::string ports) {
45   std::replace(ports.begin(), ports.end(), ',', ' ');
46   std::istringstream port_stream{ports};
47   return {std::istream_iterator<std::string>{port_stream},
48           std::istream_iterator<std::string>{}};
49 }
50 
SleepForever()51 [[noreturn]] void SleepForever() {
52   while (true) {
53     sleep(std::numeric_limits<unsigned int>::max());
54   }
55 }
56 
57 }  // namespace
58 
main(int argc,char * argv[])59 int main(int argc, char* argv[]) {
60   cuttlefish::DefaultSubprocessLogging(argv);
61   gflags::ParseCommandLineFlags(&argc, &argv, true);
62   CHECK(!FLAGS_addresses.empty()) << "Must specify --addresses flag";
63 
64   for (auto address : ParseAddressList(FLAGS_addresses)) {
65     LaunchConnectionMaintainerThread(address);
66   }
67 
68   SleepForever();
69 }
70