[virt-tools-list] [virt-viewer 18/20] ovirt: forward signals from spice to ovirt session

Christophe Fergeau cfergeau at redhat.com
Wed Jun 13 12:23:26 UTC 2012


The application code needs signals from VirtViewerSession to be
emitted for it to work. Since the VirtViewerSessionOvirt instance
wraps the VirtViewerSessionSpice instance, it needs to forward
the signals it gets.
---
 src/virt-viewer-session-ovirt.c |   66 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/src/virt-viewer-session-ovirt.c b/src/virt-viewer-session-ovirt.c
index 5b71c83..f5eb9b9 100644
--- a/src/virt-viewer-session-ovirt.c
+++ b/src/virt-viewer-session-ovirt.c
@@ -190,6 +190,59 @@ parse_uri(VirtViewerSession *session, const gchar *uri)
     return TRUE;
 }
 
+typedef struct {
+    const char *signal;
+    VirtViewerSession *session;
+} SignalContext;
+
+static void destroy_context(gpointer user_data, G_GNUC_UNUSED GClosure *closure)
+{
+    g_slice_free(SignalContext, user_data);
+}
+
+static void reemit_signal_VOID(G_GNUC_UNUSED GObject *object,
+                               gpointer user_data)
+{
+    SignalContext *context = (SignalContext *)user_data;
+
+    g_message("Forwarding %s from VirtViewerSessionSpice to VirtViewerSessionOvirt",
+              context->signal);
+    g_signal_emit_by_name(context->session, context->signal);
+}
+
+static void reemit_signal_POINTER(G_GNUC_UNUSED GObject *object,
+                                  gpointer signal_data,
+                                  gpointer *user_data)
+{
+    SignalContext *context = (SignalContext *)user_data;
+
+    g_message("Forwarding %s from VirtViewerSessionSpice to VirtViewerSessionOvirt",
+              context->signal);
+    g_signal_emit_by_name(context->session, context->signal, signal_data);
+}
+
+static void proxy_signal_VOID(VirtViewerSessionOvirt *ovirt,
+                              const char *signal)
+{
+    SignalContext *context = g_slice_new(SignalContext);
+    context->signal = signal;
+    context->session = VIRT_VIEWER_SESSION(ovirt);
+    g_signal_connect_data(G_OBJECT(ovirt->priv->real_session), signal,
+                          G_CALLBACK(reemit_signal_VOID), context,
+                          destroy_context, 0);
+}
+
+static void proxy_signal_POINTER(VirtViewerSessionOvirt *ovirt,
+                                 const char *signal)
+{
+    SignalContext *context = g_slice_new(SignalContext);
+    context->signal = signal;
+    context->session = VIRT_VIEWER_SESSION(ovirt);
+    g_signal_connect_data(G_OBJECT(ovirt->priv->real_session), signal,
+                          G_CALLBACK(reemit_signal_POINTER), context,
+                          destroy_context, 0);
+}
+
 static void
 create_spice_session(VirtViewerSessionOvirt *ovirt,
                      const char *address,
@@ -219,6 +272,19 @@ create_spice_session(VirtViewerSessionOvirt *ovirt,
     ovirt->priv->real_session = virt_viewer_session_spice_new(app, ovirt->priv->main_window);
     g_object_unref(app);
 
+    proxy_signal_POINTER(ovirt, "session-auth-failed");
+    proxy_signal_POINTER(ovirt, "session-auth-refused");
+    proxy_signal_VOID(ovirt, "session-bell");
+    proxy_signal_VOID(ovirt, "session-cancelled");
+    proxy_signal_POINTER(ovirt, "session-channel-open");
+    proxy_signal_POINTER(ovirt, "session-cut-text");
+    proxy_signal_VOID(ovirt, "session-connected");
+    proxy_signal_VOID(ovirt, "session-disconnected");
+    proxy_signal_POINTER(ovirt, "session-display-added");
+    proxy_signal_POINTER(ovirt, "session-display-removed");
+    proxy_signal_VOID(ovirt, "session-initialized");
+    proxy_signal_POINTER(ovirt, "session-usb-failed");
+
     virt_viewer_session_open_uri(ovirt->priv->real_session, spice_uri);
     g_free(spice_uri);
 }
-- 
1.7.10.2




More information about the virt-tools-list mailing list