[virt-tools-list] [PATCH 19/47] Make osinfo DB struct private & change to use a OsinfoList internally

Daniel P. Berrange berrange at redhat.com
Wed Aug 25 19:37:14 UTC 2010


Classes should expose their private bits to each other. Make
the OsinfoDb private struct truely private. Switch from using
a GTree in OsinfoDb over to a OsinfoList to simplify the code.

* osinfo/osinfo_db.c, osinfo/osinfo_db.h: Add private data
  struct & convert from OsinfoList instead of GTree
* osinfo/osinfo_common.h: Remove OsinfoDbPrivate
* osinfo/osinfo_dataread.c, osinfo/osinfo_devicelist.h,
  osinfo/osinfo_hypervisorlist.h, osinfo/osinfo_oslist.h: Update
  for API changes
* osinfo/osinfo_list.c, osinfo/osinfo_list.h: Add API
  for iterating over elements & finding an entity based
  on its id.
---
 osinfo/osinfo_common.h         |   15 +----
 osinfo/osinfo_dataread.c       |   38 +++++++-----
 osinfo/osinfo_db.c             |  128 +++++++++++++---------------------------
 osinfo/osinfo_db.h             |   10 +--
 osinfo/osinfo_devicelist.h     |    2 +-
 osinfo/osinfo_hypervisorlist.h |    2 +-
 osinfo/osinfo_list.c           |   22 +++++++
 osinfo/osinfo_list.h           |    4 +
 osinfo/osinfo_oslist.h         |    2 +-
 9 files changed, 99 insertions(+), 124 deletions(-)

diff --git a/osinfo/osinfo_common.h b/osinfo/osinfo_common.h
index b7ff223..1ad5088 100644
--- a/osinfo/osinfo_common.h
+++ b/osinfo/osinfo_common.h
@@ -23,6 +23,9 @@ typedef struct _OsinfoHypervisor OsinfoHypervisor;
 typedef struct _OsinfoOs         OsinfoOs;
 typedef struct _OsinfoFilter     OsinfoFilter;
 typedef struct _OsinfoList       OsinfoList;
+typedef struct _OsinfoDeviceList       OsinfoDeviceList;
+typedef struct _OsinfoHypervisorList       OsinfoHypervisorList;
+typedef struct _OsinfoOsList       OsinfoOsList;
 
 typedef enum OSI_RELATIONSHIP {
     DERIVES_FROM,
@@ -131,18 +134,6 @@ struct _OsinfoFilterPrivate
     GTree *relationshipConstraints;
 };
 
-struct _OsinfoDbPrivate
-{
-    int ready;
-
-    gchar *backing_dir;
-    gchar *libvirt_ver;
-
-    GTree *devices;
-    GTree *hypervisors;
-    GTree *oses;
-};
-
 struct _OsinfoDevicePrivate
 {
     int tmp;
diff --git a/osinfo/osinfo_dataread.c b/osinfo/osinfo_dataread.c
index 4b5394f..166c82b 100644
--- a/osinfo/osinfo_dataread.c
+++ b/osinfo/osinfo_dataread.c
@@ -44,8 +44,9 @@ static gboolean __osinfoResolveDeviceLink(gpointer key, gpointer value, gpointer
     struct __osinfoDbRet *dbRet = (struct __osinfoDbRet *) data;
     OsinfoDb *db = dbRet->db;
     int *ret = dbRet->ret;
+    OsinfoDeviceList *devices = osinfo_db_get_device_list(db);
 
-    OsinfoDevice *dev = g_tree_lookup(db->priv->devices, id);
+    OsinfoDevice *dev = OSINFO_DEVICE(osinfo_list_find_by_id(OSINFO_LIST(devices), id));
     if (!dev) {
         *ret = -EINVAL;
         return TRUE;
@@ -80,12 +81,13 @@ static gboolean __osinfoResolveHvLink(gpointer key, gpointer value, gpointer dat
     int *ret = dbRet->ret;
     struct __osinfoHvSection *hvSection = (struct __osinfoHvSection *) value;
     OsinfoHypervisor *hv;
+    OsinfoHypervisorList *hypervisors = osinfo_db_get_hypervisor_list(db);
 
     g_tree_foreach(hvSection->sections, __osinfoResolveSectionDevices, dbRet);
     if (*ret)
         return TRUE;
 
-    hv = g_tree_lookup(db->priv->hypervisors, hvId);
+    hv = OSINFO_HYPERVISOR(osinfo_list_find_by_id(OSINFO_LIST(hypervisors), hvId));
     if (!hv) {
         *ret = -EINVAL;
         return TRUE;
@@ -103,9 +105,10 @@ static gboolean __osinfoResolveOsLink(gpointer key, gpointer value, gpointer dat
     OsinfoDb *db = dbRet->db;
     int *ret = dbRet->ret;
     struct __osinfoOsLink *osLink = (struct __osinfoOsLink *) value;
-
     OsinfoOs *targetOs;
-    targetOs = g_tree_lookup(db->priv->oses, targetOsId);
+    OsinfoOsList *oslist = osinfo_db_get_os_list(db);
+
+    targetOs = OSINFO_OS(osinfo_list_find_by_id(OSINFO_LIST(oslist), targetOsId));
     if (!targetOs) {
         *ret = -EINVAL;
         return TRUE;
@@ -116,11 +119,11 @@ static gboolean __osinfoResolveOsLink(gpointer key, gpointer value, gpointer dat
     return FALSE;
 }
 
-static gboolean __osinfoFixOsLinks(gpointer key, gpointer value, gpointer data)
+static gboolean __osinfoFixOsLinks(OsinfoList *list, OsinfoEntity *entity, gpointer data)
 {
-    struct __osinfoDbRet *dbRet = (struct __osinfoDbRet *) data;
+    struct __osinfoDbRet *dbRet = data;
     int *ret = dbRet->ret;
-    OsinfoOs *os = OSINFO_OS(value);
+    OsinfoOs *os = OSINFO_OS(entity);
     if (!os) {
         *ret = -EINVAL;
         return TRUE;
@@ -142,11 +145,11 @@ static gboolean __osinfoFixOsLinks(gpointer key, gpointer value, gpointer data)
     return FALSE;
 }
 
-static gboolean __osinfoFixHvLinks(gpointer key, gpointer value, gpointer data)
+static gboolean __osinfoFixHvLinks(OsinfoList *list, OsinfoEntity *entity, gpointer data)
 {
-    struct __osinfoDbRet *dbRet = (struct __osinfoDbRet *) data;
+    struct __osinfoDbRet *dbRet = data;
     int *ret = dbRet->ret;
-    OsinfoHypervisor *hv = OSINFO_HYPERVISOR(value);
+    OsinfoHypervisor *hv = OSINFO_HYPERVISOR(entity);
     if (!hv) {
         *ret = -EINVAL;
         return TRUE;
@@ -166,11 +169,13 @@ static int __osinfoFixObjLinks(OsinfoDb *db)
         return -EINVAL;
 
     struct __osinfoDbRet dbRet = {db, &ret};
+    OsinfoHypervisorList *hypervisors = osinfo_db_get_hypervisor_list(db);
+    OsinfoOsList *oses = osinfo_db_get_os_list(db);
 
-    g_tree_foreach(db->priv->hypervisors, __osinfoFixHvLinks, &dbRet);
+    osinfo_list_foreach(OSINFO_LIST(hypervisors), __osinfoFixHvLinks, &dbRet);
     if (ret)
         return ret;
-    g_tree_foreach(db->priv->oses, __osinfoFixOsLinks, &dbRet);
+    osinfo_list_foreach(OSINFO_LIST(oses), __osinfoFixOsLinks, &dbRet);
 
     return ret;
 }
@@ -426,6 +431,7 @@ static int __osinfoProcessOs(OsinfoDb *db,
     gchar* id, * key = NULL, * val = NULL;
     const gchar* name;
     OsinfoOs *os;
+    OsinfoOsList *oses = osinfo_db_get_os_list(db);
 
     id = (gchar *)xmlTextReaderGetAttribute(reader, BAD_CAST "id");
     empty = xmlTextReaderIsEmptyElement(reader);
@@ -518,7 +524,7 @@ static int __osinfoProcessOs(OsinfoDb *db,
     }
 
 finished:
-    osinfo_db_add_os(db, os);
+    osinfo_list_add(OSINFO_LIST(oses), OSINFO_ENTITY(os));
     return 0;
     /* At end, cursor is at end of os node */
 
@@ -544,6 +550,7 @@ static int __osinfoProcessHypervisor(OsinfoDb *db,
     gchar* id;
     const gchar * name;
     OsinfoHypervisor *hv;
+    OsinfoHypervisorList *hypervisors = osinfo_db_get_hypervisor_list(db);
 
     id = (gchar *)xmlTextReaderGetAttribute(reader, BAD_CAST "id");
     empty = xmlTextReaderIsEmptyElement(reader);
@@ -625,7 +632,7 @@ static int __osinfoProcessHypervisor(OsinfoDb *db,
     }
 
 finished:
-    osinfo_db_add_hypervisor(db, hv);
+    osinfo_list_add(OSINFO_LIST(hypervisors), OSINFO_ENTITY(hv));
     return 0;
     /* At end, cursor is at end of hv node */
 
@@ -651,6 +658,7 @@ static int __osinfoProcessDevice(OsinfoDb *db,
     gchar* id, * key, * val;
     const gchar* name;
     OsinfoDevice *dev;
+    OsinfoDeviceList *devices = osinfo_db_get_device_list(db);
 
     id = (gchar *)xmlTextReaderGetAttribute(reader, BAD_CAST "id");
     empty = xmlTextReaderIsEmptyElement(reader);
@@ -716,7 +724,7 @@ static int __osinfoProcessDevice(OsinfoDb *db,
 
 finished:
     // Add dev to db
-    osinfo_db_add_device(db, dev);
+    osinfo_list_add(OSINFO_LIST(devices), OSINFO_ENTITY(dev));
     return 0;
     /* At end, cursor is at end of device node */
 
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index 51e4030..4ecf8bf 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -4,6 +4,19 @@ G_DEFINE_TYPE (OsinfoDb, osinfo_db, G_TYPE_OBJECT);
 
 #define OSINFO_DB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_DB, OsinfoDbPrivate))
 
+struct _OsinfoDbPrivate
+{
+    int ready;
+
+    gchar *backing_dir;
+    gchar *libvirt_ver;
+
+    OsinfoDeviceList *devices;
+    OsinfoHypervisorList *hypervisors;
+    OsinfoOsList *oses;
+};
+
+
 static void osinfo_db_set_property(GObject * object, guint prop_id,
                                          const GValue * value,
                                          GParamSpec * pspec);
@@ -27,9 +40,9 @@ osinfo_db_finalize (GObject *object)
     g_free (self->priv->backing_dir);
     g_free (self->priv->libvirt_ver);
 
-    g_tree_destroy(self->priv->devices);
-    g_tree_destroy(self->priv->hypervisors);
-    g_tree_destroy(self->priv->oses);
+    g_object_unref(self->priv->devices);
+    g_object_unref(self->priv->hypervisors);
+    g_object_unref(self->priv->oses);
 
     /* Chain up to the parent class */
     G_OBJECT_CLASS (osinfo_db_parent_class)->finalize (object);
@@ -126,9 +139,9 @@ osinfo_db_init (OsinfoDb *self)
     OsinfoDbPrivate *priv;
     self->priv = priv = OSINFO_DB_GET_PRIVATE(self);
 
-    self->priv->devices = g_tree_new_full(__osinfoStringCompare, NULL, g_free, g_object_unref);
-    self->priv->hypervisors = g_tree_new_full(__osinfoStringCompare, NULL, g_free, g_object_unref);
-    self->priv->oses = g_tree_new_full(__osinfoStringCompare, NULL, g_free, g_object_unref);
+    self->priv->devices = osinfo_devicelist_new();
+    self->priv->hypervisors = osinfo_hypervisorlist_new();
+    self->priv->oses = osinfo_oslist_new();
 
     self->priv->ready = 0;
 }
@@ -162,7 +175,7 @@ OsinfoHypervisor *osinfo_db_get_hypervisor(OsinfoDb *self, gchar *id)
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
     g_return_val_if_fail(id != NULL, NULL);
 
-    return g_tree_lookup(self->priv->hypervisors, id);
+    return OSINFO_HYPERVISOR(osinfo_list_find_by_id(OSINFO_LIST(self->priv->hypervisors), id));
 }
 
 OsinfoDevice *osinfo_db_get_device(OsinfoDb *self, gchar *id)
@@ -170,7 +183,7 @@ OsinfoDevice *osinfo_db_get_device(OsinfoDb *self, gchar *id)
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
     g_return_val_if_fail(id != NULL, NULL);
 
-    return g_tree_lookup(self->priv->devices, id);
+    return OSINFO_DEVICE(osinfo_list_find_by_id(OSINFO_LIST(self->priv->hypervisors), id));
 }
 
 OsinfoOs *osinfo_db_get_os(OsinfoDb *self, gchar *id)
@@ -178,72 +191,36 @@ OsinfoOs *osinfo_db_get_os(OsinfoDb *self, gchar *id)
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
     g_return_val_if_fail(id != NULL, NULL);
 
-    return g_tree_lookup(self->priv->oses, id);
-}
-
-static gboolean __osinfoFilteredAddToList(gpointer key, gpointer value, gpointer data)
-{
-    struct __osinfoPopulateListArgs *args;
-    args = (struct __osinfoPopulateListArgs *) data;
-    OsinfoFilter *filter = args->filter;
-    OsinfoList *list = args->list;
-
-    // Key is string ID, value is pointer to entity
-    OsinfoEntity *entity = (OsinfoEntity *) value;
-    if (__osinfoEntityPassesFilter(filter, entity)) {
-        osinfo_list_add(list, entity);
-    }
-
-    return FALSE; // continue iteration
+    return OSINFO_OS(osinfo_list_find_by_id(OSINFO_LIST(self->priv->oses), id));
 }
 
-static void osinfo_db_populate_list(GTree *entities, OsinfoList *newList, OsinfoFilter *filter)
-{
-    struct __osinfoPopulateListArgs args = { filter, newList};
-    g_tree_foreach(entities, __osinfoFilteredAddToList, &args);
-}
 
-OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self, OsinfoFilter *filter)
+OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self)
 {
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
-    g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL);
 
-    // Create list
-    OsinfoOsList *newList = osinfo_oslist_new();
-    osinfo_db_populate_list(self->priv->oses, OSINFO_LIST (newList), filter);
-    return newList;
+    return self->priv->oses;
 }
 
-OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self, OsinfoFilter *filter)
+OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self)
 {
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
-    g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL);
 
-    // Create list
-    OsinfoHypervisorList *newList = osinfo_hypervisorlist_new();
-    osinfo_db_populate_list(self->priv->hypervisors, OSINFO_LIST (newList), filter);
-    return newList;
+    return self->priv->hypervisors;
 }
 
-OsinfoDeviceList *osinfo_db_get_device_list(OsinfoDb *self, OsinfoFilter *filter)
+OsinfoDeviceList *osinfo_db_get_device_list(OsinfoDb *self)
 {
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
-    g_return_val_if_fail(OSINFO_IS_FILTER(filter), NULL);
 
-    // Create list
-    OsinfoDeviceList *newList = osinfo_devicelist_new();
-    osinfo_db_populate_list(self->priv->devices, OSINFO_LIST (newList), filter);
-    return newList;
+    return self->priv->devices;
 }
 
-static gboolean osinfo_db_get_property_values_in_entity(gpointer key, gpointer value, gpointer data)
+static gboolean osinfo_db_get_property_values_in_entity(OsinfoList *list, OsinfoEntity *entity, gpointer data)
 {
-    struct __osinfoPopulateValuesArgs *args;
-    args = (struct __osinfoPopulateValuesArgs *) data;
+    struct __osinfoPopulateValuesArgs *args = data;
     GTree *values = args->values;
     gchar *property = args->property;
-
-    OsinfoEntity *entity = OSINFO_ENTITY (value);
     GPtrArray *valueArray = NULL;
 
     valueArray = g_tree_lookup(entity->priv->params, property);
@@ -275,12 +252,12 @@ static gboolean __osinfoPutKeysInList(gpointer key, gpointer value, gpointer dat
 }
 
 
-static GPtrArray *osinfo_db_unique_values_for_property_in_entity(GTree *entities, gchar *propName)
+static GPtrArray *osinfo_db_unique_values_for_property_in_entity(OsinfoList *entities, gchar *propName)
 {
     GTree *values = g_tree_new(__osinfoStringCompareBase);
 
     struct __osinfoPopulateValuesArgs args = { values, propName};
-    g_tree_foreach(entities, osinfo_db_get_property_values_in_entity, &args);
+    osinfo_list_foreach(entities, osinfo_db_get_property_values_in_entity, &args);
 
     // For each key in tree, add to gptrarray
     GPtrArray *valuesList = g_ptr_array_sized_new(g_tree_nnodes(values));
@@ -296,7 +273,7 @@ GPtrArray *osinfo_db_unique_values_for_property_in_os(OsinfoDb *self, gchar *pro
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
     g_return_val_if_fail(propName != NULL, NULL);
 
-    return osinfo_db_unique_values_for_property_in_entity(self->priv->oses, propName);
+    return osinfo_db_unique_values_for_property_in_entity(OSINFO_LIST(self->priv->oses), propName);
 }
 
 // Get me all unique values for property "vendor" among hypervisors
@@ -305,7 +282,7 @@ GPtrArray *osinfo_db_unique_values_for_property_in_hv(OsinfoDb *self, gchar *pro
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
     g_return_val_if_fail(propName != NULL, NULL);
 
-    return osinfo_db_unique_values_for_property_in_entity(self->priv->hypervisors, propName);
+    return osinfo_db_unique_values_for_property_in_entity(OSINFO_LIST(self->priv->hypervisors), propName);
 }
 
 // Get me all unique values for property "vendor" among devices
@@ -314,20 +291,19 @@ GPtrArray *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *self, gchar *pr
     g_return_val_if_fail(OSINFO_IS_DB(self), NULL);
     g_return_val_if_fail(propName != NULL, NULL);
 
-    return osinfo_db_unique_values_for_property_in_entity(self->priv->devices, propName);
+    return osinfo_db_unique_values_for_property_in_entity(OSINFO_LIST(self->priv->devices), propName);
 }
 
-static gboolean __osinfoAddOsIfRelationship(gpointer key, gpointer value, gpointer data)
+static gboolean __osinfoAddOsIfRelationship(OsinfoList *list, OsinfoEntity *entity, gpointer data)
 {
-    OsinfoOs *os = (OsinfoOs *) value;
-    struct __osinfoOsCheckRelationshipArgs *args;
-    args = (struct __osinfoOsCheckRelationshipArgs *) data;
-    OsinfoList *list = args->list;
+    struct __osinfoOsCheckRelationshipArgs *args = data;
+    OsinfoOs *os = OSINFO_OS(entity);
+    OsinfoList *newList = args->list;
 
     GPtrArray *relatedOses = NULL;
     relatedOses = g_tree_lookup(os->priv->relationshipsByType, (gpointer) args->relshp);
     if (relatedOses) {
-        osinfo_list_add(list, OSINFO_ENTITY (os));
+        osinfo_list_add(newList, OSINFO_ENTITY (os));
     }
 
     return FALSE;
@@ -343,29 +319,7 @@ OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *self, osinfo
 
     struct __osinfoOsCheckRelationshipArgs args = {OSINFO_LIST (newList), relshp};
 
-    g_tree_foreach(self->priv->oses, __osinfoAddOsIfRelationship, &args);
+    osinfo_list_foreach(OSINFO_LIST(self->priv->oses), __osinfoAddOsIfRelationship, &args);
 
     return newList;
 }
-
-
-void osinfo_db_add_device(OsinfoDb *db, OsinfoDevice *dev)
-{
-    gchar *id;
-    g_object_get(G_OBJECT(dev), "id", &id, NULL);
-    g_tree_insert(db->priv->devices, id, dev);
-}
-
-void osinfo_db_add_hypervisor(OsinfoDb *db, OsinfoHypervisor *hv)
-{
-    gchar *id;
-    g_object_get(G_OBJECT(hv), "id", &id, NULL);
-    g_tree_insert(db->priv->hypervisors, id, hv);
-}
-
-void osinfo_db_add_os(OsinfoDb *db, OsinfoOs *os)
-{
-    gchar *id;
-    g_object_get(G_OBJECT(os), "id", &id, NULL);
-    g_tree_insert(db->priv->oses, id, os);
-}
diff --git a/osinfo/osinfo_db.h b/osinfo/osinfo_db.h
index 61bf13e..d435ed3 100644
--- a/osinfo/osinfo_db.h
+++ b/osinfo/osinfo_db.h
@@ -68,9 +68,9 @@ OsinfoHypervisor *osinfo_db_get_hypervisor(OsinfoDb *self, gchar *hvId);
 OsinfoDevice *osinfo_db_get_device(OsinfoDb *self, gchar *devId);
 OsinfoOs *osinfo_db_get_os(OsinfoDb *self, gchar *osId);
 
-OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self, OsinfoFilter *filter);
-OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self, OsinfoFilter *filter);
-OsinfoDeviceList *osinfo_db_get_device_list(OsinfoDb *self, OsinfoFilter *filter);
+OsinfoOsList *osinfo_db_get_os_list(OsinfoDb *self);
+OsinfoHypervisorList *osinfo_db_get_hypervisor_list(OsinfoDb *self);
+OsinfoDeviceList *osinfo_db_get_device_list(OsinfoDb *self);
 
 // Get me all unique values for property "vendor" among operating systems
 GPtrArray *osinfo_db_unique_values_for_property_in_os(OsinfoDb *self, gchar *propName);
@@ -84,9 +84,5 @@ GPtrArray *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *self, gchar *pr
 // Get me all OSes that 'upgrade' another OS (or whatever relationship is specified)
 OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *self, osinfoRelationship relshp);
 
-void osinfo_db_add_device(OsinfoDb *db, OsinfoDevice *dev);
-void osinfo_db_add_hypervisor(OsinfoDb *db, OsinfoHypervisor *hv);
-void osinfo_db_add_os(OsinfoDb *db, OsinfoOs *os);
-
 
 #endif /* __OSINFO_DB_H__ */
diff --git a/osinfo/osinfo_devicelist.h b/osinfo/osinfo_devicelist.h
index e5cb25d..9245620 100644
--- a/osinfo/osinfo_devicelist.h
+++ b/osinfo/osinfo_devicelist.h
@@ -17,7 +17,7 @@
 #define OSINFO_IS_DEVICELIST_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_DEVICELIST))
 #define OSINFO_DEVICELIST_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_DEVICELIST, OsinfoDeviceListClass))
 
-typedef struct _OsinfoDeviceList        OsinfoDeviceList;
+//typedef struct _OsinfoDeviceList        OsinfoDeviceList;
 
 typedef struct _OsinfoDeviceListClass   OsinfoDeviceListClass;
 
diff --git a/osinfo/osinfo_hypervisorlist.h b/osinfo/osinfo_hypervisorlist.h
index 2487ac2..160a9c9 100644
--- a/osinfo/osinfo_hypervisorlist.h
+++ b/osinfo/osinfo_hypervisorlist.h
@@ -17,7 +17,7 @@
 #define OSINFO_IS_HYPERVISORLIST_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_HYPERVISORLIST))
 #define OSINFO_HYPERVISORLIST_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_HYPERVISORLIST, OsinfoHypervisorListClass))
 
-typedef struct _OsinfoHypervisorList        OsinfoHypervisorList;
+//typedef struct _OsinfoHypervisorList        OsinfoHypervisorList;
 
 typedef struct _OsinfoHypervisorListClass   OsinfoHypervisorListClass;
 
diff --git a/osinfo/osinfo_list.c b/osinfo/osinfo_list.c
index 872f520..1200ef0 100644
--- a/osinfo/osinfo_list.c
+++ b/osinfo/osinfo_list.c
@@ -51,6 +51,19 @@ OsinfoEntity *osinfo_list_get_nth(OsinfoList *self, gint idx)
     return g_ptr_array_index(self->priv->array, idx);
 }
 
+OsinfoEntity *osinfo_list_find_by_id(OsinfoList *self, const gchar *id)
+{
+    int i;
+    for (i = 0 ; i < self->priv->array->len ; i++) {
+        OsinfoEntity *ent = g_ptr_array_index(self->priv->array, i);
+	const gchar *thisid = osinfo_entity_get_id(ent);
+	if (g_strcmp0(id, thisid) == 0)
+	    return ent;
+    }
+    return NULL;
+}
+
+
 void osinfo_list_add(OsinfoList *self, OsinfoEntity *entity)
 {
     g_ptr_array_add(self->priv->array, entity);
@@ -133,3 +146,12 @@ void osinfo_list_add_union(OsinfoList *self, OsinfoList *sourceOne, OsinfoList *
     g_tree_destroy(newSet);
 }
 
+
+void osinfo_list_foreach(OsinfoList *self, osinfo_list_iterator iter, gpointer data)
+{
+    int i;
+    for (i = 0 ; i < self->priv->array->len ; i++) {
+        OsinfoEntity *ent = g_ptr_array_index(self->priv->array, i);
+	iter(self, ent, data);
+    }
+}
diff --git a/osinfo/osinfo_list.h b/osinfo/osinfo_list.h
index 4daeea9..3263061 100644
--- a/osinfo/osinfo_list.h
+++ b/osinfo/osinfo_list.h
@@ -44,10 +44,14 @@ GType osinfo_list_get_type(void);
 
 gint osinfo_list_get_length(OsinfoList *self);
 OsinfoEntity *osinfo_list_get_nth(OsinfoList *self, gint idx);
+OsinfoEntity *osinfo_list_find_by_id(OsinfoList *self, const gchar *id);
 
 void osinfo_list_add(OsinfoList *self, OsinfoEntity *entity);
 void osinfo_list_add_filtered(OsinfoList *self, OsinfoList *source, OsinfoFilter *filter);
 void osinfo_list_add_intersection(OsinfoList *self, OsinfoList *sourceOne, OsinfoList *sourceTwo);
 void osinfo_list_add_union(OsinfoList *self, OsinfoList *sourceOne, OsinfoList *sourceTwo);
 
+typedef gboolean (*osinfo_list_iterator)(OsinfoList *self, OsinfoEntity *entity, gpointer data);
+void osinfo_list_foreach(OsinfoList *self, osinfo_list_iterator iter, gpointer data);
+
 #endif /* __OSINFO_LIST_H__ */
diff --git a/osinfo/osinfo_oslist.h b/osinfo/osinfo_oslist.h
index 7adc69f..d5d0ef9 100644
--- a/osinfo/osinfo_oslist.h
+++ b/osinfo/osinfo_oslist.h
@@ -18,7 +18,7 @@
 #define OSINFO_IS_OSLIST_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_OSLIST))
 #define OSINFO_OSLIST_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_OSLIST, OsinfoOsListClass))
 
-typedef struct _OsinfoOsList        OsinfoOsList;
+//typedef struct _OsinfoOsList        OsinfoOsList;
 
 typedef struct _OsinfoOsListClass   OsinfoOsListClass;
 
-- 
1.7.2.1




More information about the virt-tools-list mailing list