From: Daniel Drake Date: Fri, 4 Jan 2008 01:13:25 +0000 (+0000) Subject: Use "transfer" instead of "msg" X-Git-Tag: upstream/1.0.21~1142 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=132d84bf8ae34bd0892b3d8207a53d87cc0a9cba;p=platform%2Fupstream%2Flibusb.git Use "transfer" instead of "msg" Based on a discussion with Tim Roberts. --- diff --git a/examples/dpfp.c b/examples/dpfp.c index 78251a7..84c4905 100644 --- a/examples/dpfp.c +++ b/examples/dpfp.c @@ -66,13 +66,13 @@ static libusb_urb_handle *irq_urbh = NULL; static int img_idx = 0; static int do_exit = 0; -static struct libusb_bulk_msg imgmsg = { +static struct libusb_bulk_transfer imgtrf = { .endpoint = EP_DATA, .data = imgbuf, .length = sizeof(imgbuf), }; -static struct libusb_bulk_msg irqmsg = { +static struct libusb_bulk_transfer irqtrf = { .endpoint = EP_INTR, .data = irqbuf, .length = sizeof(irqbuf), @@ -96,7 +96,7 @@ static struct libusb_dev *find_dpfp_device(void) static int print_f0_data(void) { unsigned char data[0x10]; - struct libusb_ctrl_msg msg = { + struct libusb_control_transfer transfer = { .requesttype = CTRL_IN, .request = USB_RQ, .value = 0xf0, @@ -107,7 +107,7 @@ static int print_f0_data(void) int r; unsigned int i; - r = libusb_ctrl_msg(devh, &msg, 0); + r = libusb_control_transfer(devh, &transfer, 0); if (r < 0) { fprintf(stderr, "F0 error %d\n", r); return r; @@ -126,7 +126,7 @@ static int print_f0_data(void) static int get_hwstat(unsigned char *status) { - struct libusb_ctrl_msg msg = { + struct libusb_control_transfer transfer = { .requesttype = CTRL_IN, .request = USB_RQ, .value = 0x07, @@ -136,7 +136,7 @@ static int get_hwstat(unsigned char *status) }; int r; - r = libusb_ctrl_msg(devh, &msg, 0); + r = libusb_control_transfer(devh, &transfer, 0); if (r < 0) { fprintf(stderr, "read hwstat error %d\n", r); return r; @@ -153,7 +153,7 @@ static int get_hwstat(unsigned char *status) static int set_hwstat(unsigned char data) { int r; - struct libusb_ctrl_msg msg = { + struct libusb_control_transfer transfer = { .requesttype = CTRL_OUT, .request = USB_RQ, .value = 0x07, @@ -164,7 +164,7 @@ static int set_hwstat(unsigned char data) printf("set hwstat to %02x\n", data); - r = libusb_ctrl_msg(devh, &msg, 0); + r = libusb_control_transfer(devh, &transfer, 0); if (r < 0) { fprintf(stderr, "set hwstat error %d\n", r); return r; @@ -180,7 +180,7 @@ static int set_hwstat(unsigned char data) static int set_mode(unsigned char data) { int r; - struct libusb_ctrl_msg msg = { + struct libusb_control_transfer transfer = { .requesttype = CTRL_OUT, .request = USB_RQ, .value = 0x4e, @@ -191,7 +191,7 @@ static int set_mode(unsigned char data) printf("set mode %02x\n", data); - r = libusb_ctrl_msg(devh, &msg, 0); + r = libusb_control_transfer(devh, &transfer, 0); if (r < 0) { fprintf(stderr, "set mode error %d\n", r); return r; @@ -222,7 +222,7 @@ static void cb_mode_changed(struct libusb_dev_handle *_devh, static int set_mode_async(unsigned char data) { libusb_urb_handle *urbh; - struct libusb_ctrl_msg msg = { + struct libusb_control_transfer transfer = { .requesttype = CTRL_OUT, .request = USB_RQ, .value = 0x4e, @@ -233,7 +233,8 @@ static int set_mode_async(unsigned char data) printf("async set mode %02x\n", data); - urbh = libusb_submit_ctrl_msg(devh, &msg, cb_mode_changed, NULL, 1000); + urbh = libusb_async_control_transfer(devh, &transfer, cb_mode_changed, NULL, + 1000); if (!urbh) { fprintf(stderr, "set mode submit error\n"); return -1; @@ -244,7 +245,7 @@ static int set_mode_async(unsigned char data) static int do_sync_intr(unsigned char *data) { - struct libusb_bulk_msg msg = { + struct libusb_bulk_transfer transfer = { .endpoint = EP_INTR, .data = data, .length = INTR_LENGTH, @@ -252,7 +253,7 @@ static int do_sync_intr(unsigned char *data) int r; int transferred; - r = libusb_intr_msg(devh, &msg, &transferred, 1000); + r = libusb_interrupt_transfer(devh, &transfer, &transferred, 1000); if (r < 0) { fprintf(stderr, "intr error %d\n", r); return r; @@ -397,14 +398,14 @@ static void cb_img(libusb_dev_handle *_devh, libusb_urb_handle *urbh, static int submit_irq_urb(void) { libusb_urb_handle_free(irq_urbh); - irq_urbh = libusb_submit_intr_msg(devh, &irqmsg, cb_irq, NULL, 0); + irq_urbh = libusb_async_interrupt_transfer(devh, &irqtrf, cb_irq, NULL, 0); return irq_urbh != NULL; } static int submit_img_urb(void) { libusb_urb_handle_free(img_urbh); - img_urbh = libusb_submit_bulk_msg(devh, &imgmsg, cb_img, NULL, 0); + img_urbh = libusb_async_bulk_transfer(devh, &imgtrf, cb_img, NULL, 0); return img_urbh != NULL; } diff --git a/libusb/io.c b/libusb/io.c index 20b2798..9d4bcec 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -196,14 +196,14 @@ static int submit_urb(struct libusb_dev_handle *devh, return 0; } -API_EXPORTED struct libusb_urb_handle *libusb_submit_ctrl_msg( - struct libusb_dev_handle *devh, struct libusb_ctrl_msg *msg, +API_EXPORTED struct libusb_urb_handle *libusb_async_control_transfer( + struct libusb_dev_handle *devh, struct libusb_control_transfer *transfer, libusb_ctrl_cb_fn callback, void *user_data, unsigned int timeout) { struct libusb_urb_handle *urbh = malloc(sizeof(*urbh)); struct libusb_ctrl_setup *setup; unsigned char *urbdata; - int urbdata_length = sizeof(struct libusb_ctrl_setup) + msg->length; + int urbdata_length = sizeof(struct libusb_ctrl_setup) + transfer->length; int r; if (!urbh) @@ -225,17 +225,19 @@ API_EXPORTED struct libusb_urb_handle *libusb_submit_ctrl_msg( } fp_dbg("RQT=%02x RQ=%02x VAL=%04x IDX=%04x length=%d", - msg->requesttype, msg->request, msg->value, msg->index, msg->length); + transfer->requesttype, transfer->request, transfer->value, + transfer->index, transfer->length); setup = (struct libusb_ctrl_setup *) urbdata; - setup->bRequestType = msg->requesttype; - setup->bRequest = msg->request; - setup->wValue = cpu_to_le16(msg->value); - setup->wIndex = cpu_to_le16(msg->index); - setup->wLength = cpu_to_le16(msg->length); + setup->bRequestType = transfer->requesttype; + setup->bRequest = transfer->request; + setup->wValue = cpu_to_le16(transfer->value); + setup->wIndex = cpu_to_le16(transfer->index); + setup->wLength = cpu_to_le16(transfer->length); - if ((msg->requesttype & 0x80) == LIBUSB_ENDPOINT_OUT) - memcpy(urbdata + sizeof(struct libusb_ctrl_setup), msg->data, msg->length); + if ((transfer->requesttype & 0x80) == LIBUSB_ENDPOINT_OUT) + memcpy(urbdata + sizeof(struct libusb_ctrl_setup), transfer->data, + transfer->length); urbh->urb_type = USB_URB_TYPE_CONTROL; urbh->buffer = urbdata; @@ -251,14 +253,15 @@ API_EXPORTED struct libusb_urb_handle *libusb_submit_ctrl_msg( return urbh; } -static struct libusb_urb_handle *submit_bulk_msg(struct libusb_dev_handle *devh, - struct libusb_bulk_msg *msg, libusb_bulk_cb_fn callback, void *user_data, - unsigned int timeout, unsigned char urbtype) +static struct libusb_urb_handle *submit_bulk_transfer( + struct libusb_dev_handle *devh, struct libusb_bulk_transfer *transfer, + libusb_bulk_cb_fn callback, void *user_data, unsigned int timeout, + unsigned char urbtype) { struct libusb_urb_handle *urbh = malloc(sizeof(*urbh)); int r; - fp_dbg("length %d timeout %d", msg->length, timeout); + fp_dbg("length %d timeout %d", transfer->length, timeout); if (!urbh) return NULL; @@ -272,10 +275,10 @@ static struct libusb_urb_handle *submit_bulk_msg(struct libusb_dev_handle *devh, urbh->callback = callback; urbh->user_data = user_data; urbh->flags |= LIBUSB_URBH_DATA_BELONGS_TO_USER; - urbh->endpoint = msg->endpoint; + urbh->endpoint = transfer->endpoint; urbh->urb_type = urbtype; - urbh->buffer = msg->data; - urbh->transfer_len = msg->length; + urbh->buffer = transfer->data; + urbh->transfer_len = transfer->length; r = submit_urb(devh, urbh); if (r < 0) { @@ -286,19 +289,19 @@ static struct libusb_urb_handle *submit_bulk_msg(struct libusb_dev_handle *devh, return urbh; } -API_EXPORTED struct libusb_urb_handle *libusb_submit_bulk_msg( - struct libusb_dev_handle *devh, struct libusb_bulk_msg *msg, +API_EXPORTED struct libusb_urb_handle *libusb_async_bulk_transfer( + struct libusb_dev_handle *devh, struct libusb_bulk_transfer *transfer, libusb_bulk_cb_fn callback, void *user_data, unsigned int timeout) { - return submit_bulk_msg(devh, msg, callback, user_data, timeout, + return submit_bulk_transfer(devh, transfer, callback, user_data, timeout, USB_URB_TYPE_BULK); } -API_EXPORTED struct libusb_urb_handle *libusb_submit_intr_msg( - struct libusb_dev_handle *devh, struct libusb_bulk_msg *msg, +API_EXPORTED struct libusb_urb_handle *libusb_async_interrupt_transfer( + struct libusb_dev_handle *devh, struct libusb_bulk_transfer *transfer, libusb_bulk_cb_fn callback, void *user_data, unsigned int timeout) { - return submit_bulk_msg(devh, msg, callback, user_data, timeout, + return submit_bulk_transfer(devh, transfer, callback, user_data, timeout, USB_URB_TYPE_INTERRUPT); } @@ -565,7 +568,7 @@ struct sync_ctrl_handle { int actual_length; }; -static void ctrl_msg_cb(struct libusb_dev_handle *devh, +static void ctrl_transfer_cb(struct libusb_dev_handle *devh, struct libusb_urb_handle *urbh, enum fp_urb_cb_status status, struct libusb_ctrl_setup *setup, unsigned char *data, int actual_length, void *user_data) @@ -584,16 +587,17 @@ static void ctrl_msg_cb(struct libusb_dev_handle *devh, /* caller frees urbh */ } -API_EXPORTED int libusb_ctrl_msg(struct libusb_dev_handle *devh, - struct libusb_ctrl_msg *msg, unsigned int timeout) +API_EXPORTED int libusb_control_transfer(struct libusb_dev_handle *devh, + struct libusb_control_transfer *transfer, unsigned int timeout) { struct libusb_urb_handle *urbh; struct sync_ctrl_handle ctrlh; memset(&ctrlh, 0, sizeof(ctrlh)); - ctrlh.data = msg->data; + ctrlh.data = transfer->data; - urbh = libusb_submit_ctrl_msg(devh, msg, ctrl_msg_cb, &ctrlh, timeout); + urbh = libusb_async_control_transfer(devh, transfer, ctrl_transfer_cb, + &ctrlh, timeout); if (!urbh) return -1; @@ -623,7 +627,7 @@ struct sync_bulk_handle { int actual_length; }; -static void bulk_msg_cb(struct libusb_dev_handle *devh, +static void bulk_transfer_cb(struct libusb_dev_handle *devh, struct libusb_urb_handle *urbh, enum fp_urb_cb_status status, unsigned char endpoint, int rqlength, unsigned char *data, int actual_length, void *user_data) @@ -635,16 +639,17 @@ static void bulk_msg_cb(struct libusb_dev_handle *devh, /* caller frees urbh */ } -static int do_sync_bulk_msg(struct libusb_dev_handle *devh, - struct libusb_bulk_msg *msg, int *transferred, unsigned int timeout, - unsigned char urbtype) +static int do_sync_bulk_transfer(struct libusb_dev_handle *devh, + struct libusb_bulk_transfer *transfer, int *transferred, + unsigned int timeout, unsigned char urbtype) { struct libusb_urb_handle *urbh; struct sync_bulk_handle bulkh; memset(&bulkh, 0, sizeof(bulkh)); - urbh = submit_bulk_msg(devh, msg, bulk_msg_cb, &bulkh, timeout, urbtype); + urbh = submit_bulk_transfer(devh, transfer, bulk_transfer_cb, &bulkh, + timeout, urbtype); if (!urbh) return -1; @@ -671,17 +676,19 @@ static int do_sync_bulk_msg(struct libusb_dev_handle *devh, } } -API_EXPORTED int libusb_intr_msg(struct libusb_dev_handle *devh, - struct libusb_bulk_msg *msg, int *transferred, unsigned int timeout) +API_EXPORTED int libusb_interrupt_transfer(struct libusb_dev_handle *devh, + struct libusb_bulk_transfer *transfer, int *transferred, + unsigned int timeout) { - return do_sync_bulk_msg(devh, msg, transferred, timeout, + return do_sync_bulk_transfer(devh, transfer, transferred, timeout, USB_URB_TYPE_INTERRUPT); } -API_EXPORTED int libusb_bulk_msg(struct libusb_dev_handle *devh, - struct libusb_bulk_msg *msg, int *transferred, unsigned int timeout) +API_EXPORTED int libusb_bulk_transfer(struct libusb_dev_handle *devh, + struct libusb_bulk_transfer *transfer, int *transferred, + unsigned int timeout) { - return do_sync_bulk_msg(devh, msg, transferred, timeout, + return do_sync_bulk_transfer(devh, transfer, transferred, timeout, USB_URB_TYPE_BULK); } diff --git a/libusb/libusb.h b/libusb/libusb.h index 63edb75..7d0bf92 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -191,7 +191,7 @@ enum fp_urb_cb_status { FP_URB_CANCELLED, }; -struct libusb_ctrl_msg { +struct libusb_control_transfer { uint8_t requesttype; uint8_t request; uint16_t value; @@ -204,7 +204,7 @@ typedef void (*libusb_ctrl_cb_fn)(libusb_dev_handle *devh, libusb_urb_handle *ur enum fp_urb_cb_status status, struct libusb_ctrl_setup *setup, unsigned char *data, int actual_length, void *user_data); -struct libusb_bulk_msg { +struct libusb_bulk_transfer { unsigned char endpoint; unsigned char *data; int length; @@ -231,15 +231,15 @@ int libusb_devh_release_intf(libusb_dev_handle *dev, int iface); /* async I/O */ -libusb_urb_handle *libusb_submit_ctrl_msg(libusb_dev_handle *devh, - struct libusb_ctrl_msg *msg, libusb_ctrl_cb_fn callback, void *user_data, - unsigned int timeout); -libusb_urb_handle *libusb_submit_bulk_msg(libusb_dev_handle *devh, - struct libusb_bulk_msg *msg, libusb_bulk_cb_fn callback, void *user_data, - unsigned int timeout); -libusb_urb_handle *libusb_submit_intr_msg(libusb_dev_handle *devh, - struct libusb_bulk_msg *msg, libusb_bulk_cb_fn callback, void *user_data, - unsigned int timeout); +libusb_urb_handle *libusb_async_control_transfer(libusb_dev_handle *devh, + struct libusb_control_transfer *transfer, libusb_ctrl_cb_fn callback, + void *user_data, unsigned int timeout); +libusb_urb_handle *libusb_async_bulk_transfer(libusb_dev_handle *devh, + struct libusb_bulk_transfer *transfer, libusb_bulk_cb_fn callback, + void *user_data, unsigned int timeout); +libusb_urb_handle *libusb_async_interrupt_transfer(libusb_dev_handle *devh, + struct libusb_bulk_transfer *transfer, libusb_bulk_cb_fn callback, + void *user_data, unsigned int timeout); int libusb_urb_handle_cancel(libusb_dev_handle *devh, libusb_urb_handle *urbh); int libusb_urb_handle_cancel_sync(libusb_dev_handle *devh, @@ -252,11 +252,13 @@ int libusb_get_pollfd(void); /* sync I/O */ -int libusb_ctrl_msg(libusb_dev_handle *devh, struct libusb_ctrl_msg *msg, +int libusb_control_transfer(libusb_dev_handle *devh, + struct libusb_control_transfer *transfer, unsigned int timeout); +int libusb_bulk_transfer(libusb_dev_handle *devh, + struct libusb_bulk_transfer *transfer, int *transferred, + unsigned int timeout); +int libusb_interrupt_transfer(libusb_dev_handle *devh, + struct libusb_bulk_transfer *transfer, int *transferred, unsigned int timeout); -int libusb_bulk_msg(libusb_dev_handle *devh, struct libusb_bulk_msg *msg, - int *transferred, unsigned int timeout); -int libusb_intr_msg(libusb_dev_handle *devh, struct libusb_bulk_msg *msg, - int *transferred, unsigned int timeout); #endif