[gnome-color-manager] trivial: Try to unwatch the USB file descriptors when unloaded



commit 6d547bffabc1dff6cceed8b7dedd819ebcab2b0f
Author: Richard Hughes <richard hughsie com>
Date:   Sun Jul 25 18:04:14 2010 +0100

    trivial: Try to unwatch the USB file descriptors when unloaded

 libcolor-glib/gcm-usb.c |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)
---
diff --git a/libcolor-glib/gcm-usb.c b/libcolor-glib/gcm-usb.c
index 57fa4d0..c536444 100644
--- a/libcolor-glib/gcm-usb.c
+++ b/libcolor-glib/gcm-usb.c
@@ -107,12 +107,11 @@ gcm_libusb_pollfd_added_cb (int fd, short events, void *user_data)
 }
 
 /**
- * gcm_libusb_pollfd_removed_cb:
+ * gcm_libusb_pollfd_remove:
  **/
 static void
-gcm_libusb_pollfd_removed_cb (int fd, void *user_data)
+gcm_libusb_pollfd_remove (GcmUsb *usb, int fd)
 {
-	GcmUsb *usb = user_data;
 	GcmUsbSource *source = usb->priv->source;
 	GPollFD *pollfd;
 	GSList *elem = source->pollfds;
@@ -140,6 +139,40 @@ gcm_libusb_pollfd_removed_cb (int fd, void *user_data)
 }
 
 /**
+ * gcm_libusb_pollfd_remove_all:
+ **/
+static void
+gcm_libusb_pollfd_remove_all (GcmUsb *usb)
+{
+	GcmUsbSource *source = usb->priv->source;
+	GPollFD *pollfd;
+	GSList *elem = source->pollfds;
+
+	/* nothing to see here, move along */
+	if (elem == NULL)
+		return;
+
+	/* rip apart all the pollfd's */
+	do {
+		pollfd = elem->data;
+		egg_warning ("removing %i", pollfd->fd);
+		g_source_remove_poll ((GSource *) source, pollfd);
+		g_slice_free (GPollFD, pollfd);
+		source->pollfds = g_slist_delete_link (source->pollfds, elem);
+	} while ((elem = g_slist_next(elem)));
+}
+
+/**
+ * gcm_libusb_pollfd_removed_cb:
+ **/
+static void
+gcm_libusb_pollfd_removed_cb (int fd, void *user_data)
+{
+	GcmUsb *usb = user_data;
+	gcm_libusb_pollfd_remove (usb, fd);
+}
+
+/**
  * gcm_usb_source_prepare:
  *
  * Called before all the file descriptors are polled.
@@ -470,6 +503,7 @@ gcm_usb_finalize (GObject *object)
 
 	if (priv->ctx != NULL) {
 		libusb_set_pollfd_notifiers (usb->priv->ctx, NULL, NULL, NULL);
+		gcm_libusb_pollfd_remove_all (usb);
 		libusb_exit (priv->ctx);
 	}
 	if (priv->handle != NULL)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]