mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 20:45:18 +00:00
vbox: Rewrite vboxConnectListDefinedDomains
This commit is contained in:
parent
3611c4000c
commit
4ebae5e8b6
@ -3934,3 +3934,62 @@ char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
|
|||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
return ret;
|
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;
|
||||||
|
}
|
||||||
|
@ -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)
|
static int vboxConnectNumOfDefinedDomains(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
VBOX_OBJECT_CHECK(conn, int, -1);
|
VBOX_OBJECT_CHECK(conn, int, -1);
|
||||||
@ -9369,6 +9315,12 @@ static bool _machineStateOnline(PRUint32 state)
|
|||||||
(state <= MachineState_LastOnline));
|
(state <= MachineState_LastOnline));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _machineStateInactive(PRUint32 state)
|
||||||
|
{
|
||||||
|
return ((state > MachineState_FirstOnline) &&
|
||||||
|
(state < MachineState_LastOnline));
|
||||||
|
}
|
||||||
|
|
||||||
static bool _machineStateNotStart(PRUint32 state)
|
static bool _machineStateNotStart(PRUint32 state)
|
||||||
{
|
{
|
||||||
return ((state == MachineState_PoweredOff) ||
|
return ((state == MachineState_PoweredOff) ||
|
||||||
@ -9622,6 +9574,7 @@ static vboxUniformedISharedFolder _UISharedFolder = {
|
|||||||
|
|
||||||
static uniformedMachineStateChecker _machineStateChecker = {
|
static uniformedMachineStateChecker _machineStateChecker = {
|
||||||
.Online = _machineStateOnline,
|
.Online = _machineStateOnline,
|
||||||
|
.Inactive = _machineStateInactive,
|
||||||
.NotStart = _machineStateNotStart,
|
.NotStart = _machineStateNotStart,
|
||||||
.Running = _machineStateRunning,
|
.Running = _machineStateRunning,
|
||||||
.Paused = _machineStatePaused,
|
.Paused = _machineStatePaused,
|
||||||
|
@ -412,6 +412,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool (*Online)(PRUint32 state);
|
bool (*Online)(PRUint32 state);
|
||||||
|
bool (*Inactive)(PRUint32 state);
|
||||||
bool (*NotStart)(PRUint32 state);
|
bool (*NotStart)(PRUint32 state);
|
||||||
bool (*Running)(PRUint32 state);
|
bool (*Running)(PRUint32 state);
|
||||||
bool (*Paused)(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 vboxDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags);
|
||||||
int vboxDomainGetMaxVcpus(virDomainPtr dom);
|
int vboxDomainGetMaxVcpus(virDomainPtr dom);
|
||||||
char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags);
|
char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags);
|
||||||
|
int vboxConnectListDefinedDomains(virConnectPtr conn,
|
||||||
|
char ** const names, int maxnames);
|
||||||
|
|
||||||
/* Version specified functions for installing uniformed API */
|
/* Version specified functions for installing uniformed API */
|
||||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user