--- src/vbox/vbox_common.c | 59 +++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 61 +++++------------------------------------ src/vbox/vbox_uniformed_api.h | 3 ++ 3 files changed, 69 insertions(+), 54 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index fa9c0b0..fcde620 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 f017840..7479f23 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -966,60 +966,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); @@ -9368,6 +9314,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) || @@ -9621,6 +9573,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 518dd2a..7ff6b57 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); -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list