[Spice-devel] [PATCH 05/11] spicevmc: Move SpiceVmcState::pipe_item to RedCharDeviceSpiceVmc

Frediano Ziglio fziglio at redhat.com
Fri Apr 1 12:37:43 UTC 2016


From: Christophe Fergeau <cfergeau at redhat.com>

This pipe item belongs to the char device, not to the spicevmc channel.
---
 server/spicevmc.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/server/spicevmc.c b/server/spicevmc.c
index cb8bcc6..cf7e236 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -56,7 +56,6 @@ typedef struct SpiceVmcState {
     RedChannelClient *rcc;
     RedCharDevice *chardev;
     SpiceCharDeviceInstance *chardev_sin;
-    SpiceVmcPipeItem *pipe_item;
     RedCharDeviceWriteBuffer *recv_from_client_buf;
     uint8_t port_opened;
 } SpiceVmcState;
@@ -71,9 +70,11 @@ typedef struct SpiceVmcState {
 
 typedef struct RedCharDeviceSpiceVmc RedCharDeviceSpiceVmc;
 typedef struct RedCharDeviceSpiceVmcClass RedCharDeviceSpiceVmcClass;
+typedef struct RedCharDeviceSpiceVmcPrivate RedCharDeviceSpiceVmcPrivate;
 
 struct RedCharDeviceSpiceVmc {
     RedCharDevice parent;
+    RedCharDeviceSpiceVmcPrivate *priv;
 };
 
 struct RedCharDeviceSpiceVmcClass
@@ -81,6 +82,10 @@ struct RedCharDeviceSpiceVmcClass
     RedCharDeviceClass parent_class;
 };
 
+struct RedCharDeviceSpiceVmcPrivate {
+    SpiceVmcPipeItem *pipe_item;
+};
+
 static GType red_char_device_spicevmc_get_type(void) G_GNUC_CONST;
 static RedCharDevice *red_char_device_spicevmc_new(SpiceCharDeviceInstance *sin,
                                                    RedsState *reds,
@@ -88,6 +93,8 @@ static RedCharDevice *red_char_device_spicevmc_new(SpiceCharDeviceInstance *sin,
 
 G_DEFINE_TYPE(RedCharDeviceSpiceVmc, red_char_device_spicevmc, RED_TYPE_CHAR_DEVICE)
 
+#define RED_CHAR_DEVICE_SPICEVMC_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RED_TYPE_CHAR_DEVICE_SPICEVMC, RedCharDeviceSpiceVmcPrivate))
+
 typedef struct PortInitPipeItem {
     PipeItem base;
     char* name;
@@ -135,6 +142,7 @@ static RedCharDeviceMsgToClient *spicevmc_chardev_read_msg_from_dev(SpiceCharDev
                                                                     void *opaque)
 {
     SpiceVmcState *state = opaque;
+    RedCharDeviceSpiceVmc *dev = RED_CHAR_DEVICE_SPICEVMC(sin->st);
     SpiceCharDeviceInterface *sif;
     SpiceVmcPipeItem *msg_item;
     int n;
@@ -145,14 +153,14 @@ static RedCharDeviceMsgToClient *spicevmc_chardev_read_msg_from_dev(SpiceCharDev
         return NULL;
     }
 
-    if (!state->pipe_item) {
+    if (!dev->priv->pipe_item) {
         msg_item = spice_new0(SpiceVmcPipeItem, 1);
         msg_item->refs = 1;
         pipe_item_init(&msg_item->base, PIPE_ITEM_TYPE_SPICEVMC_DATA);
     } else {
-        spice_assert(state->pipe_item->buf_used == 0);
-        msg_item = state->pipe_item;
-        state->pipe_item = NULL;
+        spice_assert(dev->priv->pipe_item->buf_used == 0);
+        msg_item = dev->priv->pipe_item;
+        dev->priv->pipe_item = NULL;
     }
 
     n = sif->read(sin, msg_item->buf,
@@ -162,7 +170,7 @@ static RedCharDeviceMsgToClient *spicevmc_chardev_read_msg_from_dev(SpiceCharDev
         msg_item->buf_used = n;
         return msg_item;
     } else {
-        state->pipe_item = msg_item;
+        dev->priv->pipe_item = msg_item;
         return NULL;
     }
 }
@@ -580,7 +588,6 @@ void spicevmc_device_disconnect(RedsState *reds, SpiceCharDeviceInstance *sin)
     sin->st = NULL;
 
     reds_unregister_channel(reds, &state->channel);
-    free(state->pipe_item);
     red_channel_destroy(&state->channel);
 }
 
@@ -609,13 +616,27 @@ SPICE_GNUC_VISIBLE void spice_server_port_event(SpiceCharDeviceInstance *sin, ui
 }
 
 static void
+red_char_device_spicevmc_finalize(GObject *object)
+{
+    RedCharDeviceSpiceVmc *self = RED_CHAR_DEVICE_SPICEVMC(object);
+
+    free(self->priv->pipe_item);
+}
+
+static void
 red_char_device_spicevmc_class_init(RedCharDeviceSpiceVmcClass *klass)
 {
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    g_type_class_add_private(klass, sizeof (RedCharDeviceSpiceVmcPrivate));
+
+    object_class->finalize = red_char_device_spicevmc_finalize;
 }
 
 static void
 red_char_device_spicevmc_init(RedCharDeviceSpiceVmc *self)
 {
+    self->priv = RED_CHAR_DEVICE_SPICEVMC_PRIVATE(self);
 }
 
 static RedCharDevice *
-- 
2.5.5



More information about the Spice-devel mailing list