[Spice-commits] 3 commits - server/char-device.c server/char-device.h server/dcc.c server/reds.c server/smartcard.c server/spicevmc.c
Jonathon Jongsma
jjongsma at kemper.freedesktop.org
Fri Apr 15 16:20:42 UTC 2016
server/char-device.c | 38 ++++++++++----------------------------
server/char-device.h | 15 +++++----------
server/dcc.c | 25 ++++++++++---------------
server/reds.c | 24 +++++-------------------
server/smartcard.c | 22 ++++------------------
server/spicevmc.c | 24 +++++-------------------
6 files changed, 39 insertions(+), 109 deletions(-)
New commits:
commit 48e85a11c71983358b8bc706f01e3376cb6d7cdb
Author: Christophe Fergeau <cfergeau at redhat.com>
Date: Thu Apr 7 17:11:23 2016 -0500
char-device: Remove RedCharDeviceClass::{un, }ref_msg_to_client
Now that client messages are always RedPipeItem, we don't need virtual
functions to know how to ref/unref them.
diff --git a/server/char-device.c b/server/char-device.c
index ce89d37..ebe7633 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -110,24 +110,6 @@ red_char_device_read_one_msg_from_device(RedCharDevice *dev)
return klass->read_one_msg_from_device(dev->priv->sin, dev->priv->opaque);
}
-static PipeItem *
-red_char_device_ref_msg_to_client(RedCharDevice *dev,
- PipeItem *msg)
-{
- RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
-
- return klass->ref_msg_to_client(msg, dev->priv->opaque);
-}
-
-static void
-red_char_device_unref_msg_to_client(RedCharDevice *dev,
- PipeItem *msg)
-{
- RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
-
- klass->unref_msg_to_client(msg, dev->priv->opaque);
-}
-
static void
red_char_device_send_msg_to_client(RedCharDevice *dev,
PipeItem *msg,
@@ -215,7 +197,7 @@ static void red_char_device_client_send_queue_free(RedCharDevice *dev,
link);
ring_remove(item);
- red_char_device_unref_msg_to_client(dev, msg_item->msg);
+ pipe_item_unref(msg_item->msg);
free(msg_item);
}
dev_client->num_send_tokens += dev_client->send_queue_size;
@@ -331,7 +313,7 @@ static void red_char_device_add_msg_to_client_queue(RedCharDeviceClient *dev_cli
}
msg_item = spice_new0(RedCharDeviceMsgToClientItem, 1);
- msg_item->msg = red_char_device_ref_msg_to_client(dev, msg);
+ msg_item->msg = pipe_item_ref(msg);
ring_add(&dev_client->send_queue, &msg_item->link);
dev_client->send_queue_size++;
if (!dev_client->wait_for_tokens_started) {
@@ -401,7 +383,7 @@ static int red_char_device_read_from_device(RedCharDevice *dev)
}
did_read = TRUE;
red_char_device_send_msg_to_clients(dev, msg);
- red_char_device_unref_msg_to_client(dev, msg);
+ pipe_item_unref(msg);
max_send_tokens--;
}
dev->priv->during_read_from_device = 0;
@@ -426,7 +408,7 @@ static void red_char_device_client_send_queue_push(RedCharDeviceClient *dev_clie
red_char_device_send_msg_to_client(dev_client->dev,
msg_item->msg,
dev_client->client);
- red_char_device_unref_msg_to_client(dev_client->dev, msg_item->msg);
+ pipe_item_unref(msg_item->msg);
dev_client->send_queue_size--;
free(msg_item);
}
diff --git a/server/char-device.h b/server/char-device.h
index b5a8383..f793c54 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -58,12 +58,10 @@ struct RedCharDeviceClass
* or till the reading fails */
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);
-
+ /* after this call, the message is unreferenced */
void (*send_msg_to_client)(PipeItem *msg,
RedClient *client,
- void *opaque); /* after this call, the message is unreferenced */
+ void *opaque);
/* The cb is called when a predefined number of write buffers were consumed by the
* device */
diff --git a/server/reds.c b/server/reds.c
index 555b254..6e4fee4 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -855,18 +855,6 @@ static PipeItem *vdi_port_read_one_msg_from_device(SpiceCharDeviceInstance *sin,
return NULL;
}
-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(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(PipeItem *msg,
RedClient *client,
@@ -4331,8 +4319,6 @@ red_char_device_vdi_port_class_init(RedCharDeviceVDIPortClass *klass)
object_class->constructed = red_char_device_vdi_port_constructed;
char_dev_class->read_one_msg_from_device = vdi_port_read_one_msg_from_device;
- char_dev_class->ref_msg_to_client = vdi_port_ref_msg_to_client;
- char_dev_class->unref_msg_to_client = vdi_port_unref_msg_to_client;
char_dev_class->send_msg_to_client = vdi_port_send_msg_to_client;
char_dev_class->send_tokens_to_client = vdi_port_send_tokens_to_client;
char_dev_class->remove_client = vdi_port_remove_client;
diff --git a/server/smartcard.c b/server/smartcard.c
index 6bdbef5..b9b8967 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -166,18 +166,6 @@ static PipeItem *smartcard_read_msg_from_device(SpiceCharDeviceInstance *sin,
return NULL;
}
-static PipeItem *smartcard_ref_msg_to_client(PipeItem *msg,
- void *opaque)
-{
- return pipe_item_ref(msg);
-}
-
-static void smartcard_unref_msg_to_client(PipeItem *msg,
- void *opaque)
-{
- pipe_item_ref(msg);
-}
-
static void smartcard_send_msg_to_client(PipeItem *msg,
RedClient *client,
void *opaque)
@@ -857,8 +845,6 @@ 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 = smartcard_ref_msg_to_client;
- char_dev_class->unref_msg_to_client = smartcard_unref_msg_to_client;
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;
diff --git a/server/spicevmc.c b/server/spicevmc.c
index 3ab067f..aa6a0ed 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -105,20 +105,8 @@ enum {
PIPE_ITEM_TYPE_PORT_EVENT,
};
-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(PipeItem *msg,
- void *opaque)
-{
- pipe_item_unref(msg);
-}
-
static PipeItem *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *sin,
- void *opaque)
+ void *opaque)
{
SpiceVmcState *state = opaque;
SpiceCharDeviceInterface *sif;
@@ -599,8 +587,6 @@ red_char_device_spicevmc_class_init(RedCharDeviceSpiceVmcClass *klass)
RedCharDeviceClass *char_dev_class = RED_CHAR_DEVICE_CLASS(klass);
char_dev_class->read_one_msg_from_device = spicevmc_chardev_read_msg_from_dev;
- char_dev_class->ref_msg_to_client = spicevmc_chardev_ref_msg_to_client;
- char_dev_class->unref_msg_to_client = spicevmc_chardev_unref_msg_to_client;
char_dev_class->send_msg_to_client = spicevmc_chardev_send_msg_to_client;
char_dev_class->send_tokens_to_client = spicevmc_char_dev_send_tokens_to_client;
char_dev_class->remove_client = spicevmc_char_dev_remove_client;
commit 021d960471559cb1f65cd676c16da6f71bef3352
Author: Christophe Fergeau <cfergeau at redhat.com>
Date: Thu Apr 7 17:11:22 2016 -0500
char-device: Replace RedCharDeviceMsgToClient with PipeItem
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.
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 246886c..3ab067f 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);
commit 521dd24ffbbfd9ae2864ad3f8dd21126fc60f899
Author: Jonathon Jongsma <jjongsma at redhat.com>
Date: Thu Apr 14 16:18:29 2016 -0500
dcc: Use refcounting for MonitorsConfigItem
diff --git a/server/dcc.c b/server/dcc.c
index daf3180..91c3f82 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -510,6 +510,12 @@ void dcc_stream_agent_clip(DisplayChannelClient* dcc, StreamAgent *agent)
red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc), (PipeItem *)item);
}
+static void monitors_config_item_free(MonitorsConfigItem *item)
+{
+ monitors_config_unref(item->monitors_config);
+ free(item);
+}
+
static MonitorsConfigItem *monitors_config_item_new(RedChannel* channel,
MonitorsConfig *monitors_config)
{
@@ -518,7 +524,8 @@ static MonitorsConfigItem *monitors_config_item_new(RedChannel* channel,
mci = (MonitorsConfigItem *)spice_malloc(sizeof(*mci));
mci->monitors_config = monitors_config;
- pipe_item_init(&mci->pipe_item, PIPE_ITEM_TYPE_MONITORS_CONFIG);
+ pipe_item_init_full(&mci->pipe_item, PIPE_ITEM_TYPE_MONITORS_CONFIG,
+ (GDestroyNotify)monitors_config_item_free);
return mci;
}
@@ -1602,6 +1609,7 @@ static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
case PIPE_ITEM_TYPE_DRAW:
case PIPE_ITEM_TYPE_IMAGE:
case PIPE_ITEM_TYPE_STREAM_CLIP:
+ case PIPE_ITEM_TYPE_MONITORS_CONFIG:
pipe_item_unref(item);
break;
case PIPE_ITEM_TYPE_UPGRADE:
@@ -1612,13 +1620,6 @@ static void release_item_after_push(DisplayChannelClient *dcc, PipeItem *item)
case PIPE_ITEM_TYPE_VERB:
free(item);
break;
- case PIPE_ITEM_TYPE_MONITORS_CONFIG: {
- MonitorsConfigItem *monconf_item = SPICE_CONTAINEROF(item,
- MonitorsConfigItem, pipe_item);
- monitors_config_unref(monconf_item->monitors_config);
- free(item);
- break;
- }
default:
spice_critical("invalid item type");
}
@@ -1653,6 +1654,7 @@ static void release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
upgrade_item_unref(display, (UpgradeItem *)item);
break;
case PIPE_ITEM_TYPE_IMAGE:
+ case PIPE_ITEM_TYPE_MONITORS_CONFIG:
pipe_item_unref(item);
break;
case PIPE_ITEM_TYPE_CREATE_SURFACE: {
@@ -1667,13 +1669,6 @@ static void release_item_before_push(DisplayChannelClient *dcc, PipeItem *item)
free(surface_destroy);
break;
}
- case PIPE_ITEM_TYPE_MONITORS_CONFIG: {
- MonitorsConfigItem *monconf_item = SPICE_CONTAINEROF(item,
- MonitorsConfigItem, pipe_item);
- monitors_config_unref(monconf_item->monitors_config);
- free(item);
- break;
- }
case PIPE_ITEM_TYPE_INVAL_ONE:
case PIPE_ITEM_TYPE_VERB:
case PIPE_ITEM_TYPE_MIGRATE_DATA:
More information about the Spice-commits
mailing list