]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
network_conf: Introduce virNetworkObjListForEach
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 23 Feb 2015 16:21:46 +0000 (17:21 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 9 Mar 2015 13:03:30 +0000 (14:03 +0100)
This API will be used in the future to call passed callback over
each network object in the list. It's slightly different to its
virDomainObjListForEach counterpart, because virDomainObjList
uses a hash table to store domain object, while virNetworkObjList
uses an array.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/network_conf.c
src/conf/network_conf.h
src/libvirt_private.syms

index d0e7e1b1c59c694dd93d7bb54aeb953fe4a0efb7..cb54e56571492dcce6f018090318a18aee17940b 100644 (file)
@@ -4290,3 +4290,30 @@ virNetworkObjListExport(virConnectPtr conn,
     VIR_FREE(tmp_nets);
     return ret;
 }
+
+/**
+ * virNetworkObjListForEach:
+ * @nets: a list of network objects
+ * @callback: function to call over each of object in the list
+ * @opaque: pointer to pass to the @callback
+ *
+ * Function iterates over the list of network objects and calls
+ * passed callback over each one of them.
+ *
+ * Returns: 0 on success, -1 otherwise.
+ */
+int
+virNetworkObjListForEach(virNetworkObjListPtr nets,
+                         virNetworkObjListIterator callback,
+                         void *opaque)
+{
+    int ret = 0;
+    size_t i = 0;
+
+    for (i = 0; i < nets->count; i++) {
+        if (callback(nets->objs[i], opaque) < 0)
+            ret = -1;
+    }
+
+    return ret;
+}
index 16aea999b3c539521f46bf9db248f3afb2313241..749c7fbf62e7e0e5ce71de7cc9f340541be2d1cf 100644 (file)
@@ -445,6 +445,12 @@ int virNetworkObjListExport(virConnectPtr conn,
                             virNetworkObjListFilter filter,
                             unsigned int flags);
 
+typedef int (*virNetworkObjListIterator)(virNetworkObjPtr net,
+                                         void *opaque);
+
+int virNetworkObjListForEach(virNetworkObjListPtr nets,
+                             virNetworkObjListIterator callback,
+                             void *opaque);
 /* for testing */
 int
 virNetworkDefUpdateSection(virNetworkDefPtr def,
index a579bc5516a23f9280247e4d6fdc7c475f0cdbb0..460730e28bf53aafb38e699ed2978f922b48c20a 100644 (file)
@@ -569,6 +569,7 @@ virNetworkObjFree;
 virNetworkObjGetPersistentDef;
 virNetworkObjIsDuplicate;
 virNetworkObjListExport;
+virNetworkObjListForEach;
 virNetworkObjListFree;
 virNetworkObjLock;
 virNetworkObjReplacePersistentDef;