From: Daniel Drake Date: Fri, 27 Jun 2008 03:47:05 +0000 (-0500) Subject: Allow user data pointer to be passed through pollfd notification API X-Git-Tag: upstream/1.0.21~1026 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=819e65f880ca43526036e56c65c415042c91f58f;p=platform%2Fupstream%2Flibusb.git Allow user data pointer to be passed through pollfd notification API --- diff --git a/libusb/io.c b/libusb/io.c index f2de833..ef6ad9f 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1634,13 +1634,17 @@ API_EXPORTED int libusb_get_next_timeout(libusb_context *ctx, * \param ctx the context to operate on, or NULL for the default context * \param added_cb pointer to function for addition notifications * \param removed_cb pointer to function for removal notifications + * \param user_data User data to be passed back to callbacks (useful for + * passing context information) */ API_EXPORTED void libusb_set_pollfd_notifiers(libusb_context *ctx, - libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb) + libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, + void *user_data) { USBI_GET_CONTEXT(ctx); ctx->fd_added_cb = added_cb; ctx->fd_removed_cb = removed_cb; + ctx->fd_cb_user_data = user_data; } /* Add a file descriptor to the list of file descriptors to be monitored. @@ -1660,7 +1664,7 @@ int usbi_add_pollfd(struct libusb_context *ctx, int fd, short events) pthread_mutex_unlock(&ctx->pollfds_lock); if (ctx->fd_added_cb) - ctx->fd_added_cb(fd, events); + ctx->fd_added_cb(fd, events, ctx->fd_cb_user_data); return 0; } @@ -1688,7 +1692,7 @@ void usbi_remove_pollfd(struct libusb_context *ctx, int fd) pthread_mutex_unlock(&ctx->pollfds_lock); free(ipollfd); if (ctx->fd_removed_cb) - ctx->fd_removed_cb(fd); + ctx->fd_removed_cb(fd, ctx->fd_cb_user_data); } /** \ingroup poll diff --git a/libusb/libusb.h b/libusb/libusb.h index 20d1988..685a1c8 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -1166,22 +1166,27 @@ struct libusb_pollfd { * \param fd the new file descriptor * \param events events to monitor for, see \ref libusb_pollfd for a * description + * \param user_data User data pointer specified in + * libusb_set_pollfd_notifiers() call * \see libusb_set_pollfd_notifiers() */ -typedef void (*libusb_pollfd_added_cb)(int fd, short events); +typedef void (*libusb_pollfd_added_cb)(int fd, short events, void *user_data); /** \ingroup poll * Callback function, invoked when a file descriptor should be removed from * the set of file descriptors being monitored for events. After returning * from this callback, do not use that file descriptor again. * \param fd the file descriptor to stop monitoring + * \param user_data User data pointer specified in + * libusb_set_pollfd_notifiers() call * \see libusb_set_pollfd_notifiers() */ -typedef void (*libusb_pollfd_removed_cb)(int fd); +typedef void (*libusb_pollfd_removed_cb)(int fd, void *user_data); const struct libusb_pollfd **libusb_get_pollfds(libusb_context *ctx); void libusb_set_pollfd_notifiers(libusb_context *ctx, - libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb); + libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, + void *user_data); #ifdef __cplusplus } diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 8eb4c5c..ec79a20 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -166,6 +166,7 @@ struct libusb_context { /* user callbacks for pollfd changes */ libusb_pollfd_added_cb fd_added_cb; libusb_pollfd_removed_cb fd_removed_cb; + void *fd_cb_user_data; /* ensures that only one thread is handling events at any one time */ pthread_mutex_t events_lock;