Introduce contexts to the API
Suggested by David Zeuthen. This allows multiple libraries in the same
process to independently use libusb without interfering.
diff --git a/examples/dpfp.c b/examples/dpfp.c
index 7808184..bd9702a 100644
--- a/examples/dpfp.c
+++ b/examples/dpfp.c
@@ -67,7 +67,7 @@
static int find_dpfp_device(void)
{
- devh = libusb_open_device_with_vid_pid(0x05ba, 0x000a);
+ devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a);
return devh ? 0 : -EIO;
}
@@ -347,7 +347,7 @@
if (r < 0) {
libusb_cancel_transfer(irq_transfer);
while (irq_transfer)
- if (libusb_handle_events() < 0)
+ if (libusb_handle_events(NULL) < 0)
break;
return r;
}
@@ -419,7 +419,7 @@
struct sigaction sigact;
int r = 1;
- r = libusb_init();
+ r = libusb_init(NULL);
if (r < 0) {
fprintf(stderr, "failed to initialise libusb\n");
exit(1);
@@ -464,7 +464,7 @@
sigaction(SIGQUIT, &sigact, NULL);
while (!do_exit) {
- r = libusb_handle_events();
+ r = libusb_handle_events(NULL);
if (r < 0)
goto out_deinit;
}
@@ -484,7 +484,7 @@
}
while (irq_transfer || img_transfer)
- if (libusb_handle_events() < 0)
+ if (libusb_handle_events(NULL) < 0)
break;
if (do_exit == 1)
@@ -501,7 +501,7 @@
libusb_release_interface(devh, 0);
out:
libusb_close(devh);
- libusb_exit();
+ libusb_exit(NULL);
return r >= 0 ? r : -r;
}
diff --git a/examples/dpfp_threaded.c b/examples/dpfp_threaded.c
index 2d106d3..59540e3 100644
--- a/examples/dpfp_threaded.c
+++ b/examples/dpfp_threaded.c
@@ -83,7 +83,7 @@
while (!do_exit) {
struct timeval tv = { 1, 0 };
- r = libusb_handle_events_timeout(&tv);
+ r = libusb_handle_events_timeout(NULL, &tv);
if (r < 0) {
request_exit(2);
break;
@@ -96,7 +96,7 @@
static int find_dpfp_device(void)
{
- devh = libusb_open_device_with_vid_pid(0x05ba, 0x000a);
+ devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a);
return devh ? 0 : -EIO;
}
@@ -374,7 +374,7 @@
if (r < 0) {
libusb_cancel_transfer(irq_transfer);
while (irq_transfer)
- if (libusb_handle_events() < 0)
+ if (libusb_handle_events(NULL) < 0)
break;
return r;
}
@@ -446,7 +446,7 @@
struct sigaction sigact;
int r = 1;
- r = libusb_init();
+ r = libusb_init(NULL);
if (r < 0) {
fprintf(stderr, "failed to initialise libusb\n");
exit(1);
@@ -522,7 +522,7 @@
}
while (img_transfer || irq_transfer)
- if (libusb_handle_events() < 0)
+ if (libusb_handle_events(NULL) < 0)
break;
if (do_exit == 1)
@@ -539,7 +539,7 @@
libusb_release_interface(devh, 0);
out:
libusb_close(devh);
- libusb_exit();
+ libusb_exit(NULL);
return r >= 0 ? r : -r;
}
diff --git a/examples/lsusb.c b/examples/lsusb.c
index 5a83020..7e9f48e 100644
--- a/examples/lsusb.c
+++ b/examples/lsusb.c
@@ -47,18 +47,18 @@
int r;
ssize_t cnt;
- r = libusb_init();
+ r = libusb_init(NULL);
if (r < 0)
return r;
- cnt = libusb_get_device_list(&devs);
+ cnt = libusb_get_device_list(NULL, &devs);
if (cnt < 0)
return (int) cnt;
print_devs(devs);
libusb_free_device_list(devs, 1);
- libusb_exit();
+ libusb_exit(NULL);
return 0;
}