---
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 ed6597c..8eedd4d 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -96,6 +96,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;
@@ -472,3 +476,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 569ae29..1138566 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -917,45 +917,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);
@@ -11288,6 +11249,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
_virtualboxGetVersion(IVirtualBox *vboxObj, PRUnichar **versionUtf16)
{
@@ -11318,6 +11284,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
@@ -11390,6 +11368,12 @@ static nsresult _nsisupportsRelease(void *Ihandle)
return nsi->vtbl->Release(nsi);
}
+static bool _machineStateOnline(PRUint32 state)
+{
+ return ((state >= MachineState_FirstOnline) &&
+ (state <= MachineState_LastOnline));
+}
+
static vboxUniformedPFN _UPFN = {
.Initialize = _pfnInitialize,
.Uninitialize = _pfnUninitialize,
@@ -11410,12 +11394,23 @@ static vboxUniformedIID _UIID = {
.DEBUGIID = _DEBUGIID,
};
+static vboxUniformedArray _UArray = {
+ .vboxArrayGet = vboxArrayGet,
+ .vboxArrayRelease = vboxArrayRelease,
+ .handleGetMachines = _handleGetMachines,
+};
+
static vboxUniformedIVirtualBox _UIVirtualBox = {
.GetVersion = _virtualboxGetVersion,
.GetMachine = _virtualboxGetMachine,
.GetSystemProperties = _virtualboxGetSystemProperties,
};
+static vboxUniformedIMachine _UIMachine = {
+ .GetAccessible = _machineGetAccessible,
+ .GetState = _machineGetState,
+};
+
static vboxUniformedISession _UISession = {
.OpenExisting = _sessionOpenExisting,
.GetConsole = _sessionGetConsole,
@@ -11439,6 +11434,10 @@ static vboxUniformednsISupports _nsUISupports = {
.Release = _nsisupportsRelease,
};
+static uniformedMachineStateChecker _machineStateChecker = {
+ .Online = _machineStateOnline,
+};
+
void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
{
pVBoxAPI->APIVersion = VBOX_API_VERSION;
@@ -11447,12 +11446,15 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
pVBoxAPI->registerGlobalData = _registerGlobalData;
pVBoxAPI->UPFN = _UPFN;
pVBoxAPI->UIID = _UIID;
+ pVBoxAPI->UArray = _UArray;
pVBoxAPI->UIVirtualBox = _UIVirtualBox;
+ pVBoxAPI->UIMachine = _UIMachine;
pVBoxAPI->UISession = _UISession;
pVBoxAPI->UIConsole = _UIConsole;
pVBoxAPI->UIProgress = _UIProgress;
pVBoxAPI->UISystemProperties = _UISystemProperties;
pVBoxAPI->nsUISupports = _nsUISupports;
+ pVBoxAPI->machineStateChecker = _machineStateChecker;
#if (VBOX_XPCOMC_VERSION == 0x00010000U) || (VBOX_API_VERSION == 2002000)
/* No event queue functionality in 2.2.* as of now */
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 18f6870..1035ce8 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -159,6 +159,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 IVirtualBox */
typedef struct {
nsresult (*GetVersion)(IVirtualBox *vboxObj, PRUnichar **versionUtf16);
@@ -166,6 +174,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);
@@ -195,6 +209,10 @@ typedef struct {
} vboxUniformednsISupports;
typedef struct {
+ bool (*Online)(PRUint32 state);
+} uniformedMachineStateChecker;
+
+typedef struct {
/* vbox API version */
uint32_t APIVersion;
uint32_t XPCOMCVersion;
@@ -203,12 +221,15 @@ typedef struct {
void (*registerGlobalData)(vboxGlobalData *data);
vboxUniformedPFN UPFN;
vboxUniformedIID UIID;
+ vboxUniformedArray UArray;
vboxUniformedIVirtualBox UIVirtualBox;
+ vboxUniformedIMachine UIMachine;
vboxUniformedISession UISession;
vboxUniformedIConsole UIConsole;
vboxUniformedIProgress UIProgress;
vboxUniformedISystemProperties UISystemProperties;
vboxUniformednsISupports nsUISupports;
+ uniformedMachineStateChecker machineStateChecker;
/* vbox API features */
bool fWatchNeedInitialize;
bool domainEventCallbacks;
@@ -231,6 +252,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