[Libosinfo] [PATCH 4/7] media: Add variant info API/XML

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Nov 26 16:16:30 UTC 2013


Add:

* ability to associate media to a variant of the OS in the 'media' XML
  node.
* API to query variant of the OS, media is associated with.
---
 data/schemas/libosinfo.rng |  5 +++++
 osinfo/libosinfo.syms      |  2 ++
 osinfo/osinfo_db.c         |  5 +++++
 osinfo/osinfo_loader.c     |  7 +++++++
 osinfo/osinfo_media.c      | 31 +++++++++++++++++++++++++++++++
 osinfo/osinfo_media.h      |  3 +++
 6 files changed, 53 insertions(+)

diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
index cc13982..ecd83c2 100644
--- a/data/schemas/libosinfo.rng
+++ b/data/schemas/libosinfo.rng
@@ -338,6 +338,11 @@
         </attribute>
       </optional>
       <optional>
+        <attribute name='variant'>
+          <text/>
+        </attribute>
+      </optional>
+      <optional>
         <element name='url'>
           <ref name='url'/>
         </element>
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 528c2a5..1de56e3 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -448,6 +448,8 @@ LIBOSINFO_0.2.9 {
 	osinfo_os_get_release_status;
 	osinfo_release_status_get_type;
 
+	osinfo_media_get_variant;
+
 	osinfo_os_add_variant;
 	osinfo_os_get_variant_list;
 
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index f19d9b4..d851499 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -627,6 +627,7 @@ static void fill_media (OsinfoDb *db, OsinfoMedia *media,
     const gchar *initrd_path;
     const gchar *arch;
     const gchar *url;
+    const gchar *variant;
 
     languages = match_languages(db, media, matched_media);
     if (languages != NULL)
@@ -642,6 +643,10 @@ static void fill_media (OsinfoDb *db, OsinfoMedia *media,
     url = osinfo_media_get_url(matched_media);
     if (url != NULL)
         g_object_set(G_OBJECT(media), "url", url, NULL);
+    variant = osinfo_entity_get_param_value(OSINFO_ENTITY(matched_media),
+                                            "variant");
+    if (variant != NULL)
+        osinfo_entity_set_param(OSINFO_ENTITY(media), "variant", variant);
 
     kernel_path = osinfo_media_get_kernel_path(matched_media);
     if (kernel_path != NULL)
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 84dd843..85e036e 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -892,6 +892,13 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
         xmlFree(installer_reboots);
     }
 
+    if (variant) {
+        osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                OSINFO_MEDIA_PROP_VARIANT,
+                                (gchar *)variant);
+        xmlFree(variant);
+    }
+
     gint nnodes = osinfo_loader_nodeset("./iso/*", ctxt, &nodes, err);
     if (error_is_set(err)) {
         g_object_unref(media);
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 118ff8b..c3c9d20 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -1136,6 +1136,37 @@ void osinfo_media_set_os(OsinfoMedia *media, OsinfoOs *os)
 }
 
 /**
+ * osinfo_media_get_variant:
+ * @media: an #OsinfoMedia instance
+ *
+ * Gets the variant of the associated operating system.
+ *
+ * Returns: (transfer full): the operating system variant, or NULL
+ */
+OsinfoVariant *osinfo_media_get_variant(OsinfoMedia *media)
+{
+    const char *id;
+    OsinfoOs *os;
+    OsinfoVariantList *variants;
+    OsinfoEntity *variant;
+
+    g_return_val_if_fail(OSINFO_IS_MEDIA(media), NULL);
+
+    id = osinfo_entity_get_param_value(OSINFO_ENTITY(media),
+                                       OSINFO_MEDIA_PROP_VARIANT);
+    if (id == NULL)
+        return NULL;
+
+    os = g_weak_ref_get(&media->priv->os);
+    variants = osinfo_os_get_variant_list(os);
+    g_object_unref (os);
+    variant = osinfo_list_find_by_id(OSINFO_LIST(variants), id);
+    g_return_val_if_fail(OSINFO_IS_VARIANT(variant), NULL);
+
+    return g_object_ref (variant);
+}
+
+/**
  * osinfo_media_get_languages:
  * @media: an #OsinfoMedia instance
  *
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 308f75e..87ef8af 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -26,6 +26,7 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 #include <osinfo/osinfo_entity.h>
+#include <osinfo/osinfo_variant.h>
 
 #ifndef __OSINFO_MEDIA_H__
 #define __OSINFO_MEDIA_H__
@@ -84,6 +85,7 @@ typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 #define OSINFO_MEDIA_PROP_LANG           "l10n-language"
 #define OSINFO_MEDIA_PROP_LANG_REGEX     "l10n-language-regex"
 #define OSINFO_MEDIA_PROP_LANG_MAP       "l10n-language-map"
+#define OSINFO_MEDIA_PROP_VARIANT        "variant"
 
 /* object */
 struct _OsinfoMedia
@@ -128,6 +130,7 @@ const gchar *osinfo_media_get_application_id(OsinfoMedia *media);
 const gchar *osinfo_media_get_kernel_path(OsinfoMedia *media);
 const gchar *osinfo_media_get_initrd_path(OsinfoMedia *media);
 OsinfoOs *osinfo_media_get_os(OsinfoMedia *media);
+OsinfoVariant *osinfo_media_get_variant(OsinfoMedia *media);
 GList *osinfo_media_get_languages(OsinfoMedia *media);
 gboolean osinfo_media_get_installer(OsinfoMedia *media);
 gboolean osinfo_media_get_live(OsinfoMedia *media);
-- 
1.8.4.2




More information about the Libosinfo mailing list