[PATCH 17/36] datatypes: convert virNWFilter to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/virnwfilterobj.c |  6 +++--
 src/datatypes.c           | 46 ++++++++++++++++++++++++---------------
 src/datatypes.h           | 10 +++++----
 src/libvirt-nwfilter.c    |  7 +++---
 src/libvirt_private.syms  |  1 -
 5 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index c9e224061d..6d89701199 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -473,8 +473,10 @@ virNWFilterObjListExport(virConnectPtr conn,
 
  cleanup:
     if (tmp_filters) {
-        for (i = 0; i < nfilters; i ++)
-            virObjectUnref(tmp_filters[i]);
+        for (i = 0; i < nfilters; i ++) {
+            if (tmp_filters[i])
+                g_object_unref(tmp_filters[i]);
+        }
     }
     VIR_FREE(tmp_filters);
 
diff --git a/src/datatypes.c b/src/datatypes.c
index fd39c96b31..d4f60db2be 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -40,7 +40,6 @@ virClassPtr virInterfaceClass;
 virClassPtr virNetworkClass;
 virClassPtr virNetworkPortClass;
 virClassPtr virNodeDeviceClass;
-virClassPtr virNWFilterClass;
 virClassPtr virNWFilterBindingClass;
 virClassPtr virSecretClass;
 virClassPtr virStreamClass;
@@ -54,7 +53,6 @@ static void virInterfaceDispose(void *obj);
 static void virNetworkDispose(void *obj);
 static void virNetworkPortDispose(void *obj);
 static void virNodeDeviceDispose(void *obj);
-static void virNWFilterDispose(void *obj);
 static void virNWFilterBindingDispose(void *obj);
 static void virSecretDispose(void *obj);
 static void virStreamDispose(void *obj);
@@ -93,6 +91,22 @@ vir_domain_snapshot_class_init(virDomainSnapshotClass *klass)
     obj->finalize = virDomainSnapshotFinalize;
 }
 
+G_DEFINE_TYPE(virNWFilter, vir_nw_filter, G_TYPE_OBJECT);
+static void virNWFilterFinalize(GObject *obj);
+
+static void
+vir_nw_filter_init(virNWFilter *filter G_GNUC_UNUSED)
+{
+}
+
+static void
+vir_nw_filter_class_init(virNWFilterClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virNWFilterFinalize;
+}
+
 virClassPtr virAdmConnectClass;
 virClassPtr virAdmConnectCloseCallbackDataClass;
 
@@ -149,7 +163,6 @@ virDataTypesOnceInit(void)
     DECLARE_CLASS(virNetwork);
     DECLARE_CLASS(virNetworkPort);
     DECLARE_CLASS(virNodeDevice);
-    DECLARE_CLASS(virNWFilter);
     DECLARE_CLASS(virNWFilterBinding);
     DECLARE_CLASS(virSecret);
     DECLARE_CLASS(virStream);
@@ -883,7 +896,7 @@ virStreamDispose(void *obj)
  * @uuid: pointer to the uuid
  *
  * Allocates a new network filter object. When the object is no longer needed,
- * virObjectUnref() must be called in order to not leak data.
+ * g_object_unref() must be called in order to not leak data.
  *
  * Returns a pointer to the network filter object, or NULL on error.
  */
@@ -891,17 +904,16 @@ virNWFilterPtr
 virGetNWFilter(virConnectPtr conn, const char *name,
                const unsigned char *uuid)
 {
-    virNWFilterPtr ret = NULL;
+    g_autoptr(virNWFilter) ret = NULL;
 
     if (virDataTypesInitialize() < 0)
         return NULL;
 
-    virCheckConnectGoto(conn, error);
-    virCheckNonNullArgGoto(name, error);
-    virCheckNonNullArgGoto(uuid, error);
+    virCheckConnectReturn(conn, NULL);
+    virCheckNonNullArgReturn(name, NULL);
+    virCheckNonNullArgReturn(uuid, NULL);
 
-    if (!(ret = virObjectNew(virNWFilterClass)))
-        goto error;
+    ret = VIR_NW_FILTER(g_object_new(VIR_TYPE_NW_FILTER, NULL));
 
     ret->name = g_strdup(name);
 
@@ -909,16 +921,12 @@ virGetNWFilter(virConnectPtr conn, const char *name,
 
     ret->conn = virObjectRef(conn);
 
-    return ret;
-
- error:
-    virObjectUnref(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }
 
 
 /**
- * virNWFilterDispose:
+ * virNWFilterFinalize:
  * @obj: the network filter to release
  *
  * Unconditionally release all memory associated with a nwfilter.
@@ -928,9 +936,9 @@ virGetNWFilter(virConnectPtr conn, const char *name,
  * which may also be released if its ref count hits zero.
  */
 static void
-virNWFilterDispose(void *obj)
+virNWFilterFinalize(GObject *obj)
 {
-    virNWFilterPtr nwfilter = obj;
+    virNWFilterPtr nwfilter = VIR_NW_FILTER(obj);
     char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     virUUIDFormat(nwfilter->uuid, uuidstr);
@@ -938,6 +946,8 @@ virNWFilterDispose(void *obj)
 
     VIR_FREE(nwfilter->name);
     virObjectUnref(nwfilter->conn);
+
+    G_OBJECT_CLASS(vir_nw_filter_parent_class)->finalize(obj);
 }
 
 
diff --git a/src/datatypes.h b/src/datatypes.h
index 296196523b..e8bd9bf1e5 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -36,7 +36,6 @@ extern virClassPtr virInterfaceClass;
 extern virClassPtr virNetworkClass;
 extern virClassPtr virNetworkPortClass;
 extern virClassPtr virNodeDeviceClass;
-extern virClassPtr virNWFilterClass;
 extern virClassPtr virNWFilterBindingClass;
 extern virClassPtr virSecretClass;
 extern virClassPtr virStreamClass;
@@ -58,6 +57,9 @@ G_DECLARE_FINAL_TYPE(virDomainSnapshot,
                      DOMAIN_SNAPSHOT,
                      GObject);
 
+#define VIR_TYPE_NW_FILTER vir_nw_filter_get_type()
+G_DECLARE_FINAL_TYPE(virNWFilter, vir_nw_filter, VIR, NW_FILTER, GObject);
+
 extern virClassPtr virAdmConnectClass;
 
 #define VIR_TYPE_ADM_SERVER vir_adm_server_get_type()
@@ -312,8 +314,8 @@ G_DECLARE_FINAL_TYPE(virAdmClient, vir_adm_client, VIR, ADM_CLIENT, GObject);
 
 #define virCheckNWFilterReturn(obj, retval) \
     do { \
-        virNWFilterPtr _nw = (obj); \
-        if (!virObjectIsClass(_nw, virNWFilterClass) || \
+        virNWFilterPtr _nw = VIR_NW_FILTER(obj); \
+        if (!G_IS_OBJECT(_nw) || !(G_OBJECT_TYPE(_nw) == VIR_TYPE_NW_FILTER) || \
             !virObjectIsClass(_nw->conn, virConnectClass)) { \
             virReportErrorHelper(VIR_FROM_NWFILTER, \
                                  VIR_ERR_INVALID_NWFILTER, \
@@ -785,7 +787,7 @@ struct _virDomainSnapshot {
 * Internal structure associated to a network filter
 */
 struct _virNWFilter {
-    virObject parent;
+    GObject parent;
     virConnectPtr conn;                  /* pointer back to the connection */
     char *name;                          /* the network filter external name */
     unsigned char uuid[VIR_UUID_BUFLEN]; /* the network filter unique identifier */
diff --git a/src/libvirt-nwfilter.c b/src/libvirt-nwfilter.c
index d28220db8a..cd3f5759b7 100644
--- a/src/libvirt-nwfilter.c
+++ b/src/libvirt-nwfilter.c
@@ -281,7 +281,7 @@ virNWFilterFree(virNWFilterPtr nwfilter)
 
     virCheckNWFilterReturn(nwfilter, -1);
 
-    virObjectUnref(nwfilter);
+    g_object_unref(nwfilter);
     return 0;
 }
 
@@ -503,14 +503,13 @@ virNWFilterGetXMLDesc(virNWFilterPtr nwfilter, unsigned int flags)
 int
 virNWFilterRef(virNWFilterPtr nwfilter)
 {
-    VIR_DEBUG("nwfilter=%p refs=%d", nwfilter,
-              nwfilter ? nwfilter->parent.u.s.refs : 0);
+    VIR_DEBUG("nwfilter=%p", nwfilter);
 
     virResetLastError();
 
     virCheckNWFilterReturn(nwfilter, -1);
 
-    virObjectRef(nwfilter);
+    g_object_ref(nwfilter);
     return 0;
 }
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7528779127..aff0688548 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1369,7 +1369,6 @@ virNetworkClass;
 virNetworkPortClass;
 virNewConnectCloseCallbackData;
 virNodeDeviceClass;
-virNWFilterClass;
 virSecretClass;
 virStoragePoolClass;
 virStorageVolClass;
-- 
2.25.1






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

  Powered by Linux