[Spice-devel] [PATCH 05/14] Use weak gobject ref instead of reds_on_char_device_state_destroy

Jonathon Jongsma jjongsma at redhat.com
Thu Apr 21 21:43:51 UTC 2016


From: Christophe Fergeau <cfergeau at redhat.com>

RedCharDevice implementation had to callback into reds.c in order to let
it know a char device was being destroyed. Now that RedCharDevice is a
gobject, a weak reference can be used instead allowing to remove that
coupling.
---
Changes:
 - Renamed reds_on_char_device_state_destroy() to red_on_char_device_destroy()
 - removed local 'reds' variable from spice_server_char_device_add_interface()

 server/char-device.c |  2 --
 server/reds.c        | 15 ++++++++-------
 server/reds.h        |  1 -
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/server/char-device.c b/server/char-device.c
index a8d31e8..8cdf326 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -1114,8 +1114,6 @@ red_char_device_finalize(GObject *object)
 {
     RedCharDevice *self = RED_CHAR_DEVICE(object);
 
-    /* FIXME: replace with g_object_weak_ref () */
-    reds_on_char_device_state_destroy(self->priv->reds, self);
     if (self->priv->write_to_dev_timer) {
         reds_core_timer_remove(self->priv->reds, self->priv->write_to_dev_timer);
         self->priv->write_to_dev_timer = NULL;
diff --git a/server/reds.c b/server/reds.c
index 3c95864..4e553c3 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -252,7 +252,6 @@ static void reds_mig_target_client_free(RedsMigTargetClient *mig_client);
 static void reds_mig_cleanup_wait_disconnect(RedsState *reds);
 static void reds_mig_remove_wait_disconnect_client(RedsState *reds, RedClient *client);
 static void reds_add_char_device(RedsState *reds, RedCharDevice *dev);
-static void reds_remove_char_device(RedsState *reds, RedCharDevice *dev);
 static void reds_send_mm_time(RedsState *reds);
 static void reds_on_ic_change(RedsState *reds);
 static void reds_on_sv_change(RedsState *reds);
@@ -3142,15 +3141,13 @@ static void reds_add_char_device(RedsState *reds, RedCharDevice *dev)
     reds->char_devices = g_list_append(reds->char_devices, dev);
 }
 
-static void reds_remove_char_device(RedsState *reds, RedCharDevice *dev)
+static void reds_on_char_device_destroy(RedsState *reds,
+                                        RedCharDevice *dev)
 {
+    g_return_if_fail(reds != NULL);
     g_warn_if_fail(g_list_find(reds->char_devices, dev) != NULL);
-    reds->char_devices = g_list_remove(reds->char_devices, dev);
-}
 
-void reds_on_char_device_state_destroy(RedsState *reds, RedCharDevice *dev)
-{
-    reds_remove_char_device(reds, dev);
+    reds->char_devices = g_list_remove(reds->char_devices, dev);
 }
 
 static int spice_server_char_device_add_interface(SpiceServer *reds,
@@ -3188,6 +3185,10 @@ static int spice_server_char_device_add_interface(SpiceServer *reds,
 
     if (dev_state) {
         spice_assert(char_device->st);
+
+        g_object_weak_ref(G_OBJECT(dev_state),
+                          (GWeakNotify)reds_on_char_device_destroy,
+                          reds);
         /* setting the char_device state to "started" for backward compatibily with
          * qemu releases that don't call spice api for start/stop (not implemented yet) */
         if (reds->vm_running) {
diff --git a/server/reds.h b/server/reds.h
index 2cfd451..5b33432 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -100,7 +100,6 @@ int reds_on_migrate_dst_set_seamless(RedsState *reds, MainChannelClient *mcc, ui
 void reds_on_client_semi_seamless_migrate_complete(RedsState *reds, RedClient *client);
 void reds_on_client_seamless_migrate_complete(RedsState *reds, RedClient *client);
 void reds_on_main_channel_migrate(RedsState *reds, MainChannelClient *mcc);
-void reds_on_char_device_state_destroy(RedsState *reds, RedCharDevice *dev);
 
 void reds_set_client_mm_time_latency(RedsState *reds, RedClient *client, uint32_t latency);
 uint32_t reds_get_streaming_video(const RedsState *reds);
-- 
2.4.11



More information about the Spice-devel mailing list