[Spice-commits] 4 commits - doc/reference gtk/Makefile.am gtk/channel-usbredir.c gtk/gusb gtk/map-file gtk/smartcard-manager.c gtk/spice-marshal.txt gtk/spicy.c gtk/usb-device-manager.c gtk/usb-device-manager.h
Hans de Goede
jwrdegoede at kemper.freedesktop.org
Thu Sep 1 06:54:57 PDT 2011
doc/reference/spice-gtk-sections.txt | 1
gtk/Makefile.am | 4 +-
gtk/channel-usbredir.c | 6 +--
gtk/gusb/gusb-context.c | 6 +--
gtk/gusb/gusb-source.c | 6 +--
gtk/gusb/gusb-util.c | 65 +++++++++++++++++++++++++++++++++++
gtk/gusb/gusb-util.h | 32 +++++++++++++++++
gtk/map-file | 1
gtk/smartcard-manager.c | 8 ++--
gtk/spice-marshal.txt | 2 -
gtk/spicy.c | 24 ++++++++++++
gtk/usb-device-manager.c | 61 +++++++++++++++++++++++++++++---
gtk/usb-device-manager.h | 5 ++
13 files changed, 196 insertions(+), 25 deletions(-)
New commits:
commit ef3f5fc84afeaaeda1eeb18b4fc942d31f99fa3f
Author: Hans de Goede <hdegoede at redhat.com>
Date: Wed Aug 31 15:19:38 2011 +0200
usbredir: provide out own libusb_strerror for now
libusb_strerror is not going upstream because of i18n worries, provide
our own for now.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 74a45dc..6759d45 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -173,7 +173,9 @@ GUSB_SRCS = \
gusb/gusb-device-list.h \
gusb/gusb-marshal.h \
gusb/gusb-source.c \
- gusb/gusb-source.h
+ gusb/gusb-source.h \
+ gusb/gusb-util.c \
+ gusb/gusb-util.h
else
GUSB_SRCS =
endif
diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
index b567fcc..bb90dca 100644
--- a/gtk/channel-usbredir.c
+++ b/gtk/channel-usbredir.c
@@ -25,6 +25,7 @@
#include <usbredirhost.h>
#include <gusb/gusb-context-private.h>
#include <gusb/gusb-device-private.h>
+#include <gusb/gusb-util.h>
#include "channel-usbredir-priv.h"
#endif
@@ -33,9 +34,6 @@
#include "spice-channel-priv.h"
-/* libusb_strerror is awaiting merging upstream */
-#define libusb_strerror(error) "unknown"
-
/**
* SECTION:channel-usbredir
* @short_description: usb redirection
@@ -140,7 +138,7 @@ gboolean spice_usbredir_channel_connect(SpiceUsbredirChannel *channel,
if (rc != 0) {
g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
"Could not open usb device: %s [%i]",
- libusb_strerror(rc), rc);
+ gusb_strerror(rc), rc);
return FALSE;
}
diff --git a/gtk/gusb/gusb-context.c b/gtk/gusb/gusb-context.c
index 339b821..01eac06 100644
--- a/gtk/gusb/gusb-context.c
+++ b/gtk/gusb/gusb-context.c
@@ -30,12 +30,10 @@
#include <libusb-1.0/libusb.h>
+#include "gusb-util.h"
#include "gusb-context.h"
#include "gusb-context-private.h"
-/* libusb_strerror is awaiting merging upstream */
-#define libusb_strerror(error) "unknown"
-
static void g_usb_context_finalize (GObject *object);
#define G_USB_CONTEXT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), G_USB_TYPE_CONTEXT, GUsbContextPrivate))
@@ -282,7 +280,7 @@ g_usb_context_new (GError **error)
G_USB_CONTEXT_ERROR,
G_USB_CONTEXT_ERROR_INTERNAL,
"failed to init libusb: %s [%i]",
- libusb_strerror (rc), rc);
+ gusb_strerror (rc), rc);
return NULL;
}
diff --git a/gtk/gusb/gusb-source.c b/gtk/gusb/gusb-source.c
index 0324e68..bb0af49 100644
--- a/gtk/gusb/gusb-source.c
+++ b/gtk/gusb/gusb-source.c
@@ -33,6 +33,7 @@
#include <poll.h>
#include <stdlib.h>
+#include "gusb-util.h"
#include "gusb-context.h"
#include "gusb-context-private.h"
#include "gusb-source.h"
@@ -53,9 +54,6 @@ g_usb_source_error_quark (void)
return quark;
}
-/* libusb_strerror is awaiting merging upstream */
-#define libusb_strerror(error) "unknown"
-
struct _GUsbSource {
GSource source;
GSList *pollfds;
@@ -193,7 +191,7 @@ g_usb_source_dispatch (GSource *source,
rc = libusb_handle_events_timeout (usb_source->ctx, &tv);
if (rc < 0) {
g_warning ("failed to handle event: %s [%i]",
- libusb_strerror (rc), rc);
+ gusb_strerror (rc), rc);
}
if (callback)
diff --git a/gtk/gusb/gusb-util.c b/gtk/gusb/gusb-util.c
new file mode 100644
index 0000000..ca91700
--- /dev/null
+++ b/gtk/gusb/gusb-util.c
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011 Hans de Goede <hdegoede at redhat.com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2.1
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <libusb-1.0/libusb.h>
+
+#include "gusb-util.h"
+
+/* libusb_strerror is not going upstream in the forseeable future because of
+ i18n worries, provide our own implementation for now, later this can
+ hopefully became just a wrapper of the upstream version */
+const gchar* gusb_strerror(gint error_code)
+{
+ enum libusb_error error = error_code;
+
+ switch (error) {
+ case LIBUSB_SUCCESS:
+ return "Success";
+ case LIBUSB_ERROR_IO:
+ return "Input/output error";
+ case LIBUSB_ERROR_INVALID_PARAM:
+ return "Invalid parameter";
+ case LIBUSB_ERROR_ACCESS:
+ return "Access denied (insufficient permissions)";
+ case LIBUSB_ERROR_NO_DEVICE:
+ return "No such device (it may have been disconnected)";
+ case LIBUSB_ERROR_NOT_FOUND:
+ return "Entity not found";
+ case LIBUSB_ERROR_BUSY:
+ return "Resource busy";
+ case LIBUSB_ERROR_TIMEOUT:
+ return "Operation timed out";
+ case LIBUSB_ERROR_OVERFLOW:
+ return "Overflow";
+ case LIBUSB_ERROR_PIPE:
+ return "Pipe error";
+ case LIBUSB_ERROR_INTERRUPTED:
+ return "System call interrupted (perhaps due to signal)";
+ case LIBUSB_ERROR_NO_MEM:
+ return "Insufficient memory";
+ case LIBUSB_ERROR_NOT_SUPPORTED:
+ return "Operation not supported or unimplemented on this platform";
+ case LIBUSB_ERROR_OTHER:
+ return "Other error";
+ }
+ return "Unknown error";
+}
diff --git a/gtk/gusb/gusb-util.h b/gtk/gusb/gusb-util.h
new file mode 100644
index 0000000..c270853
--- /dev/null
+++ b/gtk/gusb/gusb-util.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011 Hans de Goede <hdegoede at redhat.com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2.1
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GUSB_UTIL_H__
+#define __GUSB_UTIL_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+const gchar* gusb_strerror(gint error_code);
+
+G_END_DECLS
+
+#endif /* __GUSB_UTIL_H__ */
commit ce6411a73e1290af0f62c20a3896c40d0e7c6711
Author: Hans de Goede <hdegoede at redhat.com>
Date: Wed Aug 31 13:24:04 2011 +0200
usb-device-manager: Add a auto-connect-failed signal
And use it in spicy to inform users of auto redirect failures (usually due
to insufficient rights on the /dev/bus/usb device nodes).
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/gtk/spice-marshal.txt b/gtk/spice-marshal.txt
index 55467e1..9c76054 100644
--- a/gtk/spice-marshal.txt
+++ b/gtk/spice-marshal.txt
@@ -11,3 +11,4 @@ VOID:UINT,UINT,POINTER,UINT
BOOLEAN:UINT,POINTER,UINT
BOOLEAN:UINT,UINT
VOID:OBJECT,OBJECT
+VOID:BOXED,BOXED
diff --git a/gtk/spicy.c b/gtk/spicy.c
index 761e056..362ba04 100644
--- a/gtk/spicy.c
+++ b/gtk/spicy.c
@@ -1533,12 +1533,30 @@ signal_handler(int signum)
g_main_loop_quit(mainloop);
}
+static void auto_connect_failed(SpiceUsbDeviceManager *manager,
+ SpiceUsbDevice *device,
+ GError *error,
+ gpointer data)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "USB redirection error");
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
+ "Unable to auto redirect %s: %s",
+ spice_usb_device_get_description(device), error->message);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+}
+
int main(int argc, char *argv[])
{
GError *error = NULL;
GOptionContext *context;
spice_connection *conn;
gchar *conf_file, *conf;
+ SpiceUsbDeviceManager *manager;
g_thread_init(NULL);
bindtextdomain(GETTEXT_PACKAGE, SPICE_GTK_LOCALEDIR);
@@ -1599,6 +1617,12 @@ int main(int argc, char *argv[])
g_signal_connect(rrscreen, "changed", G_CALLBACK(on_screen_changed), NULL);
on_screen_changed(rrscreen, NULL);
+ manager = spice_usb_device_manager_get(NULL, NULL);
+ if (manager) {
+ g_signal_connect(manager, "auto-connect-failed",
+ G_CALLBACK(auto_connect_failed), NULL);
+ }
+
conn = connection_new();
spice_set_session_option(conn->session);
spice_cmdline_session_setup(conn->session);
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 251153c..ae8296a 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -61,6 +61,7 @@ enum
{
DEVICE_ADDED,
DEVICE_REMOVED,
+ AUTO_CONNECT_FAILED,
LAST_SIGNAL,
};
@@ -295,6 +296,28 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
1,
SPICE_TYPE_USB_DEVICE);
+ /**
+ * SpiceUsbDeviceManager::auto-connect-failed:
+ * @manager: the #SpiceUsbDeviceManager that emitted the signal
+ * @device: #SpiceUsbDevice boxed object corresponding to the device which failed to auto connect
+ * @error: #GError describing the reason why the autoconnect failed
+ *
+ * The #SpiceUsbDeviceManager::auto-connect-failed signal is emitted
+ * whenever the auto-connect property is true, and a newly plugged in
+ * device could not be auto-connected.
+ **/
+ signals[AUTO_CONNECT_FAILED] =
+ g_signal_new("auto-connect-failed",
+ G_OBJECT_CLASS_TYPE(gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET(SpiceUsbDeviceManagerClass, auto_connect_failed),
+ NULL, NULL,
+ g_cclosure_user_marshal_VOID__BOXED_BOXED,
+ G_TYPE_NONE,
+ 2,
+ SPICE_TYPE_USB_DEVICE,
+ G_TYPE_ERROR);
+
g_type_class_add_private(klass, sizeof(SpiceUsbDeviceManagerPrivate));
}
@@ -338,6 +361,7 @@ static void spice_usb_device_manager_dev_added(GUsbDeviceList *devlist,
if (err) {
g_warning("Could not auto-redirect %s: %s",
spice_usb_device_get_description(device), err->message);
+ g_signal_emit(manager, signals[AUTO_CONNECT_FAILED], 0, device, err);
g_error_free(err);
}
}
diff --git a/gtk/usb-device-manager.h b/gtk/usb-device-manager.h
index 674e2ff..46a5e55 100644
--- a/gtk/usb-device-manager.h
+++ b/gtk/usb-device-manager.h
@@ -60,6 +60,7 @@ struct _SpiceUsbDeviceManager
* @parent_class: Parent class.
* @device_added: Signal class handler for the #SpiceUsbDeviceManager::device-added signal.
* @device_removed: Signal class handler for the #SpiceUsbDeviceManager::device-removed signal.
+ * @auto_connect_failed: Signal class handler for the #SpiceUsbDeviceManager::auto-connect-failed signal.
*
* Class structure for #SpiceUsbDeviceManager.
*/
@@ -72,6 +73,8 @@ struct _SpiceUsbDeviceManagerClass
SpiceUsbDevice *device);
void (*device_removed) (SpiceUsbDeviceManager *manager,
SpiceUsbDevice *device);
+ void (*auto_connect_failed) (SpiceUsbDeviceManager *manager,
+ SpiceUsbDevice *device, GError *error);
/*< private >*/
/*
* If adding fields to this struct, remove corresponding
commit 03b67fe957b6f5d61df28d86cdf8e2197b066e67
Author: Hans de Goede <hdegoede at redhat.com>
Date: Wed Aug 31 13:10:21 2011 +0200
usb-device-manager: Add a spice_usb_device_get_description() method
This is just a place holder for now. A better implementation requires
gusb changes, and I hope there will be an official gusb release by the
time I get around to fixing this up.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/doc/reference/spice-gtk-sections.txt b/doc/reference/spice-gtk-sections.txt
index 4ac8576..d789d5a 100644
--- a/doc/reference/spice-gtk-sections.txt
+++ b/doc/reference/spice-gtk-sections.txt
@@ -271,6 +271,7 @@ spice_usb_device_manager_get_devices
spice_usb_device_manager_is_device_connected
spice_usb_device_manager_connect_device
spice_usb_device_manager_disconnect_device
+spice_usb_device_get_description
SpiceUsbDevice
<SUBSECTION Standard>
SPICE_USB_DEVICE_MANAGER
diff --git a/gtk/map-file b/gtk/map-file
index d9765c0..b383edf 100644
--- a/gtk/map-file
+++ b/gtk/map-file
@@ -77,6 +77,7 @@ spice_smartcard_reader_get_type;
spice_smartcard_reader_is_software;
spice_usbredir_channel_get_type;
spice_usb_device_get_type;
+spice_usb_device_get_description;
spice_usb_device_manager_get_type;
spice_usb_device_manager_get;
spice_usb_device_manager_register_channel;
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 7449ba0..251153c 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -322,22 +322,22 @@ static gboolean spice_usb_device_manager_source_callback(gpointer user_data)
}
static void spice_usb_device_manager_dev_added(GUsbDeviceList *devlist,
- GUsbDevice *device,
+ GUsbDevice *_device,
GUdevDevice *udev,
gpointer user_data)
{
SpiceUsbDeviceManager *manager = user_data;
SpiceUsbDeviceManagerPrivate *priv = manager->priv;
+ SpiceUsbDevice *device = (SpiceUsbDevice *)_device;
g_ptr_array_add(priv->devices, g_object_ref(device));
if (priv->auto_connect) {
GError *err = NULL;
- spice_usb_device_manager_connect_device(manager,
- (SpiceUsbDevice *)device,
- &err);
+ spice_usb_device_manager_connect_device(manager, device, &err);
if (err) {
- g_warning("Could not auto-redirect USB device: %s", err->message);
+ g_warning("Could not auto-redirect %s: %s",
+ spice_usb_device_get_description(device), err->message);
g_error_free(err);
}
}
@@ -589,3 +589,26 @@ void spice_usb_device_manager_disconnect_device(SpiceUsbDeviceManager *self,
spice_usbredir_channel_disconnect(channel);
#endif
}
+
+/**
+ * spice_usb_device_get_description:
+ * @device: #SpiceUsbDevice to get the description of
+ *
+ * Get a string describing the device which is suitable as a description of
+ * the device for the end user. The returned string should be freed with
+ * g_free() when no longer needed.
+ *
+ * Returns: a newly-allocated string holding the description
+ */
+gchar *spice_usb_device_get_description(SpiceUsbDevice *device)
+{
+ /* FIXME, extend gusb to get vid:pid + usb descriptor strings, use those */
+ int bus, address;
+
+ g_return_val_if_fail(device != NULL, "Unknown");
+
+ bus = g_usb_device_get_bus((GUsbDevice *)device);
+ address = g_usb_device_get_address((GUsbDevice *)device);
+
+ return g_strdup_printf("USB device at %d-%d", bus, address);
+}
diff --git a/gtk/usb-device-manager.h b/gtk/usb-device-manager.h
index 03048f4..674e2ff 100644
--- a/gtk/usb-device-manager.h
+++ b/gtk/usb-device-manager.h
@@ -83,6 +83,8 @@ struct _SpiceUsbDeviceManagerClass
GType spice_usb_device_get_type(void);
GType spice_usb_device_manager_get_type(void);
+gchar *spice_usb_device_get_description(SpiceUsbDevice *device);
+
SpiceUsbDeviceManager *spice_usb_device_manager_get(GMainContext *main_context,
GError **err);
commit 75dac23ab34e10f5fdc0c5085383c67549b9a751
Author: Hans de Goede <hdegoede at redhat.com>
Date: Wed Aug 31 12:02:31 2011 +0200
Drop VOID:BOXED user marshaller
We were generating a user marshaller for VOID:BOXED, but there is a standard
marshaller for that, use that instead.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
diff --git a/gtk/smartcard-manager.c b/gtk/smartcard-manager.c
index 067e14e..806aee5 100644
--- a/gtk/smartcard-manager.c
+++ b/gtk/smartcard-manager.c
@@ -157,7 +157,7 @@ static void spice_smartcard_manager_class_init(SpiceSmartcardManagerClass *klass
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(SpiceSmartcardManagerClass, reader_added),
NULL, NULL,
- g_cclosure_user_marshal_VOID__BOXED,
+ g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
SPICE_TYPE_SMARTCARD_READER);
@@ -176,7 +176,7 @@ static void spice_smartcard_manager_class_init(SpiceSmartcardManagerClass *klass
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(SpiceSmartcardManagerClass, reader_removed),
NULL, NULL,
- g_cclosure_user_marshal_VOID__BOXED,
+ g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
SPICE_TYPE_SMARTCARD_READER);
@@ -196,7 +196,7 @@ static void spice_smartcard_manager_class_init(SpiceSmartcardManagerClass *klass
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(SpiceSmartcardManagerClass, card_inserted),
NULL, NULL,
- g_cclosure_user_marshal_VOID__BOXED,
+ g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
SPICE_TYPE_SMARTCARD_READER);
@@ -216,7 +216,7 @@ static void spice_smartcard_manager_class_init(SpiceSmartcardManagerClass *klass
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(SpiceSmartcardManagerClass, card_removed),
NULL, NULL,
- g_cclosure_user_marshal_VOID__BOXED,
+ g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
SPICE_TYPE_SMARTCARD_READER);
diff --git a/gtk/spice-marshal.txt b/gtk/spice-marshal.txt
index b9630eb..55467e1 100644
--- a/gtk/spice-marshal.txt
+++ b/gtk/spice-marshal.txt
@@ -6,7 +6,6 @@ VOID:INT,INT,INT,INT,INT,POINTER
VOID:POINTER,INT
BOOLEAN:POINTER,UINT
BOOLEAN:UINT
-VOID:BOXED
VOID:UINT,POINTER,UINT
VOID:UINT,UINT,POINTER,UINT
BOOLEAN:UINT,POINTER,UINT
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index da0368f..7449ba0 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -271,7 +271,7 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(SpiceUsbDeviceManagerClass, device_added),
NULL, NULL,
- g_cclosure_user_marshal_VOID__BOXED,
+ g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
SPICE_TYPE_USB_DEVICE);
@@ -290,7 +290,7 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(SpiceUsbDeviceManagerClass, device_removed),
NULL, NULL,
- g_cclosure_user_marshal_VOID__BOXED,
+ g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
SPICE_TYPE_USB_DEVICE);
More information about the Spice-commits
mailing list