[virt-tools-list] [virt-viewer 04/20] Add OvirtVmDisplay class
Christophe Fergeau
cfergeau at redhat.com
Wed Jun 13 12:23:12 UTC 2012
---
src/Makefile.am | 2 +
src/ovirt-vm-display.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++
src/ovirt-vm-display.h | 66 ++++++++++++++++
3 files changed, 266 insertions(+)
create mode 100644 src/ovirt-vm-display.c
create mode 100644 src/ovirt-vm-display.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 356609c..6064b92 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,10 +53,12 @@ CLEANFILES = $(BUILT_SOURCES)
OVIRT_HEADER_FILES = \
ovirt-rest-call.h \
+ ovirt-vm-display.h \
$(NULL)
COMMON_SOURCES += \
ovirt-rest-call.c \
+ ovirt-vm-display.c \
$(OVIRT_HEADER_FILES) \
$(NULL)
diff --git a/src/ovirt-vm-display.c b/src/ovirt-vm-display.c
new file mode 100644
index 0000000..deebbe1
--- /dev/null
+++ b/src/ovirt-vm-display.c
@@ -0,0 +1,198 @@
+/*
+ * ovirt-vm-display.c: oVirt virtual machine display information
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Christophe Fergeau <cfergeau at redhat.com>
+ */
+
+#include <config.h>
+
+#include "ovirt-enum-types.h"
+#include "ovirt-vm-display.h"
+
+#define OVIRT_VM_DISPLAY_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), OVIRT_TYPE_VM_DISPLAY, OvirtVmDisplayPrivate))
+
+struct _OvirtVmDisplayPrivate {
+ OvirtVmDisplayType type;
+ char *address;
+ guint port;
+ guint monitor_count;
+ char *ticket;
+ guint expiry;
+};
+
+G_DEFINE_TYPE(OvirtVmDisplay, ovirt_vm_display, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_TYPE,
+ PROP_ADDRESS,
+ PROP_PORT,
+ PROP_MONITOR_COUNT,
+ PROP_TICKET,
+ PROP_EXPIRY
+};
+
+static void ovirt_vm_display_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ OvirtVmDisplay *display = OVIRT_VM_DISPLAY(object);
+
+ switch (prop_id) {
+ case PROP_TYPE:
+ g_value_set_enum(value, display->priv->type);
+ break;
+ case PROP_ADDRESS:
+ g_value_set_string(value, display->priv->address);
+ break;
+ case PROP_PORT:
+ g_value_set_uint(value, display->priv->port);
+ break;
+ case PROP_MONITOR_COUNT:
+ g_value_set_uint(value, display->priv->monitor_count);
+ break;
+ case PROP_TICKET:
+ g_value_set_string(value, display->priv->ticket);
+ break;
+ case PROP_EXPIRY:
+ g_value_set_uint(value, display->priv->expiry);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+static void ovirt_vm_display_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ OvirtVmDisplay *display = OVIRT_VM_DISPLAY(object);
+
+ switch (prop_id) {
+ case PROP_TYPE:
+ display->priv->type = g_value_get_enum(value);
+ break;
+ case PROP_ADDRESS:
+ g_free(display->priv->address);
+ display->priv->address = g_value_dup_string(value);
+ break;
+ case PROP_PORT:
+ display->priv->port = g_value_get_uint(value);
+ break;
+ case PROP_MONITOR_COUNT:
+ display->priv->monitor_count = g_value_get_uint(value);
+ break;
+ case PROP_TICKET:
+ g_free(display->priv->ticket);
+ display->priv->ticket = g_value_dup_string(value);
+ break;
+ case PROP_EXPIRY:
+ display->priv->expiry = g_value_get_uint(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+static void ovirt_vm_display_finalize(GObject *object)
+{
+ OvirtVmDisplay *display = OVIRT_VM_DISPLAY(object);
+
+ g_free(display->priv->address);
+ g_free(display->priv->ticket);
+
+ G_OBJECT_CLASS(ovirt_vm_display_parent_class)->finalize(object);
+}
+
+static void ovirt_vm_display_class_init(OvirtVmDisplayClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ g_type_class_add_private(klass, sizeof(OvirtVmDisplayPrivate));
+
+ object_class->finalize = ovirt_vm_display_finalize;
+ object_class->get_property = ovirt_vm_display_get_property;
+ object_class->set_property = ovirt_vm_display_set_property;
+
+ g_object_class_install_property(object_class,
+ PROP_TYPE,
+ g_param_spec_enum("type",
+ "Type",
+ "Display Type",
+ OVIRT_TYPE_VM_DISPLAY_TYPE,
+ OVIRT_VM_DISPLAY_SPICE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property(object_class,
+ PROP_ADDRESS,
+ g_param_spec_string("address",
+ "Address",
+ "Display Address",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property(object_class,
+ PROP_PORT,
+ g_param_spec_uint("port",
+ "Port",
+ "Display Port",
+ 0, G_MAXUINT16,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property(object_class,
+ PROP_MONITOR_COUNT,
+ g_param_spec_uint("monitor-count",
+ "Monitor Count",
+ "Virtual Machine Monitor Count",
+ 0, G_MAXUINT,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property(object_class,
+ PROP_TICKET,
+ g_param_spec_string("ticket",
+ "Ticket",
+ "Ticket to access the VM",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property(object_class,
+ PROP_EXPIRY,
+ g_param_spec_uint("expiry",
+ "Expiry",
+ "Ticket Expiry Time",
+ 0, G_MAXUINT,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void ovirt_vm_display_init(G_GNUC_UNUSED OvirtVmDisplay *display)
+{
+ display->priv = OVIRT_VM_DISPLAY_GET_PRIVATE(display);
+}
+
+OvirtVmDisplay *ovirt_vm_display_new(void)
+{
+ return OVIRT_VM_DISPLAY(g_object_new(OVIRT_TYPE_VM_DISPLAY, NULL));
+}
diff --git a/src/ovirt-vm-display.h b/src/ovirt-vm-display.h
new file mode 100644
index 0000000..6034306
--- /dev/null
+++ b/src/ovirt-vm-display.h
@@ -0,0 +1,66 @@
+/*
+ * ovirt-vm-display.h: oVirt virtual machine display information
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Christophe Fergeau <cfergeau at redhat.com>
+ */
+#ifndef __OVIRT_VM_DISPLAY_H__
+#define __OVIRT_VM_DISPLAY_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define OVIRT_TYPE_VM_DISPLAY (ovirt_vm_display_get_type ())
+#define OVIRT_VM_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OVIRT_TYPE_VM_DISPLAY, OvirtVmDisplay))
+#define OVIRT_VM_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OVIRT_TYPE_VM_DISPLAY, OvirtVmDisplayClass))
+#define OVIRT_IS_VM_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OVIRT_TYPE_VM_DISPLAY))
+#define OVIRT_IS_VM_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OVIRT_TYPE_VM_DISPLAY))
+#define OVIRT_VM_DISPLAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OVIRT_TYPE_VM_DISPLAY, OvirtVmDisplayClass))
+
+typedef struct _OvirtVmDisplay OvirtVmDisplay;
+typedef struct _OvirtVmDisplayPrivate OvirtVmDisplayPrivate;
+typedef struct _OvirtVmDisplayClass OvirtVmDisplayClass;
+
+struct _OvirtVmDisplay
+{
+ GObject parent;
+
+ OvirtVmDisplayPrivate *priv;
+
+ /* Do not add fields to this struct */
+};
+
+struct _OvirtVmDisplayClass
+{
+ GObjectClass parent_class;
+
+ gpointer padding[20];
+};
+
+typedef enum {
+ OVIRT_VM_DISPLAY_SPICE,
+ OVIRT_VM_DISPLAY_VNC
+} OvirtVmDisplayType;
+
+GType ovirt_vm_display_get_type(void);
+OvirtVmDisplay *ovirt_vm_display_new(void);
+
+G_END_DECLS
+
+#endif /* __OVIRT_VM_DISPLAY_H__ */
--
1.7.10.2
More information about the virt-tools-list
mailing list