[Spice-devel] [PATCH] client: add announce_capabilities

Hans de Goede hdegoede at redhat.com
Sun Aug 29 22:57:18 PDT 2010


Hi,

On 08/29/2010 07:24 PM, Alon Levy wrote:
> send VDAgentAnnounceCapabilities on agent connection, DisplayConfig
> only sent if response received (another VDAgentAnnounceCapabilities)
> and contains the VD_AGENT_CAP_DISPLAY_CONFIG capability.
>
> ---
>   client/red_client.cpp |   46 ++++++++++++++++++++++++++++++++++++++++++----
>   client/red_client.h   |    2 ++
>   2 files changed, 44 insertions(+), 4 deletions(-)
>
> diff --git a/client/red_client.cpp b/client/red_client.cpp
> index b6a412e..c8ab78b 100644
> --- a/client/red_client.cpp
> +++ b/client/red_client.cpp
> @@ -639,6 +639,30 @@ void RedClient::send_agent_monitors_config()
>       _agent_reply_wait_type = VD_AGENT_MONITORS_CONFIG;
>   }
>
> +void RedClient::send_agent_announce_capabilities()
> +{
> +    Message* message = new Message(SPICE_MSGC_MAIN_AGENT_DATA);
> +    VDAgentMessage* msg = (VDAgentMessage*)
> +        spice_marshaller_reserve_space(message->marshaller(),
> +                                       sizeof(VDAgentMessage));
> +    VDAgentAnnounceCapabilities* caps;
> +
> +    msg->protocol = VD_AGENT_PROTOCOL;
> +    msg->type = VD_AGENT_ANNOUNCE_CAPABILITIES;
> +    msg->opaque = 0;
> +    msg->size = sizeof(VDAgentAnnounceCapabilities);
> +
> +    caps = (VDAgentAnnounceCapabilities*)
> +        spice_marshaller_reserve_space(message->marshaller(),
> +                        sizeof(VDAgentAnnounceCapabilities));
> +
> +    memset(caps->caps, 0, sizeof(caps->caps));
> +    VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_DISPLAY_CONFIG);

I think that the capability bits for all msg types the client may send /
knows how to handle when receiving should be set. This way if we ever
need to do a VD_AGENT_CLIPBOARD_V2 (which is quite likely), we
can remove support for the old VD_AGENT_CAP_CLIPBOARD even
further in the future (once everything should support
VD_AGENT_CLIPBOARD_V2) and then make this clear by no longer
advertising VD_AGENT_CAP_CLIPBOARD

Also I see little use in having a separate enum for capabilities

(form your 1st patch):
+enum {
+    // supports DisplayConfig message
+    VD_AGENT_CAP_DISPLAY_CONFIG=0,
+
+    VD_AGENT_CAP_MAX=256,
+};

We already have the enum for the VDAgentMessage.type, which we can
use just fine to also set capabilities bits:

enum {
     VD_AGENT_MOUSE_STATE = 1,
     VD_AGENT_MONITORS_CONFIG,
     VD_AGENT_REPLY,
     VD_AGENT_CLIPBOARD,
     VD_AGENT_DISPLAY_CONFIG,
};





> +    ASSERT(_agent_tokens)
> +    _agent_tokens--;
> +    post_message(message);
> +}
> +
>   void RedClient::send_agent_display_config()
>   {
>       Message* message = new Message(SPICE_MSGC_MAIN_AGENT_DATA);
> @@ -654,7 +678,7 @@ void RedClient::send_agent_display_config()
>
>       disp_config = (VDAgentDisplayConfig*)
>           spice_marshaller_reserve_space(message->marshaller(), sizeof(VDAgentDisplayConfig));
> -
> +
>       disp_config->flags = 0;
>       if (_display_setting._disable_wallpaper) {
>           disp_config->flags |= VD_AGENT_DISPLAY_CONFIG_FLAG_DISABLE_WALLPAPER;

Whitespace changes like this should be done in a separate patch (imho).

> @@ -872,12 +896,10 @@ void RedClient::handle_init(RedPeer::InMessage* message)
>       }
>
>       if (_agent_connected) {
> +        send_agent_announce_capabilities();
>           if (_auto_display_res) {
>              send_agent_monitors_config();
>           }
> -        // not sending the color depth through send_agent_monitors_config, since
> -        // it applies only for attached screens.
> -        send_agent_display_config();
>       }
>
>       if (!_auto_display_res&&  _display_setting.is_empty()) {
> @@ -932,6 +954,17 @@ void RedClient::handle_agent_disconnected(RedPeer::InMessage* message)
>       _agent_connected = false;
>   }
>
> +void RedClient::on_agent_announce_capabilities(
> +    VDAgentAnnounceCapabilities* caps)
> +{
> +    if (VD_AGENT_HAS_CAPABILITY(caps->caps,
> +        VD_AGENT_CAP_DISPLAY_CONFIG)) {
> +        // not sending the color depth through send_agent_monitors_config, since
> +        // it applies only for attached screens.
> +        send_agent_display_config();
> +    }
> +}
> +
>   void RedClient::on_agent_reply(VDAgentReply* reply)
>   {
>       DBG(0, "agent reply type: %d", reply->type);
> @@ -990,6 +1023,11 @@ void RedClient::handle_agent_data(RedPeer::InMessage* message)
>           if (_agent_msg_pos == sizeof(VDAgentMessage) + _agent_msg->size) {
>               DBG(0, "agent msg end");
>               switch (_agent_msg->type) {
> +            case VD_AGENT_ANNOUNCE_CAPABILITIES: {
> +                on_agent_announce_capabilities(
> +                    (VDAgentAnnounceCapabilities*)_agent_msg_data);
> +                break;
> +            }
>               case VD_AGENT_REPLY: {
>                   on_agent_reply((VDAgentReply*)_agent_msg_data);
>                   break;
> diff --git a/client/red_client.h b/client/red_client.h
> index 6b4d4ab..328a9ee 100644
> --- a/client/red_client.h
> +++ b/client/red_client.h
> @@ -210,6 +210,7 @@ protected:
>   private:
>       void on_channel_disconnected(RedChannel&  channel);
>       void migrate_channel(RedChannel&  channel);
> +    void send_agent_announce_capabilities();
>       void send_agent_monitors_config();
>       void send_agent_display_config();
>       void calc_pixmap_cach_and_glz_window_size(uint32_t display_channels_hint,
> @@ -229,6 +230,7 @@ private:
>       void handle_migrate_switch_host(RedPeer::InMessage* message);
>
>       void on_agent_reply(VDAgentReply* reply);
> +    void on_agent_announce_capabilities(VDAgentAnnounceCapabilities* caps);
>       void on_agent_clipboard(VDAgentClipboard* clipboard, uint32_t size);
>       void send_agent_clipboard();
>       void do_send_agent_clipboard();

Regards,

Hans


More information about the Spice-devel mailing list