[PATCH 11/66] vbox: Rewrite vboxConnectListDomains

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

 



---
 src/vbox/vbox_common.c        |   42 ++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   80 +++++++++++++++++++++--------------------
 src/vbox/vbox_uniformed_api.h |   22 ++++++++++++
 3 files changed, 105 insertions(+), 39 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index eaefe81..6de5757 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -97,6 +97,10 @@ if (!data->vboxObj) {\
 
 #define VBOX_IID_INITIALIZE(iid)                gVBoxAPI.UIID.vboxIIDInitialize(iid)
 
+#define ARRAY_GET_MACHINES \
+    (gVBoxAPI.UArray.handleGetMachines(data->vboxObj))
+
+
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
@@ -474,3 +478,41 @@ char *vboxConnectGetCapabilities(virConnectPtr conn)
 
     return ret;
 }
+
+int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
+{
+    VBOX_OBJECT_CHECK(conn, int, -1);
+    vboxArray machines = VBOX_ARRAY_INITIALIZER;
+    PRUint32 state;
+    nsresult rc;
+    size_t i, j;
+
+    rc = gVBoxAPI.UArray.vboxArrayGet(&machines, data->vboxObj, ARRAY_GET_MACHINES);
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Could not get list of Domains, rc=%08x"),
+                       (unsigned)rc);
+        goto cleanup;
+    }
+
+    ret = 0;
+    for (i = 0, j = 0; (i < machines.count) && (j < nids); ++i) {
+        IMachine *machine = machines.items[i];
+
+        if (machine) {
+            PRBool isAccessible = PR_FALSE;
+            gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
+            if (isAccessible) {
+                gVBoxAPI.UIMachine.GetState(machine, &state);
+                if (gVBoxAPI.machineStateChecker.Online(state)) {
+                    ret++;
+                    ids[j++] = i + 1;
+                }
+            }
+        }
+    }
+
+ cleanup:
+    gVBoxAPI.UArray.vboxArrayRelease(&machines);
+    return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 7f9b4cc..e0033b9 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -920,45 +920,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
     return result;
 }
 
-static int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
-{
-    VBOX_OBJECT_CHECK(conn, int, -1);
-    vboxArray machines = VBOX_ARRAY_INITIALIZER;
-    PRUint32 state;
-    nsresult rc;
-    size_t i, j;
-
-    rc = vboxArrayGet(&machines, data->vboxObj, data->vboxObj->vtbl->GetMachines);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not get list of Domains, rc=%08x"),
-                       (unsigned)rc);
-        goto cleanup;
-    }
-
-    ret = 0;
-    for (i = 0, j = 0; (i < machines.count) && (j < nids); ++i) {
-        IMachine *machine = machines.items[i];
-
-        if (machine) {
-            PRBool isAccessible = PR_FALSE;
-            machine->vtbl->GetAccessible(machine, &isAccessible);
-            if (isAccessible) {
-                machine->vtbl->GetState(machine, &state);
-                if ((state >= MachineState_FirstOnline) &&
-                    (state <= MachineState_LastOnline)) {
-                    ret++;
-                    ids[j++] = i + 1;
-                }
-            }
-        }
-    }
-
- cleanup:
-    vboxArrayRelease(&machines);
-    return ret;
-}
-
 static int vboxConnectNumOfDomains(virConnectPtr conn)
 {
     VBOX_OBJECT_CHECK(conn, int, -1);
@@ -11289,6 +11250,11 @@ static void _DEBUGIID(const char *msg, vboxIIDUnion *iidu)
 
 #endif /* VBOX_API_VERSION != 2002000 */
 
+static void* _handleGetMachines(IVirtualBox *vboxObj)
+{
+    return vboxObj->vtbl->GetMachines;
+}
+
 static nsresult _nsisupportsRelease(nsISupports *nsi)
 {
     return nsi->vtbl->Release(nsi);
@@ -11324,6 +11290,18 @@ _virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties **systemP
     return vboxObj->vtbl->GetSystemProperties(vboxObj, systemProperties);
 }
 
+static nsresult
+_machineGetAccessible(IMachine *machine, PRBool *isAccessible)
+{
+    return machine->vtbl->GetAccessible(machine, isAccessible);
+}
+
+static nsresult
+_machineGetState(IMachine *machine, PRUint32 *state)
+{
+    return machine->vtbl->GetState(machine, state);
+}
+
 #if VBOX_API_VERSION < 4000000
 
 static nsresult
@@ -11388,6 +11366,12 @@ _systemPropertiesGetMaxGuestCPUCount(ISystemProperties *systemProperties, PRUint
     return systemProperties->vtbl->GetMaxGuestCPUCount(systemProperties, maxCPUCount);
 }
 
+static bool _machineStateOnline(PRUint32 state)
+{
+    return ((state >= MachineState_FirstOnline) &&
+            (state <= MachineState_LastOnline));
+}
+
 static vboxUniformedPFN _UPFN = {
     .Initialize = _pfnInitialize,
     .Uninitialize = _pfnUninitialize,
@@ -11408,6 +11392,12 @@ static vboxUniformedIID _UIID = {
     .DEBUGIID = _DEBUGIID,
 };
 
+static vboxUniformedArray _UArray = {
+    .vboxArrayGet = vboxArrayGet,
+    .vboxArrayRelease = vboxArrayRelease,
+    .handleGetMachines = _handleGetMachines,
+};
+
 static vboxUniformednsISupports _nsUISupports = {
     .Release = _nsisupportsRelease,
 };
@@ -11418,6 +11408,11 @@ static vboxUniformedIVirtualBox _UIVirtualBox = {
     .GetSystemProperties = _virtualboxGetSystemProperties,
 };
 
+static vboxUniformedIMachine _UIMachine = {
+    .GetAccessible = _machineGetAccessible,
+    .GetState = _machineGetState,
+};
+
 static vboxUniformedISession _UISession = {
     .OpenExisting = _sessionOpenExisting,
     .GetConsole = _sessionGetConsole,
@@ -11437,6 +11432,10 @@ static vboxUniformedISystemProperties _UISystemProperties = {
     .GetMaxGuestCPUCount = _systemPropertiesGetMaxGuestCPUCount,
 };
 
+static uniformedMachineStateChecker _machineStateChecker = {
+    .Online = _machineStateOnline,
+};
+
 void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
 {
     pVBoxAPI->APIVersion = VBOX_API_VERSION;
@@ -11445,12 +11444,15 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
     pVBoxAPI->registerGlobalData = _registerGlobalData;
     pVBoxAPI->UPFN = _UPFN;
     pVBoxAPI->UIID = _UIID;
+    pVBoxAPI->UArray = _UArray;
     pVBoxAPI->nsUISupports = _nsUISupports;
     pVBoxAPI->UIVirtualBox = _UIVirtualBox;
+    pVBoxAPI->UIMachine = _UIMachine;
     pVBoxAPI->UISession = _UISession;
     pVBoxAPI->UIConsole = _UIConsole;
     pVBoxAPI->UIProgress = _UIProgress;
     pVBoxAPI->UISystemProperties = _UISystemProperties;
+    pVBoxAPI->machineStateChecker = _machineStateChecker;
 
 #if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
     pVBoxAPI->domainEventCallbacks = 0;
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index e49b881..b72429b 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -162,6 +162,14 @@ typedef struct {
     void (*DEBUGIID)(const char *msg, vboxIIDUnion *iidu);
 } vboxUniformedIID;
 
+/* Functions for vboxArray */
+typedef struct {
+    nsresult (*vboxArrayGet)(vboxArray *array, void *self, void *getter);
+    void (*vboxArrayRelease)(vboxArray *array);
+    /* Generate function pointers for vboxArrayGet */
+    void* (*handleGetMachines)(IVirtualBox *vboxObj);
+} vboxUniformedArray;
+
 /* Functions for nsISupports */
 typedef struct {
     nsresult (*Release)(nsISupports *nsi);
@@ -174,6 +182,12 @@ typedef struct {
     nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
 } vboxUniformedIVirtualBox;
 
+/* Functions for IMachine */
+typedef struct {
+    nsresult (*GetAccessible)(IMachine *machine, PRBool *isAccessible);
+    nsresult (*GetState)(IMachine *machine, PRUint32 *state);
+} vboxUniformedIMachine;
+
 /* Functions for ISession */
 typedef struct {
     nsresult (*OpenExisting)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine *machine);
@@ -198,6 +212,10 @@ typedef struct {
 } vboxUniformedISystemProperties;
 
 typedef struct {
+    bool (*Online)(PRUint32 state);
+} uniformedMachineStateChecker;
+
+typedef struct {
     /* vbox API version */
     uint32_t APIVersion;
     uint32_t XPCOMCVersion;
@@ -206,12 +224,15 @@ typedef struct {
     void (*registerGlobalData)(vboxGlobalData *data);
     vboxUniformedPFN UPFN;
     vboxUniformedIID UIID;
+    vboxUniformedArray UArray;
     vboxUniformednsISupports nsUISupports;
     vboxUniformedIVirtualBox UIVirtualBox;
+    vboxUniformedIMachine UIMachine;
     vboxUniformedISession UISession;
     vboxUniformedIConsole UIConsole;
     vboxUniformedIProgress UIProgress;
     vboxUniformedISystemProperties UISystemProperties;
+    uniformedMachineStateChecker machineStateChecker;
     /* vbox API features */
     bool domainEventCallbacks;
     bool hasStaticGlobalData;
@@ -234,6 +255,7 @@ int vboxConnectIsEncrypted(virConnectPtr conn);
 int vboxConnectIsAlive(virConnectPtr conn);
 int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
 char *vboxConnectGetCapabilities(virConnectPtr conn);
+int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids);
 
 /* 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]