Re: [PATCH 07/14] smartcard: Derive MsgItem from RedPipeItem

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

 



On Thu, 2016-04-07 at 17:11 -0500, Jonathon Jongsma wrote:
> From: Christophe Fergeau <cfergeau@xxxxxxxxxx>
> 
> This allows to reuse red_pipe_item_{ref, unref} rather than
> reimplementing them in smartcard.c
> ---
>  server/smartcard.c | 37 +++++++++++++------------------------
>  1 file changed, 13 insertions(+), 24 deletions(-)
> 
> diff --git a/server/smartcard.c b/server/smartcard.c
> index 557a622..eab2f20 100644
> --- a/server/smartcard.c
> +++ b/server/smartcard.c
> @@ -90,15 +90,12 @@ typedef struct ErrorItem {
>  
>  
>  typedef struct MsgItem {
> -    PipeItem base;
> -    uint32_t refs;
> +    RedPipeItem base;
>  
>      VSCMsgHeader* vheader;
>  } MsgItem;
>  
>  static MsgItem *smartcard_get_vsc_msg_item(RedChannelClient *rcc,
> VSCMsgHeader *vheader);
> -static MsgItem *smartcard_ref_vsc_msg_item(MsgItem *item);
> -static void smartcard_unref_vsc_msg_item(MsgItem *item);
>  static void smartcard_channel_client_pipe_add_push(RedChannelClient *rcc,
> PipeItem *item);
>  
>  typedef struct SmartCardChannel {
> @@ -176,7 +173,7 @@ static void
> smartcard_send_msg_to_client(RedCharDeviceMsgToClient *msg,
>  {
>      RedCharDeviceSmartcard *dev = opaque;
>      spice_assert(dev->priv->scc && dev->priv->scc->base.client == client);
> -    smartcard_channel_client_pipe_add_push(&dev->priv->scc->base, &((MsgItem
> *)msg)->base);
> +    smartcard_channel_client_pipe_add_push(&dev->priv->scc->base, (PipeItem
> *)msg);
>  
>  }
>  
> @@ -513,7 +510,7 @@ static void
> smartcard_channel_release_pipe_item(RedChannelClient *rcc,
>                                        PipeItem *item, int item_pushed)
>  {
>      if (item->type == PIPE_ITEM_TYPE_SMARTCARD_DATA) {
> -        smartcard_unref_vsc_msg_item((MsgItem *)item);
> +        red_pipe_item_unref(item);
>      } else {
>          free(item);
>      }
> @@ -553,30 +550,22 @@ static void smartcard_push_error(RedChannelClient *rcc,
> uint32_t reader_id, VSCE
>      smartcard_channel_client_pipe_add_push(rcc, &error_item->base);
>  }
>  
> +static void smartcard_free_vsc_msg_item(MsgItem *item)
> +{
> +    free(item->vheader);
> +    free(item);
> +}
> +
>  static MsgItem *smartcard_get_vsc_msg_item(RedChannelClient *rcc,
> VSCMsgHeader *vheader)
>  {
>      MsgItem *msg_item = spice_new0(MsgItem, 1);
>  
> -    pipe_item_init(&msg_item->base, PIPE_ITEM_TYPE_SMARTCARD_DATA);
> -    msg_item->refs = 1;
> +    red_pipe_item_init(&msg_item->base, PIPE_ITEM_TYPE_SMARTCARD_DATA,
> +                       (GDestroyNotify)smartcard_free_vsc_msg_item);
>      msg_item->vheader = vheader;
>      return msg_item;
>  }
>  
> -static MsgItem *smartcard_ref_vsc_msg_item(MsgItem *item)
> -{
> -    item->refs++;
> -    return item;
> -}
> -
> -static void smartcard_unref_vsc_msg_item(MsgItem *item)
> -{
> -    if (!--item->refs) {
> -        free(item->vheader);
> -        free(item);
> -    }
> -}
> -
>  static void smartcard_remove_reader(SmartCardChannelClient *scc, uint32_t
> reader_id)
>  {
>      SpiceCharDeviceInstance *char_device = smartcard_readers_get(reader_id);
> @@ -857,8 +846,8 @@
> red_char_device_smartcard_class_init(RedCharDeviceSmartcardClass *klass)
>      object_class->finalize = red_char_device_smartcard_finalize;
>  
>      char_dev_class->read_one_msg_from_device =
> smartcard_read_msg_from_device;
> -    char_dev_class->ref_msg_to_client =
> (RedCharDeviceRefMsgToClient)smartcard_ref_vsc_msg_item;
> -    char_dev_class->unref_msg_to_client =
> (RedCharDeviceUnrefMsgToClient)smartcard_unref_vsc_msg_item;
> +    char_dev_class->ref_msg_to_client =
> (RedCharDeviceRefMsgToClient)red_pipe_item_ref;
> +    char_dev_class->unref_msg_to_client =
> (RedCharDeviceUnrefMsgToClient)red_pipe_item_unref;
>      char_dev_class->send_msg_to_client = smartcard_send_msg_to_client;
>      char_dev_class->send_tokens_to_client = smartcard_send_tokens_to_client;
>      char_dev_class->remove_client = smartcard_remove_client;

As I mentioned in an earlier patch, I personally prefer to use adapter functions
for typesafety. But since these ref/unref functions are removed in a future
patch, so it doesn't matter so much, I guess.

The rest of the patch looks fine.

Reviewed-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>

_______________________________________________
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]