[Spice-devel] [PATCH 2/3] Use and introduce channel client cast macros

Frediano Ziglio fziglio at redhat.com
Mon Sep 19 16:34:04 UTC 2016


> 
> In anticipation of porting to GObject, use casting macros (e.g.
> MAIN_CHANNEL_CLIENT()) to cast RedChannelClient types. This will help
> reduce the changeset slightly porting to GObject and thus make it easier
> to review those upcoming changes.
> ---
>  server/cursor-channel-client.c |  4 ++--
>  server/dcc.c                   |  4 ++--
>  server/inputs-channel-client.c |  6 +++---
>  server/inputs-channel-client.h |  2 ++
>  server/inputs-channel.c        |  4 ++--
>  server/main-channel-client.c   | 12 ++++++------
>  server/main-channel-client.h   |  2 ++
>  server/main-channel.c          | 16 ++++++++--------
>  server/red-channel-client.c    | 10 +++++-----
>  server/smartcard.c             | 28 +++++++++++++++-------------
>  10 files changed, 47 insertions(+), 41 deletions(-)
> 
> diff --git a/server/cursor-channel-client.c b/server/cursor-channel-client.c
> index bbcc290..89c23a3 100644
> --- a/server/cursor-channel-client.c
> +++ b/server/cursor-channel-client.c
> @@ -97,14 +97,14 @@ CursorChannelClient*
> cursor_channel_client_new(CursorChannel *cursor, RedClient
>      spice_return_val_if_fail(!num_caps || caps, NULL);
>  
>      CursorChannelClient *ccc =
> -
> (CursorChannelClient*)red_channel_client_create(sizeof(CursorChannelClient),
> +
> CURSOR_CHANNEL_CLIENT(red_channel_client_create(sizeof(CursorChannelClient),
>                                                          RED_CHANNEL(cursor),
>                                                          client, stream,
>                                                          FALSE,
>                                                          num_common_caps,
>                                                          common_caps,
>                                                          num_caps,
> -                                                        caps);
> +                                                        caps));
>      spice_return_val_if_fail(ccc != NULL, NULL);
>      COMMON_GRAPHICS_CHANNEL(cursor)->during_target_migrate = mig_target;
>  
> diff --git a/server/dcc.c b/server/dcc.c
> index f0a1ef8..0fdce29 100644
> --- a/server/dcc.c
> +++ b/server/dcc.c
> @@ -350,12 +350,12 @@ DisplayChannelClient *dcc_new(DisplayChannel *display,
>  {
>      DisplayChannelClient *dcc;
>  
> -    dcc = (DisplayChannelClient*)red_channel_client_create(
> +    dcc = DISPLAY_CHANNEL_CLIENT(red_channel_client_create(
>          sizeof(DisplayChannelClient),
>          &COMMON_GRAPHICS_CHANNEL(display)->base,
>          client, stream, TRUE,
>          num_common_caps, common_caps,
> -        num_caps, caps);
> +        num_caps, caps));
>  
>      display->common.during_target_migrate = mig_target;
>      dcc->priv->id = display->common.qxl->id;
> diff --git a/server/inputs-channel-client.c b/server/inputs-channel-client.c
> index a07008b..7b38625 100644
> --- a/server/inputs-channel-client.c
> +++ b/server/inputs-channel-client.c
> @@ -46,13 +46,13 @@ RedChannelClient* inputs_channel_client_create(RedChannel
> *channel,
>                                                 uint32_t *caps)
>  {
>      InputsChannelClient* icc =
> -
> (InputsChannelClient*)red_channel_client_create(sizeof(InputsChannelClient),
> +
> INPUTS_CHANNEL_CLIENT(red_channel_client_create(sizeof(InputsChannelClient),
>                                                          channel, client,
>                                                          stream,
>                                                          monitor_latency,
>                                                          num_common_caps,
>                                                          common_caps,
>                                                          num_caps,
> -                                                        caps);
> +                                                        caps));
>      if (icc) {
>          icc->priv->motion_count = 0;
>      }
> @@ -63,7 +63,7 @@ void
> inputs_channel_client_send_migrate_data(RedChannelClient *rcc,
>                                               SpiceMarshaller *m,
>                                               RedPipeItem *item)
>  {
> -    InputsChannelClient *icc = SPICE_CONTAINEROF(rcc, InputsChannelClient,
> base);
> +    InputsChannelClient *icc = INPUTS_CHANNEL_CLIENT(rcc);
>  
>      red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE_DATA, item);
>  
> diff --git a/server/inputs-channel-client.h b/server/inputs-channel-client.h
> index e83cc29..82dbbaf 100644
> --- a/server/inputs-channel-client.h
> +++ b/server/inputs-channel-client.h
> @@ -45,4 +45,6 @@ enum {
>      RED_PIPE_ITEM_MIGRATE_DATA,
>  };
>  
> +#define INPUTS_CHANNEL_CLIENT(rcc) ((InputsChannelClient*)rcc)
> +
>  #endif /* _INPUTS_CHANNEL_CLIENT_H_ */
> diff --git a/server/inputs-channel.c b/server/inputs-channel.c
> index 2738be4..840d5e9 100644
> --- a/server/inputs-channel.c
> +++ b/server/inputs-channel.c
> @@ -273,7 +273,7 @@ static int inputs_channel_handle_parsed(RedChannelClient
> *rcc, uint32_t size, ui
>                                          void *message)
>  {
>      InputsChannel *inputs_channel = (InputsChannel
>      *)red_channel_client_get_channel(rcc);
> -    InputsChannelClient *icc = (InputsChannelClient *)rcc;
> +    InputsChannelClient *icc = INPUTS_CHANNEL_CLIENT(rcc);
>      uint32_t i;
>      RedsState *reds = red_channel_get_server(&inputs_channel->base);
>  
> @@ -547,7 +547,7 @@ static int
> inputs_channel_handle_migrate_data(RedChannelClient *rcc,
>                                                uint32_t size,
>                                                void *message)
>  {
> -    InputsChannelClient *icc = (InputsChannelClient*)rcc;
> +    InputsChannelClient *icc = INPUTS_CHANNEL_CLIENT(rcc);
>      InputsChannel *inputs =
>      (InputsChannel*)red_channel_client_get_channel(rcc);
>      SpiceMigrateDataHeader *header;
>      SpiceMigrateDataInputs *mig_data;
> diff --git a/server/main-channel-client.c b/server/main-channel-client.c
> index 236a2e7..693e832 100644
> --- a/server/main-channel-client.c
> +++ b/server/main-channel-client.c
> @@ -384,7 +384,7 @@ void
> main_channel_client_handle_migrate_dst_do_seamless(MainChannelClient *mcc,
>  void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing
>  *ping, uint32_t size)
>  {
>      uint64_t roundtrip;
> -    RedChannelClient* rcc = (RedChannelClient*)mcc;
> +    RedChannelClient* rcc = RED_CHANNEL_CLIENT(mcc);
>  
>      roundtrip = g_get_monotonic_time() - ping->timestamp;
>  
> @@ -559,10 +559,10 @@ MainChannelClient
> *main_channel_client_create(MainChannel *main_chan, RedClient
>                                                int num_common_caps, uint32_t
>                                                *common_caps,
>                                                int num_caps, uint32_t *caps)
>  {
> -    MainChannelClient *mcc = (MainChannelClient*)
> +    MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(
>                               red_channel_client_create(sizeof(MainChannelClient),
>                               &main_chan->base,
>                                                         client, stream,
>                                                         FALSE,
>                                                         num_common_caps,
> -                                                       common_caps,
> num_caps, caps);
> +                                                       common_caps,
> num_caps, caps));
>      spice_assert(mcc != NULL);
>      mcc->priv->connection_id = connection_id;
>      mcc->priv->bitrate_per_sec = ~0;
> @@ -599,7 +599,7 @@ uint64_t
> main_channel_client_get_roundtrip_ms(MainChannelClient *mcc)
>  void main_channel_client_migrate(RedChannelClient *rcc)
>  {
>      RedChannel *channel = red_channel_client_get_channel(rcc);
> -    reds_on_main_channel_migrate(channel->reds, SPICE_CONTAINEROF(rcc,
> MainChannelClient, base));
> +    reds_on_main_channel_migrate(channel->reds, MAIN_CHANNEL_CLIENT(rcc));
>      red_channel_client_default_migrate(rcc);
>  }
>  
> @@ -671,7 +671,7 @@ static void main_channel_marshall_ping(RedChannelClient
> *rcc,
>                                         SpiceMarshaller *m,
>                                         RedPingPipeItem *item)
>  {
> -    MainChannelClient *mcc = (MainChannelClient*)rcc;
> +    MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>      SpiceMsgPing ping;
>      int size_left = item->size;
>  
> @@ -870,7 +870,7 @@ static void
> main_channel_marshall_agent_connected(SpiceMarshaller *m,
>  
>  void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base)
>  {
> -    MainChannelClient *mcc = SPICE_CONTAINEROF(rcc, MainChannelClient,
> base);
> +    MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>      SpiceMarshaller *m = red_channel_client_get_marshaller(rcc);
>  
>      /* In semi-seamless migration (dest side), the connection is started
>      from scratch, and
> diff --git a/server/main-channel-client.h b/server/main-channel-client.h
> index 9f05af3..3bb8729 100644
> --- a/server/main-channel-client.h
> +++ b/server/main-channel-client.h
> @@ -105,4 +105,6 @@ typedef struct MainMultiMediaTimeItemInfo {
>  RedPipeItem *main_multi_media_time_item_new(RedChannelClient *rcc,
>                                              void *data, int num);
>  
> +#define MAIN_CHANNEL_CLIENT(rcc) ((MainChannelClient*)rcc)
> +
>  #endif /* __MAIN_CHANNEL_CLIENT_H__ */
> diff --git a/server/main-channel.c b/server/main-channel.c
> index 4670315..d176498 100644
> --- a/server/main-channel.c
> +++ b/server/main-channel.c
> @@ -48,7 +48,7 @@ RedClient *main_channel_get_client_by_link_id(MainChannel
> *main_chan, uint32_t c
>      RedChannelClient *rcc;
>  
>      FOREACH_CLIENT(main_chan, link, next, rcc) {
> -        MainChannelClient *mcc = (MainChannelClient*) rcc;
> +        MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>          if (main_channel_client_get_connection_id(mcc) == connection_id) {
>              return red_channel_client_get_client(rcc);
>          }
> @@ -102,7 +102,7 @@ static int
> main_channel_handle_migrate_data(RedChannelClient *rcc,
>      uint32_t size, void *message)
>  {
>      RedChannel *channel = red_channel_client_get_channel(rcc);
> -    MainChannelClient *mcc = (MainChannelClient*)rcc;
> +    MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>      SpiceMigrateDataHeader *header = (SpiceMigrateDataHeader *)message;
>  
>      /* not supported with multi-clients */
> @@ -157,7 +157,7 @@ static int main_channel_handle_parsed(RedChannelClient
> *rcc, uint32_t size, uint
>  {
>      RedChannel *channel = red_channel_client_get_channel(rcc);
>      MainChannel *main_chan = SPICE_CONTAINEROF(channel, MainChannel, base);
> -    MainChannelClient *mcc = (MainChannelClient*)rcc;
> +    MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>  
>      switch (type) {
>      case SPICE_MSGC_MAIN_AGENT_START: {
> @@ -226,7 +226,7 @@ static uint8_t
> *main_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
>  {
>      RedChannel *channel = red_channel_client_get_channel(rcc);
>      MainChannel *main_chan = SPICE_CONTAINEROF(channel, MainChannel, base);
> -    MainChannelClient *mcc = (MainChannelClient*)rcc;
> +    MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>  
>      if (type == SPICE_MSGC_MAIN_AGENT_DATA) {
>          return reds_get_agent_data_buffer(channel->reds, mcc, size);
> @@ -338,7 +338,7 @@ static int main_channel_connect_semi_seamless(MainChannel
> *main_channel)
>      RedChannelClient *rcc;
>  
>      FOREACH_CLIENT(main_channel, link, next, rcc) {
> -        MainChannelClient *mcc = (MainChannelClient*)rcc;
> +        MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>          if (main_channel_client_connect_semi_seamless(mcc))
>              main_channel->num_clients_mig_wait++;
>      }
> @@ -353,7 +353,7 @@ static int main_channel_connect_seamless(MainChannel
> *main_channel)
>      spice_assert(g_list_length(main_channel->base.clients) == 1);
>  
>      FOREACH_CLIENT(main_channel, link, next, rcc) {
> -        MainChannelClient *mcc = (MainChannelClient*)rcc;
> +        MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>          main_channel_client_connect_seamless(mcc);
>          main_channel->num_clients_mig_wait++;
>      }
> @@ -393,7 +393,7 @@ void main_channel_migrate_cancel_wait(MainChannel
> *main_chan)
>      RedChannelClient *rcc;
>  
>      FOREACH_CLIENT(main_chan, link, next, rcc) {
> -        MainChannelClient *mcc = (MainChannelClient*)rcc;
> +        MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>          main_channel_client_migrate_cancel_wait(mcc);
>      }
>      main_chan->num_clients_mig_wait = 0;
> @@ -413,7 +413,7 @@ int main_channel_migrate_src_complete(MainChannel
> *main_chan, int success)
>      }
>  
>      FOREACH_CLIENT(main_chan, link, next, rcc) {
> -        MainChannelClient *mcc = (MainChannelClient*)rcc;
> +        MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
>          if (main_channel_client_migrate_src_complete(mcc, success))
>              semi_seamless_count++;
>     }
> diff --git a/server/red-channel-client.c b/server/red-channel-client.c
> index 50b295c..8ec2d7c 100644
> --- a/server/red-channel-client.c
> +++ b/server/red-channel-client.c
> @@ -128,7 +128,7 @@ void red_channel_client_on_input(void *opaque, int n)
>  
>  int red_channel_client_get_out_msg_size(void *opaque)
>  {
> -    RedChannelClient *rcc = (RedChannelClient *)opaque;
> +    RedChannelClient *rcc = RED_CHANNEL_CLIENT(opaque);
>  
>      return rcc->priv->send_data.size;
>  }
> @@ -136,7 +136,7 @@ int red_channel_client_get_out_msg_size(void *opaque)
>  void red_channel_client_prepare_out_msg(void *opaque, struct iovec *vec,
>                                          int *vec_size, int pos)
>  {
> -    RedChannelClient *rcc = (RedChannelClient *)opaque;
> +    RedChannelClient *rcc = RED_CHANNEL_CLIENT(opaque);
>  
>      *vec_size = spice_marshaller_fill_iovec(rcc->priv->send_data.marshaller,
>                                              vec, IOV_MAX, pos);
> @@ -144,7 +144,7 @@ void red_channel_client_prepare_out_msg(void *opaque,
> struct iovec *vec,
>  
>  void red_channel_client_on_out_block(void *opaque)
>  {
> -    RedChannelClient *rcc = (RedChannelClient *)opaque;
> +    RedChannelClient *rcc = RED_CHANNEL_CLIENT(opaque);
>  
>      rcc->priv->send_data.blocked = TRUE;
>      rcc->priv->channel->core->watch_update_mask(rcc->priv->stream->watch,
> @@ -313,7 +313,7 @@ static void
> red_channel_client_restore_main_sender(RedChannelClient *rcc)
>  
>  void red_channel_client_on_out_msg_done(void *opaque)
>  {
> -    RedChannelClient *rcc = (RedChannelClient *)opaque;
> +    RedChannelClient *rcc = RED_CHANNEL_CLIENT(opaque);
>      int fd;
>  
>      rcc->priv->send_data.size = 0;
> @@ -529,7 +529,7 @@ void
> red_channel_client_start_connectivity_monitoring(RedChannelClient *rcc, uin
>  
>  static void red_channel_client_event(int fd, int event, void *data)
>  {
> -    RedChannelClient *rcc = (RedChannelClient *)data;
> +    RedChannelClient *rcc = RED_CHANNEL_CLIENT(data);
>  
>      red_channel_client_ref(rcc);
>      if (event & SPICE_WATCH_EVENT_READ) {
> diff --git a/server/smartcard.c b/server/smartcard.c
> index 3ea8a25..41dc106 100644
> --- a/server/smartcard.c
> +++ b/server/smartcard.c
> @@ -66,6 +66,8 @@ typedef struct SmartCardChannelClient {
>      SmartCardChannelClientPrivate priv[1];
>  } SmartCardChannelClient;
>  
> +#define SMARTCARD_CHANNEL_CLIENT(rcc) ((SmartCardChannelClient*)rcc)
> +
>  G_DEFINE_TYPE(RedCharDeviceSmartcard, red_char_device_smartcard,
>  RED_TYPE_CHAR_DEVICE)
>  
>  #define RED_CHAR_DEVICE_SMARTCARD_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE
>  ((o), RED_TYPE_CHAR_DEVICE_SMARTCARD, RedCharDeviceSmartcardPrivate))
> @@ -387,7 +389,7 @@ static uint8_t
> *smartcard_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
>                                                      uint16_t type,
>                                                      uint32_t size)
>  {
> -    SmartCardChannelClient *scc = SPICE_CONTAINEROF(rcc,
> SmartCardChannelClient, base);
> +    SmartCardChannelClient *scc = SMARTCARD_CHANNEL_CLIENT(rcc);
>  
>      /* todo: only one reader is actually supported. When we fix the code to
>      support
>       * multiple readers, we will porbably associate different devices to
> @@ -420,7 +422,7 @@ static void
> smartcard_channel_release_msg_rcv_buf(RedChannelClient *rcc,
>                                                    uint32_t size,
>                                                    uint8_t *msg)
>  {
> -    SmartCardChannelClient *scc = SPICE_CONTAINEROF(rcc,
> SmartCardChannelClient, base);
> +    SmartCardChannelClient *scc = SMARTCARD_CHANNEL_CLIENT(rcc);
>  
>      /* todo: only one reader is actually supported. When we fix the code to
>      support
>       * multiple readers, we will porbably associate different devices to
> @@ -472,7 +474,7 @@ static void
> smartcard_channel_send_migrate_data(RedChannelClient *rcc,
>      RedCharDeviceSmartcard *dev;
>      SpiceMarshaller *m2;
>  
> -    scc = SPICE_CONTAINEROF(rcc, SmartCardChannelClient, base);
> +    scc = SMARTCARD_CHANNEL_CLIENT(rcc);
>      dev = scc->priv->smartcard;
>      red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE_DATA, item);
>      spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_SMARTCARD_MAGIC);
> @@ -517,7 +519,7 @@ static void smartcard_channel_send_item(RedChannelClient
> *rcc, RedPipeItem *item
>  
>  static void smartcard_channel_on_disconnect(RedChannelClient *rcc)
>  {
> -    SmartCardChannelClient *scc = SPICE_CONTAINEROF(rcc,
> SmartCardChannelClient, base);
> +    SmartCardChannelClient *scc = SMARTCARD_CHANNEL_CLIENT(rcc);
>  
>      if (scc->priv->smartcard) {
>          RedCharDeviceSmartcard *dev = scc->priv->smartcard;
> @@ -665,7 +667,7 @@ static int
> smartcard_channel_client_handle_migrate_data(RedChannelClient *rcc,
>      SpiceMigrateDataHeader *header;
>      SpiceMigrateDataSmartcard *mig_data;
>  
> -    scc = SPICE_CONTAINEROF(rcc, SmartCardChannelClient, base);
> +    scc = SMARTCARD_CHANNEL_CLIENT(rcc);
>      header = (SpiceMigrateDataHeader *)message;
>      mig_data = (SpiceMigrateDataSmartcard *)(header + 1);
>      if (size < sizeof(SpiceMigrateDataHeader) +
>      sizeof(SpiceMigrateDataSmartcard)) {
> @@ -706,7 +708,7 @@ static int
> smartcard_channel_handle_message(RedChannelClient *rcc,
>                                              uint8_t *msg)
>  {
>      VSCMsgHeader* vheader = (VSCMsgHeader*)msg;
> -    SmartCardChannelClient *scc = SPICE_CONTAINEROF(rcc,
> SmartCardChannelClient, base);
> +    SmartCardChannelClient *scc = SMARTCARD_CHANNEL_CLIENT(rcc);
>  
>      if (type != SPICE_MSGC_SMARTCARD_DATA) {
>          /* Handles seamless migration protocol. Also handles ack's,
> @@ -760,13 +762,13 @@ static void smartcard_connect_client(RedChannel
> *channel, RedClient *client,
>  
>      SmartCardChannelClient *scc;
>  
> -    scc = (SmartCardChannelClient
> *)red_channel_client_create(sizeof(SmartCardChannelClient),
> -                                                              channel,
> -                                                              client,
> -                                                              stream,
> -                                                              FALSE,
> -
> num_common_caps,
> common_caps,
> -                                                              num_caps,
> caps);
> +    scc =
> SMARTCARD_CHANNEL_CLIENT(red_channel_client_create(sizeof(SmartCardChannelClient),
> +                                                             channel,
> +                                                             client,
> +                                                             stream,
> +                                                             FALSE,
> +
> num_common_caps,
> common_caps,
> +                                                             num_caps,
> caps));
>      if (!scc) {
>          return;
>      }

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

Frediano


More information about the Spice-devel mailing list