[Spice-devel] [PATCH 06/18] Move vdagent to RedsState struct

Frediano Ziglio fziglio at redhat.com
Mon Feb 1 15:05:01 CET 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           | 55
>  ++++++++++++++++++++++++-------------------------
>  server/reds.h           |  2 +-
>  5 files changed, 34 insertions(+), 34 deletions(-)
> 
> diff --git a/server/inputs-channel.c b/server/inputs-channel.c
> index 97959b5..8f5ab37 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 60c38aa..4d620ec 100644
> --- a/server/reds-private.h
> +++ b/server/reds-private.h
> @@ -200,6 +200,7 @@ struct RedsState {
>  
>      int spice_port;
>      int spice_secure_port;
> +    SpiceCharDeviceInstance *vdagent;
>  };
>  
>  #endif
> diff --git a/server/reds.c b/server/reds.c
> index 0c94d6e..c81efc9 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
> @@ -467,9 +465,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);
>      }
>  }
>  
> @@ -611,7 +609,8 @@ static void reds_update_mouse_mode(RedsState *reds)
>      int allowed = 0;
>      int qxl_count = red_dispatcher_qxl_count();
>  
> -    if ((agent_mouse && vdagent) ||
> (inputs_channel_has_tablet(reds->inputs_channel) && qxl_count == 1)) {
> +    if ((agent_mouse && reds->vdagent) ||
> +        (inputs_channel_has_tablet(reds->inputs_channel) && qxl_count == 1))
> {
>          allowed = reds->dispatcher_allows_client_mouse;
>      }
>      if (allowed == reds->is_client_mouse_allowed) {
> @@ -634,7 +633,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))
>          {
> @@ -733,15 +732,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;
>              }
> @@ -763,7 +762,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;
>              }
> @@ -842,9 +841,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)
> @@ -941,10 +940,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;
>      /*
> @@ -980,11 +979,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);
>  }
> @@ -1180,7 +1179,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
> @@ -1342,7 +1341,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");
> @@ -1365,7 +1364,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);
> @@ -1697,7 +1696,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");
>          }
> @@ -2991,12 +2990,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)) {
> @@ -3121,7 +3120,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;
>          }
> @@ -3168,7 +3167,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);

Acked-by: Frediano Ziglio <fziglio at redhat.com>

Frediano


More information about the Spice-devel mailing list