[Spice-devel] [PATCH 14/16] Move vdagent to RedsState struct

Frediano Ziglio fziglio at redhat.com
Wed Jan 27 04:48:40 PST 2016


From: Jonathon Jongsma <jjongsma at redhat.com>

Also change API of reds_has_vdagent() to take RedsState arg.  Removes
another global variable.
---
 server/inputs-channel.c |  8 ++++----
 server/main-channel.c   |  2 +-
 server/reds-private.h   |  1 +
 server/reds.c           | 54 ++++++++++++++++++++++++-------------------------
 server/reds.h           |  2 +-
 5 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index e28b4b0..58768d1 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -355,8 +355,8 @@ static int inputs_channel_handle_parsed(RedChannelClient *rcc, uint32_t size, ui
         if (reds_get_mouse_mode(reds) != SPICE_MOUSE_MODE_CLIENT) {
             break;
         }
-        spice_assert((reds_get_agent_mouse() && reds_has_vdagent()) || tablet);
-        if (!reds_get_agent_mouse() || !reds_has_vdagent()) {
+        spice_assert((reds_get_agent_mouse() && reds_has_vdagent(reds)) || tablet);
+        if (!reds_get_agent_mouse() || !reds_has_vdagent(reds)) {
             SpiceTabletInterface *sif;
             sif = SPICE_CONTAINEROF(tablet->base.sif, SpiceTabletInterface, base);
             sif->position(tablet, pos->x, pos->y, RED_MOUSE_STATE_TO_LOCAL(pos->buttons_state));
@@ -379,7 +379,7 @@ static int inputs_channel_handle_parsed(RedChannelClient *rcc, uint32_t size, ui
             dz = 1;
         }
         if (reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_CLIENT) {
-            if (reds_get_agent_mouse() && reds_has_vdagent()) {
+            if (reds_get_agent_mouse() && reds_has_vdagent(reds)) {
                 inputs_channel->mouse_state.buttons =
                     RED_MOUSE_BUTTON_STATE_TO_AGENT(mouse_press->buttons_state) |
                     (dz == -1 ? VD_AGENT_UBUTTON_MASK : 0) |
@@ -401,7 +401,7 @@ static int inputs_channel_handle_parsed(RedChannelClient *rcc, uint32_t size, ui
     case SPICE_MSGC_INPUTS_MOUSE_RELEASE: {
         SpiceMsgcMouseRelease *mouse_release = message;
         if (reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_CLIENT) {
-            if (reds_get_agent_mouse() && reds_has_vdagent()) {
+            if (reds_get_agent_mouse() && reds_has_vdagent(reds)) {
                 inputs_channel->mouse_state.buttons =
                     RED_MOUSE_BUTTON_STATE_TO_AGENT(mouse_release->buttons_state);
                 reds_handle_agent_mouse_event(reds, &inputs_channel->mouse_state);
diff --git a/server/main-channel.c b/server/main-channel.c
index 1f4fcaa..aa2b03c 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -545,7 +545,7 @@ static void main_channel_marshall_init(RedChannelClient *rcc,
     if (item->is_client_mouse_allowed) {
         init.supported_mouse_modes |= SPICE_MOUSE_MODE_CLIENT;
     }
-    init.agent_connected = reds_has_vdagent();
+    init.agent_connected = reds_has_vdagent(reds);
     init.agent_tokens = REDS_AGENT_WINDOW_SIZE;
     init.multi_media_time = item->multi_media_time;
     init.ram_hint = item->ram_hint;
diff --git a/server/reds-private.h b/server/reds-private.h
index 7f1a6df..4b7bf50 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -199,6 +199,7 @@ struct RedsState {
     GArray *renderers;
 
     int spice_port;
+    SpiceCharDeviceInstance *vdagent;
 };
 
 #endif
diff --git a/server/reds.c b/server/reds.c
index dfde212..ca4508e 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -73,7 +73,6 @@
 #include "reds-private.h"
 
 SpiceCoreInterfaceInternal *core = NULL;
-
 static SpiceCoreInterface *core_public = NULL;
 
 static SpiceTimer *adapter_timer_add(const SpiceCoreInterfaceInternal *iface, SpiceTimerFunc func, void *opaque)
@@ -130,7 +129,6 @@ static SpiceCoreInterfaceInternal core_interface_adapter = {
     .channel_event = adapter_channel_event,
 };
 
-static SpiceCharDeviceInstance *vdagent = NULL;
 static SpiceMigrateInstance *migration_interface = NULL;
 
 /* Debugging only variable: allow multiple client connections to the spice
@@ -468,9 +466,9 @@ static void reds_reset_vdp(RedsState *reds)
         spice_char_device_reset(state->base);
     }
 
-    sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
+    sif = SPICE_CONTAINEROF(reds->vdagent->base.sif, SpiceCharDeviceInterface, base);
     if (sif->state) {
-        sif->state(vdagent, 0);
+        sif->state(reds->vdagent, 0);
     }
 }
 
@@ -612,7 +610,7 @@ static void reds_update_mouse_mode(RedsState *reds)
     int allowed = 0;
     int qxl_count = red_dispatcher_qxl_count();
 
-    if ((agent_mouse && vdagent) ||
+    if ((agent_mouse && reds->vdagent) ||
         ((reds->inputs_channel && inputs_channel_has_tablet(reds->inputs_channel)) &&
          qxl_count == 1)) {
         allowed = reds->dispatcher_allows_client_mouse;
@@ -637,7 +635,7 @@ static void reds_agent_remove(RedsState *reds)
     // part of the clients are during target migration.
     reds_reset_vdp(reds);
 
-    vdagent = NULL;
+    reds->vdagent = NULL;
     reds_update_mouse_mode(reds);
     if (reds_main_channel_connected(reds) &&
         !red_channel_is_waiting_for_migrate_data(&reds->main_channel->base)) {
@@ -736,15 +734,15 @@ static SpiceCharDeviceMsgToClient *vdi_port_read_one_msg_from_device(SpiceCharDe
     VDIReadBuf *dispatch_buf;
     int n;
 
-    if (!vdagent) {
+    if (!reds->vdagent) {
         return NULL;
     }
-    spice_assert(vdagent == sin);
-    sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
-    while (vdagent) {
+    spice_assert(reds->vdagent == sin);
+    sif = SPICE_CONTAINEROF(reds->vdagent->base.sif, SpiceCharDeviceInterface, base);
+    while (reds->vdagent) {
         switch (state->read_state) {
         case VDI_PORT_READ_STATE_READ_HEADER:
-            n = sif->read(vdagent, state->receive_pos, state->receive_len);
+            n = sif->read(reds->vdagent, state->receive_pos, state->receive_len);
             if (!n) {
                 return NULL;
             }
@@ -766,7 +764,7 @@ static SpiceCharDeviceMsgToClient *vdi_port_read_one_msg_from_device(SpiceCharDe
             state->read_state = VDI_PORT_READ_STATE_READ_DATA;
         }
         case VDI_PORT_READ_STATE_READ_DATA:
-            n = sif->read(vdagent, state->receive_pos, state->receive_len);
+            n = sif->read(reds->vdagent, state->receive_pos, state->receive_len);
             if (!n) {
                 return NULL;
             }
@@ -845,9 +843,9 @@ static void vdi_port_remove_client(RedClient *client, void *opaque)
 
 /****************************************************************************/
 
-int reds_has_vdagent(void)
+int reds_has_vdagent(RedsState *reds)
 {
-    return !!vdagent;
+    return !!reds->vdagent;
 }
 
 void reds_handle_agent_mouse_event(RedsState *reds, const VDAgentMouseState *mouse_state)
@@ -944,10 +942,10 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t
     SpiceCharDeviceState *dev_state = reds->agent_state.base;
     RedChannelClient *rcc;
 
-    if (!vdagent) {
+    if (!reds->vdagent) {
         return;
     }
-    spice_assert(vdagent->st && vdagent->st == dev_state);
+    spice_assert(reds->vdagent->st && reds->vdagent->st == dev_state);
     rcc = main_channel_client_get_base(mcc);
     reds->agent_state.client_agent_started = TRUE;
     /*
@@ -983,11 +981,11 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t
 
 void reds_on_main_agent_tokens(MainChannelClient *mcc, uint32_t num_tokens)
 {
-    if (!vdagent) {
+    if (!reds->vdagent) {
         return;
     }
-    spice_assert(vdagent->st);
-    spice_char_device_send_to_client_tokens_add(vdagent->st,
+    spice_assert(reds->vdagent->st);
+    spice_char_device_send_to_client_tokens_add(reds->vdagent->st,
                                                 main_channel_client_get_base(mcc)->client,
                                                 num_tokens);
 }
@@ -1183,7 +1181,7 @@ void reds_marshall_migrate_data(RedsState *reds, SpiceMarshaller *m)
     spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_MAIN_MAGIC);
     spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_MAIN_VERSION);
 
-    if (!vdagent) {
+    if (!reds->vdagent) {
         uint8_t *null_agent_mig_data;
 
         spice_assert(!agent_state->base); /* MSG_AGENT_CONNECTED_TOKENS is supported by the client
@@ -1345,7 +1343,7 @@ int reds_handle_migrate_data(RedsState *reds, MainChannelClient *mcc,
     }
     if (mig_data->agent_base.connected) {
         if (agent_state->base) { // agent was attached before migration data has arrived
-            if (!vdagent) {
+            if (!reds->vdagent) {
                 spice_assert(agent_state->plug_generation > 0);
                 main_channel_push_agent_disconnected(reds->main_channel);
                 spice_debug("agent is no longer connected");
@@ -1368,7 +1366,7 @@ int reds_handle_migrate_data(RedsState *reds, MainChannelClient *mcc,
         }
     } else {
         spice_debug("agent was not attached on the source host");
-        if (vdagent) {
+        if (reds->vdagent) {
             /* spice_char_device_client_remove disables waiting for migration data */
             spice_char_device_client_remove(agent_state->base,
                                             main_channel_client_get_base(mcc)->client);
@@ -1700,7 +1698,7 @@ static void reds_handle_main_link(RedsState *reds, RedLinkInfo *link)
     free(link_mess);
     red_client_set_main(client, mcc);
 
-    if (vdagent) {
+    if (reds->vdagent) {
         if (mig_target) {
             spice_warning("unexpected: vdagent attached to destination during migration");
         }
@@ -2994,12 +2992,12 @@ static SpiceCharDeviceState *attach_to_red_agent(RedsState *reds, SpiceCharDevic
         spice_char_device_state_reset_dev_instance(state->base, sin);
     }
 
-    vdagent = sin;
+    reds->vdagent = sin;
     reds_update_mouse_mode(reds);
 
-    sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
+    sif = SPICE_CONTAINEROF(reds->vdagent->base.sif, SpiceCharDeviceInterface, base);
     if (sif->state) {
-        sif->state(vdagent, 1);
+        sif->state(reds->vdagent, 1);
     }
 
     if (!reds_main_channel_connected(reds)) {
@@ -3124,7 +3122,7 @@ static int spice_server_char_device_add_interface(SpiceServer *s,
 
     spice_info("CHAR_DEVICE %s", char_device->subtype);
     if (strcmp(char_device->subtype, SUBTYPE_VDAGENT) == 0) {
-        if (vdagent) {
+        if (s->vdagent) {
             spice_warning("vdagent already attached");
             return -1;
         }
@@ -3171,7 +3169,7 @@ static void spice_server_char_device_remove_interface(RedsState *reds, SpiceBase
 
     spice_info("remove CHAR_DEVICE %s", char_device->subtype);
     if (strcmp(char_device->subtype, SUBTYPE_VDAGENT) == 0) {
-        if (vdagent) {
+        if (reds->vdagent) {
             reds_agent_remove(reds);
         }
     }
diff --git a/server/reds.h b/server/reds.h
index 4034199..24fb2a6 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -60,7 +60,7 @@ void reds_register_channel(RedsState *reds, RedChannel *channel);
 void reds_unregister_channel(RedsState *reds, RedChannel *channel);
 int reds_get_mouse_mode(RedsState *reds); // used by inputs_channel
 int reds_get_agent_mouse(void); // used by inputs_channel
-int reds_has_vdagent(void); // used by inputs channel
+int reds_has_vdagent(RedsState *reds); // used by inputs channel
 void reds_handle_agent_mouse_event(RedsState *reds, const VDAgentMouseState *mouse_state); // used by inputs_channel
 
 GArray* reds_get_renderers(RedsState *reds);
-- 
2.4.3



More information about the Spice-devel mailing list