[Libosinfo] [[PATCHv2] 3/7] os: Add variant info API/XML
Zeeshan Ali (Khattak)
zeeshanak at gnome.org
Thu Nov 28 01:07:13 UTC 2013
Add:
* ability to specificy various variants of an OS under the 'os' XML node.
For example:
<os id="http://microsoft.com/win/7">
<short-id>win7</short-id>
<name>Microsoft Windows 7</name>
..
<variant id="starter">
<name>Microsoft Windows 7 Starter</name>
</variant>
<variant id="home-basic">
<name>Microsoft Windows 7 Home Basic</name>
</variant>
<variant id="home-premium">
<name>Microsoft Windows 7 Home Premium</name>
</variant>
..
</os>
* API to add and query variants of an OS.
---
data/schemas/libosinfo.rng | 13 +++++++++++++
osinfo/libosinfo.syms | 3 +++
osinfo/osinfo_loader.c | 41 +++++++++++++++++++++++++++++++++++++++++
osinfo/osinfo_os.c | 37 +++++++++++++++++++++++++++++++++++++
osinfo/osinfo_os.h | 4 ++++
5 files changed, 98 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 9fdce6b..21d80f4 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_os_variant_get_type;
osinfo_os_variant_get_name;
osinfo_os_variant_new;
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index bb7e9a4..affc49b 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 OsinfoOsVariant *osinfo_loader_os_variant (OsinfoLoader *loader,
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr root,
+ GError **err)
+{
+ const OsinfoEntityKey keys[] = {
+ { OSINFO_OS_VARIANT_PROP_NAME, G_TYPE_STRING },
+ { NULL, G_TYPE_INVALID }
+ };
+
+ gchar *id = (gchar *)xmlGetProp(root, BAD_CAST "id");
+ OsinfoOsVariant *variant= osinfo_os_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,27 @@ 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];
+ OsinfoOsVariant *variant = osinfo_loader_os_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 9f5a4d6..cbb26a4 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -52,6 +52,7 @@ struct _OsinfoOsPrivate
OsinfoMediaList *medias;
OsinfoTreeList *trees;
+ OsinfoOsVariantList *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_os_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
+ */
+OsinfoOsVariantList *osinfo_os_get_variant_list(OsinfoOs *os)
+{
+ g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
+
+ OsinfoOsVariantList *newList = osinfo_os_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, OsinfoOsVariant *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 9323bb2..96bd6e3 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_os_variant.h>
+#include <osinfo/osinfo_os_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);
+OsinfoOsVariantList *osinfo_os_get_variant_list(OsinfoOs *os);
+void osinfo_os_add_variant(OsinfoOs *os, OsinfoOsVariant *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
More information about the Libosinfo
mailing list