[libvirt] [libvirt-glib 1/2] Add host capabilities API

Christophe Fergeau cfergeau at redhat.com
Mon May 14 10:01:44 UTC 2012


ACK

On Fri, May 11, 2012 at 04:18:15PM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
> 
> Not quite complete but its a good start.
> ---
>  libvirt-gconfig/Makefile.am                        |    6 +
>  .../libvirt-gconfig-capabilities-cpu-feature.c     |   58 ++++++++++
>  .../libvirt-gconfig-capabilities-cpu-feature.h     |   67 ++++++++++++
>  libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c |  114 ++++++++++++++++++++
>  libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h |   69 ++++++++++++
>  .../libvirt-gconfig-capabilities-host.c            |   80 ++++++++++++++
>  .../libvirt-gconfig-capabilities-host.h            |   72 ++++++++++++
>  libvirt-gconfig/libvirt-gconfig-capabilities.c     |   23 ++++
>  libvirt-gconfig/libvirt-gconfig-capabilities.h     |    5 +-
>  libvirt-gconfig/libvirt-gconfig.h                  |    3 +
>  libvirt-gconfig/libvirt-gconfig.sym                |   13 +++
>  11 files changed, 509 insertions(+), 1 deletions(-)
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.c
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.h
> 
> diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
> index fd32c3d..54899a3 100644
> --- a/libvirt-gconfig/Makefile.am
> +++ b/libvirt-gconfig/Makefile.am
> @@ -12,6 +12,9 @@ GCONFIG_HEADER_FILES = \
>  			libvirt-gconfig-main.h \
>  			libvirt-gconfig-object.h \
>  			libvirt-gconfig-capabilities.h \
> +			libvirt-gconfig-capabilities-host.h \
> +			libvirt-gconfig-capabilities-cpu.h \
> +			libvirt-gconfig-capabilities-cpu-feature.h \
>  			libvirt-gconfig-domain.h \
>  			libvirt-gconfig-domain-address.h \
>  			libvirt-gconfig-domain-address-pci.h \
> @@ -72,6 +75,9 @@ GCONFIG_SOURCE_FILES = \
>  			libvirt-gconfig-object.c \
>  			libvirt-gconfig-main.c \
>  			libvirt-gconfig-capabilities.c \
> +			libvirt-gconfig-capabilities-host.c \
> +			libvirt-gconfig-capabilities-cpu.c \
> +			libvirt-gconfig-capabilities-cpu-feature.c \
>  			libvirt-gconfig-domain.c \
>  			libvirt-gconfig-domain-address.c \
>  			libvirt-gconfig-domain-address-pci.c \
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c
> new file mode 100644
> index 0000000..0c71885
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c
> @@ -0,0 +1,58 @@
> +/*
> + * libvirt-gconfig-capabilities-cpu-feature.c: libvirt CPU feature capabilities
> + *
> + * Copyright (C) 2008 Daniel P. Berrange
> + * Copyright (C) 2010-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 <zeenix at redhat.com>
> + *          Daniel P. Berrange <berrange at redhat.com>
> + */
> +
> +#include <config.h>
> +
> +#include "libvirt-gconfig/libvirt-gconfig.h"
> +#include "libvirt-gconfig/libvirt-gconfig-private.h"
> +
> +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(obj)                         \
> +        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeaturePrivate))
> +
> +struct _GVirConfigCapabilitiesCpuFeaturePrivate
> +{
> +    gboolean unused;
> +};
> +
> +G_DEFINE_TYPE(GVirConfigCapabilitiesCpuFeature, gvir_config_capabilities_cpu_feature, GVIR_CONFIG_TYPE_OBJECT);
> +
> +static void gvir_config_capabilities_cpu_feature_class_init(GVirConfigCapabilitiesCpuFeatureClass *klass)
> +{
> +    g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuFeaturePrivate));
> +}
> +
> +static void gvir_config_capabilities_cpu_feature_init(GVirConfigCapabilitiesCpuFeature *feature)
> +{
> +    g_debug("Init GVirConfigCapabilitiesCpuFeature=%p", feature);
> +
> +    feature->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(feature);
> +}
> +
> +const gchar *
> +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *feature)
> +{
> +    return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(feature),
> +                                            NULL,
> +                                            "name");
> +}
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h
> new file mode 100644
> index 0000000..8bb2f2b
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h
> @@ -0,0 +1,67 @@
> +/*
> + * libvirt-gconfig-capabilities-cpu-feature.h: libvirt CPU feature capabilities
> + *
> + * Copyright (C) 2010-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 <zeenix at redhat.com>
> + *          Daniel P. Berrange <berrange 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_CAPABILITIES_CPU_FEATURE_H__
> +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__
> +
> +G_BEGIN_DECLS
> +
> +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE            (gvir_config_capabilities_cpu_feature_get_type ())
> +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeature))
> +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass))
> +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE))
> +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE))
> +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass))
> +
> +typedef struct _GVirConfigCapabilitiesCpuFeature GVirConfigCapabilitiesCpuFeature;
> +typedef struct _GVirConfigCapabilitiesCpuFeaturePrivate GVirConfigCapabilitiesCpuFeaturePrivate;
> +typedef struct _GVirConfigCapabilitiesCpuFeatureClass GVirConfigCapabilitiesCpuFeatureClass;
> +
> +struct _GVirConfigCapabilitiesCpuFeature
> +{
> +    GVirConfigObject parent;
> +
> +    GVirConfigCapabilitiesCpuFeaturePrivate *priv;
> +
> +    /* Do not add fields to this struct */
> +};
> +
> +struct _GVirConfigCapabilitiesCpuFeatureClass
> +{
> +    GVirConfigObjectClass parent_class;
> +
> +    gpointer padding[20];
> +};
> +
> +GType gvir_config_capabilities_cpu_feature_get_type(void);
> +
> +const gchar *
> +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *feature);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
> new file mode 100644
> index 0000000..e9a3f10
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
> @@ -0,0 +1,114 @@
> +/*
> + * libvirt-gconfig-capabilities-cpu.c: libvirt CPU capabilities
> + *
> + * Copyright (C) 2008 Daniel P. Berrange
> + * Copyright (C) 2010-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 <zeenix at redhat.com>
> + *          Daniel P. Berrange <berrange at redhat.com>
> + */
> +
> +#include <config.h>
> +
> +#include "libvirt-gconfig/libvirt-gconfig.h"
> +#include "libvirt-gconfig/libvirt-gconfig-private.h"
> +
> +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(obj)                         \
> +        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuPrivate))
> +
> +struct _GVirConfigCapabilitiesCpuPrivate
> +{
> +    gboolean unused;
> +};
> +
> +G_DEFINE_TYPE(GVirConfigCapabilitiesCpu, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT);
> +
> +
> +static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCpuClass *klass)
> +{
> +    g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuPrivate));
> +}
> +
> +static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCpu *cpu)
> +{
> +    g_debug("Init GVirConfigCapabilitiesCpu=%p", cpu);
> +
> +    cpu->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(cpu);
> +}
> +
> +const gchar *
> +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *cpu)
> +{
> +    return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(cpu), "arch");
> +}
> +
> +struct GetFeatureData {
> +    GVirConfigXmlDoc *doc;
> +    const gchar *schema;
> +    GList *features;
> +};
> +
> +static gboolean add_feature(xmlNodePtr node, gpointer opaque)
> +{
> +    struct GetFeatureData* data = (struct GetFeatureData*)opaque;
> +    GVirConfigObject *feature;
> +
> +    if (g_strcmp0((const gchar *)node->name, "feature") != 0)
> +        return TRUE;
> +
> +    feature = gvir_config_object_new_from_tree
> +                                (GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE,
> +                                 data->doc,
> +                                 data->schema,
> +                                 node);
> +    if (feature != NULL)
> +        data->features = g_list_append(data->features, feature);
> +    else
> +        g_debug("Failed to parse %s node", node->name);
> +
> +    return TRUE;
> +}
> +
> +/**
> + * gvir_config_capabilities_cpu_get_features:
> + *
> + * Gets the features of this CPU.
> + *
> + * Returns: (element-type LibvirtGConfig.CapabilitiesCpuFeature) (transfer full):
> + * a newly allocated #GList of #GVirConfigCapabilitiesCpuFeature.
> + */
> +GList *
> +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
> +{
> +    struct GetFeatureData data;
> +
> +    g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(cpu), NULL);
> +
> +    data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(cpu));
> +    g_object_get(G_OBJECT(cpu), "doc", &data.doc, NULL);
> +    g_return_val_if_fail(data.doc != NULL, NULL);
> +    data.features = NULL;
> +
> +    gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(cpu),
> +                                     NULL,
> +                                     add_feature,
> +                                     &data);
> +    g_clear_object(&data.doc);
> +
> +    return data.features;
> +}
> +
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
> new file mode 100644
> index 0000000..8b221ae
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h
> @@ -0,0 +1,69 @@
> +/*
> + * libvirt-gconfig-capabilities-cpu.h: libvirt CPU capabilities
> + *
> + * Copyright (C) 2010-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 <zeenix at redhat.com>
> + *          Daniel P. Berrange <berrange 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_CAPABILITIES_CPU_H__
> +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__
> +
> +G_BEGIN_DECLS
> +
> +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU            (gvir_config_capabilities_cpu_get_type ())
> +#define GVIR_CONFIG_CAPABILITIES_CPU(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpu))
> +#define GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass))
> +#define GVIR_CONFIG_IS_CAPABILITIES_CPU(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU))
> +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU))
> +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass))
> +
> +typedef struct _GVirConfigCapabilitiesCpu GVirConfigCapabilitiesCpu;
> +typedef struct _GVirConfigCapabilitiesCpuPrivate GVirConfigCapabilitiesCpuPrivate;
> +typedef struct _GVirConfigCapabilitiesCpuClass GVirConfigCapabilitiesCpuClass;
> +
> +struct _GVirConfigCapabilitiesCpu
> +{
> +    GVirConfigObject parent;
> +
> +    GVirConfigCapabilitiesCpuPrivate *priv;
> +
> +    /* Do not add fields to this struct */
> +};
> +
> +struct _GVirConfigCapabilitiesCpuClass
> +{
> +    GVirConfigObjectClass parent_class;
> +
> +    gpointer padding[20];
> +};
> +
> +GType gvir_config_capabilities_cpu_get_type(void);
> +
> +const gchar *
> +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *cpu);
> +GList *
> +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.c b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c
> new file mode 100644
> index 0000000..47ad0fc
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c
> @@ -0,0 +1,80 @@
> +/*
> + * libvirt-gconfig-capabilities-host.c: libvirt host capabilities
> + *
> + * Copyright (C) 2008 Daniel P. Berrange
> + * Copyright (C) 2010-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 <zeenix at redhat.com>
> + *          Daniel P. Berrange <berrange at redhat.com>
> + */
> +
> +#include <config.h>
> +
> +#include "libvirt-gconfig/libvirt-gconfig.h"
> +#include "libvirt-gconfig/libvirt-gconfig-private.h"
> +
> +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(obj)                         \
> +        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostPrivate))
> +
> +struct _GVirConfigCapabilitiesHostPrivate
> +{
> +    gboolean unused;
> +};
> +
> +G_DEFINE_TYPE(GVirConfigCapabilitiesHost, gvir_config_capabilities_host, GVIR_CONFIG_TYPE_OBJECT);
> +
> +
> +static void gvir_config_capabilities_host_class_init(GVirConfigCapabilitiesHostClass *klass)
> +{
> +    g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesHostPrivate));
> +}
> +
> +static void gvir_config_capabilities_host_init(GVirConfigCapabilitiesHost *host)
> +{
> +    g_debug("Init GVirConfigCapabilitiesHost=%p", host);
> +
> +    host->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(host);
> +}
> +
> +const gchar *
> +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *host)
> +{
> +    return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(host), "uuid");
> +}
> +
> +/**
> + * gvir_config_capabilities_host_get_cpu:
> + *
> + * Gets the CPU capabilities of the host.
> + *
> + * Returns: (transfer full): a new #GVirConfigCapabilitiesCpu.
> + */
> +GVirConfigCapabilitiesCpu *
> +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *host)
> +{
> +    GVirConfigObject *object;
> +
> +    g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(host), NULL);
> +
> +    object = gvir_config_object_get_child_with_type
> +                                (GVIR_CONFIG_OBJECT(host),
> +                                 "cpu",
> +                                 GVIR_CONFIG_TYPE_CAPABILITIES_CPU);
> +
> +    return GVIR_CONFIG_CAPABILITIES_CPU(object);
> +}
> +
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h
> new file mode 100644
> index 0000000..d5e325b
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h
> @@ -0,0 +1,72 @@
> +/*
> + * libvirt-gconfig-capabilities-host.h: libvirt host capabilities
> + *
> + * Copyright (C) 2010-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 <zeenix at redhat.com>
> + *          Daniel P. Berrange <berrange 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_CAPABILITIES_HOST_H__
> +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__
> +
> +#include "libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h"
> +
> +G_BEGIN_DECLS
> +
> +#define GVIR_CONFIG_TYPE_CAPABILITIES_HOST            (gvir_config_capabilities_host_get_type ())
> +#define GVIR_CONFIG_CAPABILITIES_HOST(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHost))
> +#define GVIR_CONFIG_CAPABILITIES_HOST_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass))
> +#define GVIR_CONFIG_IS_CAPABILITIES_HOST(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST))
> +#define GVIR_CONFIG_IS_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST))
> +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass))
> +
> +typedef struct _GVirConfigCapabilitiesHost GVirConfigCapabilitiesHost;
> +typedef struct _GVirConfigCapabilitiesHostPrivate GVirConfigCapabilitiesHostPrivate;
> +typedef struct _GVirConfigCapabilitiesHostClass GVirConfigCapabilitiesHostClass;
> +
> +struct _GVirConfigCapabilitiesHost
> +{
> +    GVirConfigObject parent;
> +
> +    GVirConfigCapabilitiesHostPrivate *priv;
> +
> +    /* Do not add fields to this struct */
> +};
> +
> +struct _GVirConfigCapabilitiesHostClass
> +{
> +    GVirConfigObjectClass parent_class;
> +
> +    gpointer padding[20];
> +};
> +
> +GType gvir_config_capabilities_host_get_type(void);
> +
> +const gchar *
> +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *host);
> +
> +GVirConfigCapabilitiesCpu *
> +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *host);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ */
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c
> index 6fb9af7..43b91e0 100644
> --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c
> @@ -24,6 +24,7 @@
>  #include <config.h>
>  
>  #include "libvirt-gconfig/libvirt-gconfig.h"
> +#include "libvirt-gconfig/libvirt-gconfig-private.h"
>  
>  #define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj)                         \
>          (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES, GVirConfigCapabilitiesPrivate))
> @@ -71,3 +72,25 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml,
>                                               xml, error);
>      return GVIR_CONFIG_CAPABILITIES(object);
>  }
> +
> +/**
> + * gvir_config_capabilities_get_host:
> + *
> + * Gets the host capabilities.
> + *
> + * Returns: (transfer full): a new #GVirConfigCapabilitiesHost.
> + */
> +GVirConfigCapabilitiesHost *
> +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps)
> +{
> +    GVirConfigObject *object;
> +
> +    g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL);
> +
> +    object = gvir_config_object_get_child_with_type
> +                                (GVIR_CONFIG_OBJECT(caps),
> +                                 "host",
> +                                 GVIR_CONFIG_TYPE_CAPABILITIES_HOST);
> +
> +    return GVIR_CONFIG_CAPABILITIES_HOST(object);
> +}
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h
> index 733886d..2ec8369 100644
> --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h
> @@ -27,6 +27,8 @@
>  #ifndef __LIBVIRT_GCONFIG_CAPABILITIES_H__
>  #define __LIBVIRT_GCONFIG_CAPABILITIES_H__
>  
> +#include "libvirt-gconfig/libvirt-gconfig-capabilities-host.h"
> +
>  G_BEGIN_DECLS
>  
>  #define GVIR_CONFIG_TYPE_CAPABILITIES            (gvir_config_capabilities_get_type ())
> @@ -56,12 +58,13 @@ struct _GVirConfigCapabilitiesClass
>      gpointer padding[20];
>  };
>  
> -
>  GType gvir_config_capabilities_get_type(void);
>  
>  GVirConfigCapabilities *gvir_config_capabilities_new(void);
>  GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml,
>                                                                GError **error);
> +GVirConfigCapabilitiesHost *
> +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps);
>  
>  G_END_DECLS
>  
> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
> index bd16244..f9be83f 100644
> --- a/libvirt-gconfig/libvirt-gconfig.h
> +++ b/libvirt-gconfig/libvirt-gconfig.h
> @@ -29,6 +29,9 @@
>  #include <libvirt-gconfig/libvirt-gconfig-main.h>
>  #include <libvirt-gconfig/libvirt-gconfig-object.h>
>  #include <libvirt-gconfig/libvirt-gconfig-capabilities.h>
> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h>
> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h>
> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-address.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h>
> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
> index 7bc9e2d..7d015f5 100644
> --- a/libvirt-gconfig/libvirt-gconfig.sym
> +++ b/libvirt-gconfig/libvirt-gconfig.sym
> @@ -378,6 +378,19 @@ LIBVIRT_GCONFIG_0.0.9 {
>    global:
>  	gvir_config_domain_get_os;
>  	gvir_config_domain_os_get_boot_devices;
> +
> +	gvir_config_capabilities_get_host;
> +
> +	gvir_config_capabilities_cpu_get_type;
> +	gvir_config_capabilities_cpu_get_arch;
> +	gvir_config_capabilities_cpu_get_features;
> +
> +	gvir_config_capabilities_cpu_feature_get_type;
> +	gvir_config_capabilities_cpu_feature_get_name;
> +
> +	gvir_config_capabilities_host_get_type;
> +	gvir_config_capabilities_host_get_uuid;
> +	gvir_config_capabilities_host_get_cpu;
>  } LIBVIRT_GCONFIG_0.0.8;
>  
>  # .... define new API here using predicted next version number ....
> -- 
> 1.7.7.6
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- 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/20120514/06ba02e3/attachment-0001.sig>


More information about the libvir-list mailing list