From 4eaa78be7ab780b60484ebea172b7c7f0edebcc2 Mon Sep 17 00:00:00 2001 From: Taowei Date: Mon, 11 Aug 2014 18:06:45 +0800 Subject: [PATCH] vbox: Rewrite vboxConnectNumOfDefinedDomains --- src/vbox/vbox_common.c | 40 +++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 38 --------------------------------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 2010f4390c..0741ff732f 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3993,3 +3993,43 @@ int vboxConnectListDefinedDomains(virConnectPtr conn, gVBoxAPI.UArray.vboxArrayRelease(&machines); return ret; } + +int vboxConnectNumOfDefinedDomains(virConnectPtr conn) +{ + VBOX_OBJECT_CHECK(conn, int, -1); + vboxArray machines = VBOX_ARRAY_INITIALIZER; + PRUint32 state; + nsresult rc; + size_t i; + + rc = gVBoxAPI.UArray.vboxArrayGet(&machines, data->vboxObj, + ARRAY_GET_MACHINES); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not get number of Defined Domains, rc=%08x"), + (unsigned)rc); + goto cleanup; + } + + ret = 0; + for (i = 0; i < machines.count; ++i) { + PRBool isAccessible = PR_FALSE; + IMachine *machine = machines.items[i]; + + if (!machine) + continue; + + gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible); + if (!isAccessible) + continue; + + gVBoxAPI.UIMachine.GetState(machine, &state); + if (gVBoxAPI.machineStateChecker.Inactive(state)) { + ret++; + } + } + + cleanup: + gVBoxAPI.UArray.vboxArrayRelease(&machines); + return ret; +} diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 1efaa0ecf3..f626cda153 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -967,44 +967,6 @@ static virDomainState _vboxConvertState(PRUint32 state) } } -static int vboxConnectNumOfDefinedDomains(virConnectPtr conn) -{ - VBOX_OBJECT_CHECK(conn, int, -1); - vboxArray machines = VBOX_ARRAY_INITIALIZER; - PRUint32 state = MachineState_Null; - nsresult rc; - size_t i; - - rc = vboxArrayGet(&machines, data->vboxObj, data->vboxObj->vtbl->GetMachines); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not get number of Defined Domains, rc=%08x"), - (unsigned)rc); - goto cleanup; - } - - ret = 0; - for (i = 0; i < machines.count; ++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++; - } - } - } - } - - cleanup: - vboxArrayRelease(&machines); - return ret; -} - #if VBOX_API_VERSION < 3001000 static void diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 7ff6b57760..f57eaa952a 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -520,6 +520,7 @@ int vboxDomainGetMaxVcpus(virDomainPtr dom); char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags); int vboxConnectListDefinedDomains(virConnectPtr conn, char ** const names, int maxnames); +int vboxConnectNumOfDefinedDomains(virConnectPtr conn); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- GitLab