summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDaniel Drake <dsd@gentoo.org>2008-04-27 23:27:04 +0100
committerDaniel Drake <dsd@gentoo.org>2008-04-29 12:08:35 +0100
commit7ac0a405b4c57db42e88cbcba5f135697f03b646 (patch)
tree464387a50ab952d388a05a234c7d0c962eda2023 /examples
parenta5006fd7b9dae6f1db7969c8744086ba3a7c027b (diff)
downloadlibusb-7ac0a405b4c57db42e88cbcba5f135697f03b646.tar.gz
Remove libusb_cancel_transfer_sync
This wasn't a particularly nice API. Cancellation should be handled by the completion handler.
Diffstat (limited to 'examples')
-rw-r--r--examples/dpfp.c35
-rw-r--r--examples/dpfp_threaded.c39
2 files changed, 32 insertions, 42 deletions
diff --git a/examples/dpfp.c b/examples/dpfp.c
index 6aa97a1..a64abdc 100644
--- a/examples/dpfp.c
+++ b/examples/dpfp.c
@@ -46,8 +46,6 @@ enum {
};
static int next_state(void);
-static int submit_irq_transfer(void);
-static int submit_img_transfer(void);
enum {
STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON = 1,
@@ -285,6 +283,7 @@ static void cb_irq(struct libusb_transfer *transfer)
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "irq transfer status %d?\n", transfer->status);
do_exit = 2;
+ irq_transfer = NULL;
return;
}
@@ -311,7 +310,7 @@ static void cb_irq(struct libusb_transfer *transfer)
}
break;
}
- if (submit_irq_transfer() < 0)
+ if (libusb_submit_transfer(irq_transfer) < 0)
do_exit = 2;
}
@@ -320,6 +319,7 @@ static void cb_img(struct libusb_transfer *transfer)
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "img transfer status %d?\n", transfer->status);
do_exit = 2;
+ img_transfer = NULL;
return;
}
@@ -329,31 +329,24 @@ static void cb_img(struct libusb_transfer *transfer)
do_exit = 2;
return;
}
- if (submit_img_transfer() < 0)
+ if (libusb_submit_transfer(img_transfer) < 0)
do_exit = 2;
}
-static int submit_irq_transfer(void)
-{
- return libusb_submit_transfer(irq_transfer);
-}
-
-static int submit_img_transfer(void)
-{
- return libusb_submit_transfer(img_transfer);
-}
-
static int init_capture(void)
{
int r;
- r = submit_irq_transfer();
+ r = libusb_submit_transfer(irq_transfer);
if (r < 0)
return r;
- r = submit_img_transfer();
+ r = libusb_submit_transfer(img_transfer);
if (r < 0) {
- libusb_cancel_transfer_sync(img_transfer);
+ libusb_cancel_transfer(irq_transfer);
+ while (irq_transfer)
+ if (libusb_handle_events() < 0)
+ break;
return r;
}
@@ -476,14 +469,18 @@ int main(void)
printf("shutting down...\n");
- r = libusb_cancel_transfer_sync(irq_transfer);
+ r = libusb_cancel_transfer(irq_transfer);
if (r < 0)
goto out_deinit;
- r = libusb_cancel_transfer_sync(img_transfer);
+ r = libusb_cancel_transfer(img_transfer);
if (r < 0)
goto out_deinit;
+ while (irq_transfer || img_transfer)
+ if (libusb_handle_events() < 0)
+ break;
+
if (do_exit == 1)
r = 0;
else
diff --git a/examples/dpfp_threaded.c b/examples/dpfp_threaded.c
index 18d3caa..2d106d3 100644
--- a/examples/dpfp_threaded.c
+++ b/examples/dpfp_threaded.c
@@ -47,8 +47,6 @@ enum {
};
static int next_state(void);
-static int submit_irq_transfer(void);
-static int submit_img_transfer(void);
enum {
STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON = 1,
@@ -313,6 +311,7 @@ static void cb_irq(struct libusb_transfer *transfer)
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "irq transfer status %d?\n", transfer->status);
+ irq_transfer = NULL;
request_exit(2);
return;
}
@@ -340,7 +339,7 @@ static void cb_irq(struct libusb_transfer *transfer)
}
break;
}
- if (submit_irq_transfer() < 0)
+ if (libusb_submit_transfer(irq_transfer) < 0)
request_exit(2);
}
@@ -348,6 +347,7 @@ static void cb_img(struct libusb_transfer *transfer)
{
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "img transfer status %d?\n", transfer->status);
+ img_transfer = NULL;
request_exit(2);
return;
}
@@ -358,31 +358,24 @@ static void cb_img(struct libusb_transfer *transfer)
request_exit(2);
return;
}
- if (submit_img_transfer() < 0)
+ if (libusb_submit_transfer(img_transfer) < 0)
request_exit(2);
}
-static int submit_irq_transfer(void)
-{
- return libusb_submit_transfer(irq_transfer);
-}
-
-static int submit_img_transfer(void)
-{
- return libusb_submit_transfer(img_transfer);
-}
-
static int init_capture(void)
{
int r;
- r = submit_irq_transfer();
+ r = libusb_submit_transfer(irq_transfer);
if (r < 0)
return r;
- r = submit_img_transfer();
+ r = libusb_submit_transfer(img_transfer);
if (r < 0) {
- libusb_cancel_transfer_sync(img_transfer);
+ libusb_cancel_transfer(irq_transfer);
+ while (irq_transfer)
+ if (libusb_handle_events() < 0)
+ break;
return r;
}
@@ -516,22 +509,22 @@ int main(void)
printf("shutting down...\n");
pthread_join(poll_thread, NULL);
- r = libusb_cancel_transfer_sync(irq_transfer);
+ r = libusb_cancel_transfer(irq_transfer);
if (r < 0) {
request_exit(1);
goto out_deinit;
}
- printf("done first cancel\n");
-
- r = libusb_cancel_transfer_sync(img_transfer);
+ r = libusb_cancel_transfer(img_transfer);
if (r < 0) {
request_exit(1);
goto out_deinit;
}
- printf("done 2nd cancel\n");
-
+ while (img_transfer || irq_transfer)
+ if (libusb_handle_events() < 0)
+ break;
+
if (do_exit == 1)
r = 0;
else