On Tue, Nov 26, 2013 at 04:16:29PM +0000, Zeeshan Ali (Khattak) wrote: > Add: > > * ability to specificy various variants of an OS under the 'os' XML node. > * API to add and query variants of an OS. An example of the XML in the log would be nice > --- > data/schemas/libosinfo.rng | 13 +++++++++++++ > osinfo/libosinfo.syms | 3 +++ > osinfo/osinfo_loader.c | 38 ++++++++++++++++++++++++++++++++++++++ > osinfo/osinfo_os.c | 37 +++++++++++++++++++++++++++++++++++++ > osinfo/osinfo_os.h | 4 ++++ > 5 files changed, 95 insertions(+) > > diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng > index a504266..cc13982 100644 > --- a/data/schemas/libosinfo.rng > +++ b/data/schemas/libosinfo.rng > @@ -215,6 +215,16 @@ > </interleave> > </define> > > + <define name='variant'> > + <element name='variant'> > + <attribute name='id'> > + </attribute> > + <element name='name'> > + <text/> > + </element> > + </element> > + </define> > + > <define name='devices-rel'> > <element name='devices'> > <zeroOrMore> > @@ -485,6 +495,9 @@ > <ref name='release-status'/> > </optional> > <zeroOrMore> > + <ref name='variant'/> > + </zeroOrMore> > + <zeroOrMore> > <ref name='resources'/> > </zeroOrMore> > <zeroOrMore> > diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms > index a70ac86..528c2a5 100644 > --- a/osinfo/libosinfo.syms > +++ b/osinfo/libosinfo.syms > @@ -448,6 +448,9 @@ LIBOSINFO_0.2.9 { > osinfo_os_get_release_status; > osinfo_release_status_get_type; > > + osinfo_os_add_variant; > + osinfo_os_get_variant_list; > + > osinfo_variant_get_type; > osinfo_variant_get_name; > osinfo_variant_new; > diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c > index bb7e9a4..84dd843 100644 > --- a/osinfo/osinfo_loader.c > +++ b/osinfo/osinfo_loader.c > @@ -859,6 +859,7 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader, > xmlChar *installer = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALLER); > xmlChar *installer_reboots = > xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALLER_REBOOTS); > + xmlChar *variant = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_VARIANT); > const OsinfoEntityKey keys[] = { > { OSINFO_MEDIA_PROP_URL, G_TYPE_STRING }, > { OSINFO_MEDIA_PROP_KERNEL, G_TYPE_STRING }, > @@ -1005,6 +1006,25 @@ static OsinfoTree *osinfo_loader_tree (OsinfoLoader *loader, > return tree; > } > > +static OsinfoVariant *osinfo_loader_variant (OsinfoLoader *loader, > + xmlXPathContextPtr ctxt, > + xmlNodePtr root, > + GError **err) > +{ > + const OsinfoEntityKey keys[] = { > + { OSINFO_VARIANT_PROP_NAME, G_TYPE_STRING }, > + { NULL, G_TYPE_INVALID } > + }; > + > + gchar *id = (gchar *)xmlGetProp(root, BAD_CAST "id"); > + OsinfoVariant *variant= osinfo_variant_new(id); > + xmlFree(id); > + > + osinfo_loader_entity(loader, OSINFO_ENTITY(variant), keys, ctxt, root, err); > + > + return variant; > +} > + > static OsinfoResources *osinfo_loader_resources(OsinfoLoader *loader, > xmlXPathContextPtr ctxt, > xmlNodePtr root, > @@ -1230,6 +1250,24 @@ static void osinfo_loader_os(OsinfoLoader *loader, > > g_free(nodes); > > + nnodes = osinfo_loader_nodeset("./variant", ctxt, &nodes, err); > + if (error_is_set(err)) > + goto cleanup; > + > + for (i = 0 ; i < nnodes ; i++) { > + xmlNodePtr saved = ctxt->node; > + ctxt->node = nodes[i]; > + OsinfoVariant *variant = osinfo_loader_variant(loader, ctxt, nodes[i], err); > + ctxt->node = saved; > + if (error_is_set(err)) > + goto cleanup; > + > + osinfo_os_add_variant (os, variant); > + g_object_unref(G_OBJECT(variant)); > + } > + > + g_free(nodes); > + > nnodes = osinfo_loader_nodeset("./resources", ctxt, &nodes, err); > if (error_is_set(err)) > goto cleanup; > diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c > index 8d1cc66..ecab1c2 100644 > --- a/osinfo/osinfo_os.c > +++ b/osinfo/osinfo_os.c > @@ -52,6 +52,7 @@ struct _OsinfoOsPrivate > > OsinfoMediaList *medias; > OsinfoTreeList *trees; > + OsinfoVariantList *variants; > OsinfoResourcesList *minimum; > OsinfoResourcesList *recommended; > > @@ -115,6 +116,7 @@ osinfo_os_finalize (GObject *object) > g_list_free(os->priv->deviceLinks); > g_object_unref(os->priv->medias); > g_object_unref(os->priv->trees); > + g_object_unref(os->priv->variants); > > g_object_unref(os->priv->scripts); > > @@ -177,6 +179,7 @@ osinfo_os_init (OsinfoOs *os) > os->priv->deviceLinks = NULL; > os->priv->medias = osinfo_medialist_new (); > os->priv->trees = osinfo_treelist_new (); > + os->priv->variants = osinfo_variantlist_new (); > os->priv->minimum = osinfo_resourceslist_new (); > os->priv->recommended = osinfo_resourceslist_new (); > os->priv->scripts = osinfo_install_scriptlist_new (); > @@ -490,6 +493,40 @@ void osinfo_os_add_tree(OsinfoOs *os, OsinfoTree *tree) > } > > /** > + * osinfo_os_get_variant_list: > + * @os: an operating system > + * > + * Gets all known variants of operating system @os. > + * > + * Returns: (transfer full): A list of variants > + */ > +OsinfoVariantList *osinfo_os_get_variant_list(OsinfoOs *os) > +{ > + g_return_val_if_fail(OSINFO_IS_OS(os), NULL); > + > + OsinfoVariantList *newList = osinfo_variantlist_new(); > + > + osinfo_list_add_all(OSINFO_LIST(newList), OSINFO_LIST(os->priv->variants)); > + > + return newList; > +} > + > +/** > + * osinfo_os_add_variant: > + * @os: an operating system > + * @variant: (transfer none): the variant to add > + * > + * Adds a variant @variant to operating system @os. > + */ > +void osinfo_os_add_variant(OsinfoOs *os, OsinfoVariant *variant) > +{ > + g_return_if_fail(OSINFO_IS_OS(os)); > + g_return_if_fail(OSINFO_IS_VARIANT(variant)); > + > + osinfo_list_add(OSINFO_LIST(os->priv->variants), OSINFO_ENTITY(variant)); > +} > + > +/** > * osinfo_os_get_minimum_resources: > * @os: an operating system > * > diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h > index 433c511..f3ff54b 100644 > --- a/osinfo/osinfo_os.h > +++ b/osinfo/osinfo_os.h > @@ -29,6 +29,8 @@ > #include <osinfo/osinfo_medialist.h> > #include <osinfo/osinfo_media.h> > #include <osinfo/osinfo_treelist.h> > +#include <osinfo/osinfo_variant.h> > +#include <osinfo/osinfo_variantlist.h> > #include <osinfo/osinfo_tree.h> > #include <osinfo/osinfo_resources.h> > #include <osinfo/osinfo_resourceslist.h> > @@ -114,6 +116,8 @@ OsinfoMediaList *osinfo_os_get_media_list(OsinfoOs *os); > void osinfo_os_add_media(OsinfoOs *os, OsinfoMedia *media); > OsinfoTreeList *osinfo_os_get_tree_list(OsinfoOs *os); > void osinfo_os_add_tree(OsinfoOs *os, OsinfoTree *tree); > +OsinfoVariantList *osinfo_os_get_variant_list(OsinfoOs *os); > +void osinfo_os_add_variant(OsinfoOs *os, OsinfoVariant *variant); > OsinfoResourcesList *osinfo_os_get_minimum_resources(OsinfoOs *os); > OsinfoResourcesList *osinfo_os_get_recommended_resources(OsinfoOs *os); > void osinfo_os_add_minimum_resources(OsinfoOs *os, OsinfoResources *resources); > -- > 1.8.4.2 > > _______________________________________________ > Libosinfo mailing list > Libosinfo@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libosinfo
Attachment:
pgpIKwqD2BWzE.pgp
Description: PGP signature
_______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo