From 283ae96c3ccbcee1c3950fce18ae47093ae8200e Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Sun, 9 Mar 2008 16:15:02 +0000 Subject: [PATCH] Simplify cancellation API No need to provide the device here. --- examples/dpfp.c | 6 +++--- libusb/io.c | 17 +++++++---------- libusb/libusb.h | 6 ++---- libusb/sync.c | 4 ++-- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/examples/dpfp.c b/examples/dpfp.c index e8ff4c7..6006bf5 100644 --- a/examples/dpfp.c +++ b/examples/dpfp.c @@ -353,7 +353,7 @@ static int init_capture(void) r = submit_img_transfer(); if (r < 0) { - libusb_cancel_transfer_sync(devh, img_transfer); + libusb_cancel_transfer_sync(img_transfer); return r; } @@ -476,11 +476,11 @@ int main(void) printf("shutting down...\n"); - r = libusb_cancel_transfer_sync(devh, irq_transfer); + r = libusb_cancel_transfer_sync(irq_transfer); if (r < 0) goto out_deinit; - r = libusb_cancel_transfer_sync(devh, img_transfer); + r = libusb_cancel_transfer_sync(img_transfer); if (r < 0) goto out_deinit; diff --git a/libusb/io.c b/libusb/io.c index bd362c7..77b68ab 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -206,27 +206,25 @@ API_EXPORTED int libusb_submit_transfer(struct libusb_transfer *transfer) return submit_transfer(itransfer); } -API_EXPORTED int libusb_cancel_transfer(struct libusb_device_handle *devh, - struct libusb_transfer *transfer) +API_EXPORTED int libusb_cancel_transfer(struct libusb_transfer *transfer) { struct usbi_transfer *itransfer = TRANSFER_TO_PRIV(transfer); int r; usbi_dbg(""); - r = ioctl(devh->fd, IOCTL_USB_DISCARDURB, &itransfer->urb); + r = ioctl(transfer->dev_handle->fd, IOCTL_USB_DISCARDURB, &itransfer->urb); if (r < 0) usbi_err("cancel transfer failed error %d", r); return r; } -API_EXPORTED int libusb_cancel_transfer_sync(struct libusb_device_handle *devh, - struct libusb_transfer *transfer) +API_EXPORTED int libusb_cancel_transfer_sync(struct libusb_transfer *transfer) { struct usbi_transfer *itransfer = TRANSFER_TO_PRIV(transfer); int r; usbi_dbg(""); - r = ioctl(devh->fd, IOCTL_USB_DISCARDURB, &itransfer->urb); + r = ioctl(transfer->dev_handle->fd, IOCTL_USB_DISCARDURB, &itransfer->urb); if (r < 0) { usbi_err("cancel transfer failed error %d", r); return r; @@ -256,8 +254,7 @@ static void handle_transfer_completion(struct usbi_transfer *itransfer, transfer->callback(transfer); } -static void handle_transfer_cancellation(struct libusb_device_handle *devh, - struct usbi_transfer *transfer) +static void handle_transfer_cancellation(struct usbi_transfer *transfer) { /* if the URB is being cancelled synchronously, raise cancellation * completion event by unsetting flag, and ensure that user callback does @@ -306,7 +303,7 @@ static int reap_for_devh(struct libusb_device_handle *devh) list_del(&itransfer->list); if (urb->status == -2) { - handle_transfer_cancellation(devh, itransfer); + handle_transfer_cancellation(itransfer); return 0; } @@ -356,7 +353,7 @@ static void handle_timeout(struct usbi_transfer *itransfer) int r; itransfer->flags |= USBI_TRANSFER_TIMED_OUT; - r = libusb_cancel_transfer(transfer->dev_handle, transfer); + r = libusb_cancel_transfer(transfer); if (r < 0) usbi_warn("async cancel failed %d errno=%d", r, errno); } diff --git a/libusb/libusb.h b/libusb/libusb.h index d9b5710..c00e270 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -262,10 +262,8 @@ void libusb_init_transfer(struct libusb_transfer *transfer); struct libusb_transfer *libusb_alloc_transfer(void); int libusb_submit_transfer(struct libusb_transfer *transfer); -int libusb_cancel_transfer(libusb_device_handle *devh, - struct libusb_transfer *transfer); -int libusb_cancel_transfer_sync(libusb_device_handle *devh, - struct libusb_transfer *transfer); +int libusb_cancel_transfer(struct libusb_transfer *transfer); +int libusb_cancel_transfer_sync(struct libusb_transfer *transfer); void libusb_free_transfer(struct libusb_transfer *transfer); static inline void libusb_fill_control_transfer( diff --git a/libusb/sync.c b/libusb/sync.c index 720f6f9..d400470 100644 --- a/libusb/sync.c +++ b/libusb/sync.c @@ -68,7 +68,7 @@ API_EXPORTED int libusb_control_transfer(libusb_device_handle *dev_handle, while (!completed) { r = libusb_poll(); if (r < 0) { - libusb_cancel_transfer_sync(dev_handle, transfer); + libusb_cancel_transfer_sync(transfer); libusb_free_transfer(transfer); return r; } @@ -126,7 +126,7 @@ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle, while (!completed) { r = libusb_poll(); if (r < 0) { - libusb_cancel_transfer_sync(dev_handle, transfer); + libusb_cancel_transfer_sync(transfer); libusb_free_transfer(transfer); return r; } -- 2.7.4