On Wed, May 09, 2012 at 04:16:15AM +0300, Zeeshan Ali (Khattak) wrote: > From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx> > > Not quite complete but its a good start. > --- > libvirt-gconfig/Makefile.am | 8 + > .../libvirt-gconfig-capabilities-guest-arch.c | 122 +++++++++++++++++ > .../libvirt-gconfig-capabilities-guest-arch.h | 71 ++++++++++ > .../libvirt-gconfig-capabilities-guest-domain.c | 68 ++++++++++ > .../libvirt-gconfig-capabilities-guest-domain.h | 72 ++++++++++ > .../libvirt-gconfig-capabilities-guest-feature.c | 61 +++++++++ > .../libvirt-gconfig-capabilities-guest-feature.h | 67 ++++++++++ > .../libvirt-gconfig-capabilities-guest.c | 139 ++++++++++++++++++++ > .../libvirt-gconfig-capabilities-guest.h | 75 +++++++++++ > libvirt-gconfig/libvirt-gconfig-capabilities.c | 57 ++++++++ > libvirt-gconfig/libvirt-gconfig-capabilities.h | 1 + > libvirt-gconfig/libvirt-gconfig.h | 6 +- > libvirt-gconfig/libvirt-gconfig.sym | 19 +++ > 13 files changed, 765 insertions(+), 1 deletions(-) > create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c > create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h > create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c > create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h > create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c > create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h > create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.c > create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.h > > diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am > index 54899a3..4bc3ee1 100644 > --- a/libvirt-gconfig/Makefile.am > +++ b/libvirt-gconfig/Makefile.am > @@ -15,6 +15,10 @@ GCONFIG_HEADER_FILES = \ > libvirt-gconfig-capabilities-host.h \ > libvirt-gconfig-capabilities-cpu.h \ > libvirt-gconfig-capabilities-cpu-feature.h \ > + libvirt-gconfig-capabilities-guest.h \ > + libvirt-gconfig-capabilities-guest-arch.h \ > + libvirt-gconfig-capabilities-guest-domain.h \ > + libvirt-gconfig-capabilities-guest-feature.h \ > libvirt-gconfig-domain.h \ > libvirt-gconfig-domain-address.h \ > libvirt-gconfig-domain-address-pci.h \ > @@ -78,6 +82,10 @@ GCONFIG_SOURCE_FILES = \ > libvirt-gconfig-capabilities-host.c \ > libvirt-gconfig-capabilities-cpu.c \ > libvirt-gconfig-capabilities-cpu-feature.c \ > + libvirt-gconfig-capabilities-guest.c \ > + libvirt-gconfig-capabilities-guest-arch.c \ > + libvirt-gconfig-capabilities-guest-domain.c \ > + libvirt-gconfig-capabilities-guest-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-guest-arch.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c > new file mode 100644 > index 0000000..fde835b > --- /dev/null > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c > @@ -0,0 +1,122 @@ > +/* > + * libvirt-gconfig-capabilities-cpu-arch.c: libvirt guest architecture capabilities s/cpu/guest > + * > + * 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@xxxxxxxxxx> > + * Daniel P. Berrange <berrange@xxxxxxxxxx> > + */ > + > +#include <config.h> > + > +#include "libvirt-gconfig/libvirt-gconfig.h" > +#include "libvirt-gconfig/libvirt-gconfig-private.h" > + > +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(obj) \ > + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchPrivate)) > + > +struct _GVirConfigCapabilitiesGuestArchPrivate > +{ > + gboolean unused; > +}; > + > +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestArch, gvir_config_capabilities_guest_arch, GVIR_CONFIG_TYPE_OBJECT); > + > +static void gvir_config_capabilities_guest_arch_class_init(GVirConfigCapabilitiesGuestArchClass *klass) > +{ > + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestArchPrivate)); > +} > + > +static void gvir_config_capabilities_guest_arch_init(GVirConfigCapabilitiesGuestArch *conn) usual nit about 'conn' here > +{ > + g_debug("Init GVirConfigCapabilitiesGuestArch=%p", conn); > + > + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(conn); > +} > + > +const gchar * > +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *caps) s/caps/arch > +{ g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL); > + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(caps), > + NULL, > + "name"); > +} > + > +struct GetDomainData { > + GVirConfigXmlDoc *doc; > + const gchar *schema; > + GList *domains; > +}; > + > +static gboolean add_domain(xmlNodePtr node, gpointer opaque) > +{ > + struct GetDomainData* data = (struct GetDomainData*)opaque; > + GVirConfigObject *object; > + > + if (g_strcmp0((const gchar *)node->name, "domain") != 0) > + return TRUE; > + > + object = gvir_config_object_new_from_tree > + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, > + data->doc, > + data->schema, > + node); > + if (object != NULL) > + data->domains = g_list_append(data->domains, object); > + else > + g_debug("Failed to parse %s node", node->name); > + > + return TRUE; > +} > + > +/** > + * gvir_config_capabilities_guest_arch_get_domains: > + * > + * Gets the possible domains for this architecture. > + * > + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestDomain) (transfer full): > + * a newly allocated #GList of #GVirConfigCapabilitiesGuestDomain. > + */ > +GList * > +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *caps) s/caps/arch > +{ > + struct GetDomainData data; > + > + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(caps), NULL); > + > + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); > + g_return_val_if_fail(data.doc != NULL, NULL); > + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); > + g_return_val_if_fail(data.schema != NULL, NULL); I don't think the schema needs to be mandatory > + data.domains = NULL; > + > + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), > + NULL, > + add_domain, > + &data); > + g_clear_object(&data.doc); > + > + return data.domains; > +} > + > +const gchar * > +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *caps) s/caps/arch > +{ g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL); > + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), > + "emulator"); > +} > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h > new file mode 100644 > index 0000000..05bb0e7 > --- /dev/null > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h > @@ -0,0 +1,71 @@ > +/* > + * libvirt-gconfig-capabilities-cpu-arch.h: libvirt guest architecture capabilities s/cpu/guest > + * > + * 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@xxxxxxxxxx> > + * Daniel P. Berrange <berrange@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_CAPABILITIES_GUEST_ARCH_H__ > +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ > + > +G_BEGIN_DECLS > + > +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH (gvir_config_capabilities_guest_arch_get_type ()) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArch)) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) > +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) > +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) > + > +typedef struct _GVirConfigCapabilitiesGuestArch GVirConfigCapabilitiesGuestArch; > +typedef struct _GVirConfigCapabilitiesGuestArchPrivate GVirConfigCapabilitiesGuestArchPrivate; > +typedef struct _GVirConfigCapabilitiesGuestArchClass GVirConfigCapabilitiesGuestArchClass; > + > +struct _GVirConfigCapabilitiesGuestArch > +{ > + GVirConfigObject parent; > + > + GVirConfigCapabilitiesGuestArchPrivate *priv; > + > + /* Do not add fields to this struct */ > +}; > + > +struct _GVirConfigCapabilitiesGuestArchClass > +{ > + GVirConfigObjectClass parent_class; > + > + gpointer padding[20]; > +}; > + > +GType gvir_config_capabilities_guest_arch_get_type(void); > + > +const gchar * > +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *caps); > +GList * > +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *caps); > +const gchar * > +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *caps); s/caps/arch on these 3 lines. > + > +G_END_DECLS > + > +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ */ > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c > new file mode 100644 > index 0000000..eeebfab > --- /dev/null > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c > @@ -0,0 +1,68 @@ > +/* > + * libvirt-gconfig-capabilities-domain.c: libvirt guest domain capabilities missing -guest- > + * > + * 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@xxxxxxxxxx> > + * Daniel P. Berrange <berrange@xxxxxxxxxx> > + */ > + > +#include <config.h> > + > +#include "libvirt-gconfig/libvirt-gconfig.h" > +#include "libvirt-gconfig/libvirt-gconfig-private.h" > + > +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(obj) \ > + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainPrivate)) > + > +struct _GVirConfigCapabilitiesGuestDomainPrivate > +{ > + gboolean unused; > +}; > + > +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestDomain, gvir_config_capabilities_guest_domain, GVIR_CONFIG_TYPE_OBJECT); > + > + > +static void gvir_config_capabilities_guest_domain_class_init(GVirConfigCapabilitiesGuestDomainClass *klass) > +{ > + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestDomainPrivate)); > +} > + > +static void gvir_config_capabilities_guest_domain_init(GVirConfigCapabilitiesGuestDomain *conn) s/conn/domain > +{ > + g_debug("Init GVirConfigCapabilitiesGuestDomain=%p", conn); > + > + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(conn); > +} > + > +const gchar * > +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *caps) s/caps/domain > +{ g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(domain), NULL); > + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "emulator"); > +} > + > +GVirConfigDomainVirtType > +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *caps) s/caps/domain > +{ g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(domain), GVIR_CONFIG_DOMAIN_VIRT_QEMU); > + return gvir_config_object_get_attribute_genum > + (GVIR_CONFIG_OBJECT(caps), > + NULL, > + "type", > + GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, > + GVIR_CONFIG_DOMAIN_VIRT_QEMU); > +} > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h > new file mode 100644 > index 0000000..c80bde6 > --- /dev/null > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h > @@ -0,0 +1,72 @@ > +/* > + * libvirt-gconfig-capabilities-domain.h: libvirt guest domain capabilities Missing -guest- > + * > + * 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@xxxxxxxxxx> > + * Daniel P. Berrange <berrange@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_CAPABILITIES_GUEST_DOMAIN_H__ > +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ > + > +#include "libvirt-gconfig-domain.h" > + > +G_BEGIN_DECLS > + > +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN (gvir_config_capabilities_guest_domain_get_type ()) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomain)) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) > +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) > +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) > + > +typedef struct _GVirConfigCapabilitiesGuestDomain GVirConfigCapabilitiesGuestDomain; > +typedef struct _GVirConfigCapabilitiesGuestDomainPrivate GVirConfigCapabilitiesGuestDomainPrivate; > +typedef struct _GVirConfigCapabilitiesGuestDomainClass GVirConfigCapabilitiesGuestDomainClass; > + > +struct _GVirConfigCapabilitiesGuestDomain > +{ > + GVirConfigObject parent; > + > + GVirConfigCapabilitiesGuestDomainPrivate *priv; > + > + /* Do not add fields to this struct */ > +}; > + > +struct _GVirConfigCapabilitiesGuestDomainClass > +{ > + GVirConfigObjectClass parent_class; > + > + gpointer padding[20]; > +}; > + > +GType gvir_config_capabilities_guest_domain_get_type(void); > + > +const gchar * > +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *caps); > + > +GVirConfigDomainVirtType > +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *caps); s/caps/domain > + > +G_END_DECLS > + > +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ */ > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c > new file mode 100644 > index 0000000..1554f5a > --- /dev/null > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c > @@ -0,0 +1,61 @@ > +/* > + * libvirt-gconfig-capabilities-guest-feature.c: libvirt guest 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@xxxxxxxxxx> > + * Daniel P. Berrange <berrange@xxxxxxxxxx> > + */ > + > +#include <config.h> > + > +#include "libvirt-gconfig/libvirt-gconfig.h" > +#include "libvirt-gconfig/libvirt-gconfig-private.h" > + > +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(obj) \ > + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeaturePrivate)) > + > +struct _GVirConfigCapabilitiesGuestFeaturePrivate > +{ > + gboolean unused; > +}; > + > +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestFeature, gvir_config_capabilities_guest_feature, GVIR_CONFIG_TYPE_OBJECT); > + > +static void gvir_config_capabilities_guest_feature_class_init(GVirConfigCapabilitiesGuestFeatureClass *klass) > +{ > + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestFeaturePrivate)); > +} > + > +static void gvir_config_capabilities_guest_feature_init(GVirConfigCapabilitiesGuestFeature *feature) > +{ > + g_debug("Init GVirConfigCapabilitiesGuestFeature=%p", feature); > + > + feature->priv = GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(feature); > +} > + > +const gchar * > +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *caps) s/caps/feature > +{ > + xmlNodePtr node; g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE(caps), NULL); > + > + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); > + g_return_val_if_fail(node != NULL, NULL); > + > + return (const gchar *)node->name; > +} I'd have added a gvir_config_object_get_node_name() method. > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h > new file mode 100644 > index 0000000..46e4f36 > --- /dev/null > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h > @@ -0,0 +1,67 @@ > +/* > + * libvirt-gconfig-capabilities-guest-feature.h: libvirt guest 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@xxxxxxxxxx> > + * Daniel P. Berrange <berrange@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_CAPABILITIES_GUEST_FEATURE_H__ > +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ > + > +G_BEGIN_DECLS > + > +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE (gvir_config_capabilities_guest_feature_get_type ()) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeature)) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) > +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) > +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) > + > +typedef struct _GVirConfigCapabilitiesGuestFeature GVirConfigCapabilitiesGuestFeature; > +typedef struct _GVirConfigCapabilitiesGuestFeaturePrivate GVirConfigCapabilitiesGuestFeaturePrivate; > +typedef struct _GVirConfigCapabilitiesGuestFeatureClass GVirConfigCapabilitiesGuestFeatureClass; > + > +struct _GVirConfigCapabilitiesGuestFeature > +{ > + GVirConfigObject parent; > + > + GVirConfigCapabilitiesGuestFeaturePrivate *priv; > + > + /* Do not add fields to this struct */ > +}; > + > +struct _GVirConfigCapabilitiesGuestFeatureClass > +{ > + GVirConfigObjectClass parent_class; > + > + gpointer padding[20]; > +}; > + > +GType gvir_config_capabilities_guest_feature_get_type(void); > + > +const gchar * > +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *caps); s/caps/feature > + > +G_END_DECLS > + > +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ */ > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c > new file mode 100644 > index 0000000..5d1262b > --- /dev/null > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c > @@ -0,0 +1,139 @@ > +/* > + * libvirt-gconfig-capabilities-guest.c: libvirt guest 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@xxxxxxxxxx> > + * Daniel P. Berrange <berrange@xxxxxxxxxx> > + */ > + > +#include <config.h> > + > +#include "libvirt-gconfig/libvirt-gconfig.h" > +#include "libvirt-gconfig/libvirt-gconfig-private.h" > + > +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(obj) \ > + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestPrivate)) > + > +struct _GVirConfigCapabilitiesGuestPrivate > +{ > + gboolean unused; > +}; > + > +G_DEFINE_TYPE(GVirConfigCapabilitiesGuest, gvir_config_capabilities_guest, GVIR_CONFIG_TYPE_OBJECT); > + > + > +static void gvir_config_capabilities_guest_class_init(GVirConfigCapabilitiesGuestClass *klass) > +{ > + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestPrivate)); > +} > + > +static void gvir_config_capabilities_guest_init(GVirConfigCapabilitiesGuest *conn) s/conn/caps > +{ > + g_debug("Init GVirConfigCapabilitiesGuest=%p", conn); > + > + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(conn); > +} > + > +GVirConfigDomainOsType I don't think this is the right return type, this enum currently translates to "hvm", "linux" and "exe", while "xen" and "uml" should also be valid (re-reading libvirt source code, it might have been better to use a string instead of this enum). The only valid values for guest caps os type are "xen" and "hvm" > +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps) > +{ > + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), -1); s/-1/...OS_TYPE_LINUX > + > + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(caps), > + "os_type", > + GVIR_CONFIG_TYPE_DOMAIN_OS_TYPE, > + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); > +} > + > +/** > + * gvir_config_capabilities_guest_get_arch: > + * > + * Gets the CPU architecture capabilities of the guest. > + * > + * Returns: (transfer full): a new #GVirConfigCapabilitiesGuestArch. > + */ > +GVirConfigCapabilitiesGuestArch * > +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *caps) > +{ > + GVirConfigObject *object; > + > + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); > + > + object = gvir_config_object_get_child_with_type > + (GVIR_CONFIG_OBJECT(caps), > + "arch", > + GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH); > + > + return GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(object); > +} > + > +struct GetFeatureData { > + GVirConfigXmlDoc *doc; > + const gchar *schema; > + GList *features; > +}; > + > +static gboolean add_feature(xmlNodePtr node, gpointer opaque) > +{ > + struct GetFeatureData* data = (struct GetFeatureData*)opaque; > + GVirConfigObject *object; > + > + object = gvir_config_object_new_from_tree > + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, > + data->doc, > + data->schema, > + node); > + if (object != NULL) > + data->features = g_list_append(data->features, object); > + else > + g_debug("Failed to parse %s node", node->name); > + > + return TRUE; > +} > + > +/** > + * gvir_config_capabilities_guest_get_features: > + * > + * Gets the CPU features for this guest. > + * > + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestFeature) (transfer full): > + * a newly allocated #GList of #GVirConfigCapabilitiesGuestFeature. > + */ > +GList * > +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *caps) > +{ > + struct GetFeatureData data; > + > + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); > + > + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); > + g_return_val_if_fail(data.doc != NULL, NULL); > + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); > + g_return_val_if_fail(data.schema != NULL, NULL); same here, I wouldn't bail out if schema is NULL. If you want to keep it, you need to switch the g_object_get and the _get_schema if you don't want to leak data.doc. > + data.features = NULL; > + > + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), > + "features", > + add_feature, > + &data); > + > + g_clear_object(&data.doc); > + > + return data.features; > +} > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h > new file mode 100644 > index 0000000..b75d82f > --- /dev/null > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h > @@ -0,0 +1,75 @@ > +/* > + * libvirt-gconfig-capabilities-guest.h: libvirt guest 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@xxxxxxxxxx> > + * Daniel P. Berrange <berrange@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_CAPABILITIES_GUEST_H__ > +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ > + > +#include "libvirt-gconfig-domain-os.h" > +#include "libvirt-gconfig-capabilities-guest-arch.h" > + > +G_BEGIN_DECLS > + > +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST (gvir_config_capabilities_guest_get_type ()) > +#define GVIR_CONFIG_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuest)) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) > +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) > +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) > +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) > + > +typedef struct _GVirConfigCapabilitiesGuest GVirConfigCapabilitiesGuest; > +typedef struct _GVirConfigCapabilitiesGuestPrivate GVirConfigCapabilitiesGuestPrivate; > +typedef struct _GVirConfigCapabilitiesGuestClass GVirConfigCapabilitiesGuestClass; > + > +struct _GVirConfigCapabilitiesGuest > +{ > + GVirConfigObject parent; > + > + GVirConfigCapabilitiesGuestPrivate *priv; > + > + /* Do not add fields to this struct */ > +}; > + > +struct _GVirConfigCapabilitiesGuestClass > +{ > + GVirConfigObjectClass parent_class; > + > + gpointer padding[20]; > +}; > + > +GType gvir_config_capabilities_guest_get_type(void); > + > +GVirConfigDomainOsType > +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps); > + > +GVirConfigCapabilitiesGuestArch * > +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *caps); > +GList * > +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *caps); > + > +G_END_DECLS > + > +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ */ > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c > index 0bba874..debee83 100644 > --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c > @@ -94,3 +94,60 @@ gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) > > return GVIR_CONFIG_CAPABILITIES_HOST(object); > } > + > +struct GetGuestData { > + GVirConfigXmlDoc *doc; > + const gchar *schema; > + GList *guests; > +}; > + > +static gboolean add_guest(xmlNodePtr node, gpointer opaque) > +{ > + struct GetGuestData* data = (struct GetGuestData*)opaque; > + GVirConfigObject *object; > + > + if (g_strcmp0((const gchar *)node->name, "guest") != 0) > + return TRUE; > + > + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, > + data->doc, > + data->schema, > + node); > + if (object != NULL) > + data->guests = g_list_append(data->guests, object); > + else > + g_debug("Failed to parse %s node", node->name); > + > + return TRUE; > +} > + > +/** > + * gvir_config_capabilities_get_guests: > + * > + * Gets the list of guest capabilities. > + * > + * Returns: (element-type LibvirtGConfig.CapabilitiesGuest) (transfer full): > + * a newly allocated #GList of #GVirConfigCapabilitiesGuest. > + */ > +GList * > +gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps) > +{ > + struct GetGuestData data; > + > + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); > + > + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); > + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); > + g_return_val_if_fail(data.schema != NULL, NULL); Usual comment about this test > + data.guests = NULL; > + > + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), > + NULL, > + add_guest, > + &data); > + > + if (data.doc != NULL) > + g_object_unref(G_OBJECT(data.doc)); You used g_clear_object in the other similar functions when you knew for sure that data.doc != NULL, but here you use g_object_unref when it might be NULL? I would have used g_object_unref everywhere, but I'm fine with g_clear_object too as long as things are consistent. > + > + return data.guests; > +} > diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h > index 2ec8369..2e373c9 100644 > --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h > +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h > @@ -65,6 +65,7 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, > GError **error); > GVirConfigCapabilitiesHost * > gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); > +GList *gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps); > > G_END_DECLS > > diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h > index f9be83f..1201eb8 100644 > --- a/libvirt-gconfig/libvirt-gconfig.h > +++ b/libvirt-gconfig/libvirt-gconfig.h > @@ -29,8 +29,12 @@ > #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-cpu-feature.h> > +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h> > +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h> > +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h> > +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h> > #include <libvirt-gconfig/libvirt-gconfig-capabilities-host.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 7d015f5..709f97f 100644 > --- a/libvirt-gconfig/libvirt-gconfig.sym > +++ b/libvirt-gconfig/libvirt-gconfig.sym > @@ -380,6 +380,7 @@ LIBVIRT_GCONFIG_0.0.9 { > gvir_config_domain_os_get_boot_devices; > > gvir_config_capabilities_get_host; > + gvir_config_capabilities_get_guests; > > gvir_config_capabilities_cpu_get_type; > gvir_config_capabilities_cpu_get_arch; > @@ -388,6 +389,24 @@ LIBVIRT_GCONFIG_0.0.9 { > gvir_config_capabilities_cpu_feature_get_type; > gvir_config_capabilities_cpu_feature_get_name; > > + gvir_config_capabilities_guest_get_type; > + gvir_config_capabilities_guest_get_arch; > + gvir_config_capabilities_guest_get_features; > + gvir_config_capabilities_guest_get_os_type; > + gvir_config_capabilities_guest_new_from_tree; This symbol does not exist > + > + gvir_config_capabilities_guest_arch_get_type; > + gvir_config_capabilities_guest_arch_get_domains; > + gvir_config_capabilities_guest_arch_get_emulator; > + gvir_config_capabilities_guest_arch_get_name; > + > + gvir_config_capabilities_guest_domain_get_type; > + gvir_config_capabilities_guest_domain_get_emulator; > + gvir_config_capabilities_guest_domain_get_virt_type; > + > + gvir_config_capabilities_guest_feature_get_type; > + gvir_config_capabilities_guest_feature_get_name; > + Christophe > gvir_config_capabilities_host_get_type; > gvir_config_capabilities_host_get_uuid; > gvir_config_capabilities_host_get_cpu; > -- > 1.7.7.6 > > -- > libvir-list mailing list > libvir-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libvir-list
Attachment:
pgpS8x9OKcjUy.pgp
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list