[Spice-devel] [PATCH spice-server v8 06/12] fixup! Convert RedChannel hierarchy to GObject
Frediano Ziglio
fziglio at redhat.com
Mon Oct 24 08:40:49 UTC 2016
Removed not necessary SpiceVmcStatePrivate structure
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/spicevmc.c | 143 ++++++++++++++++++++++++------------------------------
1 file changed, 64 insertions(+), 79 deletions(-)
diff --git a/server/spicevmc.c b/server/spicevmc.c
index d92a0fe..0f4c618 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -105,13 +105,17 @@ G_DEFINE_TYPE(RedCharDeviceSpiceVmc, red_char_device_spicevmc, RED_TYPE_CHAR_DEV
typedef struct SpiceVmcState SpiceVmcState;
typedef struct SpiceVmcStateClass SpiceVmcStateClass;
-typedef struct SpiceVmcStatePrivate SpiceVmcStatePrivate;
struct SpiceVmcState
{
RedChannel parent;
- SpiceVmcStatePrivate *priv;
+ RedChannelClient *rcc;
+ RedCharDevice *chardev;
+ SpiceCharDeviceInstance *chardev_sin;
+ RedVmcPipeItem *pipe_item;
+ RedCharDeviceWriteBuffer *recv_from_client_buf;
+ uint8_t port_opened;
};
struct SpiceVmcStateClass
@@ -177,19 +181,6 @@ static void spice_vmc_state_port_init(SpiceVmcStatePort *self)
}
G_DEFINE_TYPE(SpiceVmcStatePort, spice_vmc_state_port, SPICE_TYPE_VMC_STATE)
-#define VMC_STATE_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE((o), SPICE_TYPE_VMC_STATE, SpiceVmcStatePrivate))
-
-struct SpiceVmcStatePrivate
-{
- RedChannelClient *rcc;
- RedCharDevice *chardev;
- SpiceCharDeviceInstance *chardev_sin;
- RedVmcPipeItem *pipe_item;
- RedCharDeviceWriteBuffer *recv_from_client_buf;
- uint8_t port_opened;
-};
-
enum {
PROP0,
PROP_DEVICE_INSTANCE
@@ -206,7 +197,7 @@ spice_vmc_state_get_property(GObject *object,
switch (property_id)
{
case PROP_DEVICE_INSTANCE:
- g_value_set_pointer(value, self->priv->chardev_sin);
+ g_value_set_pointer(value, self->chardev_sin);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -224,7 +215,7 @@ spice_vmc_state_set_property(GObject *object,
switch (property_id)
{
case PROP_DEVICE_INSTANCE:
- self->priv->chardev_sin = g_value_get_pointer(value);
+ self->chardev_sin = g_value_get_pointer(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -253,8 +244,7 @@ spice_vmc_state_constructed(GObject *object)
red_channel_init_outgoing_messages_window(RED_CHANNEL(self));
- self->priv->chardev = red_char_device_spicevmc_new(self->priv->chardev_sin,
- reds, self);
+ self->chardev = red_char_device_spicevmc_new(self->chardev_sin, reds, self);
reds_register_channel(reds, RED_CHANNEL(self));
}
@@ -262,7 +252,6 @@ spice_vmc_state_constructed(GObject *object)
static void
spice_vmc_state_init(SpiceVmcState *self)
{
- self->priv = VMC_STATE_PRIVATE(self);
}
static SpiceVmcState *spice_vmc_state_new(RedsState *reds, uint8_t channel_type,
@@ -330,7 +319,7 @@ static RedVmcPipeItem* try_compress_lz4(SpiceVmcState *state, int n, RedVmcPipeI
RedVmcPipeItem *msg_item_compressed;
int compressed_data_count;
- if (reds_stream_get_family(red_channel_client_get_stream(state->priv->rcc)) == AF_UNIX) {
+ if (reds_stream_get_family(red_channel_client_get_stream(state->rcc)) == AF_UNIX) {
/* AF_LOCAL - data will not be compressed */
return NULL;
}
@@ -373,18 +362,18 @@ static RedPipeItem *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *
sif = spice_char_device_get_interface(sin);
- if (!state->priv->rcc) {
+ if (!state->rcc) {
return NULL;
}
- if (!state->priv->pipe_item) {
+ if (!state->pipe_item) {
msg_item = spice_new0(RedVmcPipeItem, 1);
msg_item->type = SPICE_DATA_COMPRESSION_TYPE_NONE;
red_pipe_item_init(&msg_item->base, RED_PIPE_ITEM_TYPE_SPICEVMC_DATA);
} else {
- spice_assert(state->priv->pipe_item->buf_used == 0);
- msg_item = state->priv->pipe_item;
- state->priv->pipe_item = NULL;
+ spice_assert(state->pipe_item->buf_used == 0);
+ msg_item = state->pipe_item;
+ state->pipe_item = NULL;
}
n = sif->read(sin, msg_item->buf,
@@ -403,7 +392,7 @@ static RedPipeItem *spicevmc_chardev_read_msg_from_dev(SpiceCharDeviceInstance *
msg_item->buf_used = n;
return &msg_item->base;
} else {
- state->priv->pipe_item = msg_item;
+ state->pipe_item = msg_item;
return NULL;
}
}
@@ -414,9 +403,9 @@ static void spicevmc_chardev_send_msg_to_client(RedPipeItem *msg,
{
SpiceVmcState *state = opaque;
- spice_assert(red_channel_client_get_client(state->priv->rcc) == client);
+ spice_assert(red_channel_client_get_client(state->rcc) == client);
red_pipe_item_ref(msg);
- red_channel_client_pipe_add_push(state->priv->rcc, msg);
+ red_channel_client_pipe_add_push(state->rcc, msg);
}
static SpiceVmcState *spicevmc_red_channel_client_get_state(RedChannelClient *rcc)
@@ -428,12 +417,12 @@ static SpiceVmcState *spicevmc_red_channel_client_get_state(RedChannelClient *rc
static void spicevmc_port_send_init(RedChannelClient *rcc)
{
SpiceVmcState *state = spicevmc_red_channel_client_get_state(rcc);
- SpiceCharDeviceInstance *sin = state->priv->chardev_sin;
+ SpiceCharDeviceInstance *sin = state->chardev_sin;
RedPortInitPipeItem *item = spice_malloc(sizeof(RedPortInitPipeItem));
red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_PORT_INIT);
item->name = strdup(sin->portname);
- item->opened = state->priv->port_opened;
+ item->opened = state->port_opened;
red_channel_client_pipe_add_push(rcc, &item->base);
}
@@ -458,10 +447,10 @@ static void spicevmc_char_dev_remove_client(RedClient *client, void *opaque)
SpiceVmcState *state = opaque;
spice_printerr("vmc state %p, client %p", state, client);
- spice_assert(state->priv->rcc &&
- red_channel_client_get_client(state->priv->rcc) == client);
+ spice_assert(state->rcc &&
+ red_channel_client_get_client(state->rcc) == client);
- red_channel_client_shutdown(state->priv->rcc);
+ red_channel_client_shutdown(state->rcc);
}
static int spicevmc_red_channel_client_config_socket(RedChannelClient *rcc)
@@ -498,14 +487,14 @@ static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
state = spicevmc_red_channel_client_get_state(rcc);
/* partial message which wasn't pushed to device */
- red_char_device_write_buffer_release(state->priv->chardev, &state->priv->recv_from_client_buf);
+ red_char_device_write_buffer_release(state->chardev, &state->recv_from_client_buf);
- if (state->priv->chardev) {
- if (red_char_device_client_exists(state->priv->chardev, client)) {
- red_char_device_client_remove(state->priv->chardev, client);
+ if (state->chardev) {
+ if (red_char_device_client_exists(state->chardev, client)) {
+ red_char_device_client_remove(state->chardev, client);
} else {
spice_printerr("client %p have already been removed from char dev %p",
- client, state->priv->chardev);
+ client, state->chardev);
}
}
@@ -514,10 +503,10 @@ static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
if (!red_channel_client_is_destroying(rcc))
red_channel_client_destroy(rcc);
- state->priv->rcc = NULL;
- sif = spice_char_device_get_interface(state->priv->chardev_sin);
+ state->rcc = NULL;
+ sif = spice_char_device_get_interface(state->chardev_sin);
if (sif->state) {
- sif->state(state->priv->chardev_sin, 0);
+ sif->state(state->chardev_sin, 0);
}
}
@@ -546,7 +535,7 @@ static int spicevmc_channel_client_handle_migrate_data(RedChannelClient *rcc,
spice_error("bad header");
return FALSE;
}
- return red_char_device_restore(state->priv->chardev, &mig_data->base);
+ return red_char_device_restore(state->chardev, &mig_data->base);
}
static int handle_compressed_msg(SpiceVmcState *state, RedChannelClient *rcc,
@@ -556,7 +545,7 @@ static int handle_compressed_msg(SpiceVmcState *state, RedChannelClient *rcc,
int decompressed_size;
RedCharDeviceWriteBuffer *write_buf;
- write_buf = red_char_device_write_buffer_get(state->priv->chardev,
+ write_buf = red_char_device_write_buffer_get(state->chardev,
red_channel_client_get_client(rcc),
compressed_data_msg->uncompressed_size);
if (!write_buf) {
@@ -576,16 +565,16 @@ static int handle_compressed_msg(SpiceVmcState *state, RedChannelClient *rcc,
#endif
default:
spice_warning("Invalid Compression Type");
- red_char_device_write_buffer_release(state->priv->chardev, &write_buf);
+ red_char_device_write_buffer_release(state->chardev, &write_buf);
return FALSE;
}
if (decompressed_size != compressed_data_msg->uncompressed_size) {
spice_warning("Decompression Error");
- red_char_device_write_buffer_release(state->priv->chardev, &write_buf);
+ red_char_device_write_buffer_release(state->chardev, &write_buf);
return FALSE;
}
write_buf->buf_used = decompressed_size;
- red_char_device_write_buffer_add(state->priv->chardev, write_buf);
+ red_char_device_write_buffer_add(state->chardev, write_buf);
return TRUE;
}
@@ -600,14 +589,14 @@ static int spicevmc_red_channel_client_handle_message_parsed(RedChannelClient *r
SpiceCharDeviceInterface *sif;
state = spicevmc_red_channel_client_get_state(rcc);
- sif = spice_char_device_get_interface(state->priv->chardev_sin);
+ sif = spice_char_device_get_interface(state->chardev_sin);
switch (type) {
case SPICE_MSGC_SPICEVMC_DATA:
- spice_assert(state->priv->recv_from_client_buf->buf == msg);
- state->priv->recv_from_client_buf->buf_used = size;
- red_char_device_write_buffer_add(state->priv->chardev, state->priv->recv_from_client_buf);
- state->priv->recv_from_client_buf = NULL;
+ spice_assert(state->recv_from_client_buf->buf == msg);
+ state->recv_from_client_buf->buf_used = size;
+ red_char_device_write_buffer_add(state->chardev, state->recv_from_client_buf);
+ state->recv_from_client_buf = NULL;
break;
case SPICE_MSGC_SPICEVMC_COMPRESSED_DATA:
return handle_compressed_msg(state, rcc, (SpiceMsgCompressedData*)msg);
@@ -618,7 +607,7 @@ static int spicevmc_red_channel_client_handle_message_parsed(RedChannelClient *r
return FALSE;
}
if (sif->base.minor_version >= 2 && sif->event != NULL)
- sif->event(state->priv->chardev_sin, *(uint8_t*)msg);
+ sif->event(state->chardev_sin, *(uint8_t*)msg);
break;
default:
return red_channel_client_handle_message(rcc, size, type, (uint8_t*)msg);
@@ -638,16 +627,16 @@ static uint8_t *spicevmc_red_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
switch (type) {
case SPICE_MSGC_SPICEVMC_DATA:
- assert(!state->priv->recv_from_client_buf);
+ assert(!state->recv_from_client_buf);
- state->priv->recv_from_client_buf = red_char_device_write_buffer_get(state->priv->chardev,
- client,
- size);
- if (!state->priv->recv_from_client_buf) {
+ state->recv_from_client_buf = red_char_device_write_buffer_get(state->chardev,
+ client,
+ size);
+ if (!state->recv_from_client_buf) {
spice_error("failed to allocate write buffer");
return NULL;
}
- return state->priv->recv_from_client_buf->buf;
+ return state->recv_from_client_buf->buf;
default:
return spice_malloc(size);
@@ -667,8 +656,7 @@ static void spicevmc_red_channel_release_msg_rcv_buf(RedChannelClient *rcc,
switch (type) {
case SPICE_MSGC_SPICEVMC_DATA:
/* buffer wasn't pushed to device */
- red_char_device_write_buffer_release(state->priv->chardev,
- &state->priv->recv_from_client_buf);
+ red_char_device_write_buffer_release(state->chardev, &state->recv_from_client_buf);
break;
default:
free(msg);
@@ -707,7 +695,7 @@ static void spicevmc_red_channel_send_migrate_data(RedChannelClient *rcc,
spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_SPICEVMC_MAGIC);
spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_SPICEVMC_VERSION);
- red_char_device_migrate_data_marshall(state->priv->chardev, m);
+ red_char_device_migrate_data_marshall(state->chardev, m);
}
static void spicevmc_red_channel_send_port_init(RedChannelClient *rcc,
@@ -768,8 +756,6 @@ spice_vmc_state_class_init(SpiceVmcStateClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS(klass);
RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
- g_type_class_add_private(klass, sizeof(SpiceVmcStatePrivate));
-
object_class->get_property = spice_vmc_state_get_property;
object_class->set_property = spice_vmc_state_set_property;
object_class->constructed = spice_vmc_state_constructed;
@@ -829,12 +815,12 @@ static void spicevmc_connect(RedChannel *channel, RedClient *client,
uint32_t type, id;
state = SPICE_VMC_STATE(channel);
- sin = state->priv->chardev_sin;
+ sin = state->chardev_sin;
g_object_get(channel, "channel-type", &type, "id", &id, NULL);
- if (state->priv->rcc) {
+ if (state->rcc) {
spice_printerr("channel client %d:%d (%p) already connected, refusing second connection",
- type, id, state->priv->rcc);
+ type, id, state->rcc);
// TODO: notify client in advance about the in use channel using
// SPICE_MSG_MAIN_CHANNEL_IN_USE (for example)
reds_stream_free(stream);
@@ -846,21 +832,21 @@ static void spicevmc_connect(RedChannel *channel, RedClient *client,
if (!rcc) {
return;
}
- state->priv->rcc = rcc;
+ state->rcc = rcc;
red_channel_client_ack_zero_messages_window(rcc);
if (strcmp(sin->subtype, "port") == 0) {
spicevmc_port_send_init(rcc);
}
- if (!red_char_device_client_add(state->priv->chardev, client, FALSE, 0, ~0, ~0,
+ if (!red_char_device_client_add(state->chardev, client, FALSE, 0, ~0, ~0,
red_channel_client_is_waiting_for_migrate_data(rcc))) {
spice_warning("failed to add client to spicevmc");
red_channel_client_disconnect(rcc);
return;
}
- sif = spice_char_device_get_interface(state->priv->chardev_sin);
+ sif = spice_char_device_get_interface(state->chardev_sin);
if (sif->state) {
sif->state(sin, 1);
}
@@ -872,7 +858,7 @@ RedCharDevice *spicevmc_device_connect(RedsState *reds,
{
SpiceVmcState *state = spice_vmc_state_new(reds, channel_type, sin);
- return state->priv->chardev;
+ return state->chardev;
}
/* Must be called from RedClient handling thread. */
@@ -883,15 +869,14 @@ void spicevmc_device_disconnect(RedsState *reds, SpiceCharDeviceInstance *sin)
/* FIXME */
state = (SpiceVmcState *)red_char_device_opaque_get((RedCharDevice*)sin->st);
- red_char_device_write_buffer_release(state->priv->chardev,
- &state->priv->recv_from_client_buf);
+ red_char_device_write_buffer_release(state->chardev, &state->recv_from_client_buf);
/* FIXME */
red_char_device_destroy((RedCharDevice*)sin->st);
- state->priv->chardev = NULL;
+ state->chardev = NULL;
sin->st = NULL;
reds_unregister_channel(reds, RED_CHANNEL(state));
- free(state->priv->pipe_item);
+ free(state->pipe_item);
red_channel_destroy(RED_CHANNEL(state));
}
@@ -907,16 +892,16 @@ SPICE_GNUC_VISIBLE void spice_server_port_event(SpiceCharDeviceInstance *sin, ui
/* FIXME */
state = (SpiceVmcState *)red_char_device_opaque_get((RedCharDevice*)sin->st);
if (event == SPICE_PORT_EVENT_OPENED) {
- state->priv->port_opened = TRUE;
+ state->port_opened = TRUE;
} else if (event == SPICE_PORT_EVENT_CLOSED) {
- state->priv->port_opened = FALSE;
+ state->port_opened = FALSE;
}
- if (state->priv->rcc == NULL) {
+ if (state->rcc == NULL) {
return;
}
- spicevmc_port_send_event(state->priv->rcc, event);
+ spicevmc_port_send_event(state->rcc, event);
}
static void
--
2.7.4
More information about the Spice-devel
mailing list