[PATCH 14/14] Use weak gobject ref instead of reds_on_char_device_state_destroy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Christophe Fergeau <cfergeau@xxxxxxxxxx>

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.
---
 server/char-device.c |  2 --
 server/reds.c        | 18 +++++++++++-------
 server/reds.h        |  1 -
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/server/char-device.c b/server/char-device.c
index ae8f528..d62b5ae 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -1121,8 +1121,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 ddd58e3..9c2efa1 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -253,7 +253,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);
@@ -3133,15 +3132,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_state_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,
@@ -3178,7 +3175,14 @@ static int spice_server_char_device_add_interface(SpiceServer *reds,
     }
 
     if (dev_state) {
+        RedsState *reds;
+
         spice_assert(char_device->st);
+
+        g_object_get(G_OBJECT(dev_state), "spice-server", &reds, NULL);
+        g_object_weak_ref(G_OBJECT(dev_state),
+                          (GWeakNotify)reds_on_char_device_state_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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]