[Spice-devel] [PATCHv2 13/22] gtk: do not require glib session private fields

Marc-André Lureau marcandre.lureau at redhat.com
Wed Nov 26 09:56:04 PST 2014


Use GObject object association for session helpers.

GtkSession and DesktopIntegration are in the gtk library SpiceSession is
in glib one. So far we had the SessionPriv structure shared between the
two libraries, so they could fit their pointers there. But this is no
longer possible when moving the private structure in .c. We could add
more accessors, but they would need to be in public API, and this isn't
supposed to be accessed by API users.
---
 gtk/desktop-integration.c | 7 ++-----
 gtk/spice-gtk-session.c   | 4 ++--
 gtk/spice-session-priv.h  | 2 --
 gtk/spice-session.c       | 2 --
 4 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/gtk/desktop-integration.c b/gtk/desktop-integration.c
index 145fa6a..c366fd0 100644
--- a/gtk/desktop-integration.c
+++ b/gtk/desktop-integration.c
@@ -187,9 +187,6 @@ static void spice_desktop_integration_class_init(SpiceDesktopIntegrationClass *k
     g_type_class_add_private(klass, sizeof(SpiceDesktopIntegrationPrivate));
 }
 
-/* ------------------------------------------------------------------ */
-/* public methods                                                     */
-
 SpiceDesktopIntegration *spice_desktop_integration_get(SpiceSession *session)
 {
     SpiceDesktopIntegration *self;
@@ -198,10 +195,10 @@ SpiceDesktopIntegration *spice_desktop_integration_get(SpiceSession *session)
     g_return_val_if_fail(session != NULL, NULL);
 
     g_static_mutex_lock(&mutex);
-    self = session->priv->desktop_integration;
+    self = g_object_get_data(G_OBJECT(session), "spice-desktop");
     if (self == NULL) {
         self = g_object_new(SPICE_TYPE_DESKTOP_INTEGRATION, NULL);
-        session->priv->desktop_integration = self;
+        g_object_set_data_full(G_OBJECT(session), "spice-desktop", self, g_object_unref);
     }
     g_static_mutex_unlock(&mutex);
 
diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
index 701950d..de01358 100644
--- a/gtk/spice-gtk-session.c
+++ b/gtk/spice-gtk-session.c
@@ -1119,10 +1119,10 @@ SpiceGtkSession *spice_gtk_session_get(SpiceSession *session)
     static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
 
     g_static_mutex_lock(&mutex);
-    self = session->priv->gtk_session;
+    self = g_object_get_data(G_OBJECT(session), "spice-gtk-session");
     if (self == NULL) {
         self = g_object_new(SPICE_TYPE_GTK_SESSION, "session", session, NULL);
-        session->priv->gtk_session = self;
+        g_object_set_data_full(G_OBJECT(session), "spice-gtk-session", self, g_object_unref);
     }
     g_static_mutex_unlock(&mutex);
 
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 98c3f72..c9efba3 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -115,8 +115,6 @@ struct _SpiceSessionPrivate {
 
     /* associated objects */
     SpiceAudio        *audio_manager;
-    SpiceDesktopIntegration *desktop_integration;
-    SpiceGtkSession   *gtk_session;
     SpiceUsbDeviceManager *usb_manager;
     SpicePlaybackChannel *playback_channel;
     PhodavServer      *webdav;
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 02ebd74..5ddcd5c 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -186,8 +186,6 @@ spice_session_dispose(GObject *gobject)
     g_warn_if_fail(s->after_main_init == 0);
 
     g_clear_object(&s->audio_manager);
-    g_clear_object(&s->desktop_integration);
-    g_clear_object(&s->gtk_session);
     g_clear_object(&s->usb_manager);
     g_clear_object(&s->proxy);
     g_clear_object(&s->webdav);
-- 
2.1.0



More information about the Spice-devel mailing list