[Spice-devel] [PATCH 05/13] char-device: Replace RedCharDeviceMsgToClient with RedPipeItem

Jonathon Jongsma jjongsma at redhat.com
Wed Apr 13 19:37:54 UTC 2016


From: Christophe Fergeau <cfergeau at redhat.com>

Now that all derived classes use a type deriving from RedPipeItem 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..5155cf7 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;
+    RedPipeItem *msg;
 } RedCharDeviceMsgToClientItem;
 
-static RedCharDeviceMsgToClient *
+static RedPipeItem *
 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 RedPipeItem *
 red_char_device_ref_msg_to_client(RedCharDevice *dev,
-                                  RedCharDeviceMsgToClient *msg)
+                                  RedPipeItem *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)
+                                    RedPipeItem *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,
+                                   RedPipeItem *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)
+                                                    RedPipeItem *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)
+                                                RedPipeItem *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;
+        RedPipeItem *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..3bbcd87 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,
+    RedPipeItem* (*read_one_msg_from_device)(SpiceCharDeviceInstance *sin,
+                                             void *opaque);
+    RedPipeItem* (*ref_msg_to_client)(RedPipeItem *msg, void *opaque);
+    void (*unref_msg_to_client)(RedPipeItem *msg, void *opaque);
+
+    void (*send_msg_to_client)(RedPipeItem *msg,
                                RedClient *client,
                                void *opaque); /* after this call, the message is unreferenced */
 
diff --git a/server/reds.c b/server/reds.c
index 7331687..37879ed 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 RedPipeItem *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 (RedPipeItem *)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 RedPipeItem *vdi_port_ref_msg_to_client(RedPipeItem *msg,
+                                               void *opaque)
 {
     return red_pipe_item_ref(msg);
 }
 
-static void vdi_port_unref_msg_to_client(RedCharDeviceMsgToClient *msg,
+static void vdi_port_unref_msg_to_client(RedPipeItem *msg,
                                          void *opaque)
 {
     red_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(RedPipeItem *msg,
                                         RedClient *client,
                                         void *opaque)
 {
-    VDIReadBuf *agent_data_buf = msg;
+    VDIReadBuf *agent_data_buf = (VDIReadBuf *)msg;
 
     red_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 902b2a1..4149904 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -130,8 +130,8 @@ static void smartcard_read_buf_prepare(RedCharDeviceSmartcard *dev, VSCMsgHeader
     }
 }
 
-static RedCharDeviceMsgToClient *smartcard_read_msg_from_device(SpiceCharDeviceInstance *sin,
-                                                                void *opaque)
+static RedPipeItem *smartcard_read_msg_from_device(SpiceCharDeviceInstance *sin,
+                                                   void *opaque)
 {
     RedCharDeviceSmartcard *dev = opaque;
     SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
@@ -161,25 +161,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 (RedPipeItem *)msg_to_client;
         }
     }
     return NULL;
 }
 
-static RedCharDeviceMsgToClient *smartcard_ref_msg_to_client(RedCharDeviceMsgToClient *msg,
-                                                             void *opaque)
+static RedPipeItem *smartcard_ref_msg_to_client(RedPipeItem *msg,
+                                                void *opaque)
 {
     return red_pipe_item_ref(msg);
 }
 
-static void smartcard_unref_msg_to_client(RedCharDeviceMsgToClient *msg,
+static void smartcard_unref_msg_to_client(RedPipeItem *msg,
                                           void *opaque)
 {
     red_pipe_item_ref(msg);
 }
 
-static void smartcard_send_msg_to_client(RedCharDeviceMsgToClient *msg,
+static void smartcard_send_msg_to_client(RedPipeItem *msg,
                                          RedClient *client,
                                          void *opaque)
 {
diff --git a/server/spicevmc.c b/server/spicevmc.c
index 66f819c..65990d6 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 RedPipeItem *spicevmc_chardev_ref_msg_to_client(RedPipeItem *msg,
+                                                       void *opaque)
 {
     return red_pipe_item_ref(msg);
 }
 
-static void spicevmc_chardev_unref_msg_to_client(RedCharDeviceMsgToClient *msg,
+static void spicevmc_chardev_unref_msg_to_client(RedPipeItem *msg,
                                                  void *opaque)
 {
     red_pipe_item_unref(msg);
 }
 
-static RedCharDeviceMsgToClient *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *sin,
-                                                                    void *opaque)
+static RedPipeItem *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 (RedPipeItem *)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(RedPipeItem *msg,
                                                 RedClient *client,
                                                 void *opaque)
 {
     SpiceVmcState *state = opaque;
-    SpiceVmcPipeItem *vmc_msg = msg;
+    SpiceVmcPipeItem *vmc_msg = (SpiceVmcPipeItem *)msg;
 
     spice_assert(state->rcc->client == client);
     red_pipe_item_ref(vmc_msg);
-- 
2.4.11



More information about the Spice-devel mailing list