Expose new user-friendly adb functions
Expose interruptible adb functions which return the expected result directly, without exposing the process (sc_pid) to the caller.
This commit is contained in:
parent
afb5a5e80f
commit
b7559744a7
2 changed files with 100 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "util/file.h"
|
||||
#include "util/log.h"
|
||||
#include "util/process_intr.h"
|
||||
#include "util/str.h"
|
||||
|
||||
static const char *adb_command;
|
||||
|
@ -238,3 +239,70 @@ adb_exec_get_serialno(sc_pipe *pout) {
|
|||
const char *const adb_cmd[] = {"get-serialno"};
|
||||
return adb_execute_p(NULL, adb_cmd, ARRAY_LEN(adb_cmd), pout);
|
||||
}
|
||||
|
||||
bool
|
||||
adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
||||
const char *device_socket_name) {
|
||||
sc_pid pid = adb_exec_forward(serial, local_port, device_socket_name);
|
||||
return sc_process_check_success_intr(intr, pid, "adb forward", true);
|
||||
}
|
||||
|
||||
bool
|
||||
adb_forward_remove(struct sc_intr *intr, const char *serial,
|
||||
uint16_t local_port) {
|
||||
sc_pid pid = adb_exec_forward_remove(serial, local_port);
|
||||
return sc_process_check_success_intr(intr, pid, "adb forward --remove",
|
||||
true);
|
||||
}
|
||||
|
||||
bool
|
||||
adb_reverse(struct sc_intr *intr, const char *serial,
|
||||
const char *device_socket_name, uint16_t local_port) {
|
||||
sc_pid pid = adb_exec_reverse(serial, device_socket_name, local_port);
|
||||
return sc_process_check_success_intr(intr, pid, "adb reverse", true);
|
||||
}
|
||||
|
||||
bool
|
||||
adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
||||
const char *device_socket_name) {
|
||||
sc_pid pid = adb_exec_reverse_remove(serial, device_socket_name);
|
||||
return sc_process_check_success_intr(intr, pid, "adb reverse --remove",
|
||||
true);
|
||||
}
|
||||
|
||||
bool
|
||||
adb_push(struct sc_intr *intr, const char *serial, const char *local,
|
||||
const char *remote) {
|
||||
sc_pid pid = adb_exec_push(serial, local, remote);
|
||||
return sc_process_check_success_intr(intr, pid, "adb push", true);
|
||||
}
|
||||
|
||||
bool
|
||||
adb_install(struct sc_intr *intr, const char *serial, const char *local) {
|
||||
sc_pid pid = adb_exec_install(serial, local);
|
||||
return sc_process_check_success_intr(intr, pid, "adb install", true);
|
||||
}
|
||||
|
||||
char *
|
||||
adb_get_serialno(struct sc_intr *intr) {
|
||||
sc_pipe pout;
|
||||
sc_pid pid = adb_exec_get_serialno(&pout);
|
||||
if (pid == SC_PROCESS_NONE) {
|
||||
LOGE("Could not execute \"adb get-serialno\"");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char buf[128];
|
||||
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf));
|
||||
sc_pipe_close(pout);
|
||||
|
||||
bool ok =
|
||||
sc_process_check_success_intr(intr, pid, "adb get-serialno", true);
|
||||
if (!ok) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sc_str_truncate(buf, r, " \r\n");
|
||||
|
||||
return strdup(buf);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <inttypes.h>
|
||||
|
||||
#include "util/process.h"
|
||||
#include "util/intr.h"
|
||||
|
||||
sc_pid
|
||||
adb_execute(const char *serial, const char *const adb_cmd[], size_t len);
|
||||
|
@ -43,4 +44,35 @@ adb_exec_install(const char *serial, const char *local);
|
|||
sc_pid
|
||||
adb_exec_get_serialno(sc_pipe *pout);
|
||||
|
||||
bool
|
||||
adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
||||
const char *device_socket_name);
|
||||
|
||||
bool
|
||||
adb_forward_remove(struct sc_intr *intr, const char *serial,
|
||||
uint16_t local_port);
|
||||
|
||||
bool
|
||||
adb_reverse(struct sc_intr *intr, const char *serial,
|
||||
const char *device_socket_name, uint16_t local_port);
|
||||
|
||||
bool
|
||||
adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
||||
const char *device_socket_name);
|
||||
|
||||
bool
|
||||
adb_push(struct sc_intr *intr, const char *serial, const char *local,
|
||||
const char *remote);
|
||||
|
||||
bool
|
||||
adb_install(struct sc_intr *intr, const char *serial, const char *local);
|
||||
|
||||
/**
|
||||
* Execute `adb get-serialno`
|
||||
*
|
||||
* Return the result, to be freed by the caller, or NULL on error.
|
||||
*/
|
||||
char *
|
||||
adb_get_serialno(struct sc_intr *intr);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue