[Spice-devel] [PATCH spice-html5] Inform agent about client's capabilities

Pavel Grunt pgrunt at redhat.com
Thu Jan 15 04:33:58 PST 2015


The client should inform the agent about capabilities
when the connection is established. This avoid receiving unhandled
agent messages.
---
depends on: http://lists.freedesktop.org/archives/spice-devel/2015-January/018590.html

Unhandled agent messages are related to the clipboard sharing capability
which is not implemented yet, so receiving these messages produces
the warning "1: Unknown message type 109!"
---
 enums.js    | 13 +++++++++++++
 main.js     | 19 ++++++++++++++++++-
 spicemsg.js | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/enums.js b/enums.js
index 07aa343..17d77cb 100644
--- a/enums.js
+++ b/enums.js
@@ -329,6 +329,19 @@ var VD_AGENT_MOUSE_STATE            = 1,
     VD_AGENT_CLIENT_DISCONNECTED    =13,
     VD_AGENT_MAX_CLIPBOARD          =14;
 
+var VD_AGENT_CAP_MOUSE_STATE            = 0,
+    VD_AGENT_CAP_MONITORS_CONFIG        = 1,
+    VD_AGENT_CAP_REPLY                  = 2,
+    VD_AGENT_CAP_CLIPBOARD              = 3,
+    VD_AGENT_CAP_DISPLAY_CONFIG         = 4,
+    VD_AGENT_CAP_CLIPBOARD_BY_DEMAND    = 5,
+    VD_AGENT_CAP_CLIPBOARD_SELECTION    = 6,
+    VD_AGENT_CAP_SPARSE_MONITORS_CONFIG = 7,
+    VD_AGENT_CAP_GUEST_LINEEND_LF       = 8,
+    VD_AGENT_CAP_GUEST_LINEEND_CRLF     = 9,
+    VD_AGENT_CAP_MAX_CLIPBOARD          = 10,
+    VD_AGENT_END_CAP                    = 11;
+
 var VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA = 0,
     VD_AGENT_FILE_XFER_STATUS_CANCELLED     = 1,
     VD_AGENT_FILE_XFER_STATUS_ERROR         = 2,
diff --git a/main.js b/main.js
index 24feb6d..f6006e6 100644
--- a/main.js
+++ b/main.js
@@ -185,7 +185,14 @@ SpiceMainConn.prototype.process_channel_message = function(msg)
     if (msg.type == SPICE_MSG_MAIN_AGENT_DATA)
     {
         var agent_data = new SpiceMsgMainAgentData(msg.data);
-        if (agent_data.type == VD_AGENT_FILE_XFER_STATUS)
+        if (agent_data.type == VD_AGENT_ANNOUNCE_CAPABILITIES)
+        {
+            var agent_caps = new VDAgentAnnounceCapabilities(agent_data.data);
+            if (agent_caps.request)
+                this.announce_agent_capabilities(0);
+            return true;
+        }
+        else if (agent_data.type == VD_AGENT_FILE_XFER_STATUS)
         {
             this.handle_file_xfer_status(new VDAgentFileXferStatusMessage(agent_data.data));
             return true;
@@ -262,6 +269,14 @@ SpiceMainConn.prototype.send_agent_message = function(type, message)
     }
 }
 
+SpiceMainConn.prototype.announce_agent_capabilities = function(request)
+{
+    var caps = new VDAgentAnnounceCapabilities(request, (1 << VD_AGENT_CAP_MOUSE_STATE) |
+                                                        (1 << VD_AGENT_CAP_MONITORS_CONFIG) |
+                                                        (1 << VD_AGENT_CAP_REPLY));
+    this.send_agent_message(VD_AGENT_ANNOUNCE_CAPABILITIES, caps);
+}
+
 SpiceMainConn.prototype.resize_window = function(flags, width, height, depth, x, y)
 {
     var monitors_config = new VDAgentMonitorsConfig(flags, width, height, depth, x, y);
@@ -365,6 +380,8 @@ SpiceMainConn.prototype.connect_agent = function()
     mr.build_msg(SPICE_MSGC_MAIN_AGENT_START, agent_start);
     this.send_msg(mr);
 
+    this.announce_agent_capabilities(1);
+
     if (this.onagent !== undefined)
         this.onagent(this);
 
diff --git a/spicemsg.js b/spicemsg.js
index ec2034c..e167b3d 100644
--- a/spicemsg.js
+++ b/spicemsg.js
@@ -486,6 +486,40 @@ SpiceMsgcMainAgentData.prototype =
     }
 }
 
+function VDAgentAnnounceCapabilities(request, caps)
+{
+    if (caps)
+    {
+        this.request = request;
+        this.caps = caps;
+    }
+    else
+        this.from_buffer(request);
+}
+
+VDAgentAnnounceCapabilities.prototype =
+{
+    to_buffer: function(a, at)
+    {
+        at = at || 0;
+        var dv = new SpiceDataView(a);
+        dv.setUint32(at, this.request, true); at += 4;
+        dv.setUint32(at, this.caps, true); at += 4;
+    },
+    from_buffer: function(a, at)
+    {
+        at = at || 0;
+        var dv = new SpiceDataView(a);
+        this.request = dv.getUint32(at, true); at += 4;
+        this.caps = dv.getUint32(at, true); at += 4;
+        return at;
+    },
+    buffer_size: function()
+    {
+        return 8;
+    }
+}
+
 function VDAgentMonitorsConfig(flags, width, height, depth, x, y)
 {
     this.num_mon = 1;
-- 
1.9.3



More information about the Spice-devel mailing list