[Spice-devel] [PATCH spice-gtk 1/5] channel-usbredir.c: Move usb device opening into a helper function
Hans de Goede
hdegoede at redhat.com
Tue Nov 15 07:30:57 PST 2011
This is a preparation patch for adding the usb device node acl helper
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
gtk/channel-usbredir.c | 43 ++++++++++++++++++++++++++++---------------
1 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
index c0991c9..474ffb5 100644
--- a/gtk/channel-usbredir.c
+++ b/gtk/channel-usbredir.c
@@ -116,23 +116,14 @@ static const spice_msg_handler usbredir_handlers[] = {
/* ------------------------------------------------------------------ */
/* private api */
-G_GNUC_INTERNAL
-gboolean spice_usbredir_channel_connect(SpiceUsbredirChannel *channel,
- GUsbContext *context,
- GUsbDevice *device,
- GError **err)
+static gboolean spice_usbredir_channel_open_device(
+ SpiceUsbredirChannel *channel, GError **err)
{
SpiceUsbredirChannelPrivate *priv = channel->priv;
libusb_device_handle *handle = NULL;
int rc;
- g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
-
- SPICE_DEBUG("connecting usb channel %p", channel);
-
- spice_usbredir_channel_disconnect(channel);
-
- rc = libusb_open(_g_usb_device_get_device(device), &handle);
+ rc = libusb_open(_g_usb_device_get_device(priv->device), &handle);
if (rc != 0) {
g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
"Could not open usb device: %s [%i]",
@@ -141,7 +132,7 @@ gboolean spice_usbredir_channel_connect(SpiceUsbredirChannel *channel,
}
priv->catch_error = err;
- priv->host = usbredirhost_open(_g_usb_context_get_context(context),
+ priv->host = usbredirhost_open(_g_usb_context_get_context(priv->context),
handle, usbredir_log,
usbredir_read_callback,
usbredir_write_callback,
@@ -153,10 +144,32 @@ gboolean spice_usbredir_channel_connect(SpiceUsbredirChannel *channel,
return FALSE;
}
+ spice_channel_connect(SPICE_CHANNEL(channel));
+
+ return TRUE;
+}
+
+G_GNUC_INTERNAL
+gboolean spice_usbredir_channel_connect(SpiceUsbredirChannel *channel,
+ GUsbContext *context,
+ GUsbDevice *device,
+ GError **err)
+{
+ SpiceUsbredirChannelPrivate *priv = channel->priv;
+
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+ SPICE_DEBUG("connecting usb channel %p", channel);
+
+ spice_usbredir_channel_disconnect(channel);
+
priv->context = g_object_ref(context);
priv->device = g_object_ref(device);
-
- spice_channel_connect(SPICE_CHANNEL(channel));
+ if (!spice_usbredir_channel_open_device(channel, err)) {
+ g_clear_object(&priv->context);
+ g_clear_object(&priv->device);
+ return FALSE;
+ }
return TRUE;
}
--
1.7.7.1
More information about the Spice-devel
mailing list