]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
vbox: Rewrite vboxConnectNumOfDefinedNetworks
authorTaowei <uaedante@gmail.com>
Thu, 2 Oct 2014 03:30:30 +0000 (11:30 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 3 Oct 2014 08:43:03 +0000 (10:43 +0200)
src/vbox/vbox_network.c
src/vbox/vbox_tmpl.c
src/vbox/vbox_uniformed_api.h

index 0d09041160e44eee152485e8306cf5122403a6d2..a0f7e66ee8789d44bbaefbf6f57a99f3d4f9f41d 100644 (file)
@@ -197,3 +197,48 @@ int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames)
 
     return ret;
 }
+
+int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
+{
+    vboxGlobalData *data = conn->privateData;
+    vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
+    IHost *host = NULL;
+    size_t i = 0;
+    int ret = -1;
+
+    if (!data->vboxObj)
+        return ret;
+
+    gVBoxAPI.UIVirtualBox.GetHost(data->vboxObj, &host);
+    if (!host)
+        return ret;
+
+    gVBoxAPI.UArray.vboxArrayGet(&networkInterfaces, host,
+                                 gVBoxAPI.UArray.handleHostGetNetworkInterfaces(host));
+
+    ret = 0;
+    for (i = 0; i < networkInterfaces.count; i++) {
+        IHostNetworkInterface *networkInterface = networkInterfaces.items[i];
+        PRUint32 status = HostNetworkInterfaceStatus_Unknown;
+        PRUint32 interfaceType = 0;
+
+        if (!networkInterface)
+            continue;
+
+        gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType);
+        if (interfaceType != HostNetworkInterfaceType_HostOnly)
+            continue;
+
+        gVBoxAPI.UIHNInterface.GetStatus(networkInterface, &status);
+
+        if (status == HostNetworkInterfaceStatus_Down)
+            ret++;
+    }
+
+    gVBoxAPI.UArray.vboxArrayRelease(&networkInterfaces);
+
+    VBOX_RELEASE(host);
+
+    VIR_DEBUG("numActive: %d", ret);
+    return ret;
+}
index c7aae25dda85510bf4ca12d7f4f928008cf6c3ef..fec9ce17092c9fa556e636e001984b5984a2d9ca 100644 (file)
@@ -2060,40 +2060,6 @@ _registerDomainEvent(virDriverPtr driver)
  * The Network Functions here on
  */
 
-static int vboxConnectNumOfDefinedNetworks(virConnectPtr conn)
-{
-    VBOX_OBJECT_HOST_CHECK(conn, int, 0);
-    vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
-    size_t i = 0;
-
-    vboxArrayGet(&networkInterfaces, host, host->vtbl->GetNetworkInterfaces);
-
-    for (i = 0; i < networkInterfaces.count; i++) {
-        IHostNetworkInterface *networkInterface = networkInterfaces.items[i];
-
-        if (networkInterface) {
-            PRUint32 interfaceType = 0;
-
-            networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType);
-            if (interfaceType == HostNetworkInterfaceType_HostOnly) {
-                PRUint32 status = HostNetworkInterfaceStatus_Unknown;
-
-                networkInterface->vtbl->GetStatus(networkInterface, &status);
-
-                if (status == HostNetworkInterfaceStatus_Down)
-                    ret++;
-            }
-        }
-    }
-
-    vboxArrayRelease(&networkInterfaces);
-
-    VBOX_RELEASE(host);
-
-    VIR_DEBUG("numActive: %d", ret);
-    return ret;
-}
-
 static int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) {
     VBOX_OBJECT_HOST_CHECK(conn, int, 0);
     vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
index ec8e3341a081cc37325563f1a6696b1012ac3d15..2ca90ffde2337e02256fc515d755aba2d8490617 100644 (file)
@@ -550,6 +550,7 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn,
 int vboxNetworkClose(virConnectPtr conn);
 int vboxConnectNumOfNetworks(virConnectPtr conn);
 int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames);
+int vboxConnectNumOfDefinedNetworks(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);