mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
vbox: Rewrite vboxConnectListDomains
This commit is contained in:
parent
30a95f30ef
commit
0958334ac0
@ -97,6 +97,10 @@ if (!data->vboxObj) {\
|
|||||||
|
|
||||||
#define VBOX_IID_INITIALIZE(iid) gVBoxAPI.UIID.vboxIIDInitialize(iid)
|
#define VBOX_IID_INITIALIZE(iid) gVBoxAPI.UIID.vboxIIDInitialize(iid)
|
||||||
|
|
||||||
|
#define ARRAY_GET_MACHINES \
|
||||||
|
(gVBoxAPI.UArray.handleGetMachines(data->vboxObj))
|
||||||
|
|
||||||
|
|
||||||
/* global vbox API, used for all common codes. */
|
/* global vbox API, used for all common codes. */
|
||||||
static vboxUniformedAPI gVBoxAPI;
|
static vboxUniformedAPI gVBoxAPI;
|
||||||
|
|
||||||
@ -474,3 +478,41 @@ char *vboxConnectGetCapabilities(virConnectPtr conn)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
|
||||||
|
{
|
||||||
|
VBOX_OBJECT_CHECK(conn, int, -1);
|
||||||
|
vboxArray machines = VBOX_ARRAY_INITIALIZER;
|
||||||
|
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 Domains, rc=%08x"),
|
||||||
|
(unsigned)rc);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
for (i = 0, j = 0; (i < machines.count) && (j < nids); ++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++;
|
||||||
|
ids[j++] = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
gVBoxAPI.UArray.vboxArrayRelease(&machines);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -921,45 +921,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
|
|
||||||
{
|
|
||||||
VBOX_OBJECT_CHECK(conn, int, -1);
|
|
||||||
vboxArray machines = VBOX_ARRAY_INITIALIZER;
|
|
||||||
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 Domains, rc=%08x"),
|
|
||||||
(unsigned)rc);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
for (i = 0, j = 0; (i < machines.count) && (j < nids); ++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++;
|
|
||||||
ids[j++] = i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
vboxArrayRelease(&machines);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int vboxConnectNumOfDomains(virConnectPtr conn)
|
static int vboxConnectNumOfDomains(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
VBOX_OBJECT_CHECK(conn, int, -1);
|
VBOX_OBJECT_CHECK(conn, int, -1);
|
||||||
@ -11290,6 +11251,11 @@ static void _DEBUGIID(const char *msg, vboxIIDUnion *iidu)
|
|||||||
|
|
||||||
#endif /* VBOX_API_VERSION != 2002000 */
|
#endif /* VBOX_API_VERSION != 2002000 */
|
||||||
|
|
||||||
|
static void* _handleGetMachines(IVirtualBox *vboxObj)
|
||||||
|
{
|
||||||
|
return vboxObj->vtbl->GetMachines;
|
||||||
|
}
|
||||||
|
|
||||||
static nsresult _nsisupportsRelease(nsISupports *nsi)
|
static nsresult _nsisupportsRelease(nsISupports *nsi)
|
||||||
{
|
{
|
||||||
return nsi->vtbl->Release(nsi);
|
return nsi->vtbl->Release(nsi);
|
||||||
@ -11325,6 +11291,18 @@ _virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties **systemP
|
|||||||
return vboxObj->vtbl->GetSystemProperties(vboxObj, systemProperties);
|
return vboxObj->vtbl->GetSystemProperties(vboxObj, systemProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
_machineGetAccessible(IMachine *machine, PRBool *isAccessible)
|
||||||
|
{
|
||||||
|
return machine->vtbl->GetAccessible(machine, isAccessible);
|
||||||
|
}
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
_machineGetState(IMachine *machine, PRUint32 *state)
|
||||||
|
{
|
||||||
|
return machine->vtbl->GetState(machine, state);
|
||||||
|
}
|
||||||
|
|
||||||
#if VBOX_API_VERSION < 4000000
|
#if VBOX_API_VERSION < 4000000
|
||||||
|
|
||||||
static nsresult
|
static nsresult
|
||||||
@ -11389,6 +11367,12 @@ _systemPropertiesGetMaxGuestCPUCount(ISystemProperties *systemProperties, PRUint
|
|||||||
return systemProperties->vtbl->GetMaxGuestCPUCount(systemProperties, maxCPUCount);
|
return systemProperties->vtbl->GetMaxGuestCPUCount(systemProperties, maxCPUCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _machineStateOnline(PRUint32 state)
|
||||||
|
{
|
||||||
|
return ((state >= MachineState_FirstOnline) &&
|
||||||
|
(state <= MachineState_LastOnline));
|
||||||
|
}
|
||||||
|
|
||||||
static vboxUniformedPFN _UPFN = {
|
static vboxUniformedPFN _UPFN = {
|
||||||
.Initialize = _pfnInitialize,
|
.Initialize = _pfnInitialize,
|
||||||
.Uninitialize = _pfnUninitialize,
|
.Uninitialize = _pfnUninitialize,
|
||||||
@ -11409,6 +11393,12 @@ static vboxUniformedIID _UIID = {
|
|||||||
.DEBUGIID = _DEBUGIID,
|
.DEBUGIID = _DEBUGIID,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static vboxUniformedArray _UArray = {
|
||||||
|
.vboxArrayGet = vboxArrayGet,
|
||||||
|
.vboxArrayRelease = vboxArrayRelease,
|
||||||
|
.handleGetMachines = _handleGetMachines,
|
||||||
|
};
|
||||||
|
|
||||||
static vboxUniformednsISupports _nsUISupports = {
|
static vboxUniformednsISupports _nsUISupports = {
|
||||||
.Release = _nsisupportsRelease,
|
.Release = _nsisupportsRelease,
|
||||||
};
|
};
|
||||||
@ -11419,6 +11409,11 @@ static vboxUniformedIVirtualBox _UIVirtualBox = {
|
|||||||
.GetSystemProperties = _virtualboxGetSystemProperties,
|
.GetSystemProperties = _virtualboxGetSystemProperties,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static vboxUniformedIMachine _UIMachine = {
|
||||||
|
.GetAccessible = _machineGetAccessible,
|
||||||
|
.GetState = _machineGetState,
|
||||||
|
};
|
||||||
|
|
||||||
static vboxUniformedISession _UISession = {
|
static vboxUniformedISession _UISession = {
|
||||||
.OpenExisting = _sessionOpenExisting,
|
.OpenExisting = _sessionOpenExisting,
|
||||||
.GetConsole = _sessionGetConsole,
|
.GetConsole = _sessionGetConsole,
|
||||||
@ -11438,6 +11433,10 @@ static vboxUniformedISystemProperties _UISystemProperties = {
|
|||||||
.GetMaxGuestCPUCount = _systemPropertiesGetMaxGuestCPUCount,
|
.GetMaxGuestCPUCount = _systemPropertiesGetMaxGuestCPUCount,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static uniformedMachineStateChecker _machineStateChecker = {
|
||||||
|
.Online = _machineStateOnline,
|
||||||
|
};
|
||||||
|
|
||||||
void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
|
void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
|
||||||
{
|
{
|
||||||
pVBoxAPI->APIVersion = VBOX_API_VERSION;
|
pVBoxAPI->APIVersion = VBOX_API_VERSION;
|
||||||
@ -11446,12 +11445,15 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
|
|||||||
pVBoxAPI->registerGlobalData = _registerGlobalData;
|
pVBoxAPI->registerGlobalData = _registerGlobalData;
|
||||||
pVBoxAPI->UPFN = _UPFN;
|
pVBoxAPI->UPFN = _UPFN;
|
||||||
pVBoxAPI->UIID = _UIID;
|
pVBoxAPI->UIID = _UIID;
|
||||||
|
pVBoxAPI->UArray = _UArray;
|
||||||
pVBoxAPI->nsUISupports = _nsUISupports;
|
pVBoxAPI->nsUISupports = _nsUISupports;
|
||||||
pVBoxAPI->UIVirtualBox = _UIVirtualBox;
|
pVBoxAPI->UIVirtualBox = _UIVirtualBox;
|
||||||
|
pVBoxAPI->UIMachine = _UIMachine;
|
||||||
pVBoxAPI->UISession = _UISession;
|
pVBoxAPI->UISession = _UISession;
|
||||||
pVBoxAPI->UIConsole = _UIConsole;
|
pVBoxAPI->UIConsole = _UIConsole;
|
||||||
pVBoxAPI->UIProgress = _UIProgress;
|
pVBoxAPI->UIProgress = _UIProgress;
|
||||||
pVBoxAPI->UISystemProperties = _UISystemProperties;
|
pVBoxAPI->UISystemProperties = _UISystemProperties;
|
||||||
|
pVBoxAPI->machineStateChecker = _machineStateChecker;
|
||||||
|
|
||||||
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
|
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
|
||||||
pVBoxAPI->domainEventCallbacks = 0;
|
pVBoxAPI->domainEventCallbacks = 0;
|
||||||
|
@ -162,6 +162,14 @@ typedef struct {
|
|||||||
void (*DEBUGIID)(const char *msg, vboxIIDUnion *iidu);
|
void (*DEBUGIID)(const char *msg, vboxIIDUnion *iidu);
|
||||||
} vboxUniformedIID;
|
} vboxUniformedIID;
|
||||||
|
|
||||||
|
/* Functions for vboxArray */
|
||||||
|
typedef struct {
|
||||||
|
nsresult (*vboxArrayGet)(vboxArray *array, void *self, void *getter);
|
||||||
|
void (*vboxArrayRelease)(vboxArray *array);
|
||||||
|
/* Generate function pointers for vboxArrayGet */
|
||||||
|
void* (*handleGetMachines)(IVirtualBox *vboxObj);
|
||||||
|
} vboxUniformedArray;
|
||||||
|
|
||||||
/* Functions for nsISupports */
|
/* Functions for nsISupports */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
nsresult (*Release)(nsISupports *nsi);
|
nsresult (*Release)(nsISupports *nsi);
|
||||||
@ -174,6 +182,12 @@ typedef struct {
|
|||||||
nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
|
nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
|
||||||
} vboxUniformedIVirtualBox;
|
} vboxUniformedIVirtualBox;
|
||||||
|
|
||||||
|
/* Functions for IMachine */
|
||||||
|
typedef struct {
|
||||||
|
nsresult (*GetAccessible)(IMachine *machine, PRBool *isAccessible);
|
||||||
|
nsresult (*GetState)(IMachine *machine, PRUint32 *state);
|
||||||
|
} vboxUniformedIMachine;
|
||||||
|
|
||||||
/* Functions for ISession */
|
/* Functions for ISession */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
nsresult (*OpenExisting)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine *machine);
|
nsresult (*OpenExisting)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine *machine);
|
||||||
@ -197,6 +211,10 @@ typedef struct {
|
|||||||
nsresult (*GetMaxGuestCPUCount)(ISystemProperties *systemProperties, PRUint32 *maxCPUCount);
|
nsresult (*GetMaxGuestCPUCount)(ISystemProperties *systemProperties, PRUint32 *maxCPUCount);
|
||||||
} vboxUniformedISystemProperties;
|
} vboxUniformedISystemProperties;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool (*Online)(PRUint32 state);
|
||||||
|
} uniformedMachineStateChecker;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* vbox API version */
|
/* vbox API version */
|
||||||
uint32_t APIVersion;
|
uint32_t APIVersion;
|
||||||
@ -206,12 +224,15 @@ typedef struct {
|
|||||||
void (*registerGlobalData)(vboxGlobalData *data);
|
void (*registerGlobalData)(vboxGlobalData *data);
|
||||||
vboxUniformedPFN UPFN;
|
vboxUniformedPFN UPFN;
|
||||||
vboxUniformedIID UIID;
|
vboxUniformedIID UIID;
|
||||||
|
vboxUniformedArray UArray;
|
||||||
vboxUniformednsISupports nsUISupports;
|
vboxUniformednsISupports nsUISupports;
|
||||||
vboxUniformedIVirtualBox UIVirtualBox;
|
vboxUniformedIVirtualBox UIVirtualBox;
|
||||||
|
vboxUniformedIMachine UIMachine;
|
||||||
vboxUniformedISession UISession;
|
vboxUniformedISession UISession;
|
||||||
vboxUniformedIConsole UIConsole;
|
vboxUniformedIConsole UIConsole;
|
||||||
vboxUniformedIProgress UIProgress;
|
vboxUniformedIProgress UIProgress;
|
||||||
vboxUniformedISystemProperties UISystemProperties;
|
vboxUniformedISystemProperties UISystemProperties;
|
||||||
|
uniformedMachineStateChecker machineStateChecker;
|
||||||
/* vbox API features */
|
/* vbox API features */
|
||||||
bool domainEventCallbacks;
|
bool domainEventCallbacks;
|
||||||
bool hasStaticGlobalData;
|
bool hasStaticGlobalData;
|
||||||
@ -234,6 +255,7 @@ int vboxConnectIsEncrypted(virConnectPtr conn);
|
|||||||
int vboxConnectIsAlive(virConnectPtr conn);
|
int vboxConnectIsAlive(virConnectPtr conn);
|
||||||
int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
|
int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
|
||||||
char *vboxConnectGetCapabilities(virConnectPtr conn);
|
char *vboxConnectGetCapabilities(virConnectPtr conn);
|
||||||
|
int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids);
|
||||||
|
|
||||||
/* Version specified functions for installing uniformed API */
|
/* Version specified functions for installing uniformed API */
|
||||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||||
|
Loading…
Reference in New Issue
Block a user