summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2016-04-12 16:12:39 -0500
committerJonathon Jongsma <jjongsma@redhat.com>2016-04-14 09:50:04 -0500
commite5cead4d64ddadd16929d2a814948f230de9341d (patch)
tree62ac6d22ec5f97002016801e3a56c2b4418d6a85
parent0674c54784ac69ebbe28767c6e6d4f6c1cb0648b (diff)
char-device: add 'self' param to vfuncsrefactory-20160418refactory-20160413
Add a 'self' parameter to all of the char device virtual functions so that we don't have to play games with the 'opaque' pointer.
-rw-r--r--server/char-device.c8
-rw-r--r--server/char-device.h13
-rw-r--r--server/reds.c17
-rw-r--r--server/smartcard.c29
-rw-r--r--server/spicevmc.c12
5 files changed, 49 insertions, 30 deletions
diff --git a/server/char-device.c b/server/char-device.c
index d854ac62..da8ca2a0 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -107,7 +107,7 @@ red_char_device_read_one_msg_from_device(RedCharDevice *dev)
{
RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
- return klass->read_one_msg_from_device(dev->priv->sin, dev->priv->opaque);
+ return klass->read_one_msg_from_device(dev, dev->priv->sin, dev->priv->opaque);
}
static void
@@ -117,7 +117,7 @@ red_char_device_send_msg_to_client(RedCharDevice *dev,
{
RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
- klass->send_msg_to_client(msg, client, dev->priv->opaque);
+ klass->send_msg_to_client(dev, msg, client, dev->priv->opaque);
}
static void
@@ -127,7 +127,7 @@ red_char_device_send_tokens_to_client(RedCharDevice *dev,
{
RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
- klass->send_tokens_to_client(client, tokens, dev->priv->opaque);
+ klass->send_tokens_to_client(dev, client, tokens, dev->priv->opaque);
}
static void
@@ -135,7 +135,7 @@ red_char_device_remove_client(RedCharDevice *dev, RedClient *client)
{
RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
- klass->remove_client(client, dev->priv->opaque);
+ klass->remove_client(dev, client, dev->priv->opaque);
}
static void red_char_device_write_buffer_free(RedCharDeviceWriteBuffer *buf)
diff --git a/server/char-device.h b/server/char-device.h
index 73f7cff2..e113cf8c 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -56,21 +56,26 @@ struct RedCharDeviceClass
/* reads from the device till reaching a msg that should be sent to the client,
* or till the reading fails */
- RedPipeItem* (*read_one_msg_from_device)(SpiceCharDeviceInstance *sin,
+ RedPipeItem* (*read_one_msg_from_device)(RedCharDevice *self,
+ SpiceCharDeviceInstance *sin,
void *opaque);
/* after this call, the message is unreferenced */
- void (*send_msg_to_client)(RedPipeItem *msg,
+ void (*send_msg_to_client)(RedCharDevice *self,
+ RedPipeItem *msg,
RedClient *client,
void *opaque);
/* The cb is called when a predefined number of write buffers were consumed by the
* device */
- void (*send_tokens_to_client)(RedClient *client, uint32_t tokens, void *opaque);
+ void (*send_tokens_to_client)(RedCharDevice *self,
+ RedClient *client,
+ uint32_t tokens,
+ void *opaque);
/* This cb is called if it is recommanded that a client will be removed
* due to slow flow or due to some other error.
* The called instance should disconnect the client, or at least the corresponding channel */
- void (*remove_client)(RedClient *client, void *opaque);
+ void (*remove_client)(RedCharDevice *self, RedClient *client, void *opaque);
};
GType red_char_device_get_type(void) G_GNUC_CONST;
diff --git a/server/reds.c b/server/reds.c
index 2b706485..2527524f 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -838,11 +838,12 @@ 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 RedPipeItem *vdi_port_read_one_msg_from_device(SpiceCharDeviceInstance *sin,
+static RedPipeItem *vdi_port_read_one_msg_from_device(RedCharDevice *self,
+ SpiceCharDeviceInstance *sin,
void *opaque)
{
RedsState *reds;
- RedCharDeviceVDIPort *dev = RED_CHAR_DEVICE_VDIPORT(sin->st);
+ RedCharDeviceVDIPort *dev = RED_CHAR_DEVICE_VDIPORT(self);
SpiceCharDeviceInterface *sif;
VDIReadBuf *dispatch_buf;
int n;
@@ -913,7 +914,8 @@ static RedPipeItem *vdi_port_read_one_msg_from_device(SpiceCharDeviceInstance *s
}
/* after calling this, we unref the message, and the ref is in the instance side */
-static void vdi_port_send_msg_to_client(RedPipeItem *msg,
+static void vdi_port_send_msg_to_client(RedCharDevice *self,
+ RedPipeItem *msg,
RedClient *client,
void *opaque)
{
@@ -927,7 +929,10 @@ static void vdi_port_send_msg_to_client(RedPipeItem *msg,
agent_data_buf);
}
-static void vdi_port_send_tokens_to_client(RedClient *client, uint32_t tokens, void *opaque)
+static void vdi_port_send_tokens_to_client(RedCharDevice *self,
+ RedClient *client,
+ uint32_t tokens,
+ void *opaque)
{
main_channel_client_push_agent_tokens(red_client_get_main(client),
tokens);
@@ -943,7 +948,9 @@ static void vdi_port_on_free_self_token(RedCharDevice *device, gpointer opaque)
}
}
-static void vdi_port_remove_client(RedClient *client, void *opaque)
+static void vdi_port_remove_client(RedCharDevice *self,
+ RedClient *client,
+ void *opaque)
{
red_channel_client_shutdown(RED_CHANNEL_CLIENT(red_client_get_main(client)));
}
diff --git a/server/smartcard.c b/server/smartcard.c
index 26e55e20..42314c6f 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -152,10 +152,11 @@ static void smartcard_read_buf_prepare(RedCharDeviceSmartcard *dev, VSCMsgHeader
}
}
-static RedPipeItem *smartcard_read_msg_from_device(SpiceCharDeviceInstance *sin,
+static RedPipeItem *smartcard_read_msg_from_device(RedCharDevice *self,
+ SpiceCharDeviceInstance *sin,
void *opaque)
{
- RedCharDeviceSmartcard *dev = opaque;
+ RedCharDeviceSmartcard *dev = RED_CHAR_DEVICE_SMARTCARD(self);
SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
VSCMsgHeader *vheader = (VSCMsgHeader*)dev->priv->buf;
int n;
@@ -189,11 +190,12 @@ static RedPipeItem *smartcard_read_msg_from_device(SpiceCharDeviceInstance *sin,
return NULL;
}
-static void smartcard_send_msg_to_client(RedPipeItem *msg,
+static void smartcard_send_msg_to_client(RedCharDevice *self,
+ RedPipeItem *msg,
RedClient *client,
void *opaque)
{
- RedCharDeviceSmartcard *dev = opaque;
+ RedCharDeviceSmartcard *dev = RED_CHAR_DEVICE_SMARTCARD(self);
RedClient *this_client = red_channel_client_get_client(RED_CHANNEL_CLIENT(dev->priv->scc));
spice_assert(dev->priv->scc && this_client == client);
@@ -201,14 +203,17 @@ static void smartcard_send_msg_to_client(RedPipeItem *msg,
(PipeItem *)msg);
}
-static void smartcard_send_tokens_to_client(RedClient *client, uint32_t tokens, void *opaque)
+static void smartcard_send_tokens_to_client(RedCharDevice *self,
+ RedClient *client,
+ uint32_t tokens,
+ void *opaque)
{
spice_error("not implemented");
}
-static void smartcard_remove_client(RedClient *client, void *opaque)
+static void smartcard_remove_client(RedCharDevice *self, RedClient *client, void *opaque)
{
- RedCharDeviceSmartcard *dev = opaque;
+ RedCharDeviceSmartcard *dev = RED_CHAR_DEVICE_SMARTCARD(self);
RedClient *this_client = red_channel_client_get_client(RED_CHANNEL_CLIENT(dev->priv->scc));
spice_printerr("smartcard dev %p, client %p", dev, client);
@@ -248,7 +253,7 @@ MsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard *de
static int smartcard_char_device_add_to_readers(RedsState *reds, SpiceCharDeviceInstance *char_device)
{
- RedCharDeviceSmartcard *dev = red_char_device_opaque_get(char_device->st);
+ RedCharDeviceSmartcard *dev = RED_CHAR_DEVICE_SMARTCARD(char_device->st);
if (g_smartcard_readers.num >= SMARTCARD_MAX_READERS) {
return -1;
@@ -273,7 +278,7 @@ SpiceCharDeviceInstance *smartcard_readers_get_unattached(void)
RedCharDeviceSmartcard* dev;
for (i = 0; i < g_smartcard_readers.num; ++i) {
- dev = red_char_device_opaque_get(g_smartcard_readers.sin[i]->st);
+ dev = RED_CHAR_DEVICE_SMARTCARD(g_smartcard_readers.sin[i]->st);
if (!dev->priv->scc) {
return g_smartcard_readers.sin[i];
}
@@ -292,8 +297,6 @@ static RedCharDeviceSmartcard *smartcard_device_new(RedsState *reds, SpiceCharDe
"self-tokens", ~0ULL,
NULL);
- g_object_set(char_dev, "opaque", char_dev, NULL);
-
return RED_CHAR_DEVICE_SMARTCARD(char_dev);
}
@@ -337,7 +340,7 @@ void smartcard_char_device_notify_reader_add(RedCharDeviceSmartcard *dev)
void smartcard_char_device_attach_client(SpiceCharDeviceInstance *char_device,
SmartCardChannelClient *scc)
{
- RedCharDeviceSmartcard *dev = red_char_device_opaque_get(char_device->st);
+ RedCharDeviceSmartcard *dev = RED_CHAR_DEVICE_SMARTCARD(char_device->st);
int client_added;
spice_assert(!smartcard_channel_client_get_char_device(scc) && !dev->priv->scc);
@@ -507,7 +510,7 @@ void smartcard_channel_write_to_reader(RedCharDeviceWriteBuffer *write_buf)
spice_assert(vheader->reader_id <= g_smartcard_readers.num);
sin = g_smartcard_readers.sin[vheader->reader_id];
- dev = (RedCharDeviceSmartcard *)red_char_device_opaque_get(sin->st);
+ dev = RED_CHAR_DEVICE_SMARTCARD(sin->st);
spice_assert(!dev->priv->scc ||
dev == smartcard_channel_client_get_device(dev->priv->scc));
/* protocol requires messages to be in network endianess */
diff --git a/server/spicevmc.c b/server/spicevmc.c
index 9aa72cdc..a40ab542 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -230,7 +230,8 @@ enum {
PIPE_ITEM_TYPE_PORT_EVENT,
};
-static RedPipeItem *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *sin,
+static RedPipeItem *spicevmc_chardev_read_msg_from_dev(RedCharDevice *self,
+ SpiceCharDeviceInstance *sin,
void *opaque)
{
RedVmcChannel *state = opaque;
@@ -265,7 +266,8 @@ static RedPipeItem *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *
}
}
-static void spicevmc_chardev_send_msg_to_client(RedPipeItem *msg,
+static void spicevmc_chardev_send_msg_to_client(RedCharDevice *self,
+ RedPipeItem *msg,
RedClient *client,
void *opaque)
{
@@ -299,14 +301,16 @@ static void spicevmc_port_send_event(RedChannelClient *rcc, uint8_t event)
red_channel_client_pipe_add_push(rcc, &item->base);
}
-static void spicevmc_char_dev_send_tokens_to_client(RedClient *client,
+static void spicevmc_char_dev_send_tokens_to_client(RedCharDevice *self,
+ RedClient *client,
uint32_t tokens,
void *opaque)
{
spice_printerr("Not implemented!");
}
-static void spicevmc_char_dev_remove_client(RedClient *client, void *opaque)
+static void spicevmc_char_dev_remove_client(RedCharDevice *self,
+ RedClient *client, void *opaque)
{
RedVmcChannel *state = opaque;