[libvirt] [libvirt-glib 2/3] Add host capabilities API
Christophe Fergeau
cfergeau at redhat.com
Wed May 2 14:25:43 UTC 2012
On Tue, May 01, 2012 at 08:30:39PM +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 | 11 ++-
> ...virt-gconfig-capabilities-cpu-feature-private.h | 39 ++++++
> .../libvirt-gconfig-capabilities-cpu-feature.c | 77 ++++++++++++
> .../libvirt-gconfig-capabilities-cpu-feature.h | 67 ++++++++++
> .../libvirt-gconfig-capabilities-cpu-private.h | 39 ++++++
> libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c | 127 ++++++++++++++++++++
> libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h | 69 +++++++++++
> .../libvirt-gconfig-capabilities-host-private.h | 39 ++++++
> .../libvirt-gconfig-capabilities-host.c | 98 +++++++++++++++
> .../libvirt-gconfig-capabilities-host.h | 70 +++++++++++
> libvirt-gconfig/libvirt-gconfig-capabilities.c | 27 ++++
> libvirt-gconfig/libvirt-gconfig-capabilities.h | 3 +-
> libvirt-gconfig/libvirt-gconfig-private.h | 3 +
> libvirt-gconfig/libvirt-gconfig.h | 3 +
> libvirt-gconfig/libvirt-gconfig.sym | 13 ++
> 15 files changed, 683 insertions(+), 2 deletions(-)
> create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h
> 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-private.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-private.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..9bd0df8 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 \
> @@ -67,11 +70,17 @@ noinst_HEADERS = \
> libvirt-gconfig-domain-device-private.h \
> libvirt-gconfig-helpers-private.h \
> libvirt-gconfig-object-private.h \
> - libvirt-gconfig-xml-doc.h
> + libvirt-gconfig-xml-doc.h \
> + libvirt-gconfig-capabilities-host-private.h \
> + libvirt-gconfig-capabilities-cpu-private.h \
> + libvirt-gconfig-capabilities-cpu-feature-private.h
I'd keep this one ordered alphabetically
> 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-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h
> new file mode 100644
> index 0000000..d99e374
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h
> @@ -0,0 +1,39 @@
> +/*
> + * libvirt-gconfig-capabilities-cpu-feature-private.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
This is not really useful as -private files will never be included from
libvirt-gconfig.h, just drop it (and we'll have to fix
libvirt-gconfig-helpers-private.h as well). For what it's worth, for the
device/... _new_from_tree methods I've been lazy and I've grouped them in
the same -private file, but I'm fine with a separate file per class.
> +
> +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_PRIVATE_H__
> +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_PRIVATE_H__
> +
> +G_BEGIN_DECLS
> +
> +GVirConfigCapabilitiesCPUFeature *
> +gvir_config_capabilities_cpu_feature_new_from_tree(GVirConfigXmlDoc *doc,
> + xmlNodePtr tree);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_PRIVATE_H__ */
> 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..d7f02c4
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c
> @@ -0,0 +1,77 @@
> +/*
> + * 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))
I've spelt 3 letter acronyms "Xml" instead of XML when using camel case
spelling, I'd rather use Cpu instead of cpu here too
> +
> +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 *conn)
s/conn/feature (not your fault, this c&p error is present everywhere)
> +{
> + g_debug("Init GVirConfigCapabilitiesCPUFeature=%p", conn);
> +
> + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(conn);
> +}
> +
> +G_GNUC_INTERNAL GVirConfigCapabilitiesCPUFeature *
> +gvir_config_capabilities_cpu_feature_new_from_tree(GVirConfigXmlDoc *doc,
> + xmlNodePtr tree)
> +{
> + GVirConfigObject *object;
> +
> + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE,
> + doc,
> + NULL,
> + tree);
> +
> + return GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(object);
> +}
> +
> +const gchar *
> +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCPUFeature *caps)
> +{
> + xmlNodePtr node;
> +
> + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps));
> +
> + if (g_strcmp0((const gchar *)node->name, "feature") == 0)
> + return gvir_config_xml_get_attribute_content(node, "name");
> + else
> + return (const gchar *)node->name;
This "if" is needed because we can have <features><foo/></features> VS
<feature name="foo">? This deserves a comment explaining why we do this
test. Having a per-feature GVirConfigObject seems overkill since it will
only be a string wrapper, and a GVirConfigObject wrapping just a string
with no node name identifying the type of the node is unusual.
Not having this class, and doing the parsing directly from
gvir_config_capabilities_cpu_get_features would allow to remove it.
GVirConfigDomain can also have a <features> node, the strings mentioned
above can be wrapped in a GVirConfigCpuFeatures object (or just a typedef?)
instead of in a raw GList, and then we can factor the GVirConfigDomain and
GVirConfigCapabilitiesCpu code somehow.
> +}
> 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..b96c9f1
> --- /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;
If we keep this, Cpu
> +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 *caps);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h
> new file mode 100644
> index 0000000..beebc3b
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h
> @@ -0,0 +1,39 @@
> +/*
> + * libvirt-gconfig-capabilities-cpu-private.h: libvirt CPU capabilities
> + *
> + * Copyright (C) 2010-2011 Red Hat, Inc.
2012
> + *
> + * 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
Not needed
> +
> +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__
> +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__
> +
> +G_BEGIN_DECLS
> +
> +GVirConfigCapabilitiesCPU *
> +gvir_config_capabilities_cpu_new_from_tree(GVirConfigXmlDoc *doc,
> + xmlNodePtr tree);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_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..f1488a9
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c
> @@ -0,0 +1,127 @@
> +/*
> + * 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
Cpu
> +{
> + 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 *conn)
s/conn/cpu
> +{
> + g_debug("Init GVirConfigCapabilitiesCPU=%p", conn);
> +
> + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(conn);
> +}
> +
> +G_GNUC_INTERNAL GVirConfigCapabilitiesCPU *
> +gvir_config_capabilities_cpu_new_from_tree(GVirConfigXmlDoc *doc,
> + xmlNodePtr tree)
> +{
> + GVirConfigObject *object;
> +
I don't think many _new_from_tree functions are currently doing that, but
I'd add a
g_return_val_if_fail(!GVIR_CONFIG_IS_XML_DOC(doc), NULL);
g_return_val_if_fail(g_strcmp0(tree->name, "cpu") == 0, NULL);
> + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU,
> + doc,
> + NULL,
> + tree);
> +
> + return GVIR_CONFIG_CAPABILITIES_CPU(object);
> +}
> +
> +const gchar *
> +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCPU *caps)
> +{
> + xmlNodePtr node;
> +
> + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps));
> +
> + return gvir_config_xml_get_child_element_content(node, "arch");
> +}
This is gvir_config_object_get_node_content
> +
> +struct GetFeatureData {
> + GVirConfigXmlDoc *doc;
> + GList *features;
> +};
> +
> +static gboolean add_feature(xmlNodePtr node, gpointer opaque)
> +{
> + struct GetFeatureData* data = (struct GetFeatureData*)opaque;
> + GVirConfigCapabilitiesCPUFeature *feature;
> +
> + if (g_strcmp0((const gchar *)node->name, "feature") != 0)
> + return TRUE;
Is it expected that "features" nodes are ignored? Are the 2 kind of nodes
(feature/features) two different things that we want to expose differently
in the API?
> +
> + feature = gvir_config_capabilities_cpu_feature_new_from_tree(data->doc, 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 *caps)
> +{
> + struct GetFeatureData data;
> + xmlNodePtr node;
> +
> + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(caps), NULL);
> +
> + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps));
> + g_return_val_if_fail(node != NULL, NULL);
> +
> + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL);
> + data.features = NULL;
> +
> + gvir_config_xml_foreach_child(node, add_feature, &data);
gvir_config_object_foreach_child
> +
> + 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..abad676
> --- /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;
Cpu
> +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 *caps);
> +GList *
> +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCPU *caps);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h
> new file mode 100644
> index 0000000..732b64c
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h
> @@ -0,0 +1,39 @@
> +/*
> + * libvirt-gconfig-capabilities-host-private.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_PRIVATE_H__
> +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_PRIVATE_H__
> +
> +G_BEGIN_DECLS
> +
> +GVirConfigCapabilitiesHost *
> +gvir_config_capabilities_host_new_from_tree(GVirConfigXmlDoc *doc,
> + xmlNodePtr tree);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_PRIVATE_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..becaf6d
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c
> @@ -0,0 +1,98 @@
> +/*
> + * 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 *conn)
> +{
> + g_debug("Init GVirConfigCapabilitiesHost=%p", conn);
> +
> + conn->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(conn);
> +}
> +
> +G_GNUC_INTERNAL GVirConfigCapabilitiesHost *
> +gvir_config_capabilities_host_new_from_tree(GVirConfigXmlDoc *doc,
> + xmlNodePtr tree)
> +{
> + GVirConfigObject *object;
> +
> + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_HOST,
> + doc,
> + NULL,
> + tree);
> +
> + return GVIR_CONFIG_CAPABILITIES_HOST(object);
> +}
> +
> +const gchar *
> +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps)
> +{
> + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "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 *caps)
> +{
> + GVirConfigXmlDoc *doc;
> + xmlNodePtr node;
> +
> + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(caps), NULL);
> +
> + g_object_get(G_OBJECT(caps), "doc", &doc, NULL);
> +
> + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps));
> + g_return_val_if_fail(node != NULL, NULL);
> +
> + node = gvir_config_xml_get_element(node, "cpu", NULL);
> + g_return_val_if_fail(node != NULL, NULL);
Is it a mandatory element in the capabilities XML? If not, a
if (node == NULL) {
return NULL;
}
is better
> +
> + return gvir_config_capabilities_cpu_new_from_tree(doc, node);
> +}
> +
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h
> new file mode 100644
> index 0000000..34ee19e
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h
> @@ -0,0 +1,70 @@
> +/*
> + * 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__
> +
> +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 *caps);
> +
> +GVirConfigCapabilitiesCPU *
> +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps);
> +
> +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 3d9d036..9518a30 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,29 @@ 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)
> +{
> + GVirConfigXmlDoc *doc;
> + xmlNodePtr node;
> +
> + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL);
> +
> + g_object_get(G_OBJECT(caps), "doc", &doc, NULL);
> +
> + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps));
> + g_return_val_if_fail(node != NULL, NULL);
> +
> + node = gvir_config_xml_get_element(node, "host", NULL);
> + g_return_val_if_fail(node != NULL, NULL);
> +
> + return gvir_config_capabilities_host_new_from_tree(doc, node);
> +}
This is the same code as gvir_config_capabilities_host_get_cpu, if this
pattern gets repeated often, it will be worth trying to factor it in a
helper function.
> diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h
> index 733886d..18edaf7 100644
> --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h
> +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h
> @@ -56,12 +56,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-private.h b/libvirt-gconfig/libvirt-gconfig-private.h
> index d4df030..845a883 100644
> --- a/libvirt-gconfig/libvirt-gconfig-private.h
> +++ b/libvirt-gconfig/libvirt-gconfig-private.h
> @@ -24,6 +24,9 @@
> #define __LIBVIRT_GCONFIG_PRIVATE_H__
>
> #include <libvirt-gconfig/libvirt-gconfig-domain-device-private.h>
> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h>
> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h>
> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h>
> #include <libvirt-gconfig/libvirt-gconfig-helpers-private.h>
> #include <libvirt-gconfig/libvirt-gconfig-object-private.h>
> #include <libvirt-gconfig/libvirt-gconfig-xml-doc.h>
> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
> index bd16244..b2b7c15 100644
> --- a/libvirt-gconfig/libvirt-gconfig.h
> +++ b/libvirt-gconfig/libvirt-gconfig.h
> @@ -28,6 +28,9 @@
>
> #include <libvirt-gconfig/libvirt-gconfig-main.h>
> #include <libvirt-gconfig/libvirt-gconfig-object.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-capabilities.h>
-capabilities.h comes before -capabilities-cpu-feature.h
> #include <libvirt-gconfig/libvirt-gconfig-domain.h>
> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h>
> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
> index ffeb16b..b1df17b 100644
> --- a/libvirt-gconfig/libvirt-gconfig.sym
> +++ b/libvirt-gconfig/libvirt-gconfig.sym
> @@ -6,6 +6,19 @@ LIBVIRT_GCONFIG_0.0.8 {
> gvir_config_capabilities_get_type;
> gvir_config_capabilities_new;
> gvir_config_capabilities_new_from_xml;
> + gvir_config_capabilities_get_host;
> +
> + gvir_config_capabilities_host_get_type;
> + gvir_config_capabilities_host_new_from_tree;
This should not be exported.
Christophe
> + gvir_config_capabilities_host_get_uuid;
> + gvir_config_capabilities_host_get_cpu;
> +
> + 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_domain_add_device;
> gvir_config_domain_get_type;
> --
> 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/20120502/95b23cbb/attachment-0001.sig>
More information about the libvir-list
mailing list