summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2016-04-12 16:12:39 -0500
committerJonathon Jongsma <jjongsma@redhat.com>2016-09-01 17:42:59 -0500
commit5e93c79cce2efd79c24db5bf8c33f95879ac0f43 (patch)
tree1790333b57f08f3d11bff07cd936e20d5c083fff
parent9a05a528aba5401d923e094fa9b430a4b7e8cd8d (diff)
char-device: add 'self' param to vfuncs
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 14d431ca..f59e843a 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -98,7 +98,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
@@ -108,7 +108,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
@@ -118,7 +118,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
@@ -136,7 +136,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 44e9504e..14cbe948 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -56,16 +56,21 @@ 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);
/* The cb is called when a server (self) message that was addressed to the device,
* has been completely written to it */
@@ -74,7 +79,7 @@ struct RedCharDeviceClass
/* This cb is called if it is recommended to remove the client
* 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 e49f0dc1..300ae3c1 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -836,11 +836,12 @@ static void vdi_port_read_buf_free(RedPipeItem *base)
/* 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;
RedVDIReadBuf *dispatch_buf;
int n;
@@ -911,7 +912,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)
{
@@ -925,7 +927,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);
@@ -941,7 +946,9 @@ static void vdi_port_on_free_self_token(void *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 5676ce58..bd57d661 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,
smartcard_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(dev->priv->scc), 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 @@ RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard
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);
@@ -500,7 +503,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 e9071cd1..20b5599e 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -357,7 +357,8 @@ static RedVmcPipeItem* try_compress_lz4(RedVmcChannel *state, int n, RedVmcPipeI
}
#endif
-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;
@@ -402,7 +403,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)
{
@@ -440,14 +442,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;