[Spice-devel] [PATCH spice-gtk 2/2] usb-device-manager: Add support for libusb hotplug API
Marc-André Lureau
marcandre.lureau at gmail.com
Thu Jul 4 16:47:24 PDT 2013
Hi
On Thu, Jul 4, 2013 at 5:13 PM, Hans de Goede <hdegoede at redhat.com> wrote:
> +static gboolean spice_usb_device_manager_hotplug_idle_cb(gpointer user_data)
> +{
> + struct hotplug_idle_cb_args *args = user_data;
> + SpiceUsbDeviceManager *self = SPICE_USB_DEVICE_MANAGER(args->self);
> +
> + switch (args->event) {
> + case LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED:
> + spice_usb_device_manager_add_dev(self, args->device);
> + break;
> + case LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT:
> + spice_usb_device_manager_remove_dev(self,
> + libusb_get_bus_number(args->device),
> + libusb_get_device_address(args->device));
> + break;
> + }
> + libusb_unref_device(args->device);
> + g_free(args);
> + return FALSE;
> +}
> +
> +/* Can be called from both the main-thread as well as the event_thread */
> +static int spice_usb_device_manager_hotplug_cb(libusb_context *ctx,
> + libusb_device *device,
> + libusb_hotplug_event event,
> + void *user_data)
> +{
> + struct hotplug_idle_cb_args *args = g_malloc(sizeof(*args));
> +
> + args->self = user_data;
> + args->device = libusb_ref_device(device);
> + args->event = event;
> + g_idle_add(spice_usb_device_manager_hotplug_idle_cb, args);
> + return 0;
> +}
> +#endif
Is there a good reason not to keep a reference on the idle and data,
and cancel it if self is disposed? Or add a ref of self (if that's
really short-lived and safe)?
The rest of the series looks good to me.
--
Marc-André Lureau
More information about the Spice-devel
mailing list