1 /* 2 * Copyright 2016 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 "ShellDriverMain.h" 18 19 #include <getopt.h> 20 #include <stdio.h> 21 #include <string> 22 23 #include "ShellDriver.h" 24 25 using namespace std; 26 27 // Dumps usage on stderr. 28 static void usage() { 29 fprintf( 30 stderr, 31 "Usage: vts_shell_driver --server_socket_path=<UNIX_domain_socket_path>\n" 32 "\n" 33 "Android Vts Shell Driver v0.1. To run shell commands on Android system." 34 "\n" 35 "Options:\n" 36 "--help\n" 37 " Show this message.\n" 38 "--socket_path=<Unix_socket_path>\n" 39 " Show this message.\n" 40 "\n" 41 "Recording continues until Ctrl-C is hit or the time limit is reached.\n" 42 "\n"); 43 } 44 45 // Parses command args and kicks things off. 46 int main(int argc, char* const argv[]) { 47 static const struct option longOptions[] = { 48 {"help", no_argument, NULL, 'h'}, 49 {"server_socket_path", required_argument, NULL, 's'}, 50 {NULL, 0, NULL, 0}}; 51 52 string socket_path = DEFAULT_SOCKET_PATH; 53 54 while (true) { 55 int optionIndex = 0; 56 int ic = getopt_long(argc, argv, "", longOptions, &optionIndex); 57 if (ic == -1) { 58 break; 59 } 60 61 switch (ic) { 62 case 'h': 63 usage(); 64 return 0; 65 case 's': 66 socket_path = string(optarg); 67 break; 68 default: 69 if (ic != '?') { 70 fprintf(stderr, "getopt_long returned unexpected value 0x%x\n", ic); 71 } 72 return 2; 73 } 74 } 75 76 android::vts::VtsShellDriver shellDriver(socket_path.c_str()); 77 return shellDriver.StartListen(); 78 } 79