[Spice-devel] [PATCH spice-html5 v2 1/7] Handle agent tokens

Pavel Grunt pgrunt at redhat.com
Thu Jan 15 00:01:04 PST 2015


---
v2:
 - number of agent tokens is set before sending monitor config
---
 main.js     | 19 +++++++++++++++++--
 spicemsg.js | 15 +++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/main.js b/main.js
index e487551..c71de7a 100644
--- a/main.js
+++ b/main.js
@@ -66,6 +66,7 @@ SpiceMainConn.prototype.process_channel_message = function(msg)
         this.report_success("Connected")
         this.main_init = new SpiceMsgMainInit(msg.data);
         this.connection_id = this.main_init.session_id;
+        this.agent_tokens = this.main_init.agent_tokens;
 
         if (DEBUG > 0)
         {
@@ -141,13 +142,27 @@ SpiceMainConn.prototype.process_channel_message = function(msg)
         return true;
     }
 
-    if (msg.type == SPICE_MSG_MAIN_AGENT_CONNECTED ||
-        msg.type == SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS)
+    if (msg.type == SPICE_MSG_MAIN_AGENT_CONNECTED)
     {
         this.connect_agent();
         return true;
     }
 
+    if (msg.type == SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS)
+    {
+        var connected_tokens = new SpiceMsgMainAgentTokens(msg.data);
+        this.agent_tokens = connected_tokens.num_tokens;
+        this.connect_agent();
+        return true;
+    }
+
+    if (msg.type == SPICE_MSG_MAIN_AGENT_TOKEN)
+    {
+        var tokens = new SpiceMsgMainAgentTokens(msg.data);
+        this.agent_tokens += tokens.num_tokens;
+        return true;
+    }
+
     if (msg.type == SPICE_MSG_MAIN_AGENT_DISCONNECTED)
     {
         this.agent_connected = false;
diff --git a/spicemsg.js b/spicemsg.js
index c64f5a3..0983ae7 100644
--- a/spicemsg.js
+++ b/spicemsg.js
@@ -348,6 +348,21 @@ SpiceMsgMainMouseMode.prototype =
     },
 }
 
+function SpiceMsgMainAgentTokens(a, at)
+{
+    this.from_buffer(a, at);
+}
+
+SpiceMsgMainAgentTokens.prototype =
+{
+    from_buffer: function(a, at)
+    {
+        at = at || 0;
+        var dv = new SpiceDataView(a);
+        this.num_tokens = dv.getUint32(at, true); at += 4;
+    },
+}
+
 function SpiceMsgSetAck(a, at)
 {
     this.from_buffer(a, at);
-- 
1.9.3



More information about the Spice-devel mailing list