[Spice-devel,02/55] agent: reset client tokens when notifying on agent connection

Submitted by Yonit Halperin on Aug. 15, 2012, 7:55 a.m.

Details

Message ID 1345017402-872-7-git-send-email-yhalperi@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Yonit Halperin Aug. 15, 2012, 7:55 a.m.
send SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS
---
 server/main_channel.c |   17 ++++++++++++++++-
 server/reds.c         |   16 ++++++++++------
 spice-common          |    2 +-
 3 files changed, 27 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/main_channel.c b/server/main_channel.c
index 00a6b0f..0d948de 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -388,7 +388,19 @@  static void main_channel_marshall_mouse_mode(SpiceMarshaller *m, int current_mod
 
 void main_channel_push_agent_connected(MainChannel *main_chan)
 {
-    red_channel_pipes_add_type(&main_chan->base, SPICE_MSG_MAIN_AGENT_CONNECTED);
+    if (red_channel_test_remote_cap(&main_chan->base, SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS)) {
+        red_channel_pipes_add_type(&main_chan->base, SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS);
+    } else {
+        red_channel_pipes_add_type(&main_chan->base, SPICE_MSG_MAIN_AGENT_CONNECTED);
+    }
+}
+
+static void main_channel_marshall_agent_connected(SpiceMarshaller *m)
+{
+    SpiceMsgMainAgentConnectedTokens connected;
+
+    connected.num_tokens = REDS_AGENT_WINDOW_SIZE;
+    spice_marshall_msg_main_agent_connected_tokens(m, &connected);
 }
 
 void main_channel_push_agent_disconnected(MainChannel *main_chan)
@@ -729,6 +741,9 @@  static void main_channel_send_item(RedChannelClient *rcc, PipeItem *base)
         case SPICE_MSG_MAIN_UUID:
             spice_marshall_msg_main_uuid(m, &SPICE_CONTAINEROF(base, UuidPipeItem, base)->msg);
             break;
+        case SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS:
+            main_channel_marshall_agent_connected(m);
+            break;
         default:
             break;
     };
diff --git a/server/reds.c b/server/reds.c
index e3ea154..8d6dbfb 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -605,15 +605,19 @@  static void reds_reset_vdp(void)
      *  The client tokens' are set only once, when the main channel is initialized.
      *  Instead, it would have been more appropriate to reset them upon AGEN_CONNECT.
      *  The client tokens are tracked as part of the SpiceCharDeviceClientState. Thus,
-     *  in order to be backwartd compatible with the client, we need to track the tokens
-     *  event when the agent is detached. We don't destroy the the char_device state, and
+     *  in order to be backward compatible with the client, we need to track the tokens
+     *  even if the agent is detached. We don't destroy the the char_device state, and
      *  instead we just reset it.
-     *  In addition, there is a misshandling of AGENT_TOKENS message in spice-gtk: it
+     *  In addition, there used to be a misshandling of AGENT_TOKENS message in spice-gtk: it
      *  overrides the amount of tokens, instead of adding the given amount.
-     *
-     *  TODO: change AGENT_CONNECT msg to contain tokens count.
      */
-    spice_char_device_reset(state->base);
+    if (red_channel_test_remote_cap(&reds->main_channel->base,
+                                    SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS)) {
+        spice_char_device_state_destroy(state->base);
+        state->base = NULL;
+    } else {
+        spice_char_device_reset(state->base);
+    }
 
     sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
     if (sif->state) {
diff --git a/spice-common b/spice-common
index c2adbb0..7439137 160000
--- a/spice-common
+++ b/spice-common
@@ -1 +1 @@ 
-Subproject commit c2adbb00dc0b29de0fe297f241fb0efeb4a81510
+Subproject commit 7439137509f838f95d672454cb9c30def7f84f89