[Spice-devel] [PATCH spice-gtk 1/2] usbredir: don't use emit_main_context() for non-signal code
Marc-André Lureau
marcandre.lureau at gmail.com
Thu May 29 14:22:01 PDT 2014
The following patch deprecates the signal helper code
---
gtk/channel-usbredir.c | 46 ++++++++++++++++++++++------------------------
1 file changed, 22 insertions(+), 24 deletions(-)
diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
index 239fe12..372e8bd 100644
--- a/gtk/channel-usbredir.c
+++ b/gtk/channel-usbredir.c
@@ -577,38 +577,31 @@ static void usbredir_free_lock(void *user_data) {
/* --------------------------------------------------------------------- */
-/* Events to be handled in main context */
-enum {
- DEVICE_ERROR,
-};
-
-struct DEVICE_ERROR {
+typedef struct DEVICE_ERROR {
+ SpiceUsbredirChannel *channel;
SpiceUsbDevice *spice_device;
GError *error;
-};
+ struct coroutine *caller;
+} DEVICE_ERROR;
/* main context */
-static void do_emit_main_context(GObject *object, int event, gpointer params)
+static gboolean device_error(gpointer user_data)
{
- SpiceUsbredirChannel *channel = SPICE_USBREDIR_CHANNEL(object);
+ DEVICE_ERROR *p = user_data;
+ SpiceUsbredirChannel *channel = p->channel;
SpiceUsbredirChannelPrivate *priv = channel->priv;
- switch (event) {
- case DEVICE_ERROR: {
- struct DEVICE_ERROR *p = params;
- /* Check that the device has not changed before we manage to run */
- if (p->spice_device == priv->spice_device) {
- spice_usbredir_channel_disconnect_device(channel);
- spice_usb_device_manager_device_error(
+ /* Check that the device has not changed before we manage to run */
+ if (p->spice_device == priv->spice_device) {
+ spice_usbredir_channel_disconnect_device(channel);
+ spice_usb_device_manager_device_error(
spice_usb_device_manager_get(
spice_channel_get_session(SPICE_CHANNEL(channel)), NULL),
p->spice_device, p->error);
- }
- break;
- }
- default:
- g_warn_if_reached();
}
+
+ coroutine_yieldto(p->caller, NULL);
+ return FALSE;
}
/* --------------------------------------------------------------------- */
@@ -626,6 +619,7 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
{
SpiceUsbredirChannel *channel = SPICE_USBREDIR_CHANNEL(c);
SpiceUsbredirChannelPrivate *priv = channel->priv;
+ DEVICE_ERROR e;
int r, size;
uint8_t *buf;
@@ -670,9 +664,13 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
CHANNEL_DEBUG(c, "%s", err->message);
- spice_device = g_boxed_copy(spice_usb_device_get_type(), spice_device);
- emit_main_context(channel, DEVICE_ERROR, spice_device, err);
- g_boxed_free(spice_usb_device_get_type(), spice_device);
+ e.caller = coroutine_self();
+ e.spice_device = g_boxed_copy(spice_usb_device_get_type(), spice_device);
+ e.error = err;
+ g_idle_add(device_error, &e);
+ coroutine_yield(NULL);
+
+ g_boxed_free(spice_usb_device_get_type(), e.spice_device);
g_error_free(err);
}
--
1.9.0
More information about the Spice-devel
mailing list