Update usage of GObject private structures

New functions and macros have been added in glib 2.38 to better handle
this case.

c8de2b11bb/NEWS

G_TYPE_INSTANCE_GET_PRIVATE will be deprecated in GLib 2.58.

https://gitlab.gnome.org/GNOME/glib/merge_requests/7/commits

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Eduardo Lima (Etrunko) 2019-02-07 16:54:18 -02:00 committed by Frediano Ziglio
parent 474158dfef
commit 90ff154b36
12 changed files with 36 additions and 96 deletions

View File

@ -84,9 +84,7 @@ struct RedCharDevicePrivate {
SpiceServer *reds;
};
G_DEFINE_TYPE(RedCharDevice, red_char_device, G_TYPE_OBJECT)
#define RED_CHAR_DEVICE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RED_TYPE_CHAR_DEVICE, RedCharDevicePrivate))
G_DEFINE_TYPE_WITH_PRIVATE(RedCharDevice, red_char_device, G_TYPE_OBJECT)
enum {
PROP_0,
@ -1119,8 +1117,6 @@ red_char_device_class_init(RedCharDeviceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof (RedCharDevicePrivate));
object_class->get_property = red_char_device_get_property;
object_class->set_property = red_char_device_set_property;
object_class->finalize = red_char_device_finalize;
@ -1180,7 +1176,7 @@ SPICE_GNUC_VISIBLE void spice_server_port_event(SpiceCharDeviceInstance *sin, ui
static void
red_char_device_init(RedCharDevice *self)
{
self->priv = RED_CHAR_DEVICE_PRIVATE(self);
self->priv = red_char_device_get_instance_private(self);
g_queue_init(&self->priv->write_queue);
g_queue_init(&self->priv->write_bufs_pool);

View File

@ -26,16 +26,6 @@
#define CHANNEL_RECEIVE_BUF_SIZE 1024
G_DEFINE_ABSTRACT_TYPE(CommonGraphicsChannel, common_graphics_channel, RED_TYPE_CHANNEL)
G_DEFINE_TYPE(CommonGraphicsChannelClient, common_graphics_channel_client, RED_TYPE_CHANNEL_CLIENT)
#define GRAPHICS_CHANNEL_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_COMMON_GRAPHICS_CHANNEL, CommonGraphicsChannelPrivate))
#define GRAPHICS_CHANNEL_CLIENT_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_COMMON_GRAPHICS_CHANNEL_CLIENT, \
CommonGraphicsChannelClientPrivate))
struct CommonGraphicsChannelPrivate
{
int during_target_migrate; /* TRUE when the client that is associated with the channel
@ -45,10 +35,15 @@ struct CommonGraphicsChannelPrivate
of the primary surface) */
};
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(CommonGraphicsChannel, common_graphics_channel,
RED_TYPE_CHANNEL)
struct CommonGraphicsChannelClientPrivate {
uint8_t recv_buf[CHANNEL_RECEIVE_BUF_SIZE];
};
G_DEFINE_TYPE_WITH_PRIVATE(CommonGraphicsChannelClient, common_graphics_channel_client,
RED_TYPE_CHANNEL_CLIENT)
static uint8_t *common_alloc_recv_buf(RedChannelClient *rcc, uint16_t type, uint32_t size)
{
@ -103,13 +98,12 @@ bool common_channel_client_config_socket(RedChannelClient *rcc)
static void
common_graphics_channel_class_init(CommonGraphicsChannelClass *klass)
{
g_type_class_add_private(klass, sizeof(CommonGraphicsChannelPrivate));
}
static void
common_graphics_channel_init(CommonGraphicsChannel *self)
{
self->priv = GRAPHICS_CHANNEL_PRIVATE(self);
self->priv = common_graphics_channel_get_instance_private(self);
}
void common_graphics_channel_set_during_target_migrate(CommonGraphicsChannel *self, gboolean value)
@ -125,7 +119,7 @@ gboolean common_graphics_channel_get_during_target_migrate(CommonGraphicsChannel
static void
common_graphics_channel_client_init(CommonGraphicsChannelClient *self)
{
self->priv = GRAPHICS_CHANNEL_CLIENT_PRIVATE(self);
self->priv = common_graphics_channel_client_get_instance_private(self);
}
static void
@ -133,8 +127,6 @@ common_graphics_channel_client_class_init(CommonGraphicsChannelClientClass *klas
{
RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
g_type_class_add_private(klass, sizeof(CommonGraphicsChannelClientPrivate));
client_class->config_socket = common_channel_client_config_socket;
client_class->alloc_recv_buf = common_alloc_recv_buf;
client_class->release_recv_buf = common_release_recv_buf;

View File

@ -35,11 +35,6 @@
#define CURSOR_CACHE_HASH_KEY(id) ((id) & CURSOR_CACHE_HASH_MASK)
#define CURSOR_CLIENT_TIMEOUT 30000000000ULL //nano
G_DEFINE_TYPE(CursorChannelClient, cursor_channel_client, TYPE_COMMON_GRAPHICS_CHANNEL_CLIENT)
#define CURSOR_CHANNEL_CLIENT_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_CURSOR_CHANNEL_CLIENT, CursorChannelClientPrivate))
struct CursorChannelClientPrivate
{
RedCacheItem *cursor_cache[CURSOR_CACHE_HASH_SIZE];
@ -48,6 +43,9 @@ struct CursorChannelClientPrivate
uint32_t cursor_cache_items;
};
G_DEFINE_TYPE_WITH_PRIVATE(CursorChannelClient, cursor_channel_client,
TYPE_COMMON_GRAPHICS_CHANNEL_CLIENT)
static void cursor_channel_client_on_disconnect(RedChannelClient *rcc);
static void
@ -55,15 +53,13 @@ cursor_channel_client_class_init(CursorChannelClientClass *klass)
{
RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
g_type_class_add_private(klass, sizeof(CursorChannelClientPrivate));
client_class->on_disconnect = cursor_channel_client_on_disconnect;
}
static void
cursor_channel_client_init(CursorChannelClient *self)
{
self->priv = CURSOR_CHANNEL_CLIENT_PRIVATE(self);
self->priv = cursor_channel_client_get_instance_private(self);
ring_init(&self->priv->cursor_cache_lru);
self->priv->cursor_cache_available = CLIENT_CURSOR_CACHE_SIZE;
}

View File

@ -44,11 +44,6 @@ typedef struct DispatcherMessage {
dispatcher_handle_message handler;
} DispatcherMessage;
G_DEFINE_TYPE(Dispatcher, dispatcher, G_TYPE_OBJECT)
#define DISPATCHER_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_DISPATCHER, DispatcherPrivate))
struct DispatcherPrivate {
int recv_fd;
int send_fd;
@ -63,6 +58,8 @@ struct DispatcherPrivate {
dispatcher_handle_any_message any_handler;
};
G_DEFINE_TYPE_WITH_PRIVATE(Dispatcher, dispatcher, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_MAX_MESSAGE_TYPE
@ -144,8 +141,6 @@ dispatcher_class_init(DispatcherClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof (DispatcherPrivate));
object_class->get_property = dispatcher_get_property;
object_class->set_property = dispatcher_set_property;
object_class->constructed = dispatcher_constructed;
@ -165,7 +160,7 @@ dispatcher_class_init(DispatcherClass *klass)
static void
dispatcher_init(Dispatcher *self)
{
self->priv = DISPATCHER_PRIVATE(self);
self->priv = dispatcher_get_instance_private(self);
}
Dispatcher *

View File

@ -22,11 +22,6 @@
#include "migration-protocol.h"
#include "red-channel-client.h"
G_DEFINE_TYPE(InputsChannelClient, inputs_channel_client, RED_TYPE_CHANNEL_CLIENT)
#define INPUTS_CHANNEL_CLIENT_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_INPUTS_CHANNEL_CLIENT, InputsChannelClientPrivate))
// TODO: RECEIVE_BUF_SIZE used to be the same for inputs_channel and main_channel
// since it was defined once in reds.c which contained both.
// Now that they are split we can give a more fitting value for inputs - what
@ -44,6 +39,8 @@ struct InputsChannelClientPrivate
uint8_t recv_buf[RECEIVE_BUF_SIZE];
};
G_DEFINE_TYPE_WITH_PRIVATE(InputsChannelClient, inputs_channel_client, RED_TYPE_CHANNEL_CLIENT)
static uint8_t *
inputs_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
uint16_t type, uint32_t size)
@ -77,8 +74,6 @@ inputs_channel_client_class_init(InputsChannelClientClass *klass)
{
RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
g_type_class_add_private(klass, sizeof(InputsChannelClientPrivate));
client_class->alloc_recv_buf = inputs_channel_client_alloc_msg_rcv_buf;
client_class->release_recv_buf = inputs_channel_client_release_msg_rcv_buf;
client_class->on_disconnect = inputs_channel_client_on_disconnect;
@ -87,7 +82,7 @@ inputs_channel_client_class_init(InputsChannelClientClass *klass)
static void
inputs_channel_client_init(InputsChannelClient *self)
{
self->priv = INPUTS_CHANNEL_CLIENT_PRIVATE(self);
self->priv = inputs_channel_client_get_instance_private(self);
}
RedChannelClient* inputs_channel_client_create(RedChannel *channel,

View File

@ -40,11 +40,6 @@ typedef enum {
#define CLIENT_CONNECTIVITY_TIMEOUT (MSEC_PER_SEC * 30)
G_DEFINE_TYPE(MainChannelClient, main_channel_client, RED_TYPE_CHANNEL_CLIENT)
#define MAIN_CHANNEL_CLIENT_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_MAIN_CHANNEL_CLIENT, MainChannelClientPrivate))
// approximate max receive message size for main channel
#define MAIN_CHANNEL_RECEIVE_BUF_SIZE \
(4096 + (REDS_AGENT_WINDOW_SIZE + REDS_NUM_INTERNAL_AGENT_MESSAGES) * SPICE_AGENT_MAX_DATA_SIZE)
@ -66,6 +61,8 @@ struct MainChannelClientPrivate {
uint8_t recv_buf[MAIN_CHANNEL_RECEIVE_BUF_SIZE];
};
G_DEFINE_TYPE_WITH_PRIVATE(MainChannelClient, main_channel_client, RED_TYPE_CHANNEL_CLIENT)
typedef struct RedPingPipeItem {
RedPipeItem base;
int size;
@ -211,8 +208,6 @@ static void main_channel_client_class_init(MainChannelClientClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS(klass);
RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
g_type_class_add_private(klass, sizeof(MainChannelClientPrivate));
object_class->get_property = main_channel_client_get_property;
object_class->set_property = main_channel_client_set_property;
@ -235,7 +230,7 @@ static void main_channel_client_class_init(MainChannelClientClass *klass)
static void main_channel_client_init(MainChannelClient *self)
{
self->priv = MAIN_CHANNEL_CLIENT_PRIVATE(self);
self->priv = main_channel_client_get_instance_private(self);
self->priv->bitrate_per_sec = ~0;
}

View File

@ -46,11 +46,6 @@
* main_dispatcher_handle_<event_name> - handler for callback from main thread
* seperate from self because it may send an ack or do other work in the future.
*/
G_DEFINE_TYPE(MainDispatcher, main_dispatcher, TYPE_DISPATCHER)
#define MAIN_DISPATCHER_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_MAIN_DISPATCHER, MainDispatcherPrivate))
struct MainDispatcherPrivate
{
SpiceCoreInterfaceInternal *core; /* weak */
@ -58,6 +53,7 @@ struct MainDispatcherPrivate
SpiceWatch *watch;
};
G_DEFINE_TYPE_WITH_PRIVATE(MainDispatcher, main_dispatcher, TYPE_DISPATCHER)
enum {
PROP0,
@ -113,8 +109,6 @@ main_dispatcher_class_init(MainDispatcherClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof(MainDispatcherPrivate));
object_class->constructed = main_dispatcher_constructed;
object_class->finalize = main_dispatcher_finalize;
object_class->get_property = main_dispatcher_get_property;
@ -140,7 +134,7 @@ main_dispatcher_class_init(MainDispatcherClass *klass)
static void
main_dispatcher_init(MainDispatcher *self)
{
self->priv = MAIN_DISPATCHER_PRIVATE(self);
self->priv = main_dispatcher_get_instance_private(self);
}
enum {

View File

@ -187,10 +187,8 @@ static bool red_channel_client_config_socket(RedChannelClient *rcc);
G_DEFINE_TYPE_WITH_CODE(RedChannelClient, red_channel_client, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE,
red_channel_client_initable_interface_init))
#define CHANNEL_CLIENT_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), RED_TYPE_CHANNEL_CLIENT, RedChannelClientPrivate))
red_channel_client_initable_interface_init);
G_ADD_PRIVATE(RedChannelClient));
static gboolean red_channel_client_initable_init(GInitable *initable,
GCancellable *cancellable,
@ -404,7 +402,6 @@ static void red_channel_client_class_init(RedChannelClientClass *klass)
GParamSpec *spec;
g_debug("%s", G_STRFUNC);
g_type_class_add_private(klass, sizeof(RedChannelClientPrivate));
object_class->get_property = red_channel_client_get_property;
object_class->set_property = red_channel_client_set_property;
@ -454,7 +451,7 @@ static void red_channel_client_class_init(RedChannelClientClass *klass)
static void
red_channel_client_init(RedChannelClient *self)
{
self->priv = CHANNEL_CLIENT_PRIVATE(self);
self->priv = red_channel_client_get_instance_private(self);
// blocks send message (maybe use send_data.blocked + block flags)
self->priv->ack_data.messages_window = ~0;
self->priv->ack_data.client_generation = ~0;

View File

@ -65,11 +65,6 @@
* If a call to red_channel_client_destroy is made from another location, it must be called
* from the channel's thread.
*/
G_DEFINE_ABSTRACT_TYPE(RedChannel, red_channel, G_TYPE_OBJECT)
#define CHANNEL_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), RED_TYPE_CHANNEL, RedChannelPrivate))
struct RedChannelPrivate
{
uint32_t type;
@ -99,6 +94,8 @@ struct RedChannelPrivate
RedStatNode stat;
};
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(RedChannel, red_channel, G_TYPE_OBJECT)
enum {
PROP0,
PROP_SPICE_SERVER,
@ -219,8 +216,6 @@ red_channel_class_init(RedChannelClass *klass)
GParamSpec *spec;
GObjectClass *object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof (RedChannelPrivate));
object_class->get_property = red_channel_get_property;
object_class->set_property = red_channel_set_property;
object_class->finalize = red_channel_finalize;
@ -289,7 +284,7 @@ red_channel_class_init(RedChannelClass *klass)
static void
red_channel_init(RedChannel *self)
{
self->priv = CHANNEL_PRIVATE(self);
self->priv = red_channel_get_instance_private(self);
red_channel_set_common_cap(self, SPICE_COMMON_CAP_MINI_HEADER);
self->priv->thread_id = pthread_self();

View File

@ -281,9 +281,7 @@ struct RedCharDeviceVDIPortClass
RedCharDeviceClass parent_class;
};
G_DEFINE_TYPE(RedCharDeviceVDIPort, red_char_device_vdi_port, RED_TYPE_CHAR_DEVICE)
#define RED_CHAR_DEVICE_VDIPORT_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RED_TYPE_CHAR_DEVICE_VDIPORT, RedCharDeviceVDIPortPrivate))
G_DEFINE_TYPE_WITH_PRIVATE(RedCharDeviceVDIPort, red_char_device_vdi_port, RED_TYPE_CHAR_DEVICE)
static RedCharDeviceVDIPort *red_char_device_vdi_port_new(RedsState *reds);
@ -4601,7 +4599,7 @@ static void red_char_device_vdi_port_constructed(GObject *object)
static void
red_char_device_vdi_port_init(RedCharDeviceVDIPort *self)
{
self->priv = RED_CHAR_DEVICE_VDIPORT_PRIVATE(self);
self->priv = red_char_device_vdi_port_get_instance_private(self);
self->priv->read_state = VDI_PORT_READ_STATE_READ_HEADER;
self->priv->receive_pos = (uint8_t *)&self->priv->vdi_chunk_header;
@ -4633,8 +4631,6 @@ red_char_device_vdi_port_class_init(RedCharDeviceVDIPortClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS(klass);
RedCharDeviceClass *char_dev_class = RED_CHAR_DEVICE_CLASS(klass);
g_type_class_add_private(klass, sizeof (RedCharDeviceVDIPortPrivate));
object_class->finalize = red_char_device_vdi_port_finalize;
object_class->constructed = red_char_device_vdi_port_constructed;

View File

@ -22,10 +22,6 @@
G_DEFINE_TYPE(SmartCardChannelClient, smart_card_channel_client, RED_TYPE_CHANNEL_CLIENT)
#define SMARTCARD_CHANNEL_CLIENT_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_SMARTCARD_CHANNEL_CLIENT, \
SmartCardChannelClientPrivate))
struct SmartCardChannelClientPrivate
{
RedCharDeviceSmartcard *smartcard;
@ -103,7 +99,7 @@ static void smart_card_channel_client_class_init(SmartCardChannelClientClass *kl
static void
smart_card_channel_client_init(SmartCardChannelClient *self)
{
self->priv = SMARTCARD_CHANNEL_CLIENT_PRIVATE(self);
self->priv = smart_card_channel_client_get_instance_private(self);
}
SmartCardChannelClient* smartcard_channel_client_create(RedChannel *channel,

View File

@ -83,13 +83,6 @@ red_smartcard_channel_new(RedsState *reds)
NULL);
}
G_DEFINE_TYPE(RedCharDeviceSmartcard, red_char_device_smartcard, RED_TYPE_CHAR_DEVICE)
#define RED_CHAR_DEVICE_SMARTCARD_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), RED_TYPE_CHAR_DEVICE_SMARTCARD, \
RedCharDeviceSmartcardPrivate))
struct RedCharDeviceSmartcardPrivate {
uint32_t reader_id;
/* read_from_device buffer */
@ -102,6 +95,8 @@ struct RedCharDeviceSmartcardPrivate {
int reader_added; // has reader_add been sent to the device
};
G_DEFINE_TYPE_WITH_PRIVATE(RedCharDeviceSmartcard, red_char_device_smartcard, RED_TYPE_CHAR_DEVICE)
typedef struct RedMsgItem {
RedPipeItem base;
@ -609,8 +604,6 @@ red_char_device_smartcard_class_init(RedCharDeviceSmartcardClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS(klass);
RedCharDeviceClass *char_dev_class = RED_CHAR_DEVICE_CLASS(klass);
g_type_class_add_private(klass, sizeof (RedCharDeviceSmartcardPrivate));
object_class->finalize = red_char_device_smartcard_finalize;
char_dev_class->read_one_msg_from_device = smartcard_read_msg_from_device;
@ -622,7 +615,7 @@ red_char_device_smartcard_class_init(RedCharDeviceSmartcardClass *klass)
static void
red_char_device_smartcard_init(RedCharDeviceSmartcard *self)
{
self->priv = RED_CHAR_DEVICE_SMARTCARD_PRIVATE(self);
self->priv = red_char_device_smartcard_get_instance_private(self);
self->priv->reader_id = VSCARD_UNDEFINED_READER_ID;
self->priv->buf_size = APDUBufSize + sizeof(VSCMsgHeader);