Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34d68c2b authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Switch usb_linux_client to C++."

parents 0e2d6015 2acec915
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ LIBADB_windows_SRC_FILES := \
    usb_windows.cpp \

include $(CLEAR_VARS)
LOCAL_CLANG := $(ADB_CLANG)
LOCAL_CLANG := true
LOCAL_MODULE := libadbd
LOCAL_CFLAGS := $(LIBADB_CFLAGS) -DADB_HOST=0
LOCAL_SRC_FILES := \
@@ -57,7 +57,7 @@ LOCAL_SRC_FILES := \
    fdevent.cpp \
    jdwp_service.cpp \
    qemu_tracing.cpp \
    usb_linux_client.c \
    usb_linux_client.cpp \

include $(BUILD_STATIC_LIBRARY)

+15 −29
Original line number Diff line number Diff line
@@ -239,12 +239,7 @@ static void usb_adb_kick(usb_handle *h)

static void usb_adb_init()
{
    usb_handle *h;
    adb_thread_t tid;
    int fd;

    h = calloc(1, sizeof(usb_handle));

    usb_handle* h = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
    h->write = usb_adb_write;
    h->read = usb_adb_read;
    h->kick = usb_adb_kick;
@@ -258,7 +253,7 @@ static void usb_adb_init()
    // We never touch this file again - just leave it open
    // indefinitely so the kernel will know when we are running
    // and when we are not.
    fd = unix_open("/dev/android_adb_enable", O_RDWR);
    int fd = unix_open("/dev/android_adb_enable", O_RDWR);
    if (fd < 0) {
       D("failed to open /dev/android_adb_enable\n");
    } else {
@@ -266,6 +261,7 @@ static void usb_adb_init()
    }

    D("[ usb_init - starting thread ]\n");
    adb_thread_t tid;
    if(adb_thread_create(&tid, usb_adb_open_thread, h)){
        fatal_errno("cannot create usb thread");
    }
@@ -375,7 +371,7 @@ static void *usb_ffs_open_thread(void *x)
    return 0;
}

static int bulk_write(int bulk_in, const char *buf, size_t length)
static int bulk_write(int bulk_in, const uint8_t* buf, size_t length)
{
    size_t count = 0;
    int ret;
@@ -396,20 +392,17 @@ static int bulk_write(int bulk_in, const char *buf, size_t length)

static int usb_ffs_write(usb_handle* h, const void* data, int len)
{
    int n;

    D("about to write (fd=%d, len=%d)\n", h->bulk_in, len);
    n = bulk_write(h->bulk_in, data, len);
    int n = bulk_write(h->bulk_in, reinterpret_cast<const uint8_t*>(data), len);
    if (n != len) {
        D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
            h->bulk_in, n, errno, strerror(errno));
        D("ERROR: fd = %d, n = %d: %s\n", h->bulk_in, n, strerror(errno));
        return -1;
    }
    D("[ done fd=%d ]\n", h->bulk_in);
    return 0;
}

static int bulk_read(int bulk_out, char *buf, size_t length)
static int bulk_read(int bulk_out, uint8_t* buf, size_t length)
{
    size_t count = 0;
    int ret;
@@ -432,13 +425,10 @@ static int bulk_read(int bulk_out, char *buf, size_t length)

static int usb_ffs_read(usb_handle* h, void* data, int len)
{
    int n;

    D("about to read (fd=%d, len=%d)\n", h->bulk_out, len);
    n = bulk_read(h->bulk_out, data, len);
    int n = bulk_read(h->bulk_out, reinterpret_cast<uint8_t*>(data), len);
    if (n != len) {
        D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
            h->bulk_out, n, errno, strerror(errno));
        D("ERROR: fd = %d, n = %d: %s\n", h->bulk_out, n, strerror(errno));
        return -1;
    }
    D("[ done fd=%d ]\n", h->bulk_out);
@@ -473,17 +463,12 @@ static void usb_ffs_kick(usb_handle *h)

static void usb_ffs_init()
{
    usb_handle *h;
    adb_thread_t tid;

    D("[ usb_init - using FunctionFS ]\n");

    h = calloc(1, sizeof(usb_handle));

    usb_handle* h = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
    h->write = usb_ffs_write;
    h->read = usb_ffs_read;
    h->kick = usb_ffs_kick;

    h->control = -1;
    h->bulk_out = -1;
    h->bulk_out = -1;
@@ -492,6 +477,7 @@ static void usb_ffs_init()
    adb_mutex_init(&h->lock, 0);

    D("[ usb_init - starting thread ]\n");
    adb_thread_t tid;
    if (adb_thread_create(&tid, usb_ffs_open_thread, h)){
        fatal_errno("[ cannot create usb thread ]\n");
    }