core: Preparation for handling backend-specific options
authorChris Dickens <christopher.a.dickens@gmail.com>
Sun, 16 Jul 2017 21:41:55 +0000 (14:41 -0700)
committerChris Dickens <christopher.a.dickens@gmail.com>
Sun, 16 Jul 2017 21:41:55 +0000 (14:41 -0700)
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/core.c
libusb/libusbi.h
libusb/os/haiku_usb_raw.cpp
libusb/os/netbsd_usb.c
libusb/os/openbsd_usb.c
libusb/os/wince_usb.c
libusb/os/windows_usbdk.c
libusb/os/windows_winusb.c
libusb/version_nano.h

index 7147550..b85721a 100644 (file)
@@ -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;
        }
index 919a921..9a545aa 100644 (file)
@@ -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.
         *
index d1609aa..c701e34 100644 (file)
@@ -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,
index 93a1e22..8f9fa36 100644 (file)
@@ -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,
index 4afa262..ac770f4 100644 (file)
@@ -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,
index 5498b91..b08403f 100644 (file)
@@ -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 */
index 42d1368..445c62b 100644 (file)
@@ -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,
index a1319b7..93668f3 100644 (file)
@@ -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 */
index 3d40961..e7e53ae 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11212
+#define LIBUSB_NANO 11213