vbox: Rewrite vboxConnectNumOfDomains

This commit is contained in:
Taowei 2014-08-11 18:06:15 +08:00 committed by Michal Privoznik
parent 0958334ac0
commit 5f15b511e9
3 changed files with 36 additions and 36 deletions

View File

@ -516,3 +516,38 @@ int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
gVBoxAPI.UArray.vboxArrayRelease(&machines);
return ret;
}
int vboxConnectNumOfDomains(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 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;
gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
if (isAccessible) {
gVBoxAPI.UIMachine.GetState(machine, &state);
if (gVBoxAPI.machineStateChecker.Online(state))
ret++;
}
}
}
cleanup:
gVBoxAPI.UArray.vboxArrayRelease(&machines);
return ret;
}

View File

@ -921,42 +921,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
return result;
}
static int vboxConnectNumOfDomains(virConnectPtr conn)
{
VBOX_OBJECT_CHECK(conn, int, -1);
vboxArray machines = VBOX_ARRAY_INITIALIZER;
PRUint32 state;
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 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;
}
static virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
unsigned int flags)
{

View File

@ -256,6 +256,7 @@ int vboxConnectIsAlive(virConnectPtr conn);
int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
char *vboxConnectGetCapabilities(virConnectPtr conn);
int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids);
int vboxConnectNumOfDomains(virConnectPtr conn);
/* Version specified functions for installing uniformed API */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);