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

[virt-tools-list] [virt-viewer 15/20] VirtViewerSes sionOvirt implementation



This will be a stub which will resolve the ovirt URI and
appropriately create either a VirtViewerSessionSpice or
VirtViewerSessionVnc, and it will then forward the various
VirtViewerSession calls to the actual session.
---
 src/Makefile.am                 |    2 +
 src/virt-viewer-app.c           |   11 ++
 src/virt-viewer-session-ovirt.c |  241 +++++++++++++++++++++++++++++++++++++++
 src/virt-viewer-session-ovirt.h |   77 +++++++++++++
 4 files changed, 331 insertions(+)
 create mode 100644 src/virt-viewer-session-ovirt.c
 create mode 100644 src/virt-viewer-session-ovirt.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 733fd42..bfceacf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,8 @@ COMMON_SOURCES +=			\
 	ovirt-rest-call.c		\
 	ovirt-vm.c			\
 	ovirt-vm-display.c		\
+	virt-viewer-session-ovirt.h	\
+	virt-viewer-session-ovirt.c	\
 	$(OVIRT_HEADER_FILES)		\
 	$(NULL)
 
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 2275d1c..9b577b2 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -58,6 +58,9 @@
 #ifdef HAVE_GTK_VNC
 #include "virt-viewer-session-vnc.h"
 #endif
+#ifdef HAVE_OVIRT
+#include "virt-viewer-session-ovirt.h"
+#endif
 #ifdef HAVE_SPICE_GTK
 #include "virt-viewer-session-spice.h"
 #endif
@@ -695,6 +698,14 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type)
         priv->session = virt_viewer_session_vnc_new(window);
     } else
 #endif
+#ifdef HAVE_OVIRT
+    if (g_ascii_strcasecmp(type, "ovirt") == 0) {
+        GtkWindow *window = virt_viewer_window_get_window(priv->main_window);
+        virt_viewer_app_trace(self, "Guest %s has a %s display\n",
+                              priv->guest_name, type);
+        priv->session = virt_viewer_session_ovirt_new(self, window);
+    } else
+#endif
 #ifdef HAVE_SPICE_GTK
     if (g_ascii_strcasecmp(type, "spice") == 0) {
         GtkWindow *window = virt_viewer_window_get_window(priv->main_window);
diff --git a/src/virt-viewer-session-ovirt.c b/src/virt-viewer-session-ovirt.c
new file mode 100644
index 0000000..de77306
--- /dev/null
+++ b/src/virt-viewer-session-ovirt.c
@@ -0,0 +1,241 @@
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2007-2012 Red Hat, Inc.
+ * Copyright (C) 2009-2012 Daniel P. Berrange
+ * Copyright (C) 2010 Marc-André Lureau
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Daniel P. Berrange <berrange redhat com>
+ */
+
+#include <config.h>
+
+#include <glib/gi18n.h>
+
+#include "ovirt-proxy.h"
+#include "virt-viewer-util.h"
+#include "virt-viewer-session-ovirt.h"
+
+#if !GLIB_CHECK_VERSION(2, 26, 0)
+#include "gbinding.h"
+#include "gbinding.c"
+#endif
+
+G_DEFINE_TYPE (VirtViewerSessionOvirt, virt_viewer_session_ovirt, VIRT_VIEWER_TYPE_SESSION)
+
+
+struct _VirtViewerSessionOvirtPrivate {
+    VirtViewerSession *real_session;
+    GtkWindow *main_window;
+};
+
+#define VIRT_VIEWER_SESSION_OVIRT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_SESSION_OVIRT, VirtViewerSessionOvirtPrivate))
+
+enum {
+    PROP_0,
+    PROP_SPICE_SESSION,
+};
+
+
+static void virt_viewer_session_ovirt_close(VirtViewerSession *session);
+static gboolean virt_viewer_session_ovirt_open_fd(VirtViewerSession *session, int fd);
+static gboolean virt_viewer_session_ovirt_open_host(VirtViewerSession *session, const gchar *host, const gchar *port, const gchar *tlsport);
+static gboolean virt_viewer_session_ovirt_open_uri(VirtViewerSession *session, const gchar *uri);
+static gboolean virt_viewer_session_ovirt_channel_open_fd(VirtViewerSession *session, VirtViewerSessionChannel *channel, int fd);
+static gboolean virt_viewer_session_ovirt_has_usb(VirtViewerSession *session);
+static void virt_viewer_session_ovirt_usb_device_selection(VirtViewerSession *session, GtkWindow *parent);
+static void virt_viewer_session_ovirt_smartcard_insert(VirtViewerSession *session);
+static void virt_viewer_session_ovirt_smartcard_remove(VirtViewerSession *session);
+
+
+static void
+virt_viewer_session_ovirt_dispose(GObject *obj)
+{
+    VirtViewerSessionOvirt *ovirt = VIRT_VIEWER_SESSION_OVIRT(obj);
+
+    g_clear_object(&ovirt->priv->real_session);
+    g_clear_object(&ovirt->priv->main_window);
+
+    G_OBJECT_CLASS(virt_viewer_session_ovirt_parent_class)->dispose(obj);
+}
+
+
+static void
+virt_viewer_session_ovirt_class_init(VirtViewerSessionOvirtClass *klass)
+{
+    VirtViewerSessionClass *dclass = VIRT_VIEWER_SESSION_CLASS(klass);
+    GObjectClass *oclass = G_OBJECT_CLASS(klass);
+
+    oclass->dispose = virt_viewer_session_ovirt_dispose;
+
+    dclass->close = virt_viewer_session_ovirt_close;
+    dclass->open_fd = virt_viewer_session_ovirt_open_fd;
+    dclass->open_host = virt_viewer_session_ovirt_open_host;
+    dclass->open_uri = virt_viewer_session_ovirt_open_uri;
+    dclass->channel_open_fd = virt_viewer_session_ovirt_channel_open_fd;
+    dclass->has_usb = virt_viewer_session_ovirt_has_usb;
+    dclass->usb_device_selection = virt_viewer_session_ovirt_usb_device_selection;
+    dclass->smartcard_insert = virt_viewer_session_ovirt_smartcard_insert;
+    dclass->smartcard_remove = virt_viewer_session_ovirt_smartcard_remove;
+
+    g_type_class_add_private(klass, sizeof(VirtViewerSessionOvirtPrivate));
+}
+
+static void
+virt_viewer_session_ovirt_init(VirtViewerSessionOvirt *self)
+{
+    self->priv = VIRT_VIEWER_SESSION_OVIRT_GET_PRIVATE(self);
+}
+
+static void
+virt_viewer_session_ovirt_close(VirtViewerSession *session)
+{
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_if_fail(self != NULL);
+
+    if (self->priv->real_session) {
+        virt_viewer_session_close(self->priv->real_session);
+    }
+
+#if 0
+/*FIXME: what's up?*/
+    /* FIXME: version 0.7 of spice-gtk allows reuse of session */
+    create_spice_session(self);
+#endif
+}
+
+static gboolean
+virt_viewer_session_ovirt_open_host(VirtViewerSession *session,
+                                    const gchar *host,
+                                    const gchar *port,
+                                    const gchar *tlsport)
+{
+    /* FIXME: resolve if possible ? */
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_val_if_fail(self != NULL, FALSE);
+    g_return_val_if_fail(self->priv->real_session != NULL, FALSE);
+
+    return virt_viewer_session_open_host(self->priv->real_session,
+                                         host, port, tlsport);
+}
+
+static gboolean
+virt_viewer_session_ovirt_open_uri(VirtViewerSession *session,
+                                   const gchar *uri)
+{
+    /* FIXME: resolve */
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_val_if_fail(self != NULL, FALSE);
+    g_return_val_if_fail(self->priv->real_session != NULL, FALSE);
+
+    return virt_viewer_session_open_uri(self->priv->real_session, uri);
+}
+
+static gboolean
+virt_viewer_session_ovirt_open_fd(VirtViewerSession *session,
+                                  int fd)
+{
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_val_if_fail(self != NULL, FALSE);
+    g_return_val_if_fail(self->priv->real_session != NULL, FALSE);
+
+    return virt_viewer_session_open_fd(self->priv->real_session, fd);
+}
+
+static gboolean
+virt_viewer_session_ovirt_channel_open_fd(VirtViewerSession *session,
+                                          VirtViewerSessionChannel *channel,
+                                          int fd)
+{
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_val_if_fail(self != NULL, FALSE);
+    g_return_val_if_fail(self->priv->real_session != NULL, FALSE);
+
+    return virt_viewer_session_channel_open_fd(self->priv->real_session,
+                                               channel, fd);
+}
+
+static gboolean
+virt_viewer_session_ovirt_has_usb(VirtViewerSession *session)
+{
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_val_if_fail(self != NULL, FALSE);
+    g_return_val_if_fail(self->priv->real_session != NULL, FALSE);
+
+    return virt_viewer_session_has_usb(self->priv->real_session);
+}
+
+static void
+virt_viewer_session_ovirt_usb_device_selection(VirtViewerSession *session,
+                                               GtkWindow *parent)
+{
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_if_fail(self != NULL);
+    g_return_if_fail(self->priv->real_session != NULL);
+
+    virt_viewer_session_usb_device_selection(self->priv->real_session, parent);
+
+}
+
+VirtViewerSession *
+virt_viewer_session_ovirt_new(VirtViewerApp *app, GtkWindow *main_window)
+{
+    VirtViewerSessionOvirt *self;
+
+    self = g_object_new(VIRT_VIEWER_TYPE_SESSION_OVIRT, "app", app, NULL);
+
+    self->priv->main_window = g_object_ref(main_window);
+
+    return VIRT_VIEWER_SESSION(self);
+}
+
+static void
+virt_viewer_session_ovirt_smartcard_insert(VirtViewerSession *session)
+{
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_if_fail(self != NULL);
+    g_return_if_fail(self->priv->real_session != NULL);
+
+    virt_viewer_session_smartcard_insert(self->priv->real_session);
+}
+
+static void
+virt_viewer_session_ovirt_smartcard_remove(VirtViewerSession *session)
+{
+    VirtViewerSessionOvirt *self = VIRT_VIEWER_SESSION_OVIRT(session);
+
+    g_return_if_fail(self != NULL);
+    g_return_if_fail(self->priv->real_session != NULL);
+
+    virt_viewer_session_smartcard_remove(self->priv->real_session);
+}
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  indent-tabs-mode: nil
+ * End:
+ */
diff --git a/src/virt-viewer-session-ovirt.h b/src/virt-viewer-session-ovirt.h
new file mode 100644
index 0000000..e07aad1
--- /dev/null
+++ b/src/virt-viewer-session-ovirt.h
@@ -0,0 +1,77 @@
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2007-2012 Red Hat, Inc.
+ * Copyright (C) 2009-2012 Daniel P. Berrange
+ * Copyright (C) 2010 Marc-André Lureau
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Daniel P. Berrange <berrange redhat com>
+ */
+#ifndef _VIRT_VIEWER_SESSION_OVIRT_H
+#define _VIRT_VIEWER_SESSION_OVIRT_H
+
+#include <glib-object.h>
+
+#include "virt-viewer-session.h"
+
+G_BEGIN_DECLS
+
+#define VIRT_VIEWER_TYPE_SESSION_OVIRT virt_viewer_session_ovirt_get_type()
+
+#define VIRT_VIEWER_SESSION_OVIRT(obj)                                        \
+    (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TYPE_SESSION_OVIRT, VirtViewerSessionOvirt))
+
+#define VIRT_VIEWER_SESSION_OVIRT_CLASS(klass)                                \
+    (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TYPE_SESSION_OVIRT, VirtViewerSessionOvirtClass))
+
+#define VIRT_VIEWER_IS_SESSION_OVIRT(obj)                                \
+    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TYPE_SESSION_OVIRT))
+
+#define VIRT_VIEWER_IS_SESSION_OVIRT_CLASS(klass)                        \
+    (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TYPE_SESSION_OVIRT))
+
+#define VIRT_VIEWER_SESSION_OVIRT_GET_CLASS(obj)                        \
+    (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TYPE_SESSION_OVIRT, VirtViewerSessionOvirtClass))
+
+typedef struct _VirtViewerSessionOvirt VirtViewerSessionOvirt;
+typedef struct _VirtViewerSessionOvirtClass VirtViewerSessionOvirtClass;
+typedef struct _VirtViewerSessionOvirtPrivate VirtViewerSessionOvirtPrivate;
+
+struct _VirtViewerSessionOvirt {
+    VirtViewerSession parent;
+
+    VirtViewerSessionOvirtPrivate *priv;
+};
+
+struct _VirtViewerSessionOvirtClass {
+    VirtViewerSessionClass parent_class;
+};
+
+GType virt_viewer_session_ovirt_get_type(void);
+
+VirtViewerSession* virt_viewer_session_ovirt_new(VirtViewerApp *app, GtkWindow *main_window);
+
+G_END_DECLS
+
+#endif /* _VIRT_VIEWER_SESSION_OVIRT_H */
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  indent-tabs-mode: nil
+ * End:
+ */
-- 
1.7.10.2


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