diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2015-02-20 18:19:24 +0100 |
---|---|---|
committer | Frediano Ziglio <fziglio@redhat.com> | 2016-03-09 17:33:43 +0000 |
commit | e5c89b0b6035e0af79beb13c23a27d32cbf13df1 (patch) | |
tree | 3c8f8f6e5b542b9e6a997f7ca18dfa6b1f1b4425 | |
parent | 6fef38c86e8d2dad7046110d75126a3a09debf5a (diff) |
Introduce spice_char_device_get_interface()
Hides awkward casting/dereferencing to go from a
SpiceCharDeviceInstance to a SpiceCharDeviceInterface
Acked-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r-- | server/char-device.c | 9 | ||||
-rw-r--r-- | server/char-device.h | 2 | ||||
-rw-r--r-- | server/reds.c | 6 | ||||
-rw-r--r-- | server/smartcard.c | 2 | ||||
-rw-r--r-- | server/spicevmc.c | 16 |
5 files changed, 19 insertions, 16 deletions
diff --git a/server/char-device.c b/server/char-device.c index 9858ab3f..cda2d609 100644 --- a/server/char-device.c +++ b/server/char-device.c @@ -460,7 +460,7 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev) reds_core_timer_cancel(dev->reds, dev->write_to_dev_timer); } - sif = SPICE_CONTAINEROF(dev->sin->base.sif, SpiceCharDeviceInterface, base); + sif = spice_char_device_get_interface(dev->sin); while (dev->running) { uint32_t write_len; @@ -695,7 +695,7 @@ SpiceCharDeviceState *spice_char_device_state_create(SpiceCharDeviceInstance *si ring_init(&char_dev->write_bufs_pool); ring_init(&char_dev->clients); - sif = SPICE_CONTAINEROF(char_dev->sin->base.sif, SpiceCharDeviceInterface, base); + sif = spice_char_device_get_interface(char_dev->sin); if (sif->base.minor_version <= 2 || !(sif->flags & SPICE_CHAR_DEVICE_NOTIFY_WRITABLE)) { char_dev->write_to_dev_timer = reds_core_timer_add(reds, spice_char_dev_write_retry, char_dev); @@ -1044,3 +1044,8 @@ SpiceServer* spice_char_device_get_server(SpiceCharDeviceState *dev) { return dev->reds; } + +SpiceCharDeviceInterface *spice_char_device_get_interface(SpiceCharDeviceInstance *instance) +{ + return SPICE_CONTAINEROF(instance->base.sif, SpiceCharDeviceInterface, base); +} diff --git a/server/char-device.h b/server/char-device.h index db72bfe6..7c785247 100644 --- a/server/char-device.h +++ b/server/char-device.h @@ -219,4 +219,6 @@ SpiceCharDeviceState *spicevmc_device_connect(struct RedsState *reds, void spicevmc_device_disconnect(struct RedsState *reds, SpiceCharDeviceInstance *char_device); +SpiceCharDeviceInterface *spice_char_device_get_interface(SpiceCharDeviceInstance *instance); + #endif // CHAR_DEVICE_H_ diff --git a/server/reds.c b/server/reds.c index 213d753f..3b72cc76 100644 --- a/server/reds.c +++ b/server/reds.c @@ -437,7 +437,7 @@ static void reds_reset_vdp(RedsState *reds) spice_char_device_reset(state->base); } - sif = SPICE_CONTAINEROF(reds->vdagent->base.sif, SpiceCharDeviceInterface, base); + sif = spice_char_device_get_interface(reds->vdagent); if (sif->state) { sif->state(reds->vdagent, 0); } @@ -712,7 +712,7 @@ static SpiceCharDeviceMsgToClient *vdi_port_read_one_msg_from_device(SpiceCharDe return NULL; } spice_assert(reds->vdagent == sin); - sif = SPICE_CONTAINEROF(reds->vdagent->base.sif, SpiceCharDeviceInterface, base); + sif = spice_char_device_get_interface(reds->vdagent); while (reds->vdagent) { switch (state->read_state) { case VDI_PORT_READ_STATE_READ_HEADER: @@ -2978,7 +2978,7 @@ static SpiceCharDeviceState *attach_to_red_agent(RedsState *reds, SpiceCharDevic reds->vdagent = sin; reds_update_mouse_mode(reds); - sif = SPICE_CONTAINEROF(reds->vdagent->base.sif, SpiceCharDeviceInterface, base); + sif = spice_char_device_get_interface(reds->vdagent); if (sif->state) { sif->state(reds->vdagent, 1); } diff --git a/server/smartcard.c b/server/smartcard.c index c7b1f303..e1e8e2b0 100644 --- a/server/smartcard.c +++ b/server/smartcard.c @@ -133,7 +133,7 @@ SpiceCharDeviceMsgToClient *smartcard_read_msg_from_device(SpiceCharDeviceInstan void *opaque) { SmartCardDeviceState *state = opaque; - SpiceCharDeviceInterface *sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base); + SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin); VSCMsgHeader *vheader = (VSCMsgHeader*)state->buf; int n; int remaining; diff --git a/server/spicevmc.c b/server/spicevmc.c index 35d13934..929ec0e4 100644 --- a/server/spicevmc.c +++ b/server/spicevmc.c @@ -112,7 +112,7 @@ static SpiceCharDeviceMsgToClient *spicevmc_chardev_read_msg_from_dev(SpiceCharD SpiceVmcPipeItem *msg_item; int n; - sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base); + sif = spice_char_device_get_interface(sin); if (!state->rcc) { return NULL; @@ -212,7 +212,6 @@ static int spicevmc_red_channel_client_config_socket(RedChannelClient *rcc) static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc) { SpiceVmcState *state; - SpiceCharDeviceInstance *sin; SpiceCharDeviceInterface *sif; if (!rcc) { @@ -220,8 +219,6 @@ static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc) } state = SPICE_CONTAINEROF(rcc->channel, SpiceVmcState, channel); - sin = state->chardev_sin; - sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base); if (state->recv_from_client_buf) { /* partial message which wasn't pushed to device */ spice_char_device_write_buffer_release(state->chardev_st, state->recv_from_client_buf); @@ -243,8 +240,9 @@ static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc) red_channel_client_destroy(rcc); state->rcc = NULL; + sif = spice_char_device_get_interface(state->chardev_sin); if (sif->state) { - sif->state(sin, 0); + sif->state(state->chardev_sin, 0); } } @@ -287,12 +285,10 @@ static int spicevmc_red_channel_client_handle_message(RedChannelClient *rcc, uint8_t *msg) { SpiceVmcState *state; - SpiceCharDeviceInstance *sin; SpiceCharDeviceInterface *sif; state = spicevmc_red_channel_client_get_state(rcc); - sin = state->chardev_sin; - sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base); + sif = spice_char_device_get_interface(state->chardev_sin); switch (type) { case SPICE_MSGC_SPICEVMC_DATA: @@ -307,7 +303,7 @@ static int spicevmc_red_channel_client_handle_message(RedChannelClient *rcc, return FALSE; } if (sif->base.minor_version >= 2 && sif->event != NULL) - sif->event(sin, *msg); + sif->event(state->chardev_sin, *msg); break; default: return red_channel_client_handle_message(rcc, size, type, msg); @@ -467,7 +463,6 @@ static void spicevmc_connect(RedChannel *channel, RedClient *client, state = SPICE_CONTAINEROF(channel, SpiceVmcState, channel); sin = state->chardev_sin; - sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base); if (state->rcc) { spice_printerr("channel client %d:%d (%p) already connected, refusing second connection", @@ -499,6 +494,7 @@ static void spicevmc_connect(RedChannel *channel, RedClient *client, return; } + sif = spice_char_device_get_interface(state->chardev_sin); if (sif->state) { sif->state(sin, 1); } |