New functions and macros have been added in glib 2.38 to better handle this case. https://gitlab.gnome.org/GNOME/glib/blob/c8de2b11bbbf5705ee20bf68d0c11e455b441312/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@xxxxxxxxxx> Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- in v2: - Squash with Frediano's patch replacing GET_PRIVATE macros with appropriate _get_instance_private() functions. in v3: - Squash Frediano's patch which splits long lines. --- server/char-device.c | 8 ++------ server/common-graphics-channel.c | 22 +++++++--------------- server/cursor-channel-client.c | 12 ++++-------- server/dispatcher.c | 11 +++-------- server/inputs-channel-client.c | 11 +++-------- server/main-channel-client.c | 11 +++-------- server/main-dispatcher.c | 10 ++-------- server/red-channel-client.c | 9 +++------ server/red-channel.c | 11 +++-------- server/reds.c | 8 ++------ server/smartcard-channel-client.c | 6 +----- server/smartcard.c | 13 +++---------- 12 files changed, 36 insertions(+), 96 deletions(-) diff --git a/server/char-device.c b/server/char-device.c index 64b41a94..f58402cc 100644 --- a/server/char-device.c +++ b/server/char-device.c @@ -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); diff --git a/server/common-graphics-channel.c b/server/common-graphics-channel.c index 083ab3eb..b70fa3a4 100644 --- a/server/common-graphics-channel.c +++ b/server/common-graphics-channel.c @@ -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; diff --git a/server/cursor-channel-client.c b/server/cursor-channel-client.c index 6d39e24e..d72989ab 100644 --- a/server/cursor-channel-client.c +++ b/server/cursor-channel-client.c @@ -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; } diff --git a/server/dispatcher.c b/server/dispatcher.c index 3e27f2c2..c598ed7f 100644 --- a/server/dispatcher.c +++ b/server/dispatcher.c @@ -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 * diff --git a/server/inputs-channel-client.c b/server/inputs-channel-client.c index 5fd818a1..61254c7e 100644 --- a/server/inputs-channel-client.c +++ b/server/inputs-channel-client.c @@ -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, diff --git a/server/main-channel-client.c b/server/main-channel-client.c index 54be9934..3c18bb9d 100644 --- a/server/main-channel-client.c +++ b/server/main-channel-client.c @@ -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; } diff --git a/server/main-dispatcher.c b/server/main-dispatcher.c index 43f8b79a..99d2a621 100644 --- a/server/main-dispatcher.c +++ b/server/main-dispatcher.c @@ -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 { diff --git a/server/red-channel-client.c b/server/red-channel-client.c index 375a60b3..9aa76792 100644 --- a/server/red-channel-client.c +++ b/server/red-channel-client.c @@ -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; diff --git a/server/red-channel.c b/server/red-channel.c index 448b690e..a58f757c 100644 --- a/server/red-channel.c +++ b/server/red-channel.c @@ -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(); diff --git a/server/reds.c b/server/reds.c index 24047bda..92114d1e 100644 --- a/server/reds.c +++ b/server/reds.c @@ -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); @@ -4591,7 +4589,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; @@ -4623,8 +4621,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; diff --git a/server/smartcard-channel-client.c b/server/smartcard-channel-client.c index 49e765b7..a665e933 100644 --- a/server/smartcard-channel-client.c +++ b/server/smartcard-channel-client.c @@ -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, diff --git a/server/smartcard.c b/server/smartcard.c index 4c849450..504d6f03 100644 --- a/server/smartcard.c +++ b/server/smartcard.c @@ -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); -- 2.20.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel