[Libosinfo] [libosinfo PATCH v2 07/15] os: Add osinfo_os_get_all_device_links()

Fabiano Fidêncio fidencio at redhat.com
Mon Nov 12 10:30:54 UTC 2018


This function is a helper for the commits that are about to come related
to properly dealing with "removed" devices.

https://gitlab.com/libosinfo/osinfo-db/issues/13

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/libosinfo.syms |  2 ++
 osinfo/osinfo_os.c    | 50 +++++++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_os.h    |  1 +
 3 files changed, 53 insertions(+)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index db9b8b2..62236c4 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -532,6 +532,8 @@ LIBOSINFO_0.2.13 {
 LIBOSINFO_1.3.0 {
     global:
 	osinfo_error_quark;
+
+	osinfo_os_get_all_device_links;
 } LIBOSINFO_0.2.13;
 
 /* Symbols in next release...
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 2b870c4..ec1d679 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -351,6 +351,56 @@ OsinfoDeviceLinkList *osinfo_os_get_device_links(OsinfoOs *os, OsinfoFilter *fil
 }
 
 
+struct GetAllDeviceLinksData {
+    OsinfoFilter *filter;
+    OsinfoDeviceLinkList *device_links;
+};
+
+static void get_all_device_links_cb(OsinfoProduct *product, gpointer user_data)
+{
+    OsinfoDeviceLinkList *device_links;
+    OsinfoList *tmp_list;
+    struct GetAllDeviceLinksData *foreach_data;
+
+    g_return_if_fail(OSINFO_IS_OS(product));
+
+    foreach_data = (struct GetAllDeviceLinksData *)user_data;
+    device_links = osinfo_os_get_device_links(OSINFO_OS(product),
+                                              foreach_data->filter);
+    tmp_list = osinfo_list_new_union(OSINFO_LIST(foreach_data->device_links),
+                                     OSINFO_LIST(device_links));
+    g_object_unref(foreach_data->device_links);
+    g_object_unref(device_links);
+    foreach_data->device_links = OSINFO_DEVICELINKLIST(tmp_list);
+}
+
+/**
+ * osinfo_os_get_all_device_links:
+ * @os: an operating system
+ * @filter: (allow-none)(transfer none): an optional device property filter
+ *
+ * Get all devicelinks matching a given filter but unlike
+ * osinfo_os_get_device_links this function also retrieves devices from all
+ * derived and cloned operating systems.
+ *
+ * Returns: (transfer full): A list of OsinfoDeviceLink
+ */
+OsinfoDeviceLinkList *osinfo_os_get_all_device_links(OsinfoOs *os, OsinfoFilter *filter)
+{
+    struct GetAllDeviceLinksData foreach_data = {
+        .filter = filter,
+        .device_links = osinfo_devicelinklist_new()
+    };
+
+    osinfo_product_foreach_related(OSINFO_PRODUCT(os),
+                                   OSINFO_PRODUCT_FOREACH_FLAG_DERIVES_FROM |
+                                   OSINFO_PRODUCT_FOREACH_FLAG_CLONES,
+                                   get_all_device_links_cb,
+                                   &foreach_data);
+
+    return foreach_data.device_links;
+}
+
 /**
  * osinfo_os_add_device:
  * @os: an operating system
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index 96bd6e3..d01c31c 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -107,6 +107,7 @@ OsinfoDeviceList *osinfo_os_get_devices_by_property(OsinfoOs *os,
                                                     const char *value,
                                                     gboolean inherited);
 OsinfoDeviceLinkList *osinfo_os_get_device_links(OsinfoOs *os, OsinfoFilter *filter);
+OsinfoDeviceLinkList *osinfo_os_get_all_device_links(OsinfoOs *os, OsinfoFilter *filter);
 
 OsinfoDeviceLink *osinfo_os_add_device(OsinfoOs *os, OsinfoDevice *dev);
 const gchar *osinfo_os_get_family(OsinfoOs *os);
-- 
2.19.1




More information about the Libosinfo mailing list