diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 2ae4059eaf645a08463dc3d76d28c41622686556..2010f4390c2fede75ef4090fcf30a39b8dec5945 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3934,3 +3934,62 @@ char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) virDomainDefFree(def); return ret; } + +int vboxConnectListDefinedDomains(virConnectPtr conn, + char ** const names, int maxnames) +{ + VBOX_OBJECT_CHECK(conn, int, -1); + vboxArray machines = VBOX_ARRAY_INITIALIZER; + char *machineName = NULL; + PRUnichar *machineNameUtf16 = NULL; + 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 Defined Domains, rc=%08x"), + (unsigned)rc); + goto cleanup; + } + + memset(names, 0, sizeof(names[i]) * maxnames); + + ret = 0; + for (i = 0, j = 0; (i < machines.count) && (j < maxnames); 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)) + continue; + + gVBoxAPI.UIMachine.GetName(machine, &machineNameUtf16); + VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName); + if (VIR_STRDUP(names[j], machineName) < 0) { + VBOX_UTF16_FREE(machineNameUtf16); + VBOX_UTF8_FREE(machineName); + for (j = 0; j < maxnames; j++) + VIR_FREE(names[j]); + ret = -1; + goto cleanup; + } + VBOX_UTF16_FREE(machineNameUtf16); + VBOX_UTF8_FREE(machineName); + j++; + ret++; + } + + cleanup: + gVBoxAPI.UArray.vboxArrayRelease(&machines); + return ret; +} diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 87f8a484a669651aa1a51802065cb13f1338ec79..1efaa0ecf3b29ff34fadfafa32e028caf450c34f 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -967,60 +967,6 @@ static virDomainState _vboxConvertState(PRUint32 state) } } -static int vboxConnectListDefinedDomains(virConnectPtr conn, char ** const names, int maxnames) { - VBOX_OBJECT_CHECK(conn, int, -1); - vboxArray machines = VBOX_ARRAY_INITIALIZER; - char *machineName = NULL; - PRUnichar *machineNameUtf16 = NULL; - 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 Defined Domains, rc=%08x"), - (unsigned)rc); - goto cleanup; - } - - memset(names, 0, sizeof(names[i]) * maxnames); - - ret = 0; - for (i = 0, j = 0; (i < machines.count) && (j < maxnames); 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)) { - machine->vtbl->GetName(machine, &machineNameUtf16); - VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName); - if (VIR_STRDUP(names[j], machineName) < 0) { - VBOX_UTF16_FREE(machineNameUtf16); - VBOX_UTF8_FREE(machineName); - for (j = 0; j < maxnames; j++) - VIR_FREE(names[j]); - ret = -1; - goto cleanup; - } - VBOX_UTF16_FREE(machineNameUtf16); - VBOX_UTF8_FREE(machineName); - j++; - ret++; - } - } - } - } - - cleanup: - vboxArrayRelease(&machines); - return ret; -} - static int vboxConnectNumOfDefinedDomains(virConnectPtr conn) { VBOX_OBJECT_CHECK(conn, int, -1); @@ -9369,6 +9315,12 @@ static bool _machineStateOnline(PRUint32 state) (state <= MachineState_LastOnline)); } +static bool _machineStateInactive(PRUint32 state) +{ + return ((state > MachineState_FirstOnline) && + (state < MachineState_LastOnline)); +} + static bool _machineStateNotStart(PRUint32 state) { return ((state == MachineState_PoweredOff) || @@ -9622,6 +9574,7 @@ static vboxUniformedISharedFolder _UISharedFolder = { static uniformedMachineStateChecker _machineStateChecker = { .Online = _machineStateOnline, + .Inactive = _machineStateInactive, .NotStart = _machineStateNotStart, .Running = _machineStateRunning, .Paused = _machineStatePaused, diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 518dd2a9a6054d50bd5329a14678a70aa9742eaf..7ff6b577609a9573ac07e12d0b53c040cbaba2c4 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -412,6 +412,7 @@ typedef struct { typedef struct { bool (*Online)(PRUint32 state); + bool (*Inactive)(PRUint32 state); bool (*NotStart)(PRUint32 state); bool (*Running)(PRUint32 state); bool (*Paused)(PRUint32 state); @@ -517,6 +518,8 @@ int vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus); int vboxDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags); int vboxDomainGetMaxVcpus(virDomainPtr dom); char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags); +int vboxConnectListDefinedDomains(virConnectPtr conn, + char ** const names, int maxnames); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);