[Spice-devel] [PATCH 10/20] char-device: Replace RedCharDeviceMsgToClient with PipeItem
Frediano Ziglio
fziglio at redhat.com
Fri Apr 15 10:09:09 UTC 2016
>
> From: Christophe Fergeau <cfergeau at redhat.com>
>
> Now that all derived classes use a type deriving from PipeItem for their
> RedCharDeviceMsgToClient, we can make this explicit in the
> RedCharDeviceClass vfuncs, and remove the RedCharDeviceMsgToClient
> typedef.
> ---
> server/char-device.c | 18 +++++++++---------
> server/char-device.h | 15 ++++++---------
> server/reds.c | 16 ++++++++--------
> server/smartcard.c | 14 +++++++-------
> server/spicevmc.c | 16 ++++++++--------
> 5 files changed, 38 insertions(+), 41 deletions(-)
>
> diff --git a/server/char-device.c b/server/char-device.c
> index e17e3be..ce89d37 100644
> --- a/server/char-device.c
> +++ b/server/char-device.c
> @@ -99,10 +99,10 @@ static void red_char_device_write_retry(void *opaque);
>
> typedef struct RedCharDeviceMsgToClientItem {
> RingItem link;
> - RedCharDeviceMsgToClient *msg;
> + PipeItem *msg;
> } RedCharDeviceMsgToClientItem;
>
> -static RedCharDeviceMsgToClient *
> +static PipeItem *
> red_char_device_read_one_msg_from_device(RedCharDevice *dev)
> {
> RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
> @@ -110,9 +110,9 @@ red_char_device_read_one_msg_from_device(RedCharDevice
> *dev)
> return klass->read_one_msg_from_device(dev->priv->sin,
> dev->priv->opaque);
> }
>
> -static RedCharDeviceMsgToClient *
> +static PipeItem *
> red_char_device_ref_msg_to_client(RedCharDevice *dev,
> - RedCharDeviceMsgToClient *msg)
> + PipeItem *msg)
> {
> RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
>
> @@ -121,7 +121,7 @@ red_char_device_ref_msg_to_client(RedCharDevice *dev,
>
> static void
> red_char_device_unref_msg_to_client(RedCharDevice *dev,
> - RedCharDeviceMsgToClient *msg)
> + PipeItem *msg)
> {
> RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
>
> @@ -130,7 +130,7 @@ red_char_device_unref_msg_to_client(RedCharDevice *dev,
>
> static void
> red_char_device_send_msg_to_client(RedCharDevice *dev,
> - RedCharDeviceMsgToClient *msg,
> + PipeItem *msg,
> RedClient *client)
> {
> RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
> @@ -320,7 +320,7 @@ static uint64_t
> red_char_device_max_send_tokens(RedCharDevice *dev)
> }
>
> static void red_char_device_add_msg_to_client_queue(RedCharDeviceClient
> *dev_client,
> - RedCharDeviceMsgToClient
> *msg)
> + PipeItem *msg)
> {
> RedCharDevice *dev = dev_client->dev;
> RedCharDeviceMsgToClientItem *msg_item;
> @@ -342,7 +342,7 @@ static void
> red_char_device_add_msg_to_client_queue(RedCharDeviceClient *dev_cli
> }
>
> static void red_char_device_send_msg_to_clients(RedCharDevice *dev,
> - RedCharDeviceMsgToClient
> *msg)
> + PipeItem *msg)
> {
> RingItem *item, *next;
>
> @@ -388,7 +388,7 @@ static int red_char_device_read_from_device(RedCharDevice
> *dev)
> * All messages will be discarded if no client is attached to the device
> */
> while ((max_send_tokens || ring_is_empty(&dev->priv->clients)) &&
> dev->priv->running) {
> - RedCharDeviceMsgToClient *msg;
> + PipeItem *msg;
>
> msg = red_char_device_read_one_msg_from_device(dev);
> if (!msg) {
> diff --git a/server/char-device.h b/server/char-device.h
> index f4d6283..b5a8383 100644
> --- a/server/char-device.h
> +++ b/server/char-device.h
> @@ -24,8 +24,6 @@
> #include "red-channel.h"
> #include "migration-protocol.h"
>
> -typedef void RedCharDeviceMsgToClient;
> -
> #define RED_TYPE_CHAR_DEVICE red_char_device_get_type()
>
> #define RED_CHAR_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),
> RED_TYPE_CHAR_DEVICE, RedCharDevice))
> @@ -58,13 +56,12 @@ struct RedCharDeviceClass
>
> /* reads from the device till reaching a msg that should be sent to the
> client,
> * or till the reading fails */
> - RedCharDeviceMsgToClient*
> (*read_one_msg_from_device)(SpiceCharDeviceInstance *sin,
> - void *opaque);
> - RedCharDeviceMsgToClient* (*ref_msg_to_client)(RedCharDeviceMsgToClient
> *msg,
> - void *opaque);
> - void (*unref_msg_to_client)(RedCharDeviceMsgToClient *msg,
> - void *opaque);
> - void (*send_msg_to_client)(RedCharDeviceMsgToClient *msg,
> + PipeItem* (*read_one_msg_from_device)(SpiceCharDeviceInstance *sin,
> + void *opaque);
> + PipeItem* (*ref_msg_to_client)(PipeItem *msg, void *opaque);
> + void (*unref_msg_to_client)(PipeItem *msg, void *opaque);
> +
> + void (*send_msg_to_client)(PipeItem *msg,
> RedClient *client,
> void *opaque); /* after this call, the
> message is unreferenced */
>
> diff --git a/server/reds.c b/server/reds.c
> index 521bc84..555b254 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -783,8 +783,8 @@ static void vdi_port_read_buf_free(VDIReadBuf *buf)
>
> /* reads from the device till completes reading a message that is addressed
> to the client,
> * or otherwise, when reading from the device fails */
> -static RedCharDeviceMsgToClient
> *vdi_port_read_one_msg_from_device(SpiceCharDeviceInstance *sin,
> - void
> *opaque)
> +static PipeItem *vdi_port_read_one_msg_from_device(SpiceCharDeviceInstance
> *sin,
> + void *opaque)
> {
> RedsState *reds = opaque;
> RedCharDeviceVDIPort *dev = reds->agent_dev;
> @@ -842,7 +842,7 @@ static RedCharDeviceMsgToClient
> *vdi_port_read_one_msg_from_device(SpiceCharDevi
> dev->priv->read_state = VDI_PORT_READ_STATE_GET_BUFF;
> }
> if (vdi_port_read_buf_process(reds->agent_dev, dispatch_buf,
> &error)) {
> - return dispatch_buf;
> + return (PipeItem *)dispatch_buf;
> } else {
> if (error) {
> reds_agent_remove(reds);
> @@ -855,24 +855,24 @@ static RedCharDeviceMsgToClient
> *vdi_port_read_one_msg_from_device(SpiceCharDevi
> return NULL;
> }
>
> -static RedCharDeviceMsgToClient
> *vdi_port_ref_msg_to_client(RedCharDeviceMsgToClient *msg,
> - void *opaque)
> +static PipeItem *vdi_port_ref_msg_to_client(PipeItem *msg,
> + void *opaque)
> {
> return pipe_item_ref(msg);
> }
>
> -static void vdi_port_unref_msg_to_client(RedCharDeviceMsgToClient *msg,
> +static void vdi_port_unref_msg_to_client(PipeItem *msg,
> void *opaque)
> {
> pipe_item_unref(msg);
> }
>
> /* after calling this, we unref the message, and the ref is in the instance
> side */
> -static void vdi_port_send_msg_to_client(RedCharDeviceMsgToClient *msg,
> +static void vdi_port_send_msg_to_client(PipeItem *msg,
> RedClient *client,
> void *opaque)
> {
> - VDIReadBuf *agent_data_buf = msg;
> + VDIReadBuf *agent_data_buf = (VDIReadBuf *)msg;
>
> pipe_item_ref(agent_data_buf);
> main_channel_client_push_agent_data(red_client_get_main(client),
> diff --git a/server/smartcard.c b/server/smartcard.c
> index 76b07f0..6bdbef5 100644
> --- a/server/smartcard.c
> +++ b/server/smartcard.c
> @@ -129,8 +129,8 @@ static void
> smartcard_read_buf_prepare(RedCharDeviceSmartcard *dev, VSCMsgHeader
> }
> }
>
> -static RedCharDeviceMsgToClient
> *smartcard_read_msg_from_device(SpiceCharDeviceInstance *sin,
> - void
> *opaque)
> +static PipeItem *smartcard_read_msg_from_device(SpiceCharDeviceInstance
> *sin,
> + void *opaque)
> {
> RedCharDeviceSmartcard *dev = opaque;
> SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
> @@ -160,25 +160,25 @@ static RedCharDeviceMsgToClient
> *smartcard_read_msg_from_device(SpiceCharDeviceI
> dev->priv->buf_pos = dev->priv->buf;
> dev->priv->buf_used = remaining;
> if (msg_to_client) {
> - return msg_to_client;
> + return (PipeItem *)msg_to_client;
> }
> }
> return NULL;
> }
>
> -static RedCharDeviceMsgToClient
> *smartcard_ref_msg_to_client(RedCharDeviceMsgToClient *msg,
> - void *opaque)
> +static PipeItem *smartcard_ref_msg_to_client(PipeItem *msg,
> + void *opaque)
> {
> return pipe_item_ref(msg);
> }
>
> -static void smartcard_unref_msg_to_client(RedCharDeviceMsgToClient *msg,
> +static void smartcard_unref_msg_to_client(PipeItem *msg,
> void *opaque)
> {
> pipe_item_ref(msg);
> }
>
> -static void smartcard_send_msg_to_client(RedCharDeviceMsgToClient *msg,
> +static void smartcard_send_msg_to_client(PipeItem *msg,
> RedClient *client,
> void *opaque)
> {
> diff --git a/server/spicevmc.c b/server/spicevmc.c
> index dececc5..0dcedd1 100644
> --- a/server/spicevmc.c
> +++ b/server/spicevmc.c
> @@ -105,20 +105,20 @@ enum {
> PIPE_ITEM_TYPE_PORT_EVENT,
> };
>
> -static RedCharDeviceMsgToClient
> *spicevmc_chardev_ref_msg_to_client(RedCharDeviceMsgToClient *msg,
> - void
> *opaque)
> +static PipeItem *spicevmc_chardev_ref_msg_to_client(PipeItem *msg,
> + void *opaque)
> {
> return pipe_item_ref(msg);
> }
>
> -static void spicevmc_chardev_unref_msg_to_client(RedCharDeviceMsgToClient
> *msg,
> +static void spicevmc_chardev_unref_msg_to_client(PipeItem *msg,
> void *opaque)
> {
> pipe_item_unref(msg);
> }
>
> -static RedCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *sin,
> - void
> *opaque)
> +static PipeItem *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance
> *sin,
> + void *opaque)
> {
> SpiceVmcState *state = opaque;
> SpiceCharDeviceInterface *sif;
> @@ -145,19 +145,19 @@ static RedCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharDev
> if (n > 0) {
> spice_debug("read from dev %d", n);
> msg_item->buf_used = n;
> - return msg_item;
> + return (PipeItem *)msg_item;
> } else {
> state->pipe_item = msg_item;
> return NULL;
> }
> }
>
> -static void spicevmc_chardev_send_msg_to_client(RedCharDeviceMsgToClient
> *msg,
> +static void spicevmc_chardev_send_msg_to_client(PipeItem *msg,
> RedClient *client,
> void *opaque)
> {
> SpiceVmcState *state = opaque;
> - SpiceVmcPipeItem *vmc_msg = msg;
> + SpiceVmcPipeItem *vmc_msg = (SpiceVmcPipeItem *)msg;
>
> spice_assert(state->rcc->client == client);
> pipe_item_ref(vmc_msg);
Acked-by: Frediano Ziglio <fziglio at redhat.com>
Frediano
More information about the Spice-devel
mailing list