[virt-tools-list] [PATCH 34/47] Remove all remaining Hypervisor/Os structs out of common code

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


Make OsinfoOsPrivate, OsinfoHypervisorPrivate structs private
to their respective objects, and update all code which poked
at private data to use formal APIs

* osinfo/osinfo_common.h, osinfo/osinfo_common.c: Remove the
  OsinfoOsPrivate, OsinfoHypervisorPrivate structs and
  related helper methods
* osinfo/osinfo_os.c: Add OsinfoOsPrivate struct & helper
  methods
* osinfo/osinfo_hypervisor.c: Add OsinfoHypervisorPrivate
  struct & helper methods.
* osinfo/osinfo_db.c, osinfo/osinfo_entity.c,
  osinfo/osinfo_filter.c: Convert to use APIs instead of
  accessing private data of OS/Hypervisor objects.
---
 osinfo/osinfo_common.c     |   56 +-------------------------------------------
 osinfo/osinfo_common.h     |   52 ----------------------------------------
 osinfo/osinfo_db.c         |    6 ++++
 osinfo/osinfo_entity.c     |   17 -------------
 osinfo/osinfo_filter.c     |   17 +++++++++++++
 osinfo/osinfo_hypervisor.c |   20 +++++++++++++--
 osinfo/osinfo_os.c         |   49 +++++++++++++++++++++++++++++++++-----
 7 files changed, 83 insertions(+), 134 deletions(-)

diff --git a/osinfo/osinfo_common.c b/osinfo/osinfo_common.c
index 1e3e3b3..c1c1612 100644
--- a/osinfo/osinfo_common.c
+++ b/osinfo/osinfo_common.c
@@ -1,21 +1,5 @@
 #include <osinfo/osinfo.h>
 
-void __osinfoFreeDeviceLink(gpointer ptr)
-{
-    if (!ptr)
-        return;
-    struct __osinfoDeviceLink *devLink = (struct __osinfoDeviceLink *) ptr;
-    g_free(devLink->driver);
-    g_free(devLink);
-}
-
-void __osinfoFreeDeviceSection(gpointer tree)
-{
-    if (!tree)
-        return;
-    g_tree_destroy((GTree *)tree);
-}
-
 gint __osinfoStringCompare(gconstpointer a,
                            gconstpointer b,
                            gpointer data)
@@ -26,23 +10,6 @@ gint __osinfoStringCompare(gconstpointer a,
     return g_strcmp0(str1, str2);
 }
 
-gint __osinfoStringCompareBase(gconstpointer a,
-                               gconstpointer b)
-{
-    // a and b are each gchar *, data is ignored
-    gchar *str1 = (gchar *) a;
-    gchar *str2 = (gchar *) b;
-    return g_strcmp0(str1, str2);
-}
-
-gint __osinfoIntCompareBase(gconstpointer a,
-                            gconstpointer b)
-{
-    // a and b are each gchar *, data is ignored
-    unsigned long int1 = (unsigned long) a;
-    unsigned long int2 = (unsigned long) b;
-    return a - b;
-}
 
 gint __osinfoIntCompare(gconstpointer a,
                         gconstpointer b,
@@ -54,29 +21,8 @@ gint __osinfoIntCompare(gconstpointer a,
     return a - b;
 }
 
+
 void __osinfoFreePtrArray(gpointer ptrarray)
 {
     g_ptr_array_free(ptrarray, TRUE);
 }
-
-void __osinfoFreeRelationship(gpointer ptrarray)
-{
-    if (!ptrarray)
-        return;
-    __osinfoFreePtrArray(ptrarray);
-}
-
-void __osinfoFreeParamVals(gpointer ptrarray)
-{
-    if (!ptrarray)
-        return;
-    __osinfoFreePtrArray(ptrarray);
-}
-
-void __osinfoFreeOsLink(gpointer ptr)
-{
-    if (!ptr)
-        return;
-    struct __osinfoOsLink *osLink = (struct __osinfoOsLink *) ptr;
-    g_free(osLink);
-}
diff --git a/osinfo/osinfo_common.h b/osinfo/osinfo_common.h
index 9ea70f7..309a1b0 100644
--- a/osinfo/osinfo_common.h
+++ b/osinfo/osinfo_common.h
@@ -36,76 +36,24 @@ typedef enum OSI_RELATIONSHIP {
  * Internal data structures
  ******************************************************************************/
 
-struct __osinfoDeviceLink {
-    OsinfoDevice *dev;
-    gchar *driver;
-};
-
-struct __osinfoOsLink {
-    /* <self> 'verbs' <other_os>
-     * fedora11 upgrades fedora10
-     * centos clones rhel
-     * scientificlinux derives from rhel
-     */
-    osinfoRelationship relshp;
-    OsinfoOs *otherOs;
-};
-
-struct __osinfoOsCheckRelationshipArgs {
-    OsinfoList *list;
-    osinfoRelationship relshp;
-};
-
 
 /** ****************************************************************************
  *      Convenience methods
  ******************************************************************************/
 
-gint __osinfoIntCompareBase(gconstpointer a,
-                            gconstpointer b);
 gint __osinfoIntCompare(gconstpointer a,
                         gconstpointer b,
                         gpointer data);
-gint __osinfoStringCompareBase(gconstpointer a,
-                               gconstpointer b);
 gint __osinfoStringCompare(gconstpointer a,
                            gconstpointer b,
                            gpointer data);
 
 void __osinfoFreePtrArray(gpointer ptrarray);
-void __osinfoFreeRelationship(gpointer ptrarray);
-void __osinfoFreeParamVals(gpointer ptrarray);
-void __osinfoFreeDeviceSection(gpointer tree);
-void __osinfoFreeDeviceLink(gpointer ptr);
-void __osinfoFreeOsLink(gpointer ptr);
-
-gboolean osinfo_get_keys(gpointer key, gpointer value, gpointer data);
-void osinfo_dup_array(gpointer data, gpointer user_data);
 
 /** ****************************************************************************
  *      Private structures for objects
  ******************************************************************************/
 
-struct _OsinfoHypervisorPrivate
-{
-    // Value: List of device_link structs
-    GList *deviceLinks;
-};
-
-struct _OsinfoOsPrivate
-{
-    // OS-Hypervisor specific information
-    // Key: gchar* (hypervisor id)
-    // Value: GList: Element Value: List of device_link structs
-    GHashTable *hypervisors;
-
-    // Value: List of device_link structs
-    GList *deviceLinks;
-
-    // Value: Array of os_link structs
-    GList *osLinks;
-};
-
 
 
 #endif /* __OSINFO_OBJECTS_H__ */
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index 5a39025..eb547dd 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -279,6 +279,12 @@ GList *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *self, gchar *propNa
     return osinfo_db_unique_values_for_property_in_entity(OSINFO_LIST(self->priv->devices), propName);
 }
 
+struct __osinfoOsCheckRelationshipArgs {
+    OsinfoList *list;
+    osinfoRelationship relshp;
+};
+
+
 static gboolean __osinfoAddOsIfRelationship(OsinfoList *list, OsinfoEntity *entity, gpointer data)
 {
     struct __osinfoOsCheckRelationshipArgs *args = data;
diff --git a/osinfo/osinfo_entity.c b/osinfo/osinfo_entity.c
index 2bec761..15d4ab4 100644
--- a/osinfo/osinfo_entity.c
+++ b/osinfo/osinfo_entity.c
@@ -148,23 +148,6 @@ void osinfo_entity_clear_param(OsinfoEntity *self, gchar *key)
     g_hash_table_remove(self->priv->params, key);
 }
 
-gboolean osinfo_get_keys(gpointer key, gpointer value, gpointer data)
-{
-    GPtrArray *results = data;
-    gchar *keyDup = g_strdup(key);
-
-    g_ptr_array_add(results, keyDup);
-    return FALSE; // Continue iterating
-}
-
-void osinfo_dup_array(gpointer data, gpointer user_data)
-{
-    GPtrArray *results = data;
-    gchar *valueDup = g_strdup(data);
-
-    g_ptr_array_add(results, valueDup);
-}
-
 gchar *osinfo_entity_get_id(OsinfoEntity *self)
 {
     g_return_val_if_fail(OSINFO_IS_ENTITY(self), NULL);
diff --git a/osinfo/osinfo_filter.c b/osinfo/osinfo_filter.c
index 2d826ef..59a9c82 100644
--- a/osinfo/osinfo_filter.c
+++ b/osinfo/osinfo_filter.c
@@ -16,6 +16,23 @@ struct _OsinfoFilterPrivate
     GTree *relationshipConstraints;
 };
 
+gboolean osinfo_get_keys(gpointer key, gpointer value, gpointer data)
+{
+    GPtrArray *results = data;
+    gchar *keyDup = g_strdup(key);
+
+    g_ptr_array_add(results, keyDup);
+    return FALSE; // Continue iterating
+}
+
+void osinfo_dup_array(gpointer data, gpointer user_data)
+{
+    GPtrArray *results = data;
+    gchar *valueDup = g_strdup(data);
+
+    g_ptr_array_add(results, valueDup);
+}
+
 
 static void osinfo_filter_finalize (GObject *object);
 
diff --git a/osinfo/osinfo_hypervisor.c b/osinfo/osinfo_hypervisor.c
index 3f20b56..911edca 100644
--- a/osinfo/osinfo_hypervisor.c
+++ b/osinfo/osinfo_hypervisor.c
@@ -4,11 +4,25 @@ G_DEFINE_TYPE (OsinfoHypervisor, osinfo_hypervisor, OSINFO_TYPE_ENTITY);
 
 #define OSINFO_HYPERVISOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_HYPERVISOR, OsinfoHypervisorPrivate))
 
+struct _OsinfoHypervisorPrivate
+{
+    // Value: List of device_link structs
+    GList *deviceLinks;
+};
+
+struct _OsinfoHypervisorDeviceLink {
+    OsinfoDevice *dev;
+    gchar *driver;
+};
+
 static void osinfo_hypervisor_finalize (GObject *object);
 
 static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
 {
-    __osinfoFreeDeviceLink(data);
+    struct _OsinfoHypervisorDeviceLink *link = data;
+    g_object_unref(link->dev);
+    g_free(link->driver);
+    g_free(link);
 }
 
 static void
@@ -59,7 +73,7 @@ OsinfoDeviceList *osinfo_hypervisor_get_devices(OsinfoHypervisor *self, OsinfoFi
     GList *tmp = self->priv->deviceLinks;
 
     while (tmp) {
-        struct __osinfoDeviceLink *link = tmp->data;
+        struct _OsinfoHypervisorDeviceLink *link = tmp->data;
 
         if (osinfo_entity_matches_filter(OSINFO_ENTITY(link->dev), filter))
 	    osinfo_list_add(OSINFO_LIST(newList), OSINFO_ENTITY(link->dev));
@@ -76,7 +90,7 @@ void osinfo_hypervisor_add_device(OsinfoHypervisor *self, OsinfoDevice *dev, con
     g_return_if_fail(OSINFO_IS_DEVICE(dev));
     g_return_if_fail(driver != NULL);
 
-    struct __osinfoDeviceLink *link = g_new0(struct __osinfoDeviceLink, 1);
+    struct _OsinfoHypervisorDeviceLink *link = g_new0(struct _OsinfoHypervisorDeviceLink, 1);
 
     g_object_ref(dev);
     link->dev = dev;
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 5842a12..d023888 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -4,16 +4,51 @@ G_DEFINE_TYPE (OsinfoOs, osinfo_os, OSINFO_TYPE_ENTITY);
 
 #define OSINFO_OS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_OS, OsinfoOsPrivate))
 
+struct _OsinfoOsPrivate
+{
+    // OS-Hypervisor specific information
+    // Key: gchar* (hypervisor id)
+    // Value: GList: Element Value: List of device_link structs
+    GHashTable *hypervisors;
+
+    // Value: List of device_link structs
+    GList *deviceLinks;
+
+    // Value: Array of os_link structs
+    GList *osLinks;
+};
+
+struct _OsinfoOsOsLink {
+    /* <self> 'verbs' <other_os>
+     * fedora11 upgrades fedora10
+     * centos clones rhel
+     * scientificlinux derives from rhel
+     */
+    osinfoRelationship relshp;
+    OsinfoOs *otherOs;
+};
+
+struct _OsinfoOsDeviceLink {
+    OsinfoDevice *dev;
+    gchar *driver;
+};
+
+
 static void osinfo_os_finalize (GObject *object);
 
 static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
 {
-    __osinfoFreeDeviceLink(data);
+    struct _OsinfoOsDeviceLink *link = data;
+    g_object_unref(link->dev);
+    g_free(link->driver);
+    g_free(link);
 }
 
 static void osinfo_os_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
 {
-    __osinfoFreeOsLink(data);
+    struct _OsinfoOsOsLink *link = data;
+    g_object_unref(link->otherOs);
+    g_free(link);
 }
 
 
@@ -92,7 +127,7 @@ OsinfoDevice *osinfo_os_get_preferred_device(OsinfoOs *self, OsinfoHypervisor *h
 
     // For each device in section list, apply filter. If filter passes, return device.
     while (tmp) {
-        struct __osinfoDeviceLink *link = tmp->data;
+        struct _OsinfoOsDeviceLink *link = tmp->data;
 
         if (osinfo_entity_matches_filter(OSINFO_ENTITY(link->dev), filter)) {
 	    *driver = link->driver;
@@ -114,7 +149,7 @@ OsinfoOsList *osinfo_os_get_related(OsinfoOs *self, osinfoRelationship relshp)
     GList *tmp = self->priv->osLinks;
 
     while (tmp) {
-        struct __osinfoOsLink *link = tmp->data;
+        struct _OsinfoOsOsLink *link = tmp->data;
 
 	if (link->relshp == relshp)
 	    osinfo_list_add(OSINFO_LIST(newList), OSINFO_ENTITY(link->otherOs));
@@ -141,7 +176,7 @@ OsinfoDeviceList *osinfo_os_get_devices(OsinfoOs *self, OsinfoHypervisor *hv, Os
         tmp = self->priv->deviceLinks;
 
     while (tmp) {
-        struct __osinfoDeviceLink *link = tmp->data;
+        struct _OsinfoOsDeviceLink *link = tmp->data;
 
         if (osinfo_entity_matches_filter(OSINFO_ENTITY(link->dev), filter))
 	    osinfo_list_add(OSINFO_LIST(newList), OSINFO_ENTITY(link->dev));
@@ -159,7 +194,7 @@ void osinfo_os_add_device(OsinfoOs *self, OsinfoHypervisor *hv, OsinfoDevice *de
     g_return_if_fail(OSINFO_IS_DEVICE(dev));
     g_return_if_fail(driver != NULL);
 
-    struct __osinfoDeviceLink *link = g_new0(struct __osinfoDeviceLink, 1);
+    struct _OsinfoOsDeviceLink *link = g_new0(struct _OsinfoOsDeviceLink, 1);
 
     g_object_ref(dev);
     link->dev = dev;
@@ -184,7 +219,7 @@ void osinfo_os_add_related_os(OsinfoOs *self, osinfoRelationship relshp, OsinfoO
     g_return_if_fail(OSINFO_IS_OS(self));
     g_return_if_fail(OSINFO_IS_OS(otheros));
 
-    struct __osinfoOsLink *osLink = g_new0(struct __osinfoOsLink, 1);
+    struct _OsinfoOsOsLink *osLink = g_new0(struct _OsinfoOsOsLink, 1);
 
     g_object_ref(otheros);
     osLink->otherOs = otheros;
-- 
1.7.2.1




More information about the virt-tools-list mailing list