From 468d864806af7e5caf856c66b38e06b943aa6f22 Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Sun, 16 Jul 2017 14:41:55 -0700 Subject: [PATCH] core: Preparation for handling backend-specific options Signed-off-by: Chris Dickens --- libusb/core.c | 13 +++++++++++++ libusb/libusbi.h | 10 ++++++++++ libusb/os/haiku_usb_raw.cpp | 1 + libusb/os/netbsd_usb.c | 1 + libusb/os/openbsd_usb.c | 1 + libusb/os/wince_usb.c | 1 + libusb/os/windows_usbdk.c | 1 + libusb/os/windows_winusb.c | 1 + libusb/version_nano.h | 2 +- 9 files changed, 30 insertions(+), 1 deletion(-) diff --git a/libusb/core.c b/libusb/core.c index 7147550..b85721a 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -2065,6 +2065,19 @@ int API_EXPORTED libusb_set_option(libusb_context *ctx, ctx->debug = (enum libusb_log_level)arg; #endif break; + /* Handle all backend-specific options here */ +#if 0 + /* This code is compiled out until the first backend-specific option is + * added to the library. When this time comes, remove the #if/#endif + * lines and this comment, then replace the case statement with the + * valid option name. */ + case LIBUSB_OPTION_<...>: + if (usbi_backend.set_option) + r = usbi_backend.set_option(ctx, option, ap); + else + r = LIBUSB_ERROR_NOT_SUPPORTED; + break; +#endif default: r = LIBUSB_ERROR_INVALID_PARAM; } diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 919a921..9a545aa 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -616,6 +616,16 @@ struct usbi_os_backend { */ void (*exit)(struct libusb_contex *ctx); + /* Set a backend-specific option. Optional. + * + * This function is called when the user calls libusb_set_option() and + * the option is not handled by the core library. + * + * Return 0 on success, or a LIBUSB_ERROR code on failure. + */ + int (*set_option)(struct libusb_context *ctx, enum libusb_option option, + va_list args); + /* Enumerate all the USB devices on the system, returning them in a list * of discovered devices. * diff --git a/libusb/os/haiku_usb_raw.cpp b/libusb/os/haiku_usb_raw.cpp index d1609aa..c701e34 100644 --- a/libusb/os/haiku_usb_raw.cpp +++ b/libusb/os/haiku_usb_raw.cpp @@ -201,6 +201,7 @@ const struct usbi_os_backend usbi_backend = { /*.caps =*/ 0, /*.init =*/ haiku_init, /*.exit =*/ haiku_exit, + /*.set_option =*/ NULL, /*.get_device_list =*/ NULL, /*.hotplug_poll =*/ NULL, /*.open =*/ haiku_open, diff --git a/libusb/os/netbsd_usb.c b/libusb/os/netbsd_usb.c index 93a1e22..8f9fa36 100644 --- a/libusb/os/netbsd_usb.c +++ b/libusb/os/netbsd_usb.c @@ -91,6 +91,7 @@ const struct usbi_os_backend usbi_backend = { 0, NULL, /* init() */ NULL, /* exit() */ + NULL, /* set_option() */ netbsd_get_device_list, NULL, /* hotplug_poll */ netbsd_open, diff --git a/libusb/os/openbsd_usb.c b/libusb/os/openbsd_usb.c index 4afa262..ac770f4 100644 --- a/libusb/os/openbsd_usb.c +++ b/libusb/os/openbsd_usb.c @@ -94,6 +94,7 @@ const struct usbi_os_backend usbi_backend = { 0, NULL, /* init() */ NULL, /* exit() */ + NULL, /* set_option() */ obsd_get_device_list, NULL, /* hotplug_poll */ obsd_open, diff --git a/libusb/os/wince_usb.c b/libusb/os/wince_usb.c index 5498b91..b08403f 100644 --- a/libusb/os/wince_usb.c +++ b/libusb/os/wince_usb.c @@ -854,6 +854,7 @@ const struct usbi_os_backend usbi_backend = { 0, wince_init, wince_exit, + NULL, /* set_option() */ wince_get_device_list, NULL, /* hotplug_poll */ diff --git a/libusb/os/windows_usbdk.c b/libusb/os/windows_usbdk.c index 42d1368..445c62b 100644 --- a/libusb/os/windows_usbdk.c +++ b/libusb/os/windows_usbdk.c @@ -851,6 +851,7 @@ const struct usbi_os_backend usbi_backend = { USBI_CAP_HAS_HID_ACCESS, usbdk_init, usbdk_exit, + NULL, // set_option() usbdk_get_device_list, NULL, diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c index a1319b7..93668f3 100644 --- a/libusb/os/windows_winusb.c +++ b/libusb/os/windows_winusb.c @@ -2047,6 +2047,7 @@ const struct usbi_os_backend usbi_backend = { USBI_CAP_HAS_HID_ACCESS, windows_init, windows_exit, + NULL, /* set_option */ windows_get_device_list, NULL, /* hotplug_poll */ diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 3d40961..e7e53ae 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11212 +#define LIBUSB_NANO 11213 -- 2.7.4