[libvirt-glib] gconfig: Add API to set domain/pm tree

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

 



From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>

API for new domain power management configuration.
---
 libvirt-gconfig/Makefile.am                        |   2 +
 .../libvirt-gconfig-domain-power-management.c      | 101 +++++++++++++++++++++
 .../libvirt-gconfig-domain-power-management.h      |  76 ++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain.c           |  16 ++++
 libvirt-gconfig/libvirt-gconfig-domain.h           |   3 +
 libvirt-gconfig/libvirt-gconfig.h                  |   1 +
 libvirt-gconfig/libvirt-gconfig.sym                |  11 +++
 7 files changed, 210 insertions(+)
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-power-management.c
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-power-management.h

diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index 5a80123..caa62f0 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -50,6 +50,7 @@ GCONFIG_HEADER_FILES = \
 			libvirt-gconfig-domain-memballoon.h \
 			libvirt-gconfig-domain-os.h \
 			libvirt-gconfig-domain-parallel.h \
+			libvirt-gconfig-domain-power-management.h \
 			libvirt-gconfig-domain-redirdev.h \
 			libvirt-gconfig-domain-seclabel.h \
 			libvirt-gconfig-domain-serial.h \
@@ -121,6 +122,7 @@ GCONFIG_SOURCE_FILES = \
 			libvirt-gconfig-domain-memballoon.c \
 			libvirt-gconfig-domain-os.c \
 			libvirt-gconfig-domain-parallel.c \
+			libvirt-gconfig-domain-power-management.c \
 			libvirt-gconfig-domain-redirdev.c \
 			libvirt-gconfig-domain-seclabel.c \
 			libvirt-gconfig-domain-serial.c \
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-power-management.c b/libvirt-gconfig/libvirt-gconfig-domain-power-management.c
new file mode 100644
index 0000000..c6b1962
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-power-management.c
@@ -0,0 +1,101 @@
+/*
+ * libvirt-gconfig-domain-power-management.c: libvirt domain power management configuration
+ *
+ * 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
+ *
+ * Authors:
+ *
+ * Zeeshan Ali (Khattak) <zeeshanak@xxxxxxxxx>
+ * Christophe Fergeau <cfergeau@xxxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-private.h"
+
+#define GVIR_CONFIG_DOMAIN_POWER_MANAGEMENT_GET_PRIVATE(obj) \
+        (G_TYPE_INSTANCE_GET_PRIVATE((obj),                  \
+         GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT,           \
+         GVirConfigDomainPowerManagementPrivate))
+
+struct _GVirConfigDomainPowerManagementPrivate
+{
+    gboolean unused;
+};
+
+G_DEFINE_TYPE(GVirConfigDomainPowerManagement,
+              gvir_config_domain_power_management,
+              GVIR_CONFIG_TYPE_OBJECT);
+
+static void gvir_config_domain_power_management_class_init
+        (GVirConfigDomainPowerManagementClass *klass)
+{
+    g_type_class_add_private(klass, sizeof(GVirConfigDomainPowerManagementPrivate));
+}
+
+
+static void
+gvir_config_domain_power_management_init(GVirConfigDomainPowerManagement *pm)
+{
+    g_debug("Init GVirConfigDomainPowerManagement=%p", pm);
+
+    pm->priv = GVIR_CONFIG_DOMAIN_POWER_MANAGEMENT_GET_PRIVATE(pm);
+}
+
+
+GVirConfigDomainPowerManagement *gvir_config_domain_power_management_new(void)
+{
+    GVirConfigObject *object;
+
+    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT,
+                                    "pm", NULL);
+    return GVIR_CONFIG_DOMAIN_POWER_MANAGEMENT(object);
+}
+
+GVirConfigDomainPowerManagement *
+gvir_config_domain_power_management_new_from_xml(const gchar *xml,
+                                                 GError **error)
+{
+    GVirConfigObject *object;
+
+    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT,
+                                             "pm", NULL, xml, error);
+    return GVIR_CONFIG_DOMAIN_POWER_MANAGEMENT(object);
+}
+
+void gvir_config_domain_power_management_set_ram_suspend_enabled
+        (GVirConfigDomainPowerManagement *pm, gboolean enabled)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_POWER_MANAGEMENT(pm));
+
+    gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(pm),
+                                                "suspend-to-ram",
+                                                "enabled",
+                                                enabled? "yes" : "no");
+}
+
+void gvir_config_domain_power_management_set_disk_suspend_enabled
+        (GVirConfigDomainPowerManagement *pm, gboolean enabled)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_POWER_MANAGEMENT(pm));
+
+    gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(pm),
+                                                "suspend-to-disk",
+                                                "enabled",
+                                                enabled? "yes" : "no");
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-power-management.h b/libvirt-gconfig/libvirt-gconfig-domain-power-management.h
new file mode 100644
index 0000000..1d9b3b7
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-power-management.h
@@ -0,0 +1,76 @@
+/*
+ * libvirt-gconfig-domain-power-management.h: libvirt domain power management configuration
+ *
+ * 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
+ *
+ * Zeeshan Ali (Khattak) <zeeshanak@xxxxxxxxx>
+ * Christophe Fergeau <cfergeau@xxxxxxxxxx>
+ */
+
+#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
+#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
+#endif
+
+#ifndef __LIBVIRT_GCONFIG_DOMAIN_POWER_MANAGEMENT_H__
+#define __LIBVIRT_GCONFIG_DOMAIN_POWER_MANAGEMENT_H__
+
+#include <libvirt-gconfig/libvirt-gconfig-domain-timer.h>
+
+G_BEGIN_DECLS
+
+#define GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT            (gvir_config_domain_power_management_get_type ())
+#define GVIR_CONFIG_DOMAIN_POWER_MANAGEMENT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT, GVirConfigDomainPowerManagement))
+#define GVIR_CONFIG_DOMAIN_POWER_MANAGEMENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT, GVirConfigDomainPowerManagementClass))
+#define GVIR_CONFIG_IS_DOMAIN_POWER_MANAGEMENT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT))
+#define GVIR_CONFIG_IS_DOMAIN_POWER_MANAGEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT))
+#define GVIR_CONFIG_DOMAIN_POWER_MANAGEMENT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_POWER_MANAGEMENT, GVirConfigDomainPowerManagementClass))
+
+typedef struct _GVirConfigDomainPowerManagement GVirConfigDomainPowerManagement;
+typedef struct _GVirConfigDomainPowerManagementPrivate GVirConfigDomainPowerManagementPrivate;
+typedef struct _GVirConfigDomainPowerManagementClass GVirConfigDomainPowerManagementClass;
+
+struct _GVirConfigDomainPowerManagement
+{
+    GVirConfigObject parent;
+
+    GVirConfigDomainPowerManagementPrivate *priv;
+
+    /* Do not add fields to this struct */
+};
+
+struct _GVirConfigDomainPowerManagementClass
+{
+    GVirConfigObjectClass parent_class;
+
+    gpointer padding[20];
+};
+
+GType gvir_config_domain_power_management_get_type(void);
+
+GVirConfigDomainPowerManagement *gvir_config_domain_power_management_new(void);
+GVirConfigDomainPowerManagement *
+gvir_config_domain_power_management_new_from_xml(const gchar *xml,
+                                                 GError **error);
+void gvir_config_domain_power_management_set_ram_suspend_enabled
+        (GVirConfigDomainPowerManagement *pm, gboolean enabled);
+void gvir_config_domain_power_management_set_disk_suspend_enabled
+        (GVirConfigDomainPowerManagement *pm, gboolean enabled);
+
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_DOMAIN_POWER_MANAGEMENT_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index e679e3a..e664351 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -804,3 +804,19 @@ void gvir_config_domain_set_cpu(GVirConfigDomain *domain,
                                       "cpu",
                                       GVIR_CONFIG_OBJECT(cpu));
 }
+
+/**
+ * gvir_config_domain_set_power_management:
+ * @domain: a #GVirConfigDomain
+ * @pm: (allow-none): a #GVirPowerManagement instance
+ */
+void gvir_config_domain_set_power_management(GVirConfigDomain *domain,
+                                             GVirConfigDomainPowerManagement *pm)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN(domain));
+    g_return_if_fail(pm != NULL || GVIR_CONFIG_IS_DOMAIN_POWER_MANAGEMENT(pm));
+
+    gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(domain),
+                                      "pm",
+                                      GVIR_CONFIG_OBJECT(pm));
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h
index a7bd73b..3a7be12 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain.h
@@ -32,6 +32,7 @@
 #include <libvirt-gconfig/libvirt-gconfig-domain-device.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-seclabel.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-cpu.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-power-management.h>
 
 G_BEGIN_DECLS
 
@@ -143,6 +144,8 @@ gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
 GVirConfigDomainCpu *gvir_config_domain_get_cpu(GVirConfigDomain *domain);
 void gvir_config_domain_set_cpu(GVirConfigDomain *domain,
                                 GVirConfigDomainCpu *cpu);
+void gvir_config_domain_set_power_management(GVirConfigDomain *domain,
+                                             GVirConfigDomainPowerManagement *pm);
 
 G_END_DECLS
 
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
index 4b5ccbd..0428259 100644
--- a/libvirt-gconfig/libvirt-gconfig.h
+++ b/libvirt-gconfig/libvirt-gconfig.h
@@ -67,6 +67,7 @@
 #include <libvirt-gconfig/libvirt-gconfig-domain-memballoon.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-os.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-parallel.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-power-management.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-redirdev.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-seclabel.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-serial.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 2ec2e80..c19cd79 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -472,4 +472,15 @@ LIBVIRT_GCONFIG_0.1.3 {
 	gvir_config_domain_graphics_vnc_set_socket;
 } LIBVIRT_GCONFIG_0.1.0;
 
+LIBVIRT_GCONFIG_0.1.4 {
+  global:
+	gvir_config_domain_power_management_get_type;
+	gvir_config_domain_power_management_new;
+	gvir_config_domain_power_management_new_from_xml;
+	gvir_config_domain_power_management_set_ram_suspend_enabled;
+	gvir_config_domain_power_management_set_disk_suspend_enabled;
+
+	gvir_config_domain_set_power_management;
+} LIBVIRT_GCONFIG_0.1.3;
+
 # .... define new API here using predicted next version number ....
-- 
1.7.12.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]