[virt-tools-list] [PATCH virt-viewer 19/25] spice: factor out main channel lookup code

Marc-André Lureau marcandre.lureau at gmail.com
Tue Jul 17 19:25:01 UTC 2012


---
 src/virt-viewer-display-spice.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
index 81eb16f..b2f7e6c 100644
--- a/src/virt-viewer-display-spice.c
+++ b/src/virt-viewer-display-spice.c
@@ -76,14 +76,27 @@ virt_viewer_display_spice_class_init(VirtViewerDisplaySpiceClass *klass)
     g_type_class_add_private(klass, sizeof(VirtViewerDisplaySpicePrivate));
 }
 
+static SpiceMainChannel*
+get_main(VirtViewerDisplay *self)
+{
+    VirtViewerSessionSpice *session;
+
+    session = VIRT_VIEWER_SESSION_SPICE(virt_viewer_display_get_session(self));
+
+    return virt_viewer_session_spice_get_main_channel(session);
+}
+
 static void
 show_hint_changed(VirtViewerDisplay *self)
 {
-    SpiceMainChannel *main_channel = virt_viewer_session_spice_get_main_channel(
-        VIRT_VIEWER_SESSION_SPICE(virt_viewer_display_get_session(self)));
+    SpiceMainChannel *main_channel = get_main(self);
     guint enabled = TRUE;
     guint nth;
 
+    /* this may happen when finalizing */
+    if (!main_channel)
+        return;
+
     g_object_get(self, "nth-display", &nth, NULL);
     if (virt_viewer_display_get_show_hint(self) & VIRT_VIEWER_DISPLAY_SHOW_HINT_DISABLED)
         enabled = FALSE;
@@ -191,9 +204,8 @@ virt_viewer_display_spice_size_allocate(VirtViewerDisplaySpice *self,
 
     g_object_get(self, "nth-display", &nth, NULL);
 
-    SpiceMainChannel *main_channel = virt_viewer_session_spice_get_main_channel(
-        VIRT_VIEWER_SESSION_SPICE(virt_viewer_display_get_session(VIRT_VIEWER_DISPLAY(self))));
-    spice_main_set_display(main_channel, nth, 0, 0, dw, dh);
+    spice_main_set_display(get_main(VIRT_VIEWER_DISPLAY(self)),
+                           nth, 0, 0, dw, dh);
 }
 
 static void
-- 
1.7.10.4




More information about the virt-tools-list mailing list