[PATCH 07/13] vbox: Rewrite vboxNetworkLookupByUUID

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

 



---
 src/vbox/vbox_common.c        |   43 +++++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   57 ++++++++++-------------------------------
 src/vbox/vbox_uniformed_api.h |    8 ++++++
 3 files changed, 64 insertions(+), 44 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index b8a633d..03ab8d0 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -7662,6 +7662,49 @@ int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int n
     return ret;
 }
 
+virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
+{
+    VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL);
+    PRUint32 interfaceType = 0;
+    char *nameUtf8       = NULL;
+    PRUnichar *nameUtf16 = NULL;
+    IHostNetworkInterface *networkInterface = NULL;
+    vboxIIDUnion iid;
+
+    VBOX_IID_INITIALIZE(&iid);
+    vboxIIDFromUUID(&iid, uuid);
+
+    /* TODO: "internal" networks are just strings and
+     * thus can't do much with them
+     */
+
+    gVBoxAPI.UIHost.FindHostNetworkInterfaceById(host, &iid,
+                                                 &networkInterface);
+    if (!networkInterface)
+        goto cleanup;
+
+    gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType);
+
+    if (interfaceType != HostNetworkInterfaceType_HostOnly)
+        goto cleanup;
+
+    gVBoxAPI.UIHNInterface.GetName(networkInterface, &nameUtf16);
+    VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
+
+    ret = virGetNetwork(conn, nameUtf8, uuid);
+
+    VIR_DEBUG("Network Name: %s", nameUtf8);
+    DEBUGIID("Network UUID", &iid);
+    VBOX_UTF8_FREE(nameUtf8);
+    VBOX_UTF16_FREE(nameUtf16);
+
+ cleanup:
+    VBOX_RELEASE(networkInterface);
+    VBOX_RELEASE(host);
+    vboxIIDUnalloc(&iid);
+    return ret;
+}
+
 /**
  * Function Tables
  */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index f52690a..282ab6a 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2061,50 +2061,6 @@ _registerDomainEvent(virDriverPtr driver)
  */
 
 static virNetworkPtr
-vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
-{
-    VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL);
-    vboxIID iid = VBOX_IID_INITIALIZER;
-
-    vboxIIDFromUUID(&iid, uuid);
-
-    /* TODO: "internal" networks are just strings and
-     * thus can't do much with them
-     */
-    IHostNetworkInterface *networkInterface = NULL;
-
-    host->vtbl->FindHostNetworkInterfaceById(host, iid.value, &networkInterface);
-    if (networkInterface) {
-        PRUint32 interfaceType = 0;
-
-        networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType);
-
-        if (interfaceType == HostNetworkInterfaceType_HostOnly) {
-            char *nameUtf8       = NULL;
-            PRUnichar *nameUtf16 = NULL;
-
-            networkInterface->vtbl->GetName(networkInterface, &nameUtf16);
-            VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
-
-            ret = virGetNetwork(conn, nameUtf8, uuid);
-
-            VIR_DEBUG("Network Name: %s", nameUtf8);
-            DEBUGIID("Network UUID", iid.value);
-
-            VBOX_UTF8_FREE(nameUtf8);
-            VBOX_UTF16_FREE(nameUtf16);
-        }
-
-        VBOX_RELEASE(networkInterface);
-    }
-
-    VBOX_RELEASE(host);
-
-    vboxIIDUnalloc(&iid);
-    return ret;
-}
-
-static virNetworkPtr
 vboxNetworkLookupByName(virConnectPtr conn, const char *name)
 {
     VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL);
@@ -5896,6 +5852,14 @@ _displayTakeScreenShotPNGToArray(IDisplay *display ATTRIBUTE_UNUSED,
 }
 
 static nsresult
+_hostFindHostNetworkInterfaceById(IHost *host, vboxIIDUnion *iidu,
+                                  IHostNetworkInterface **networkInterface)
+{
+    return host->vtbl->FindHostNetworkInterfaceById(host, IID_MEMBER(value),
+                                                    networkInterface);
+}
+
+static nsresult
 _hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType)
 {
     return hni->vtbl->GetInterfaceType(hni, interfaceType);
@@ -6216,6 +6180,10 @@ static vboxUniformedIDisplay _UIDisplay = {
     .TakeScreenShotPNGToArray = _displayTakeScreenShotPNGToArray,
 };
 
+static vboxUniformedIHost _UIHost = {
+    .FindHostNetworkInterfaceById = _hostFindHostNetworkInterfaceById,
+};
+
 static vboxUniformedIHNInterface _UIHNInterface = {
     .GetInterfaceType = _hnInterfaceGetInterfaceType,
     .GetStatus = _hnInterfaceGetStatus,
@@ -6275,6 +6243,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
     pVBoxAPI->UISharedFolder = _UISharedFolder;
     pVBoxAPI->UISnapshot = _UISnapshot;
     pVBoxAPI->UIDisplay = _UIDisplay;
+    pVBoxAPI->UIHost = _UIHost;
     pVBoxAPI->UIHNInterface = _UIHNInterface;
     pVBoxAPI->machineStateChecker = _machineStateChecker;
 
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index e6729f2..2e0eb10 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -466,6 +466,12 @@ typedef struct {
                                          PRUint8** screenData);
 } vboxUniformedIDisplay;
 
+/* Functions for IHost */
+typedef struct {
+    nsresult (*FindHostNetworkInterfaceById)(IHost *host, vboxIIDUnion *iidu,
+                                             IHostNetworkInterface **networkInterface);
+} vboxUniformedIHost;
+
 /* Functions for IHostNetworkInterface */
 typedef struct {
     nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType);
@@ -527,6 +533,7 @@ typedef struct {
     vboxUniformedISharedFolder UISharedFolder;
     vboxUniformedISnapshot UISnapshot;
     vboxUniformedIDisplay UIDisplay;
+    vboxUniformedIHost UIHost;
     vboxUniformedIHNInterface UIHNInterface;
     uniformedMachineStateChecker machineStateChecker;
     /* vbox API features */
@@ -552,6 +559,7 @@ int vboxConnectNumOfNetworks(virConnectPtr conn);
 int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames);
 int vboxConnectNumOfDefinedNetworks(virConnectPtr conn);
 int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames);
+virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]