/** * osp_device_open: * @device: a #GUsbDevice instance * @error: A #GError or %NULL * * Opens the device and claims the interface * * Return value: %TRUE for success * * Since: 1.2.11 **/ gboolean osp_device_open (GUsbDevice *device, GError **error) { g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (!g_usb_device_open (device, error)) return FALSE; if (!g_usb_device_claim_interface (device, 0x00, 0, error)) { g_prefix_error (error, "Failed to claim interface: "); return FALSE; } return TRUE; }
/** * cd_sensor_open_usb_device: **/ GUsbDevice * cd_sensor_open_usb_device (CdSensor *sensor, gint config, gint interface, GError **error) { CdSensorPrivate *priv = sensor->priv; gboolean ret; guint8 busnum; guint8 devnum; GUsbDevice *device; GUsbDevice *device_success = NULL; /* convert from GUdevDevice to GUsbDevice */ busnum = g_udev_device_get_sysfs_attr_as_int (priv->device, "busnum"); devnum = g_udev_device_get_sysfs_attr_as_int (priv->device, "devnum"); device = g_usb_device_list_find_by_bus_address (priv->device_list, busnum, devnum, error); if (device == NULL) goto out; /* open device, set config and claim interface */ ret = g_usb_device_open (device, error); if (!ret) goto out; ret = g_usb_device_set_configuration (device, config, error); if (!ret) goto out; ret = g_usb_device_claim_interface (device, interface, G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER, error); if (!ret) goto out; /* success */ device_success = g_object_ref (device); out: if (device != NULL) g_object_unref (device); return device_success; }
/** * cd_sensor_open_usb_device: **/ GUsbDevice * cd_sensor_open_usb_device (CdSensor *sensor, gint config, gint interface, GError **error) { #ifdef HAVE_UDEV CdSensorPrivate *priv = GET_PRIVATE (sensor); guint8 busnum; guint8 devnum; g_autoptr(GUsbDevice) device = NULL; /* convert from GUdevDevice to GUsbDevice */ busnum = g_udev_device_get_sysfs_attr_as_int (priv->device, "busnum"); devnum = g_udev_device_get_sysfs_attr_as_int (priv->device, "devnum"); device = g_usb_context_find_by_bus_address (priv->usb_ctx, busnum, devnum, error); if (device == NULL) return NULL; /* open device, set config and claim interface */ if (!g_usb_device_open (device, error)) return NULL; if (!g_usb_device_set_configuration (device, config, error)) return NULL; if (!g_usb_device_claim_interface (device, interface, G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER, error)) { return NULL; } return g_object_ref (device); #else g_set_error_literal (error, 1, 0, "failed: no gudev support"); return NULL; #endif }