[Spice-devel] [PATCH spice-gtk 1/2] usbredir: don't use emit_main_context() for non-signal code
Christophe Fergeau
cfergeau at redhat.com
Tue Jun 10 07:06:38 PDT 2014
On Thu, May 29, 2014 at 11:22:01PM +0200, Marc-André Lureau wrote:
> 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;
The DEVICE_ERROR is called 'p' here, and 'e' in the other function, is
it possible to have more descriptive names ? :)
> + 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);
e.channel is not initialised here but is used in the 'device_error'
callback.
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20140610/eaa60db1/attachment.sig>
More information about the Spice-devel
mailing list