diff options
author | Dan Albert <danalbert@google.com> | 2015-03-10 00:58:05 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-10 00:58:06 +0000 |
commit | 5f2ccb0efd1331f0137e294bed7a076c472f0ed6 (patch) | |
tree | 9763c3cb2f5e640c7061cffb47d61274a37baab8 /adb/console.cpp | |
parent | 9b1fd969a7b7f1c6f1ed19719f21d57001d3c461 (diff) | |
parent | bac3474a8256cb32a29e8d46f78cad95a5502692 (diff) | |
download | system_core-5f2ccb0efd1331f0137e294bed7a076c472f0ed6.zip system_core-5f2ccb0efd1331f0137e294bed7a076c472f0ed6.tar.gz system_core-5f2ccb0efd1331f0137e294bed7a076c472f0ed6.tar.bz2 |
Merge "Move adb to C++."
Diffstat (limited to 'adb/console.cpp')
-rw-r--r-- | adb/console.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/adb/console.cpp b/adb/console.cpp new file mode 100644 index 0000000..452ee41 --- /dev/null +++ b/adb/console.cpp @@ -0,0 +1,45 @@ +#include "sysdeps.h" +#include "adb.h" +#include "adb_client.h" +#include <stdio.h> + +static int connect_to_console(void) +{ + int fd, port; + + port = adb_get_emulator_console_port(); + if (port < 0) { + if (port == -2) + fprintf(stderr, "error: more than one emulator detected. use -s option\n"); + else + fprintf(stderr, "error: no emulator detected\n"); + return -1; + } + fd = socket_loopback_client( port, SOCK_STREAM ); + if (fd < 0) { + fprintf(stderr, "error: could not connect to TCP port %d\n", port); + return -1; + } + return fd; +} + + +int adb_send_emulator_command(int argc, const char** argv) +{ + int fd, nn; + + fd = connect_to_console(); + if (fd < 0) + return 1; + +#define QUIT "quit\n" + + for (nn = 1; nn < argc; nn++) { + adb_write( fd, argv[nn], strlen(argv[nn]) ); + adb_write( fd, (nn == argc-1) ? "\n" : " ", 1 ); + } + adb_write( fd, QUIT, sizeof(QUIT)-1 ); + adb_close(fd); + + return 0; +} |