[libvirt] [libvirt-glib] gconfig: Add API to set domain/pm tree
Christophe Fergeau
cfergeau at redhat.com
Wed Oct 10 10:12:51 UTC 2012
On Tue, Oct 09, 2012 at 11:04:46PM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
>
> 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 at gnome.org>
> + * Christophe Fergeau <cfergeau at redhat.com>
> + */
> +
> +#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)
It's generally indented as
void gvir_config_domain_power_management_set_ram_suspend_enabled(GVirConfigDomainPowerManagement *pm,
gboolean enabled)
in other files even if the first line is more than 80 chars
> +{
> + 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");
We can probably add a gvir_config_object_add_child_with_attribute_type at
some point where you'd pass G_TYPE_BOOLEAN and 'enabled', and this would do
the transformation for you. We can add that next time this would be useful.
> +}
> +
> +void gvir_config_domain_power_management_set_disk_suspend_enabled
> + (GVirConfigDomainPowerManagement *pm, gboolean enabled)
Same comment about indentation
> +{
> + 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 at gnome.org>
> + * Christophe Fergeau <cfergeau at redhat.com>
> + */
> +
> +#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>
I don't think we need to include timer?
> +
> +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;
> +
Looks good otherwise.
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20121010/f04cf322/attachment-0001.sig>
More information about the libvir-list
mailing list