[libosinfo 3/3] Implement osinfo_platform_get_all_devices()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 osinfo/libosinfo.syms    |  4 ++++
 osinfo/osinfo_platform.c | 38 ++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_platform.h |  1 +
 3 files changed, 43 insertions(+)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 45689a2..8fcf327 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -413,6 +413,10 @@ LIBOSINFO_0.2.6 {
 	osinfo_install_script_get_post_install_drivers_signing_req;
 } LIBOSINFO_0.2.3;
 
+LIBOSINFO_0.2.7 {
+	osinfo_platform_get_all_devices;
+} LIBOSINFO_0.2.6;
+
 /* Symbols in next release...
 
   LIBOSINFO_0.0.2 {
diff --git a/osinfo/osinfo_platform.c b/osinfo/osinfo_platform.c
index 222eb93..1bb3ecf 100644
--- a/osinfo/osinfo_platform.c
+++ b/osinfo/osinfo_platform.c
@@ -25,6 +25,7 @@
 #include <config.h>
 
 #include <osinfo/osinfo.h>
+#include "osinfo/osinfo_product_private.h"
 #include <glib/gi18n-lib.h>
 
 G_DEFINE_TYPE (OsinfoPlatform, osinfo_platform, OSINFO_TYPE_PRODUCT);
@@ -101,6 +102,43 @@ OsinfoPlatform *osinfo_platform_new(const gchar *id)
                         NULL);
 }
 
+struct GetAllDevicesData {
+    OsinfoFilter *filter;
+    OsinfoDeviceList *devices;
+};
+
+static void get_all_devices_cb(OsinfoProduct *product, gpointer user_data)
+{
+    OsinfoDeviceList *devices;
+    OsinfoList *tmp_list;
+    struct GetAllDevicesData *foreach_data = (struct GetAllDevicesData *)user_data;
+
+    g_return_if_fail(OSINFO_IS_PLATFORM(product));
+
+    devices = osinfo_platform_get_devices(OSINFO_PLATFORM(product),
+                                          foreach_data->filter);
+    tmp_list = osinfo_list_new_union(OSINFO_LIST(foreach_data->devices),
+                                     OSINFO_LIST(devices));
+    g_object_unref(foreach_data->devices);
+    g_object_unref(devices);
+    foreach_data->devices = OSINFO_DEVICELIST(tmp_list);
+}
+
+OsinfoDeviceList *osinfo_platform_get_all_devices(OsinfoPlatform *platform,
+                                                  OsinfoFilter *filter)
+{
+    struct GetAllDevicesData foreach_data = {
+        .filter = filter,
+        .devices = osinfo_devicelist_new()
+    };
+
+    osinfo_product_foreach_related(OSINFO_PRODUCT(platform),
+                                   OSINFO_PRODUCT_FOREACH_FLAG_UPGRADES,
+                                   get_all_devices_cb,
+                                   &foreach_data);
+
+    return foreach_data.devices;
+}
 
 /**
  * osinfo_platform_get_devices:
diff --git a/osinfo/osinfo_platform.h b/osinfo/osinfo_platform.h
index 8455a32..d5df225 100644
--- a/osinfo/osinfo_platform.h
+++ b/osinfo/osinfo_platform.h
@@ -71,6 +71,7 @@ GType osinfo_platform_get_type(void);
 OsinfoPlatform *osinfo_platform_new(const gchar *id);
 
 OsinfoDeviceList *osinfo_platform_get_devices(OsinfoPlatform *platform, OsinfoFilter *filter);
+OsinfoDeviceList *osinfo_platform_get_all_devices(OsinfoPlatform *platform, OsinfoFilter *filter);
 OsinfoDeviceLinkList *osinfo_platform_get_device_links(OsinfoPlatform *platform, OsinfoFilter *filter);
 
 OsinfoDeviceLink *osinfo_platform_add_device(OsinfoPlatform *platform, OsinfoDevice *dev);
-- 
1.8.1.4

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux