[PATCH 08/13] vbox: Rewrite vboxNetworkLookupByName

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

 



---
 src/vbox/vbox_common.c        |   37 ++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   54 ++++++++++++-----------------------------
 src/vbox/vbox_uniformed_api.h |    4 +++
 3 files changed, 57 insertions(+), 38 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 03ab8d0..2a949c5 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -7705,6 +7705,43 @@ virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *u
     return ret;
 }
 
+virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name)
+{
+    VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL);
+    PRUnichar *nameUtf16                    = NULL;
+    IHostNetworkInterface *networkInterface = NULL;
+    PRUint32 interfaceType = 0;
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    vboxIIDUnion iid;
+
+    VBOX_IID_INITIALIZE(&iid);
+    VBOX_UTF8_TO_UTF16(name, &nameUtf16);
+
+    gVBoxAPI.UIHost.FindHostNetworkInterfaceByName(host, nameUtf16, &networkInterface);
+
+    if (!networkInterface)
+        goto cleanup;
+
+    gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType);
+
+    if (interfaceType != HostNetworkInterfaceType_HostOnly)
+        goto cleanup;
+
+    gVBoxAPI.UIHNInterface.GetId(networkInterface, &iid);
+    vboxIIDToUUID(&iid, uuid);
+    ret = virGetNetwork(conn, name, uuid);
+
+    VIR_DEBUG("Network Name: %s", name);
+    DEBUGIID("Network UUID", &iid);
+    vboxIIDUnalloc(&iid);
+
+ cleanup:
+    VBOX_RELEASE(networkInterface);
+    VBOX_UTF16_FREE(nameUtf16);
+    VBOX_RELEASE(host);
+    return ret;
+}
+
 /**
  * Function Tables
  */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 282ab6a..5f81367 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2061,44 +2061,6 @@ _registerDomainEvent(virDriverPtr driver)
  */
 
 static virNetworkPtr
-vboxNetworkLookupByName(virConnectPtr conn, const char *name)
-{
-    VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL);
-    PRUnichar *nameUtf16                    = NULL;
-    IHostNetworkInterface *networkInterface = NULL;
-
-    VBOX_UTF8_TO_UTF16(name, &nameUtf16);
-
-    host->vtbl->FindHostNetworkInterfaceByName(host, nameUtf16, &networkInterface);
-
-    if (networkInterface) {
-        PRUint32 interfaceType = 0;
-
-        networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType);
-
-        if (interfaceType == HostNetworkInterfaceType_HostOnly) {
-            unsigned char uuid[VIR_UUID_BUFLEN];
-            vboxIID iid = VBOX_IID_INITIALIZER;
-
-            networkInterface->vtbl->GetId(networkInterface, &iid.value);
-            vboxIIDToUUID(&iid, uuid);
-            ret = virGetNetwork(conn, name, uuid);
-            VIR_DEBUG("Network Name: %s", name);
-
-            DEBUGIID("Network UUID", iid.value);
-            vboxIIDUnalloc(&iid);
-        }
-
-        VBOX_RELEASE(networkInterface);
-    }
-
-    VBOX_UTF16_FREE(nameUtf16);
-    VBOX_RELEASE(host);
-
-    return ret;
-}
-
-static virNetworkPtr
 vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start)
 {
     VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL);
@@ -5860,6 +5822,14 @@ _hostFindHostNetworkInterfaceById(IHost *host, vboxIIDUnion *iidu,
 }
 
 static nsresult
+_hostFindHostNetworkInterfaceByName(IHost *host, PRUnichar *name,
+                                    IHostNetworkInterface **networkInterface)
+{
+    return host->vtbl->FindHostNetworkInterfaceByName(host, name,
+                                                      networkInterface);
+}
+
+static nsresult
 _hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType)
 {
     return hni->vtbl->GetInterfaceType(hni, interfaceType);
@@ -5877,6 +5847,12 @@ _hnInterfaceGetName(IHostNetworkInterface *hni, PRUnichar **name)
     return hni->vtbl->GetName(hni, name);
 }
 
+static nsresult
+_hnInterfaceGetId(IHostNetworkInterface *hni, vboxIIDUnion *iidu)
+{
+    return hni->vtbl->GetId(hni, &IID_MEMBER(value));
+}
+
 static bool _machineStateOnline(PRUint32 state)
 {
     return ((state >= MachineState_FirstOnline) &&
@@ -6182,12 +6158,14 @@ static vboxUniformedIDisplay _UIDisplay = {
 
 static vboxUniformedIHost _UIHost = {
     .FindHostNetworkInterfaceById = _hostFindHostNetworkInterfaceById,
+    .FindHostNetworkInterfaceByName = _hostFindHostNetworkInterfaceByName,
 };
 
 static vboxUniformedIHNInterface _UIHNInterface = {
     .GetInterfaceType = _hnInterfaceGetInterfaceType,
     .GetStatus = _hnInterfaceGetStatus,
     .GetName = _hnInterfaceGetName,
+    .GetId = _hnInterfaceGetId,
 };
 
 static uniformedMachineStateChecker _machineStateChecker = {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 2e0eb10..a14ee1c 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -470,6 +470,8 @@ typedef struct {
 typedef struct {
     nsresult (*FindHostNetworkInterfaceById)(IHost *host, vboxIIDUnion *iidu,
                                              IHostNetworkInterface **networkInterface);
+    nsresult (*FindHostNetworkInterfaceByName)(IHost *host, PRUnichar *name,
+                                               IHostNetworkInterface **networkInterface);
 } vboxUniformedIHost;
 
 /* Functions for IHostNetworkInterface */
@@ -477,6 +479,7 @@ typedef struct {
     nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType);
     nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status);
     nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name);
+    nsresult (*GetId)(IHostNetworkInterface *hni, vboxIIDUnion *iidu);
 } vboxUniformedIHNInterface;
 
 typedef struct {
@@ -560,6 +563,7 @@ 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);
+virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name);
 
 /* 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]