[Spice-devel] [spice-gtk v2 3/7] channel-main: clipboard grab: wakeup only when needed

Uri Lublin uril at redhat.com
Thu Dec 13 14:03:37 UTC 2018


On 12/10/18 1:02 PM, Victor Toso wrote:
> From: Victor Toso <me at victortoso.com>
> 
> This patch makes agent_clipboard_grab() to return true only when the
> message request to the agent is successfully queued to be sent.
> 
> By checking the return value, we can avoid wakup the channel
> unnecessarily at spice_main_channel_clipboard_selection_request()
> 
> Signed-off-by: Victor Toso <victortoso at redhat.com>

Looks good to me.

Uri.

> ---
>   src/channel-main.c | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/src/channel-main.c b/src/channel-main.c
> index fb7175e..21afd87 100644
> --- a/src/channel-main.c
> +++ b/src/channel-main.c
> @@ -1341,8 +1341,9 @@ static void agent_announce_caps(SpiceMainChannel *channel)
>   }
>   
>   /* any context: the message is not flushed immediately,
> -   you can wakeup() the channel coroutine or send_msg_queue() */
> -static void agent_clipboard_grab(SpiceMainChannel *channel, guint selection,
> +   you can wakeup() the channel coroutine or send_msg_queue()
> +   Returns true if message was queued. */
> +static bool agent_clipboard_grab(SpiceMainChannel *channel, guint selection,
>                                    guint32 *types, int ntypes)
>   {
>       SpiceMainChannelPrivate *c = channel->priv;
> @@ -1352,16 +1353,16 @@ static void agent_clipboard_grab(SpiceMainChannel *channel, guint selection,
>       int i;
>   
>       if (!c->agent_connected)
> -        return;
> +        return false;
>   
> -    g_return_if_fail(test_agent_cap(channel, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND));
> +    g_return_val_if_fail(test_agent_cap(channel, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND), false);
>   
>       size = sizeof(VDAgentClipboardGrab) + sizeof(uint32_t) * ntypes;
>       if (test_agent_cap(channel, VD_AGENT_CAP_CLIPBOARD_SELECTION)) {
>           size += 4;
>       } else if (selection != VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD) {
>           CHANNEL_DEBUG(channel, "Ignoring clipboard grab");
> -        return;
> +        return false;
>       }
>   
>       msg = g_alloca(size);
> @@ -1379,6 +1380,7 @@ static void agent_clipboard_grab(SpiceMainChannel *channel, guint selection,
>       }
>   
>       agent_msg_queue(channel, VD_AGENT_CLIPBOARD_GRAB, size, msg);
> +    return true;
>   }
>   
>   /* any context: the message is not flushed immediately,
> @@ -2771,8 +2773,9 @@ void spice_main_channel_clipboard_selection_grab(SpiceMainChannel *channel, guin
>       g_return_if_fail(channel != NULL);
>       g_return_if_fail(SPICE_IS_MAIN_CHANNEL(channel));
>   
> -    agent_clipboard_grab(channel, selection, types, ntypes);
> -    spice_channel_wakeup(SPICE_CHANNEL(channel), FALSE);
> +    if (agent_clipboard_grab(channel, selection, types, ntypes)) {
> +        spice_channel_wakeup(SPICE_CHANNEL(channel), FALSE);
> +    }
>   }
>   
>   /**
> 



More information about the Spice-devel mailing list