[virt-tools-list] [libosinfo 2/2] Add osinfo_os_get_all_devices()

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Jan 10 19:06:51 UTC 2012


From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>

Add a function to retreive all supported devices from an OS.
---
 osinfo/libosinfo.syms |    1 +
 osinfo/osinfo_os.c    |   43 +++++++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_os.h    |    1 +
 3 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index f1411f7..18415e0 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -108,6 +108,7 @@ LIBOSINFO_0.0.1 {
 	osinfo_os_get_type;
 	osinfo_os_new;
 	osinfo_os_get_devices;
+	osinfo_os_get_all_devices;
 	osinfo_os_get_device_links;
 	osinfo_os_add_device;
 	osinfo_os_get_family;
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 968ef83..0facb08 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -192,7 +192,50 @@ OsinfoDeviceList *osinfo_os_get_devices(OsinfoOs *os, OsinfoFilter *filter)
     return newList;
 }
 
+/**
+ * osinfo_os_get_all_devices:
+ * @os: an operating system
+ * @filter: (allow-none)(transfer none): an optional device property filter
+ *
+ * Get all devices matching a given filter but unlike osinfo_os_get_devices
+ * this function also retreives devices from all derived and cloned operating
+ * systems.
+ *
+ * Returns: (transfer full): A list of devices
+ */
+OsinfoDeviceList *osinfo_os_get_all_devices(OsinfoOs *os, OsinfoFilter *filter)
+{
+    OsinfoProductList *derived, *cloned, *related_list;
+    OsinfoDeviceList *devices;
+    guint i;
+
+    devices = osinfo_os_get_devices(os, filter);
+
+    derived = osinfo_product_get_related
+                (OSINFO_PRODUCT(os), OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM);
+    cloned = osinfo_product_get_related(OSINFO_PRODUCT(os),
+                                        OSINFO_PRODUCT_RELATIONSHIP_CLONES);
+    related_list = osinfo_productlist_new_union(derived, cloned);
+    g_object_unref(derived);
+    g_object_unref(cloned);
+
+    for (i = 0; i < osinfo_list_get_length(OSINFO_LIST(related_list)); i++) {
+        OsinfoEntity *related;
+        OsinfoDeviceList *related_devices;
+
+        related = osinfo_list_get_nth(OSINFO_LIST(related_list), i);
+        related_devices = osinfo_os_get_all_devices(OSINFO_OS(related), filter);
+        if (osinfo_list_get_length(OSINFO_LIST(related_devices)) > 0) {
+            OsinfoDeviceList *tmp_list = devices;
+            devices = osinfo_devicelist_new_union(devices, related_devices);
+            g_object_unref(tmp_list);
+        }
+    }
+
+    g_object_unref (related_list);
 
+    return devices;
+}
 
 /**
  * osinfo_os_get_device_links:
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index efd7cea..e1daff1 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -76,6 +76,7 @@ GType osinfo_os_get_type(void);
 OsinfoOs *osinfo_os_new(const gchar *id);
 
 OsinfoDeviceList *osinfo_os_get_devices(OsinfoOs *os, OsinfoFilter *filter);
+OsinfoDeviceList *osinfo_os_get_all_devices(OsinfoOs *os, OsinfoFilter *filter);
 OsinfoDeviceLinkList *osinfo_os_get_device_links(OsinfoOs *os, OsinfoFilter *filter);
 
 OsinfoDeviceLink *osinfo_os_add_device(OsinfoOs *os, OsinfoDevice *dev);
-- 
1.7.7.5




More information about the virt-tools-list mailing list