Merge "Give enum types CamelCase names for clarity."

This commit is contained in:
Elliott Hughes 2015-05-05 21:18:11 +00:00 committed by Gerrit Code Review
commit aa76c46288
11 changed files with 78 additions and 101 deletions

View file

@ -696,7 +696,7 @@ int launch_server(int server_port)
// Try to handle a network forwarding request.
// This returns 1 on success, 0 on failure, and -1 to indicate this is not
// a forwarding-related request.
int handle_forward_request(const char* service, transport_type ttype, char* serial, int reply_fd)
int handle_forward_request(const char* service, TransportType type, char* serial, int reply_fd)
{
if (!strcmp(service, "list-forward")) {
// Create the list of forward redirections.
@ -757,13 +757,13 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
}
std::string error_msg;
transport = acquire_one_transport(CS_ANY, ttype, serial, &error_msg);
transport = acquire_one_transport(CS_ANY, type, serial, &error_msg);
if (!transport) {
SendFail(reply_fd, error_msg);
return 1;
}
install_status_t r;
InstallStatus r;
if (createForward) {
r = install_listener(local, remote, transport, no_rebind);
} else {
@ -796,7 +796,7 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
return 0;
}
int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s)
int handle_host_request(char *service, TransportType type, char* serial, int reply_fd, asocket *s)
{
if(!strcmp(service, "kill")) {
fprintf(stderr,"adb server killed by remote request\n");
@ -813,7 +813,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
// "transport-local:" is used for switching transport to the only local transport
// "transport-any:" is used for switching transport to the only transport
if (!strncmp(service, "transport", strlen("transport"))) {
transport_type type = kTransportAny;
TransportType type = kTransportAny;
if (!strncmp(service, "transport-usb", strlen("transport-usb"))) {
type = kTransportUsb;
@ -890,7 +890,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
if(!strncmp(service,"get-serialno",strlen("get-serialno"))) {
const char *out = "unknown";
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
transport = acquire_one_transport(CS_ANY, type, serial, NULL);
if (transport && transport->serial) {
out = transport->serial;
}
@ -900,7 +900,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
}
if(!strncmp(service,"get-devpath",strlen("get-devpath"))) {
const char *out = "unknown";
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
transport = acquire_one_transport(CS_ANY, type, serial, NULL);
if (transport && transport->devpath) {
out = transport->devpath;
}
@ -917,14 +917,14 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r
}
if(!strncmp(service,"get-state",strlen("get-state"))) {
transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
transport = acquire_one_transport(CS_ANY, type, serial, NULL);
SendOkay(reply_fd);
SendProtocolString(reply_fd, transport->connection_state_name());
return 0;
}
#endif // ADB_HOST
int ret = handle_forward_request(service, ttype, serial, reply_fd);
int ret = handle_forward_request(service, type, serial, reply_fd);
if (ret >= 0)
return ret - 1;
return -1;

View file

@ -161,7 +161,7 @@ struct adisconnect
** object, it's a special value used to indicate that a client wants to
** connect to a service implemented within the ADB server itself.
*/
enum transport_type {
enum TransportType {
kTransportUsb,
kTransportLocal,
kTransportAny,
@ -187,7 +187,7 @@ struct atransport
unsigned sync_token;
int connection_state;
int online;
transport_type type;
TransportType type;
/* usb handle or socket fd as needed */
usb_handle *usb;
@ -284,7 +284,7 @@ asocket* create_jdwp_tracker_service_socket();
int create_jdwp_connection_fd(int jdwp_pid);
#endif
int handle_forward_request(const char* service, transport_type ttype, char* serial, int reply_fd);
int handle_forward_request(const char* service, TransportType type, char* serial, int reply_fd);
#if !ADB_HOST
void framebuffer_service(int fd, void *cookie);
@ -353,11 +353,6 @@ extern const char *adb_device_banner;
extern int HOST;
extern int SHELL_EXIT_NOTIFY_FD;
enum subproc_mode {
SUBPROC_PTY = 0,
SUBPROC_RAW = 1,
} ;
#define CHUNK_SIZE (64*1024)
#if !ADB_HOST
@ -371,7 +366,7 @@ enum subproc_mode {
#define USB_FFS_ADB_IN USB_FFS_ADB_EP(ep2)
#endif
int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s);
int handle_host_request(char *service, TransportType type, char* serial, int reply_fd, asocket *s);
void handle_online(atransport *t);
void handle_offline(atransport *t);

View file

@ -36,7 +36,7 @@
#include "adb_io.h"
static transport_type __adb_transport = kTransportAny;
static TransportType __adb_transport = kTransportAny;
static const char* __adb_serial = NULL;
static int __adb_server_port = DEFAULT_ADB_PORT;
@ -64,7 +64,7 @@ static bool ReadProtocolString(int fd, std::string* s, std::string* error) {
return true;
}
void adb_set_transport(transport_type type, const char* serial)
void adb_set_transport(TransportType type, const char* serial)
{
__adb_transport = type;
__adb_serial = serial;

View file

@ -21,9 +21,8 @@ int adb_command(const std::string& service, std::string* error);
// Returns true on success; returns false and fills 'error' on failure.
bool adb_query(const std::string& service, std::string* result, std::string* error);
/* Set the preferred transport to connect to.
*/
void adb_set_transport(transport_type type, const char* serial);
// Set the preferred transport to connect to.
void adb_set_transport(TransportType type, const char* serial);
/* Set TCP specifics of the transport to use
*/

View file

@ -160,8 +160,7 @@ std::string format_listeners() {
return result;
}
install_status_t remove_listener(const char *local_name, atransport* transport)
{
InstallStatus remove_listener(const char *local_name, atransport* transport) {
alistener *l;
for (l = listener_list.next; l != &listener_list; l = l->next) {
@ -185,7 +184,7 @@ void remove_all_listeners(void)
}
}
install_status_t install_listener(const std::string& local_name,
InstallStatus install_listener(const std::string& local_name,
const char *connect_to,
atransport* transport,
int no_rebind)

View file

@ -22,7 +22,7 @@
#include <string>
// error/status codes for install_listener.
enum install_status_t {
enum InstallStatus {
INSTALL_STATUS_OK = 0,
INSTALL_STATUS_INTERNAL_ERROR = -1,
INSTALL_STATUS_CANNOT_BIND = -2,
@ -36,14 +36,14 @@ void listener_disconnect(void* _l, atransport* t);
void listener_event_func(int _fd, unsigned ev, void *_l);
void ss_listener_event_func(int _fd, unsigned ev, void *_l);
install_status_t install_listener(const std::string& local_name,
const char* connect_to,
atransport* transport,
int no_rebind);
InstallStatus install_listener(const std::string& local_name,
const char* connect_to,
atransport* transport,
int no_rebind);
std::string format_listeners();
install_status_t remove_listener(const char* local_name, atransport* transport);
InstallStatus remove_listener(const char* local_name, atransport* transport);
void remove_all_listeners(void);
#endif /* __ADB_LISTENERS_H */

View file

@ -47,9 +47,9 @@
#include "adb_utils.h"
#include "file_sync_service.h"
static int install_app(transport_type t, const char* serial, int argc, const char** argv);
static int install_multiple_app(transport_type t, const char* serial, int argc, const char** argv);
static int uninstall_app(transport_type t, const char* serial, int argc, const char** argv);
static int install_app(TransportType t, const char* serial, int argc, const char** argv);
static int install_multiple_app(TransportType t, const char* serial, int argc, const char** argv);
static int uninstall_app(TransportType t, const char* serial, int argc, const char** argv);
static std::string gProductOutPath;
extern int gListenAll;
@ -431,7 +431,7 @@ static int interactive_shell() {
}
static std::string format_host_command(const char* command, transport_type type, const char* serial) {
static std::string format_host_command(const char* command, TransportType type, const char* serial) {
if (serial) {
return android::base::StringPrintf("host-serial:%s:%s", serial, command);
}
@ -673,7 +673,7 @@ static int ppp(int argc, const char** argv) {
#endif /* !defined(_WIN32) */
}
static bool wait_for_device(const char* service, transport_type t, const char* serial) {
static bool wait_for_device(const char* service, TransportType t, const char* serial) {
// Was the caller vague about what they'd like us to wait for?
// If so, check they weren't more specific in their choice of transport type.
if (strcmp(service, "wait-for-device") == 0) {
@ -697,7 +697,7 @@ static bool wait_for_device(const char* service, transport_type t, const char* s
return true;
}
static int send_shell_command(transport_type transport_type, const char* serial,
static int send_shell_command(TransportType transport_type, const char* serial,
const std::string& command) {
int fd;
while (true) {
@ -719,7 +719,7 @@ static int send_shell_command(transport_type transport_type, const char* serial,
return rc;
}
static int logcat(transport_type transport, const char* serial, int argc, const char** argv) {
static int logcat(TransportType transport, const char* serial, int argc, const char** argv) {
char* log_tags = getenv("ANDROID_LOG_TAGS");
std::string quoted = escape_arg(log_tags == nullptr ? "" : log_tags);
@ -953,9 +953,7 @@ int adb_commandline(int argc, const char **argv) {
int is_daemon = 0;
int is_server = 0;
int r;
transport_type ttype = kTransportAny;
const char* serial = NULL;
const char* server_port_str = NULL;
TransportType transport_type = kTransportAny;
// If defined, this should be an absolute path to
// the directory containing all of the various system images
@ -968,10 +966,10 @@ int adb_commandline(int argc, const char **argv) {
}
// TODO: also try TARGET_PRODUCT/TARGET_DEVICE as a hint
serial = getenv("ANDROID_SERIAL");
const char* serial = getenv("ANDROID_SERIAL");
/* Validate and assign the server port */
server_port_str = getenv("ANDROID_ADB_SERVER_PORT");
const char* server_port_str = getenv("ANDROID_ADB_SERVER_PORT");
int server_port = DEFAULT_ADB_PORT;
if (server_port_str && strlen(server_port_str) > 0) {
server_port = (int) strtol(server_port_str, NULL, 0);
@ -1017,9 +1015,9 @@ int adb_commandline(int argc, const char **argv) {
argv++;
}
} else if (!strcmp(argv[0],"-d")) {
ttype = kTransportUsb;
transport_type = kTransportUsb;
} else if (!strcmp(argv[0],"-e")) {
ttype = kTransportLocal;
transport_type = kTransportLocal;
} else if (!strcmp(argv[0],"-a")) {
gListenAll = 1;
} else if (!strncmp(argv[0], "-H", 2)) {
@ -1064,7 +1062,7 @@ int adb_commandline(int argc, const char **argv) {
argv++;
}
adb_set_transport(ttype, serial);
adb_set_transport(transport_type, serial);
adb_set_tcp_specifics(server_port);
if (is_server) {
@ -1087,7 +1085,7 @@ int adb_commandline(int argc, const char **argv) {
if (!strncmp(argv[0], "wait-for-", strlen("wait-for-"))) {
const char* service = argv[0];
if (!wait_for_device(service, ttype, serial)) {
if (!wait_for_device(service, transport_type, serial)) {
return 1;
}
@ -1256,7 +1254,7 @@ int adb_commandline(int argc, const char **argv) {
}
else if (!strcmp(argv[0], "bugreport")) {
if (argc != 1) return usage();
return send_shell_command(ttype, serial, "shell:bugreport");
return send_shell_command(transport_type, serial, "shell:bugreport");
}
/* adb_command() wrapper commands */
else if (!strcmp(argv[0], "forward") || !strcmp(argv[0], "reverse")) {
@ -1297,9 +1295,9 @@ int adb_commandline(int argc, const char **argv) {
if (serial) {
snprintf(host_prefix, sizeof host_prefix, "host-serial:%s",
serial);
} else if (ttype == kTransportUsb) {
} else if (transport_type == kTransportUsb) {
snprintf(host_prefix, sizeof host_prefix, "host-usb");
} else if (ttype == kTransportLocal) {
} else if (transport_type == kTransportLocal) {
snprintf(host_prefix, sizeof host_prefix, "host-local");
} else {
snprintf(host_prefix, sizeof host_prefix, "host");
@ -1376,15 +1374,15 @@ int adb_commandline(int argc, const char **argv) {
}
else if (!strcmp(argv[0], "install")) {
if (argc < 2) return usage();
return install_app(ttype, serial, argc, argv);
return install_app(transport_type, serial, argc, argv);
}
else if (!strcmp(argv[0], "install-multiple")) {
if (argc < 2) return usage();
return install_multiple_app(ttype, serial, argc, argv);
return install_multiple_app(transport_type, serial, argc, argv);
}
else if (!strcmp(argv[0], "uninstall")) {
if (argc < 2) return usage();
return uninstall_app(ttype, serial, argc, argv);
return uninstall_app(transport_type, serial, argc, argv);
}
else if (!strcmp(argv[0], "sync")) {
std::string src;
@ -1436,11 +1434,11 @@ int adb_commandline(int argc, const char **argv) {
!strcmp(argv[0],"get-serialno") ||
!strcmp(argv[0],"get-devpath"))
{
return adb_query_command(format_host_command(argv[0], ttype, serial));
return adb_query_command(format_host_command(argv[0], transport_type, serial));
}
/* other commands */
else if (!strcmp(argv[0],"logcat") || !strcmp(argv[0],"lolcat") || !strcmp(argv[0],"longcat")) {
return logcat(ttype, serial, argc, argv);
return logcat(transport_type, serial, argc, argv);
}
else if (!strcmp(argv[0],"ppp")) {
return ppp(argc, argv);
@ -1476,9 +1474,7 @@ int adb_commandline(int argc, const char **argv) {
return 1;
}
static int pm_command(transport_type transport, const char* serial,
int argc, const char** argv)
{
static int pm_command(TransportType transport, const char* serial, int argc, const char** argv) {
std::string cmd = "shell:pm";
while (argc-- > 0) {
@ -1488,9 +1484,7 @@ static int pm_command(transport_type transport, const char* serial,
return send_shell_command(transport, serial, cmd);
}
static int uninstall_app(transport_type transport, const char* serial, int argc,
const char** argv)
{
static int uninstall_app(TransportType transport, const char* serial, int argc, const char** argv) {
/* if the user choose the -k option, we refuse to do it until devices are
out with the option to uninstall the remaining data somehow (adb/ui) */
if (argc == 3 && strcmp(argv[1], "-k") == 0)
@ -1507,8 +1501,7 @@ static int uninstall_app(transport_type transport, const char* serial, int argc,
return pm_command(transport, serial, argc, argv);
}
static int delete_file(transport_type transport, const char* serial, char* filename)
{
static int delete_file(TransportType transport, const char* serial, char* filename) {
std::string cmd = "shell:rm -f " + escape_arg(filename);
return send_shell_command(transport, serial, cmd);
}
@ -1524,9 +1517,7 @@ static const char* get_basename(const char* filename)
}
}
static int install_app(transport_type transport, const char* serial, int argc,
const char** argv)
{
static int install_app(TransportType transport, const char* serial, int argc, const char** argv) {
static const char *const DATA_DEST = "/data/local/tmp/%s";
static const char *const SD_DEST = "/sdcard/tmp/%s";
const char* where = DATA_DEST;
@ -1578,7 +1569,7 @@ cleanup_apk:
return err;
}
static int install_multiple_app(transport_type transport, const char* serial, int argc,
static int install_multiple_app(TransportType transport, const char* serial, int argc,
const char** argv)
{
int i;

View file

@ -378,12 +378,7 @@ static void subproc_waiter_service(int fd, void *cookie)
}
}
static int create_subproc_thread(const char *name, const subproc_mode mode)
{
adb_thread_t t;
int ret_fd;
pid_t pid = -1;
static int create_subproc_thread(const char *name, bool pty = false) {
const char *arg0, *arg1;
if (name == 0 || *name == 0) {
arg0 = "-"; arg1 = 0;
@ -391,16 +386,12 @@ static int create_subproc_thread(const char *name, const subproc_mode mode)
arg0 = "-c"; arg1 = name;
}
switch (mode) {
case SUBPROC_PTY:
pid_t pid = -1;
int ret_fd;
if (pty) {
ret_fd = create_subproc_pty(SHELL_COMMAND, arg0, arg1, &pid);
break;
case SUBPROC_RAW:
} else {
ret_fd = create_subproc_raw(SHELL_COMMAND, arg0, arg1, &pid);
break;
default:
fprintf(stderr, "invalid subproc_mode %d\n", mode);
return -1;
}
D("create_subproc ret_fd=%d pid=%d\n", ret_fd, pid);
@ -410,6 +401,7 @@ static int create_subproc_thread(const char *name, const subproc_mode mode)
sti->cookie = (void*) (uintptr_t) pid;
sti->fd = ret_fd;
adb_thread_t t;
if (adb_thread_create(&t, service_bootstrap_func, sti)) {
free(sti);
adb_close(ret_fd);
@ -462,9 +454,9 @@ int service_to_fd(const char *name)
} else if (!strncmp(name, "jdwp:", 5)) {
ret = create_jdwp_connection_fd(atoi(name+5));
} else if(!HOST && !strncmp(name, "shell:", 6)) {
ret = create_subproc_thread(name + 6, SUBPROC_PTY);
ret = create_subproc_thread(name + 6, true);
} else if(!HOST && !strncmp(name, "exec:", 5)) {
ret = create_subproc_thread(name + 5, SUBPROC_RAW);
ret = create_subproc_thread(name + 5);
} else if(!strncmp(name, "sync:", 5)) {
ret = create_service_thread(file_sync_service, NULL);
} else if(!strncmp(name, "remount:", 8)) {
@ -479,9 +471,9 @@ int service_to_fd(const char *name)
ret = create_service_thread(restart_unroot_service, NULL);
} else if(!strncmp(name, "backup:", 7)) {
ret = create_subproc_thread(android::base::StringPrintf("/system/bin/bu backup %s",
(name + 7)).c_str(), SUBPROC_RAW);
(name + 7)).c_str());
} else if(!strncmp(name, "restore:", 8)) {
ret = create_subproc_thread("/system/bin/bu restore", SUBPROC_RAW);
ret = create_subproc_thread("/system/bin/bu restore");
} else if(!strncmp(name, "tcpip:", 6)) {
int port;
if (sscanf(name + 6, "%d", &port) != 1) {
@ -514,7 +506,7 @@ int service_to_fd(const char *name)
#if ADB_HOST
struct state_info {
transport_type transport;
TransportType transport_type;
char* serial;
int state;
};
@ -526,7 +518,8 @@ static void wait_for_state(int fd, void* cookie)
D("wait_for_state %d\n", sinfo->state);
std::string error_msg = "unknown error";
atransport* t = acquire_one_transport(sinfo->state, sinfo->transport, sinfo->serial, &error_msg);
atransport* t = acquire_one_transport(sinfo->state, sinfo->transport_type, sinfo->serial,
&error_msg);
if (t != 0) {
SendOkay(fd);
} else {
@ -664,13 +657,13 @@ asocket* host_service_to_socket(const char* name, const char *serial)
name += strlen("wait-for-");
if (!strncmp(name, "local", strlen("local"))) {
sinfo->transport = kTransportLocal;
sinfo->transport_type = kTransportLocal;
sinfo->state = CS_DEVICE;
} else if (!strncmp(name, "usb", strlen("usb"))) {
sinfo->transport = kTransportUsb;
sinfo->transport_type = kTransportUsb;
sinfo->state = CS_DEVICE;
} else if (!strncmp(name, "any", strlen("any"))) {
sinfo->transport = kTransportAny;
sinfo->transport_type = kTransportAny;
sinfo->state = CS_DEVICE;
} else {
free(sinfo);

View file

@ -691,7 +691,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
#if ADB_HOST
char *service = NULL;
char* serial = NULL;
transport_type ttype = kTransportAny;
TransportType type = kTransportAny;
#endif
D("SS(%d): enqueue %d\n", s->id, p->len);
@ -748,13 +748,13 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
service = serial_end + 1;
}
} else if (!strncmp(service, "host-usb:", strlen("host-usb:"))) {
ttype = kTransportUsb;
type = kTransportUsb;
service += strlen("host-usb:");
} else if (!strncmp(service, "host-local:", strlen("host-local:"))) {
ttype = kTransportLocal;
type = kTransportLocal;
service += strlen("host-local:");
} else if (!strncmp(service, "host:", strlen("host:"))) {
ttype = kTransportAny;
type = kTransportAny;
service += strlen("host:");
} else {
service = NULL;
@ -768,7 +768,7 @@ static int smart_socket_enqueue(asocket *s, apacket *p)
** the OKAY or FAIL message and all we have to do
** is clean up.
*/
if(handle_host_request(service, ttype, serial, s->peer->fd, s) == 0) {
if(handle_host_request(service, type, serial, s->peer->fd, s) == 0) {
/* XXX fail message? */
D( "SS(%d): handled host service '%s'\n", s->id, service );
goto fail;

View file

@ -740,7 +740,7 @@ static int qual_match(const char *to_test,
return !*to_test;
}
atransport* acquire_one_transport(int state, transport_type ttype,
atransport* acquire_one_transport(int state, TransportType type,
const char* serial, std::string* error_out)
{
atransport *t;
@ -773,7 +773,7 @@ retry:
result = t;
}
} else {
if (ttype == kTransportUsb && t->type == kTransportUsb) {
if (type == kTransportUsb && t->type == kTransportUsb) {
if (result) {
if (error_out) *error_out = "more than one device";
ambiguous = 1;
@ -781,7 +781,7 @@ retry:
break;
}
result = t;
} else if (ttype == kTransportLocal && t->type == kTransportLocal) {
} else if (type == kTransportLocal && t->type == kTransportLocal) {
if (result) {
if (error_out) *error_out = "more than one emulator";
ambiguous = 1;
@ -789,7 +789,7 @@ retry:
break;
}
result = t;
} else if (ttype == kTransportAny) {
} else if (type == kTransportAny) {
if (result) {
if (error_out) *error_out = "more than one device/emulator";
ambiguous = 1;

View file

@ -29,7 +29,7 @@
* If serial is non-NULL then only the device with that serial will be chosen.
* If no suitable transport is found, error is set.
*/
atransport* acquire_one_transport(int state, transport_type ttype,
atransport* acquire_one_transport(int state, TransportType type,
const char* serial, std::string* error_out);
void add_transport_disconnect(atransport* t, adisconnect* dis);
void remove_transport_disconnect(atransport* t, adisconnect* dis);