Re: [PATCH 04/15] Introduce spice_char_device_get_interface()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> From: Christophe Fergeau <cfergeau@xxxxxxxxxx>
> 
> Hides awkward casting/dereferencing to go from a
> SpiceCharDeviceInstance to a SpiceCharDeviceInterface
> ---
>  server/char-device.c |  9 +++++++--
>  server/char-device.h |  2 ++
>  server/reds.c        |  6 +++---
>  server/smartcard.c   |  2 +-
>  server/spicevmc.c    | 16 ++++++----------
>  5 files changed, 19 insertions(+), 16 deletions(-)
> 
> diff --git a/server/char-device.c b/server/char-device.c
> index 9858ab3..cda2d60 100644
> --- a/server/char-device.c
> +++ b/server/char-device.c
> @@ -460,7 +460,7 @@ static int
> spice_char_device_write_to_device(SpiceCharDeviceState *dev)
>          reds_core_timer_cancel(dev->reds, dev->write_to_dev_timer);
>      }
>  
> -    sif = SPICE_CONTAINEROF(dev->sin->base.sif, SpiceCharDeviceInterface,
> base);
> +    sif = spice_char_device_get_interface(dev->sin);
>      while (dev->running) {
>          uint32_t write_len;
>  
> @@ -695,7 +695,7 @@ SpiceCharDeviceState
> *spice_char_device_state_create(SpiceCharDeviceInstance *si
>      ring_init(&char_dev->write_bufs_pool);
>      ring_init(&char_dev->clients);
>  
> -    sif = SPICE_CONTAINEROF(char_dev->sin->base.sif,
> SpiceCharDeviceInterface, base);
> +    sif = spice_char_device_get_interface(char_dev->sin);
>      if (sif->base.minor_version <= 2 ||
>          !(sif->flags & SPICE_CHAR_DEVICE_NOTIFY_WRITABLE)) {
>          char_dev->write_to_dev_timer = reds_core_timer_add(reds,
>          spice_char_dev_write_retry, char_dev);
> @@ -1044,3 +1044,8 @@ SpiceServer*
> spice_char_device_get_server(SpiceCharDeviceState *dev)
>  {
>      return dev->reds;
>  }
> +
> +SpiceCharDeviceInterface
> *spice_char_device_get_interface(SpiceCharDeviceInstance *instance)
> +{
> +   return SPICE_CONTAINEROF(instance->base.sif, SpiceCharDeviceInterface,
> base);
> +}
> diff --git a/server/char-device.h b/server/char-device.h
> index db72bfe..7c78524 100644
> --- a/server/char-device.h
> +++ b/server/char-device.h
> @@ -219,4 +219,6 @@ SpiceCharDeviceState *spicevmc_device_connect(struct
> RedsState *reds,
>  void spicevmc_device_disconnect(struct RedsState *reds,
>                                  SpiceCharDeviceInstance *char_device);
>  
> +SpiceCharDeviceInterface
> *spice_char_device_get_interface(SpiceCharDeviceInstance *instance);
> +
>  #endif // CHAR_DEVICE_H_
> diff --git a/server/reds.c b/server/reds.c
> index 1b7d394..736dca6 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -439,7 +439,7 @@ static void reds_reset_vdp(RedsState *reds)
>          spice_char_device_reset(state->base);
>      }
>  
> -    sif = SPICE_CONTAINEROF(reds->vdagent->base.sif,
> SpiceCharDeviceInterface, base);
> +    sif = spice_char_device_get_interface(reds->vdagent);
>      if (sif->state) {
>          sif->state(reds->vdagent, 0);
>      }
> @@ -714,7 +714,7 @@ static SpiceCharDeviceMsgToClient
> *vdi_port_read_one_msg_from_device(SpiceCharDe
>          return NULL;
>      }
>      spice_assert(reds->vdagent == sin);
> -    sif = SPICE_CONTAINEROF(reds->vdagent->base.sif,
> SpiceCharDeviceInterface, base);
> +    sif = spice_char_device_get_interface(reds->vdagent);
>      while (reds->vdagent) {
>          switch (state->read_state) {
>          case VDI_PORT_READ_STATE_READ_HEADER:
> @@ -2990,7 +2990,7 @@ static SpiceCharDeviceState
> *attach_to_red_agent(RedsState *reds, SpiceCharDevic
>      reds->vdagent = sin;
>      reds_update_mouse_mode(reds);
>  
> -    sif = SPICE_CONTAINEROF(reds->vdagent->base.sif,
> SpiceCharDeviceInterface, base);
> +    sif = spice_char_device_get_interface(reds->vdagent);
>      if (sif->state) {
>          sif->state(reds->vdagent, 1);
>      }
> diff --git a/server/smartcard.c b/server/smartcard.c
> index 565a71d..6071f59 100644
> --- a/server/smartcard.c
> +++ b/server/smartcard.c
> @@ -133,7 +133,7 @@ SpiceCharDeviceMsgToClient
> *smartcard_read_msg_from_device(SpiceCharDeviceInstan
>                                                             void *opaque)
>  {
>      SmartCardDeviceState *state = opaque;
> -    SpiceCharDeviceInterface *sif = SPICE_CONTAINEROF(sin->base.sif,
> SpiceCharDeviceInterface, base);
> +    SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
>      VSCMsgHeader *vheader = (VSCMsgHeader*)state->buf;
>      int n;
>      int remaining;
> diff --git a/server/spicevmc.c b/server/spicevmc.c
> index 35d1393..929ec0e 100644
> --- a/server/spicevmc.c
> +++ b/server/spicevmc.c
> @@ -112,7 +112,7 @@ static SpiceCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharD
>      SpiceVmcPipeItem *msg_item;
>      int n;
>  
> -    sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base);
> +    sif = spice_char_device_get_interface(sin);
>  
>      if (!state->rcc) {
>          return NULL;
> @@ -212,7 +212,6 @@ static int
> spicevmc_red_channel_client_config_socket(RedChannelClient *rcc)
>  static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
>  {
>      SpiceVmcState *state;
> -    SpiceCharDeviceInstance *sin;
>      SpiceCharDeviceInterface *sif;
>  
>      if (!rcc) {
> @@ -220,8 +219,6 @@ static void
> spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
>      }
>  
>      state = SPICE_CONTAINEROF(rcc->channel, SpiceVmcState, channel);
> -    sin = state->chardev_sin;
> -    sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base);
>  
>      if (state->recv_from_client_buf) { /* partial message which wasn't
>      pushed to device */
>          spice_char_device_write_buffer_release(state->chardev_st,
>          state->recv_from_client_buf);
> @@ -243,8 +240,9 @@ static void
> spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
>          red_channel_client_destroy(rcc);
>  
>      state->rcc = NULL;
> +    sif = spice_char_device_get_interface(state->chardev_sin);
>      if (sif->state) {
> -        sif->state(sin, 0);
> +        sif->state(state->chardev_sin, 0);
>      }
>  }
>  
> @@ -287,12 +285,10 @@ static int
> spicevmc_red_channel_client_handle_message(RedChannelClient *rcc,
>                                                        uint8_t *msg)
>  {
>      SpiceVmcState *state;
> -    SpiceCharDeviceInstance *sin;
>      SpiceCharDeviceInterface *sif;
>  
>      state = spicevmc_red_channel_client_get_state(rcc);
> -    sin = state->chardev_sin;
> -    sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base);
> +    sif = spice_char_device_get_interface(state->chardev_sin);
>  
>      switch (type) {
>      case SPICE_MSGC_SPICEVMC_DATA:
> @@ -307,7 +303,7 @@ static int
> spicevmc_red_channel_client_handle_message(RedChannelClient *rcc,
>              return FALSE;
>          }
>          if (sif->base.minor_version >= 2 && sif->event != NULL)
> -            sif->event(sin, *msg);
> +            sif->event(state->chardev_sin, *msg);
>          break;
>      default:
>          return red_channel_client_handle_message(rcc, size, type, msg);
> @@ -467,7 +463,6 @@ static void spicevmc_connect(RedChannel *channel,
> RedClient *client,
>  
>      state = SPICE_CONTAINEROF(channel, SpiceVmcState, channel);
>      sin = state->chardev_sin;
> -    sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base);
>  
>      if (state->rcc) {
>          spice_printerr("channel client %d:%d (%p) already connected,
>          refusing second connection",
> @@ -499,6 +494,7 @@ static void spicevmc_connect(RedChannel *channel,
> RedClient *client,
>          return;
>      }
>  
> +    sif = spice_char_device_get_interface(state->chardev_sin);
>      if (sif->state) {
>          sif->state(sin, 1);
>      }

Acked-by: Frediano Ziglio <fziglio@xxxxxxxxxx>

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]