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

[virt-tools-list] [virt-viewer 05/20] Add OvirtVm class



---
 src/Makefile.am |    2 +
 src/ovirt-vm.c  |  200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ovirt-vm.h  |   67 +++++++++++++++++++
 3 files changed, 269 insertions(+)
 create mode 100644 src/ovirt-vm.c
 create mode 100644 src/ovirt-vm.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 6064b92..cd0e988 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,11 +53,13 @@ CLEANFILES = $(BUILT_SOURCES)
 
 OVIRT_HEADER_FILES =			\
 	ovirt-rest-call.h		\
+	ovirt-vm.h			\
 	ovirt-vm-display.h		\
 	$(NULL)
 
 COMMON_SOURCES +=			\
 	ovirt-rest-call.c		\
+	ovirt-vm.c			\
 	ovirt-vm-display.c		\
 	$(OVIRT_HEADER_FILES)		\
 	$(NULL)
diff --git a/src/ovirt-vm.c b/src/ovirt-vm.c
new file mode 100644
index 0000000..516593b
--- /dev/null
+++ b/src/ovirt-vm.c
@@ -0,0 +1,200 @@
+/*
+ * ovirt-vm.c: oVirt virtual machine
+ *
+ * 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 redhat com>
+ */
+
+#include <config.h>
+
+#include "ovirt-enum-types.h"
+#include "ovirt-vm.h"
+#include "ovirt-vm-display.h"
+
+#define OVIRT_VM_GET_PRIVATE(obj)                         \
+        (G_TYPE_INSTANCE_GET_PRIVATE((obj), OVIRT_TYPE_VM, OvirtVmPrivate))
+
+struct _OvirtVmPrivate {
+    char *uuid;
+    char *href;
+    char *name;
+    OvirtVmState state;
+    GHashTable *actions;
+    OvirtVmDisplay *display;
+} ;
+
+G_DEFINE_TYPE(OvirtVm, ovirt_vm, G_TYPE_OBJECT);
+
+enum {
+    PROP_0,
+    PROP_UUID,
+    PROP_HREF,
+    PROP_NAME,
+    PROP_STATE,
+    PROP_DISPLAY
+};
+
+static void ovirt_vm_get_property(GObject *object,
+                                  guint prop_id,
+                                  GValue *value,
+                                  GParamSpec *pspec)
+{
+    OvirtVm *vm = OVIRT_VM(object);
+
+    switch (prop_id) {
+    case PROP_UUID:
+        g_value_set_string(value, vm->priv->uuid);
+        break;
+    case PROP_HREF:
+        g_value_set_string(value, vm->priv->href);
+        break;
+    case PROP_NAME:
+        g_value_set_string(value, vm->priv->name);
+        break;
+    case PROP_STATE:
+        g_value_set_enum(value, vm->priv->state);
+        break;
+    case PROP_DISPLAY:
+        g_value_set_object(value, vm->priv->display);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    }
+}
+
+static void ovirt_vm_set_property(GObject *object,
+                                  guint prop_id,
+                                  const GValue *value,
+                                  GParamSpec *pspec)
+{
+    OvirtVm *vm = OVIRT_VM(object);
+
+    switch (prop_id) {
+    case PROP_UUID:
+        g_free(vm->priv->uuid);
+        vm->priv->uuid = g_value_dup_string(value);
+        break;
+    case PROP_HREF:
+        g_free(vm->priv->href);
+        vm->priv->href = g_value_dup_string(value);
+        break;
+    case PROP_NAME:
+        g_free(vm->priv->name);
+        vm->priv->name = g_value_dup_string(value);
+        break;
+    case PROP_STATE:
+        vm->priv->state = g_value_get_enum(value);
+        break;
+    case PROP_DISPLAY:
+        if (vm->priv->display != NULL)
+            g_object_unref(vm->priv->display);
+        vm->priv->display = g_value_dup_object(value);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    }
+}
+
+
+static void ovirt_vm_dispose(GObject *object)
+{
+    OvirtVm *vm = OVIRT_VM(object);
+
+    if (vm->priv->actions != NULL) {
+        g_hash_table_unref(vm->priv->actions);
+        vm->priv->actions = NULL;
+    }
+    g_clear_object(&vm->priv->display);
+
+    G_OBJECT_CLASS(ovirt_vm_parent_class)->dispose(object);
+}
+
+static void ovirt_vm_finalize(GObject *object)
+{
+    OvirtVm *vm = OVIRT_VM(object);
+
+    g_free(vm->priv->name);
+    g_free(vm->priv->href);
+    g_free(vm->priv->uuid);
+
+    G_OBJECT_CLASS(ovirt_vm_parent_class)->finalize(object);
+}
+
+static void ovirt_vm_class_init(OvirtVmClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    g_type_class_add_private(klass, sizeof(OvirtVmPrivate));
+
+    object_class->dispose = ovirt_vm_dispose;
+    object_class->finalize = ovirt_vm_finalize;
+    object_class->get_property = ovirt_vm_get_property;
+    object_class->set_property = ovirt_vm_set_property;
+
+    g_object_class_install_property(object_class,
+                                    PROP_UUID,
+                                    g_param_spec_string("uuid",
+                                                        "UUID",
+                                                        "Virtual Machine UUID",
+                                                        NULL,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_STATIC_STRINGS));
+    g_object_class_install_property(object_class,
+                                    PROP_HREF,
+                                    g_param_spec_string("href",
+                                                        "Href",
+                                                        "Virtual Machine Href",
+                                                        NULL,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_STATIC_STRINGS));
+    g_object_class_install_property(object_class,
+                                    PROP_NAME,
+                                    g_param_spec_string("name",
+                                                        "Name",
+                                                        "Virtual Machine Name",
+                                                        NULL,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_STATIC_STRINGS));
+    g_object_class_install_property(object_class,
+                                    PROP_STATE,
+                                    g_param_spec_enum("state",
+                                                      "State",
+                                                      "Virtual Machine State",
+                                                      OVIRT_TYPE_VM_STATE,
+                                                      OVIRT_VM_STATE_DOWN,
+                                                      G_PARAM_READWRITE |
+                                                      G_PARAM_STATIC_STRINGS));
+    g_object_class_install_property(object_class,
+                                    PROP_DISPLAY,
+                                    g_param_spec_object("display",
+                                                        "Display",
+                                                        "Virtual Machine Display Information",
+                                                        OVIRT_TYPE_VM_DISPLAY,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_STATIC_STRINGS));
+}
+
+static void ovirt_vm_init(G_GNUC_UNUSED OvirtVm *vm)
+{
+    vm->priv = OVIRT_VM_GET_PRIVATE(vm);
+}
+
+OvirtVm *ovirt_vm_new(void)
+{
+    return OVIRT_VM(g_object_new(OVIRT_TYPE_VM, NULL));
+}
diff --git a/src/ovirt-vm.h b/src/ovirt-vm.h
new file mode 100644
index 0000000..7e03853
--- /dev/null
+++ b/src/ovirt-vm.h
@@ -0,0 +1,67 @@
+/*
+ * ovirt-vm.h: oVirt virtual machine
+ *
+ * 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 redhat com>
+ */
+#ifndef __OVIRT_VM_H__
+#define __OVIRT_VM_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define OVIRT_TYPE_VM            (ovirt_vm_get_type ())
+#define OVIRT_VM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), OVIRT_TYPE_VM, OvirtVm))
+#define OVIRT_VM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), OVIRT_TYPE_VM, OvirtVmClass))
+#define OVIRT_IS_VM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OVIRT_TYPE_VM))
+#define OVIRT_IS_VM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OVIRT_TYPE_VM))
+#define OVIRT_VM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), OVIRT_TYPE_VM, OvirtVmClass))
+
+typedef struct _OvirtVm OvirtVm;
+typedef struct _OvirtVmPrivate OvirtVmPrivate;
+typedef struct _OvirtVmClass OvirtVmClass;
+
+struct _OvirtVm
+{
+    GObject parent;
+
+    OvirtVmPrivate *priv;
+
+    /* Do not add fields to this struct */
+};
+
+struct _OvirtVmClass
+{
+    GObjectClass parent_class;
+
+    gpointer padding[20];
+};
+
+
+typedef enum {
+    OVIRT_VM_STATE_DOWN,
+    OVIRT_VM_STATE_UP
+} OvirtVmState;
+
+GType ovirt_vm_get_type(void);
+OvirtVm *ovirt_vm_new(void);
+
+G_END_DECLS
+
+#endif /* __OVIRT_VM_H__ */
-- 
1.7.10.2


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