Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F160372324
D55687.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D55687.diff
View Options
diff --git a/lib/libusb/Symbol.map b/lib/libusb/Symbol.map
--- a/lib/libusb/Symbol.map
+++ b/lib/libusb/Symbol.map
@@ -249,6 +249,12 @@
usb_set_debug;
usb_strerror;
local:
+ _libusb_hotplug_deregister_callback;
+ _libusb_hotplug_deregister_callback_compat;
+ _libusb_hotplug_get_user_data;
+ _libusb_hotplug_get_user_data_compat;
+ _libusb_hotplug_register_callback;
+ _libusb_hotplug_register_callback_compat;
libusb_log_va_args;
libusb20_ugen20_backend;
usbi_default_context;
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -286,8 +286,6 @@
struct libusb_device;
struct libusb_transfer;
struct libusb_device_handle;
-struct libusb_hotplug_callback_handle_struct;
-
struct libusb_pollfd {
int fd;
short events;
@@ -315,7 +313,7 @@
typedef struct libusb_pollfd libusb_pollfd;
typedef void (*libusb_pollfd_added_cb) (int fd, short events, void *user_data);
typedef void (*libusb_pollfd_removed_cb) (int fd, void *user_data);
-typedef struct libusb_hotplug_callback_handle_struct *libusb_hotplug_callback_handle;
+typedef int libusb_hotplug_callback_handle;
typedef struct libusb_device_descriptor {
uint8_t bLength;
diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h
--- a/lib/libusb/libusb10.h
+++ b/lib/libusb/libusb10.h
@@ -78,6 +78,7 @@
int vendor;
int product;
int devclass;
+ int id;
libusb_hotplug_callback_fn fn;
void *user_data;
};
diff --git a/lib/libusb/libusb10_hotplug.c b/lib/libusb/libusb10_hotplug.c
--- a/lib/libusb/libusb10_hotplug.c
+++ b/lib/libusb/libusb10_hotplug.c
@@ -54,6 +54,20 @@
#include "libusb.h"
#include "libusb10.h"
+static int hotplug_next_id = 1;
+
+static struct libusb_hotplug_callback_handle_struct *
+hotplug_find_by_id(libusb_context *ctx, int id)
+{
+ struct libusb_hotplug_callback_handle_struct *handle;
+
+ TAILQ_FOREACH(handle, &ctx->hotplug_cbh, entry) {
+ if (handle->id == id)
+ return (handle);
+ }
+ return (NULL);
+}
+
#define DEVDPIPE "/var/run/devd.seqpacket.pipe"
#define DEVCTL_MAXBUF 1024
@@ -176,7 +190,8 @@
}
static int
-libusb_hotplug_filter(libusb_context *ctx, libusb_hotplug_callback_handle pcbh,
+libusb_hotplug_filter(libusb_context *ctx,
+ struct libusb_hotplug_callback_handle_struct *pcbh,
libusb_device *dev, libusb_hotplug_event event)
{
if (!(pcbh->events & event))
@@ -216,8 +231,8 @@
{
struct pollfd pfd;
struct libusb_device_head hotplug_devs;
- libusb_hotplug_callback_handle acbh;
- libusb_hotplug_callback_handle bcbh;
+ struct libusb_hotplug_callback_handle_struct *acbh;
+ struct libusb_hotplug_callback_handle_struct *bcbh;
libusb_context *ctx = arg;
libusb_device *temp;
libusb_device *adev;
@@ -337,13 +352,14 @@
return (NULL);
}
-int libusb_hotplug_register_callback(libusb_context *ctx,
+static int
+libusb_hotplug_register_callback_sub(libusb_context *ctx,
libusb_hotplug_event events, libusb_hotplug_flag flags,
int vendor_id, int product_id, int dev_class,
libusb_hotplug_callback_fn cb_fn, void *user_data,
- libusb_hotplug_callback_handle *phandle)
+ struct libusb_hotplug_callback_handle_struct **phandlep)
{
- libusb_hotplug_callback_handle handle;
+ struct libusb_hotplug_callback_handle_struct *handle;
struct libusb_device *adev;
ctx = GET_CONTEXT(ctx);
@@ -367,7 +383,7 @@
HOTPLUG_LOCK(ctx);
if (ctx->hotplug_handler == NO_THREAD) {
- libusb_hotplug_enumerate(ctx, &ctx->hotplug_devs);
+ libusb_hotplug_enumerate(ctx, &ctx->hotplug_devs);
if (pthread_create(&ctx->hotplug_handler, NULL,
&libusb_hotplug_scan, ctx) != 0)
@@ -377,6 +393,7 @@
handle->vendor = vendor_id;
handle->product = product_id;
handle->devclass = dev_class;
+ handle->id = hotplug_next_id++;
handle->fn = cb_fn;
handle->user_data = user_data;
@@ -394,15 +411,90 @@
TAILQ_INSERT_TAIL(&ctx->hotplug_cbh, handle, entry);
HOTPLUG_UNLOCK(ctx);
- if (phandle != NULL)
- *phandle = handle;
+ *phandlep = handle;
return (LIBUSB_SUCCESS);
}
-void libusb_hotplug_deregister_callback(libusb_context *ctx,
- libusb_hotplug_callback_handle handle)
+/* new int-based API, compatible with upstream libusb */
+int
+_libusb_hotplug_register_callback(libusb_context *ctx,
+ libusb_hotplug_event events, libusb_hotplug_flag flags,
+ int vendor_id, int product_id, int dev_class,
+ libusb_hotplug_callback_fn cb_fn, void *user_data,
+ libusb_hotplug_callback_handle *phandle)
+{
+ struct libusb_hotplug_callback_handle_struct *handle;
+ int ret;
+
+ ret = libusb_hotplug_register_callback_sub(ctx, events, flags,
+ vendor_id, product_id, dev_class, cb_fn, user_data, &handle);
+ if (ret == LIBUSB_SUCCESS && phandle != NULL)
+ *phandle = handle != NULL ? handle->id : 0;
+ return (ret);
+}
+
+void
+_libusb_hotplug_deregister_callback(libusb_context *ctx,
+ libusb_hotplug_callback_handle handle_id)
{
- ctx = GET_CONTEXT(ctx);
+ struct libusb_hotplug_callback_handle_struct *handle;
+
+ ctx = GET_CONTEXT(ctx);
+ if (ctx == NULL)
+ return;
+
+ HOTPLUG_LOCK(ctx);
+ handle = hotplug_find_by_id(ctx, handle_id);
+ if (handle != NULL) {
+ TAILQ_REMOVE(&ctx->hotplug_cbh, handle, entry);
+ libusb_interrupt_event_handler(ctx);
+ }
+ HOTPLUG_UNLOCK(ctx);
+
+ free(handle);
+}
+
+void *
+_libusb_hotplug_get_user_data(struct libusb_context *ctx,
+ libusb_hotplug_callback_handle handle_id)
+{
+ struct libusb_hotplug_callback_handle_struct *handle;
+ void *user_data = NULL;
+
+ ctx = GET_CONTEXT(ctx);
+
+ HOTPLUG_LOCK(ctx);
+ handle = hotplug_find_by_id(ctx, handle_id);
+ if (handle != NULL)
+ user_data = handle->user_data;
+ HOTPLUG_UNLOCK(ctx);
+
+ return (user_data);
+}
+
+/* compat: old pointer-based API for existing binaries */
+int
+_libusb_hotplug_register_callback_compat(libusb_context *ctx,
+ libusb_hotplug_event events, libusb_hotplug_flag flags,
+ int vendor_id, int product_id, int dev_class,
+ libusb_hotplug_callback_fn cb_fn, void *user_data,
+ struct libusb_hotplug_callback_handle_struct **phandle)
+{
+ struct libusb_hotplug_callback_handle_struct *handle;
+ int ret;
+
+ ret = libusb_hotplug_register_callback_sub(ctx, events, flags,
+ vendor_id, product_id, dev_class, cb_fn, user_data, &handle);
+ if (ret == LIBUSB_SUCCESS && phandle != NULL)
+ *phandle = handle;
+ return (ret);
+}
+
+void
+_libusb_hotplug_deregister_callback_compat(libusb_context *ctx,
+ struct libusb_hotplug_callback_handle_struct *handle)
+{
+ ctx = GET_CONTEXT(ctx);
if (ctx == NULL || handle == NULL)
return;
@@ -416,10 +508,10 @@
}
void *
-libusb_hotplug_get_user_data(struct libusb_context *ctx,
- libusb_hotplug_callback_handle callback_handle)
+_libusb_hotplug_get_user_data_compat(struct libusb_context *ctx,
+ struct libusb_hotplug_callback_handle_struct *callback_handle)
{
- libusb_hotplug_callback_handle handle;
+ struct libusb_hotplug_callback_handle_struct *handle;
ctx = GET_CONTEXT(ctx);
@@ -434,3 +526,17 @@
return (handle->user_data);
return (NULL);
}
+
+__sym_default(libusb_hotplug_register_callback,
+ _libusb_hotplug_register_callback, FBSD_1.9);
+__sym_default(libusb_hotplug_deregister_callback,
+ _libusb_hotplug_deregister_callback, FBSD_1.9);
+__sym_default(libusb_hotplug_get_user_data,
+ _libusb_hotplug_get_user_data, FBSD_1.9);
+
+__sym_compat(libusb_hotplug_register_callback,
+ _libusb_hotplug_register_callback_compat, FBSD_1.9);
+__sym_compat(libusb_hotplug_deregister_callback,
+ _libusb_hotplug_deregister_callback_compat, FBSD_1.9);
+__sym_compat(libusb_hotplug_get_user_data,
+ _libusb_hotplug_get_user_data_compat, FBSD_1.9);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jun 24, 8:19 PM (12 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34292307
Default Alt Text
D55687.diff (7 KB)
Attached To
Mode
D55687: libusb: make hotplug callback handle an int
Attached
Detach File
Event Timeline
Log In to Comment