core: Add a new public libusb_get_port_numbers function
authorHans de Goede <hdegoede@redhat.com>
Fri, 17 May 2013 08:36:32 +0000 (10:36 +0200)
committerHans de Goede <hdegoede@redhat.com>
Fri, 17 May 2013 08:36:32 +0000 (10:36 +0200)
This new function replaces the now deprecated libusb_get_port_path function,
as that is the only function operating on a libusb_device which also takes
a libusb_context, which is rather inconsistent.

Note we will keep libusb_get_port_path around in the 1.0.x for the forseeable
future for ABI compatibility reasons, but it should not be used in any new
code.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb/core.c
libusb/libusb.h
libusb/version_nano.h

index 95c80b9..cc2d188 100644 (file)
@@ -740,17 +740,19 @@ uint8_t API_EXPORTED libusb_get_port_number(libusb_device *dev)
 
 /** \ingroup dev
  * Get the list of all port numbers from root for the specified device
- * \param ctx the context to operate on, or NULL for the default context
+ *
+ * Since version 1.0.16, \ref LIBUSBX_API_VERSION >= 0x01000102
  * \param dev a device
- * \param path the array that should contain the port numbers
- * \param path_len the maximum length of the array. As per the USB 3.0
+ * \param port_numbers the array that should contain the port numbers
+ * \param port_numbers_len the maximum length of the array. As per the USB 3.0
  * specs, the current maximum limit for the depth is 7.
  * \returns the number of elements filled
  * \returns LIBUSB_ERROR_OVERFLOW if the array is too small
  */
-int API_EXPORTED libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_len)
+int API_EXPORTED libusb_get_port_numbers(libusb_device *dev,
+       uint8_t* port_numbers, int port_numbers_len)
 {
-       int i = path_len;
+       int i = port_numbers_len;
 
        while(dev) {
                // HCDs can be listed as devices and would have port #0
@@ -759,13 +761,26 @@ int API_EXPORTED libusb_get_port_path(libusb_context *ctx, libusb_device *dev, u
                        break;
                i--;
                if (i < 0) {
+                       usbi_warn(DEVICE_CTX(dev),
+                               "port numbers array too small");
                        return LIBUSB_ERROR_OVERFLOW;
                }
-               path[i] = dev->port_number;
+               port_numbers[i] = dev->port_number;
                dev = dev->parent_dev;
        }
-       memmove(path, &path[i], path_len-i);
-       return path_len-i;
+       memmove(port_numbers, &port_numbers[i], port_numbers_len - i);
+       return port_numbers_len - i;
+}
+
+/** \ingroup dev
+ * Deprecated please use libusb_get_port_numbers instead.
+ */
+int API_EXPORTED libusb_get_port_path(libusb_context *ctx, libusb_device *dev,
+       uint8_t* port_numbers, uint8_t port_numbers_len)
+{
+       UNUSED(ctx);
+
+       return libusb_get_port_numbers(dev, port_numbers, port_numbers_len);
 }
 
 /** \ingroup dev
index 6915875..a67cbcb 100644 (file)
@@ -76,6 +76,13 @@ typedef unsigned __int32  uint32_t;
 #endif
 #endif
 
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define LIBUSB_DEPRECATED_FOR(f) \
+  __attribute__((deprecated("Use " #f " instead")))
+#else
+#define LIBUSB_DEPRECATED_FOR(f)
+#endif /* __GNUC__ */
+
 /** \def LIBUSB_CALL
  * \ingroup misc
  * libusbx's Windows calling convention.
@@ -1055,8 +1062,10 @@ void LIBUSB_CALL libusb_free_config_descriptor(
        struct libusb_config_descriptor *config);
 uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
 uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
-libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
+int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len);
+LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers)
 int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
+libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
 uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
 int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
 int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
index fa29883..9cd9c4a 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10696
+#define LIBUSB_NANO 10697