mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-14 08:35:15 +00:00
vbox: remove domain events support.
this was implemented only for vbox 3 series and was mostly stubs anyway.
This commit is contained in:
parent
374422ea1c
commit
1d963578e8
@ -111,8 +111,6 @@ vboxDriverDispose(void *obj)
|
|||||||
|
|
||||||
virObjectUnref(driver->caps);
|
virObjectUnref(driver->caps);
|
||||||
virObjectUnref(driver->xmlopt);
|
virObjectUnref(driver->xmlopt);
|
||||||
if (gVBoxAPI.domainEventCallbacks)
|
|
||||||
virObjectUnref(driver->domainEventState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -145,10 +143,6 @@ vboxDriverObjNew(void)
|
|||||||
NULL, NULL)))
|
NULL, NULL)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (gVBoxAPI.domainEventCallbacks &&
|
|
||||||
!(driver->domainEventState = virObjectEventStateNew()))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
return driver;
|
return driver;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -199,10 +193,6 @@ vboxSdkInitialize(void)
|
|||||||
if (gVBoxAPI.UPFN.Initialize(vbox_driver) != 0)
|
if (gVBoxAPI.UPFN.Initialize(vbox_driver) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (gVBoxAPI.domainEventCallbacks &&
|
|
||||||
gVBoxAPI.initializeDomainEvent(vbox_driver) != 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (vbox_driver->vboxObj == NULL) {
|
if (vbox_driver->vboxObj == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("IVirtualBox object is null"));
|
_("IVirtualBox object is null"));
|
||||||
@ -7816,14 +7806,6 @@ virHypervisorDriver vboxCommonDriver = {
|
|||||||
.domainScreenshot = vboxDomainScreenshot, /* 0.9.2 */
|
.domainScreenshot = vboxDomainScreenshot, /* 0.9.2 */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void updateDriver(void)
|
|
||||||
{
|
|
||||||
/* Update the vboxDriver according to the vboxUniformedAPI.
|
|
||||||
* We need to make sure the vboxUniformedAPI is initialized
|
|
||||||
* before calling this function. */
|
|
||||||
gVBoxAPI.registerDomainEvent(&vboxCommonDriver);
|
|
||||||
}
|
|
||||||
|
|
||||||
virHypervisorDriverPtr vboxGetHypervisorDriver(uint32_t uVersion)
|
virHypervisorDriverPtr vboxGetHypervisorDriver(uint32_t uVersion)
|
||||||
{
|
{
|
||||||
/* Install gVBoxAPI according to the vbox API version. */
|
/* Install gVBoxAPI according to the vbox API version. */
|
||||||
@ -7835,7 +7817,5 @@ virHypervisorDriverPtr vboxGetHypervisorDriver(uint32_t uVersion)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDriver();
|
|
||||||
|
|
||||||
return &vboxCommonDriver;
|
return &vboxCommonDriver;
|
||||||
}
|
}
|
||||||
|
@ -413,646 +413,6 @@ _vboxDomainSnapshotRestore(virDomainPtr dom,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
|
|
||||||
/* No Callback support for VirtualBox 2.2.* series */
|
|
||||||
/* No Callback support for VirtualBox 4.* series */
|
|
||||||
|
|
||||||
static void
|
|
||||||
_registerDomainEvent(virHypervisorDriverPtr driver)
|
|
||||||
{
|
|
||||||
driver->connectDomainEventRegister = NULL;
|
|
||||||
driver->connectDomainEventDeregister = NULL;
|
|
||||||
driver->connectDomainEventRegisterAny = NULL;
|
|
||||||
driver->connectDomainEventDeregisterAny = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION >= 4000000) */
|
|
||||||
|
|
||||||
/* Functions needed for Callbacks */
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId, PRUint32 state)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
virDomainPtr dom = NULL;
|
|
||||||
|
|
||||||
int event = 0;
|
|
||||||
int detail = 0;
|
|
||||||
|
|
||||||
virObjectLock(data);
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p, State: %d", callback, state);
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
|
|
||||||
if (machineId) {
|
|
||||||
char *machineIdUtf8 = NULL;
|
|
||||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
||||||
|
|
||||||
data->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8);
|
|
||||||
ignore_value(virUUIDParse(machineIdUtf8, uuid));
|
|
||||||
|
|
||||||
dom = vboxDomainLookupByUUID(callback->conn, uuid);
|
|
||||||
if (dom) {
|
|
||||||
virObjectEventPtr ev;
|
|
||||||
|
|
||||||
if (state == MachineState_Starting) {
|
|
||||||
event = VIR_DOMAIN_EVENT_STARTED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_STARTED_BOOTED;
|
|
||||||
} else if (state == MachineState_Restoring) {
|
|
||||||
event = VIR_DOMAIN_EVENT_STARTED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_STARTED_RESTORED;
|
|
||||||
} else if (state == MachineState_Paused) {
|
|
||||||
event = VIR_DOMAIN_EVENT_SUSPENDED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_SUSPENDED_PAUSED;
|
|
||||||
} else if (state == MachineState_Running) {
|
|
||||||
event = VIR_DOMAIN_EVENT_RESUMED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_RESUMED_UNPAUSED;
|
|
||||||
} else if (state == MachineState_PoweredOff) {
|
|
||||||
event = VIR_DOMAIN_EVENT_STOPPED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
|
|
||||||
} else if (state == MachineState_Stopping) {
|
|
||||||
event = VIR_DOMAIN_EVENT_STOPPED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_STOPPED_DESTROYED;
|
|
||||||
} else if (state == MachineState_Aborted) {
|
|
||||||
event = VIR_DOMAIN_EVENT_STOPPED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_STOPPED_CRASHED;
|
|
||||||
} else if (state == MachineState_Saving) {
|
|
||||||
event = VIR_DOMAIN_EVENT_STOPPED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_STOPPED_SAVED;
|
|
||||||
} else {
|
|
||||||
event = VIR_DOMAIN_EVENT_STOPPED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
ev = virDomainEventLifecycleNewFromDom(dom, event, detail);
|
|
||||||
|
|
||||||
if (ev)
|
|
||||||
virObjectEventStateQueue(data->domainEventState, ev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(data);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnMachineDataChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnExtraDataCanChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId, PRUnichar *key,
|
|
||||||
PRUnichar *value,
|
|
||||||
PRUnichar **error ATTRIBUTE_UNUSED,
|
|
||||||
PRBool *allowChange ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p, allowChange: %s", pThis, *allowChange ? "true" : "false");
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
DEBUGPRUnichar("key", key);
|
|
||||||
DEBUGPRUnichar("value", value);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnExtraDataChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId,
|
|
||||||
PRUnichar *key, PRUnichar *value)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
DEBUGPRUnichar("key", key);
|
|
||||||
DEBUGPRUnichar("value", value);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
# if VBOX_API_VERSION < 3001000
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnMediaRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *mediaId,
|
|
||||||
PRUint32 mediaType ATTRIBUTE_UNUSED,
|
|
||||||
PRBool registered ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p, registered: %s", pThis, registered ? "true" : "false");
|
|
||||||
VIR_DEBUG("mediaType: %d", mediaType);
|
|
||||||
DEBUGPRUnichar("mediaId", mediaId);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
# endif /* VBOX_API_VERSION >= 3001000 */
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId, PRBool registered)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
virDomainPtr dom = NULL;
|
|
||||||
int event = 0;
|
|
||||||
int detail = 0;
|
|
||||||
|
|
||||||
virObjectLock(data);
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p, registered: %s", pThis, registered ? "true" : "false");
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
|
|
||||||
if (machineId) {
|
|
||||||
char *machineIdUtf8 = NULL;
|
|
||||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
||||||
|
|
||||||
data->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8);
|
|
||||||
ignore_value(virUUIDParse(machineIdUtf8, uuid));
|
|
||||||
|
|
||||||
dom = vboxDomainLookupByUUID(callback->conn, uuid);
|
|
||||||
if (dom) {
|
|
||||||
virObjectEventPtr ev;
|
|
||||||
|
|
||||||
/* CURRENT LIMITATION: we never get the VIR_DOMAIN_EVENT_UNDEFINED
|
|
||||||
* event because the when the machine is de-registered the call
|
|
||||||
* to vboxDomainLookupByUUID fails and thus we don't get any
|
|
||||||
* dom pointer which is necessary (null dom pointer doesn't work)
|
|
||||||
* to show the VIR_DOMAIN_EVENT_UNDEFINED event
|
|
||||||
*/
|
|
||||||
if (registered) {
|
|
||||||
event = VIR_DOMAIN_EVENT_DEFINED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_DEFINED_ADDED;
|
|
||||||
} else {
|
|
||||||
event = VIR_DOMAIN_EVENT_UNDEFINED;
|
|
||||||
detail = VIR_DOMAIN_EVENT_UNDEFINED_REMOVED;
|
|
||||||
}
|
|
||||||
|
|
||||||
ev = virDomainEventLifecycleNewFromDom(dom, event, detail);
|
|
||||||
|
|
||||||
if (ev)
|
|
||||||
virObjectEventStateQueue(data->domainEventState, ev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(data);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnSessionStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId,
|
|
||||||
PRUint32 state ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p, state: %d", pThis, state);
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnSnapshotTaken(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId,
|
|
||||||
PRUnichar *snapshotId)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
DEBUGPRUnichar("snapshotId", snapshotId);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnSnapshotDiscarded(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId,
|
|
||||||
PRUnichar *snapshotId)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
DEBUGPRUnichar("snapshotId", snapshotId);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnSnapshotChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId,
|
|
||||||
PRUnichar *snapshotId)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
DEBUGPRUnichar("snapshotId", snapshotId);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackOnGuestPropertyChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
|
|
||||||
PRUnichar *machineId, PRUnichar *name,
|
|
||||||
PRUnichar *value, PRUnichar *flags)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
vboxDriverPtr data = callback->conn->privateData;
|
|
||||||
|
|
||||||
VIR_DEBUG("IVirtualBoxCallback: %p", pThis);
|
|
||||||
DEBUGPRUnichar("machineId", machineId);
|
|
||||||
DEBUGPRUnichar("name", name);
|
|
||||||
DEBUGPRUnichar("value", value);
|
|
||||||
DEBUGPRUnichar("flags", flags);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackAddRef(nsISupports *pThis ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
nsresult c;
|
|
||||||
|
|
||||||
c = ++callback->vboxCallBackRefCount;
|
|
||||||
|
|
||||||
VIR_DEBUG("pThis: %p, vboxCallback AddRef: %d", pThis, c);
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackRelease(nsISupports *pThis)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
nsresult c;
|
|
||||||
|
|
||||||
c = --callback->vboxCallBackRefCount;
|
|
||||||
if (c == 0) {
|
|
||||||
/* delete object */
|
|
||||||
VIR_FREE(pThis->vtbl);
|
|
||||||
VIR_FREE(pThis);
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("pThis: %p, vboxCallback Release: %d", pThis, c);
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult PR_COM_METHOD
|
|
||||||
vboxCallbackQueryInterface(nsISupports *pThis, const nsID *iid, void **resultp)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = (vboxCallbackPtr) pThis;
|
|
||||||
static const nsID ivirtualboxCallbackUUID = IVIRTUALBOXCALLBACK_IID;
|
|
||||||
static const nsID isupportIID = NS_ISUPPORTS_IID;
|
|
||||||
|
|
||||||
/* Match UUID for IVirtualBoxCallback class */
|
|
||||||
if (memcmp(iid, &ivirtualboxCallbackUUID, sizeof(nsID)) == 0 ||
|
|
||||||
memcmp(iid, &isupportIID, sizeof(nsID)) == 0) {
|
|
||||||
callback->vboxCallBackRefCount++;
|
|
||||||
*resultp = callback;
|
|
||||||
|
|
||||||
VIR_DEBUG("pThis: %p, vboxCallback QueryInterface: %d", pThis, callback->vboxCallBackRefCount);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
VIR_DEBUG("pThis: %p, vboxCallback QueryInterface didn't find a matching interface", pThis);
|
|
||||||
DEBUGUUID("The UUID Callback Interface expects", iid);
|
|
||||||
DEBUGUUID("The UUID Callback Interface got", &ivirtualboxCallbackUUID);
|
|
||||||
return NS_NOINTERFACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static vboxCallbackPtr
|
|
||||||
vboxAllocCallbackObj(virConnectPtr conn)
|
|
||||||
{
|
|
||||||
vboxCallbackPtr callback = NULL;
|
|
||||||
|
|
||||||
/* Allocate, Initialize and return a valid
|
|
||||||
* IVirtualBoxCallback object here
|
|
||||||
*/
|
|
||||||
if ((VIR_ALLOC(callback) < 0) || (VIR_ALLOC(callback->vtbl) < 0)) {
|
|
||||||
VIR_FREE(callback);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
callback->vtbl->nsisupports.AddRef = &vboxCallbackAddRef;
|
|
||||||
callback->vtbl->nsisupports.Release = &vboxCallbackRelease;
|
|
||||||
callback->vtbl->nsisupports.QueryInterface = &vboxCallbackQueryInterface;
|
|
||||||
callback->vtbl->OnMachineStateChange = &vboxCallbackOnMachineStateChange;
|
|
||||||
callback->vtbl->OnMachineDataChange = &vboxCallbackOnMachineDataChange;
|
|
||||||
callback->vtbl->OnExtraDataCanChange = &vboxCallbackOnExtraDataCanChange;
|
|
||||||
callback->vtbl->OnExtraDataChange = &vboxCallbackOnExtraDataChange;
|
|
||||||
# if VBOX_API_VERSION < 3001000
|
|
||||||
callback->vtbl->OnMediaRegistered = &vboxCallbackOnMediaRegistered;
|
|
||||||
# else /* VBOX_API_VERSION >= 3001000 */
|
|
||||||
# endif /* VBOX_API_VERSION >= 3001000 */
|
|
||||||
callback->vtbl->OnMachineRegistered = &vboxCallbackOnMachineRegistered;
|
|
||||||
callback->vtbl->OnSessionStateChange = &vboxCallbackOnSessionStateChange;
|
|
||||||
callback->vtbl->OnSnapshotTaken = &vboxCallbackOnSnapshotTaken;
|
|
||||||
# if VBOX_API_VERSION < 3002000
|
|
||||||
callback->vtbl->OnSnapshotDiscarded = &vboxCallbackOnSnapshotDiscarded;
|
|
||||||
# else /* VBOX_API_VERSION >= 3002000 */
|
|
||||||
callback->vtbl->OnSnapshotDeleted = &vboxCallbackOnSnapshotDiscarded;
|
|
||||||
# endif /* VBOX_API_VERSION >= 3002000 */
|
|
||||||
callback->vtbl->OnSnapshotChange = &vboxCallbackOnSnapshotChange;
|
|
||||||
callback->vtbl->OnGuestPropertyChange = &vboxCallbackOnGuestPropertyChange;
|
|
||||||
callback->vboxCallBackRefCount = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback->conn = conn;
|
|
||||||
|
|
||||||
return callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void vboxReadCallback(int watch ATTRIBUTE_UNUSED,
|
|
||||||
int fd,
|
|
||||||
int events ATTRIBUTE_UNUSED,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
vboxDriverPtr data = (vboxDriverPtr) opaque;
|
|
||||||
if (fd >= 0) {
|
|
||||||
data->vboxQueue->vtbl->ProcessPendingEvents(data->vboxQueue);
|
|
||||||
} else {
|
|
||||||
nsresult rc;
|
|
||||||
PLEvent *pEvent = NULL;
|
|
||||||
|
|
||||||
rc = data->vboxQueue->vtbl->WaitForEvent(data->vboxQueue, &pEvent);
|
|
||||||
if (NS_SUCCEEDED(rc))
|
|
||||||
data->vboxQueue->vtbl->HandleEvent(data->vboxQueue, pEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
vboxConnectDomainEventRegister(virConnectPtr conn,
|
|
||||||
virConnectDomainEventCallback callback,
|
|
||||||
void *opaque,
|
|
||||||
virFreeCallback freecb)
|
|
||||||
{
|
|
||||||
vboxDriverPtr data = conn->privateData;
|
|
||||||
int vboxRet = -1;
|
|
||||||
nsresult rc;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!data->vboxObj)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
/* Locking has to be there as callbacks are not
|
|
||||||
* really fully thread safe
|
|
||||||
*/
|
|
||||||
virObjectLock(data);
|
|
||||||
|
|
||||||
if (data->vboxCallback == NULL) {
|
|
||||||
data->vboxCallback = vboxAllocCallbackObj(conn);
|
|
||||||
if (data->vboxCallback != NULL) {
|
|
||||||
rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj,
|
|
||||||
(IVirtualBoxCallback *) data->vboxCallback);
|
|
||||||
if (NS_SUCCEEDED(rc))
|
|
||||||
vboxRet = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
vboxRet = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the vbox file handle and add an event handle to it
|
|
||||||
* so that the events can be passed down to the user
|
|
||||||
*/
|
|
||||||
if (vboxRet == 0) {
|
|
||||||
if (data->fdWatch < 0) {
|
|
||||||
PRInt32 vboxFileHandle;
|
|
||||||
vboxFileHandle = data->vboxQueue->vtbl->GetEventQueueSelectFD(data->vboxQueue);
|
|
||||||
|
|
||||||
data->fdWatch = virEventAddHandle(vboxFileHandle, VIR_EVENT_HANDLE_READABLE, vboxReadCallback, data, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data->fdWatch >= 0) {
|
|
||||||
/* Once a callback is registered with virtualbox, use a list
|
|
||||||
* to store the callbacks registered with libvirt so that
|
|
||||||
* later you can iterate over them
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = virDomainEventStateRegister(conn, data->domainEventState,
|
|
||||||
callback, opaque, freecb);
|
|
||||||
VIR_DEBUG("virObjectEventStateRegister (ret = %d) (conn: %p, "
|
|
||||||
"callback: %p, opaque: %p, "
|
|
||||||
"freecb: %p)", ret, conn, callback,
|
|
||||||
opaque, freecb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(data);
|
|
||||||
|
|
||||||
if (ret >= 0) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
if (data->vboxObj && data->vboxCallback)
|
|
||||||
data->vboxObj->vtbl->UnregisterCallback(data->vboxObj,
|
|
||||||
(IVirtualBoxCallback *) data->vboxCallback);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
vboxConnectDomainEventDeregister(virConnectPtr conn,
|
|
||||||
virConnectDomainEventCallback callback)
|
|
||||||
{
|
|
||||||
vboxDriverPtr data = conn->privateData;
|
|
||||||
int cnt;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!data->vboxObj)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
/* Locking has to be there as callbacks are not
|
|
||||||
* really fully thread safe
|
|
||||||
*/
|
|
||||||
virObjectLock(data);
|
|
||||||
|
|
||||||
cnt = virDomainEventStateDeregister(conn, data->domainEventState,
|
|
||||||
callback);
|
|
||||||
|
|
||||||
if (data->vboxCallback && cnt == 0) {
|
|
||||||
data->vboxObj->vtbl->UnregisterCallback(data->vboxObj,
|
|
||||||
(IVirtualBoxCallback *) data->vboxCallback);
|
|
||||||
VBOX_RELEASE(data->vboxCallback);
|
|
||||||
|
|
||||||
/* Remove the Event file handle on which we are listening as well */
|
|
||||||
virEventRemoveHandle(data->fdWatch);
|
|
||||||
data->fdWatch = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(data);
|
|
||||||
|
|
||||||
if (cnt >= 0)
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int vboxConnectDomainEventRegisterAny(virConnectPtr conn,
|
|
||||||
virDomainPtr dom,
|
|
||||||
int eventID,
|
|
||||||
virConnectDomainEventGenericCallback callback,
|
|
||||||
void *opaque,
|
|
||||||
virFreeCallback freecb)
|
|
||||||
{
|
|
||||||
vboxDriverPtr data = conn->privateData;
|
|
||||||
int vboxRet = -1;
|
|
||||||
nsresult rc;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!data->vboxObj)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
/* Locking has to be there as callbacks are not
|
|
||||||
* really fully thread safe
|
|
||||||
*/
|
|
||||||
virObjectLock(data);
|
|
||||||
|
|
||||||
if (data->vboxCallback == NULL) {
|
|
||||||
data->vboxCallback = vboxAllocCallbackObj(conn);
|
|
||||||
if (data->vboxCallback != NULL) {
|
|
||||||
rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj,
|
|
||||||
(IVirtualBoxCallback *) data->vboxCallback);
|
|
||||||
if (NS_SUCCEEDED(rc))
|
|
||||||
vboxRet = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
vboxRet = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the vbox file handle and add an event handle to it
|
|
||||||
* so that the events can be passed down to the user
|
|
||||||
*/
|
|
||||||
if (vboxRet == 0) {
|
|
||||||
if (data->fdWatch < 0) {
|
|
||||||
PRInt32 vboxFileHandle;
|
|
||||||
vboxFileHandle = data->vboxQueue->vtbl->GetEventQueueSelectFD(data->vboxQueue);
|
|
||||||
|
|
||||||
data->fdWatch = virEventAddHandle(vboxFileHandle, VIR_EVENT_HANDLE_READABLE, vboxReadCallback, data, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data->fdWatch >= 0) {
|
|
||||||
/* Once a callback is registered with virtualbox, use a list
|
|
||||||
* to store the callbacks registered with libvirt so that
|
|
||||||
* later you can iterate over them
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (virDomainEventStateRegisterID(conn, data->domainEventState,
|
|
||||||
dom, eventID,
|
|
||||||
callback, opaque, freecb, &ret) < 0)
|
|
||||||
ret = -1;
|
|
||||||
VIR_DEBUG("virDomainEventStateRegisterID (ret = %d) (conn: %p, "
|
|
||||||
"callback: %p, opaque: %p, "
|
|
||||||
"freecb: %p)", ret, conn, callback,
|
|
||||||
opaque, freecb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(data);
|
|
||||||
|
|
||||||
if (ret >= 0) {
|
|
||||||
return ret;
|
|
||||||
} else {
|
|
||||||
if (data->vboxObj && data->vboxCallback)
|
|
||||||
data->vboxObj->vtbl->UnregisterCallback(data->vboxObj,
|
|
||||||
(IVirtualBoxCallback *) data->vboxCallback);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
vboxConnectDomainEventDeregisterAny(virConnectPtr conn,
|
|
||||||
int callbackID)
|
|
||||||
{
|
|
||||||
vboxDriverPtr data = conn->privateData;
|
|
||||||
int cnt;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!data->vboxObj)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
/* Locking has to be there as callbacks are not
|
|
||||||
* really fully thread safe
|
|
||||||
*/
|
|
||||||
virObjectLock(data);
|
|
||||||
|
|
||||||
cnt = virObjectEventStateDeregisterID(conn, data->domainEventState,
|
|
||||||
callbackID);
|
|
||||||
|
|
||||||
if (data->vboxCallback && cnt == 0) {
|
|
||||||
data->vboxObj->vtbl->UnregisterCallback(data->vboxObj,
|
|
||||||
(IVirtualBoxCallback *) data->vboxCallback);
|
|
||||||
VBOX_RELEASE(data->vboxCallback);
|
|
||||||
|
|
||||||
/* Remove the Event file handle on which we are listening as well */
|
|
||||||
virEventRemoveHandle(data->fdWatch);
|
|
||||||
data->fdWatch = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(data);
|
|
||||||
|
|
||||||
if (cnt >= 0)
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
_registerDomainEvent(virHypervisorDriverPtr driver)
|
|
||||||
{
|
|
||||||
driver->connectDomainEventRegister = vboxConnectDomainEventRegister; /* 0.7.0 */
|
|
||||||
driver->connectDomainEventDeregister = vboxConnectDomainEventDeregister; /* 0.7.0 */
|
|
||||||
driver->connectDomainEventRegisterAny = vboxConnectDomainEventRegisterAny; /* 0.8.0 */
|
|
||||||
driver->connectDomainEventDeregisterAny = vboxConnectDomainEventDeregisterAny; /* 0.8.0 */
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION >= 4000000) */
|
|
||||||
|
|
||||||
static int
|
|
||||||
_initializeDomainEvent(vboxDriverPtr data ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
|
|
||||||
/* No event queue functionality in 2.2.* and 4.* as of now */
|
|
||||||
vboxUnsupported();
|
|
||||||
#else /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */
|
|
||||||
/* Initialize the fWatch needed for Event Callbacks */
|
|
||||||
data->fdWatch = -1;
|
|
||||||
data->pFuncs->pfnGetEventQueue(&data->vboxQueue);
|
|
||||||
if (data->vboxQueue == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("nsIEventQueue object is null"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_detachDevices(vboxDriverPtr data ATTRIBUTE_UNUSED,
|
_detachDevices(vboxDriverPtr data ATTRIBUTE_UNUSED,
|
||||||
IMachine *machine ATTRIBUTE_UNUSED,
|
IMachine *machine ATTRIBUTE_UNUSED,
|
||||||
@ -3302,7 +2662,6 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
|
|||||||
{
|
{
|
||||||
pVBoxAPI->APIVersion = VBOX_API_VERSION;
|
pVBoxAPI->APIVersion = VBOX_API_VERSION;
|
||||||
pVBoxAPI->XPCOMCVersion = VBOX_XPCOMC_VERSION;
|
pVBoxAPI->XPCOMCVersion = VBOX_XPCOMC_VERSION;
|
||||||
pVBoxAPI->initializeDomainEvent = _initializeDomainEvent;
|
|
||||||
pVBoxAPI->detachDevices = _detachDevices;
|
pVBoxAPI->detachDevices = _detachDevices;
|
||||||
pVBoxAPI->unregisterMachine = _unregisterMachine;
|
pVBoxAPI->unregisterMachine = _unregisterMachine;
|
||||||
pVBoxAPI->deleteConfig = _deleteConfig;
|
pVBoxAPI->deleteConfig = _deleteConfig;
|
||||||
@ -3315,7 +2674,6 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
|
|||||||
pVBoxAPI->attachFloppy = _attachFloppy;
|
pVBoxAPI->attachFloppy = _attachFloppy;
|
||||||
pVBoxAPI->detachFloppy = _detachFloppy;
|
pVBoxAPI->detachFloppy = _detachFloppy;
|
||||||
pVBoxAPI->snapshotRestore = _vboxDomainSnapshotRestore;
|
pVBoxAPI->snapshotRestore = _vboxDomainSnapshotRestore;
|
||||||
pVBoxAPI->registerDomainEvent = _registerDomainEvent;
|
|
||||||
pVBoxAPI->UPFN = _UPFN;
|
pVBoxAPI->UPFN = _UPFN;
|
||||||
pVBoxAPI->UIID = _UIID;
|
pVBoxAPI->UIID = _UIID;
|
||||||
pVBoxAPI->UArray = _UArray;
|
pVBoxAPI->UArray = _UArray;
|
||||||
@ -3346,12 +2704,6 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
|
|||||||
pVBoxAPI->UIKeyboard = _UIKeyboard;
|
pVBoxAPI->UIKeyboard = _UIKeyboard;
|
||||||
pVBoxAPI->machineStateChecker = _machineStateChecker;
|
pVBoxAPI->machineStateChecker = _machineStateChecker;
|
||||||
|
|
||||||
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
|
|
||||||
pVBoxAPI->domainEventCallbacks = 0;
|
|
||||||
#else /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */
|
|
||||||
pVBoxAPI->domainEventCallbacks = 1;
|
|
||||||
#endif /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */
|
|
||||||
|
|
||||||
#if VBOX_API_VERSION >= 4001000
|
#if VBOX_API_VERSION >= 4001000
|
||||||
pVBoxAPI->chipsetType = 1;
|
pVBoxAPI->chipsetType = 1;
|
||||||
#else /* VBOX_API_VERSION < 4001000 */
|
#else /* VBOX_API_VERSION < 4001000 */
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
*
|
*
|
||||||
* The vbox_tmpl.c is the only place where the driver knows the inside
|
* The vbox_tmpl.c is the only place where the driver knows the inside
|
||||||
* architecture of those vbox structs(vboxObj, vboxSession,
|
* architecture of those vbox structs(vboxObj, vboxSession,
|
||||||
* pFuncs, vboxCallback and vboxQueue). The file should be included
|
* pFuncs, and vboxCallback). The file should be included
|
||||||
* after the currect vbox_CAPI_v*.h, then we can use the vbox structs
|
* after the currect vbox_CAPI_v*.h, then we can use the vbox structs
|
||||||
* in vboxGlobalData. The vbox_tmpl.c should implement functions
|
* in vboxGlobalData. The vbox_tmpl.c should implement functions
|
||||||
* defined in vboxUniformedAPI.
|
* defined in vboxUniformedAPI.
|
||||||
@ -36,7 +36,7 @@
|
|||||||
* The vbox_driver.c collects vboxUniformedAPI for all versions.
|
* The vbox_driver.c collects vboxUniformedAPI for all versions.
|
||||||
* Then vboxRegister calls the vboxRegisterUniformedAPI to register.
|
* Then vboxRegister calls the vboxRegisterUniformedAPI to register.
|
||||||
* Note: In vbox_driver.c, the vbox structs in vboxGlobalData is
|
* Note: In vbox_driver.c, the vbox structs in vboxGlobalData is
|
||||||
* defined by vbox_CAPI_v2.2.h.
|
* defined by vbox_CAPI_v4_0.h.
|
||||||
*
|
*
|
||||||
* The vbox_common.c, it is used to generate common codes for all vbox
|
* The vbox_common.c, it is used to generate common codes for all vbox
|
||||||
* versions. Bacause the same member varible's offset in a vbox struct
|
* versions. Bacause the same member varible's offset in a vbox struct
|
||||||
@ -96,14 +96,6 @@ typedef union {
|
|||||||
PRInt32 resultCode;
|
PRInt32 resultCode;
|
||||||
} resultCodeUnion;
|
} resultCodeUnion;
|
||||||
|
|
||||||
struct _vboxCallback {
|
|
||||||
struct IVirtualBoxCallback_vtbl *vtbl;
|
|
||||||
virConnectPtr conn;
|
|
||||||
int vboxCallBackRefCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct _vboxCallback vboxCallback;
|
|
||||||
typedef struct _vboxCallback *vboxCallbackPtr;
|
|
||||||
|
|
||||||
struct _vboxDriver {
|
struct _vboxDriver {
|
||||||
virObjectLockable parent;
|
virObjectLockable parent;
|
||||||
@ -120,13 +112,6 @@ struct _vboxDriver {
|
|||||||
IVirtualBoxClient *vboxClient;
|
IVirtualBoxClient *vboxClient;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
int fdWatch;
|
|
||||||
vboxCallbackPtr vboxCallback;
|
|
||||||
# if VBOX_API_VERSION > 2002000 && VBOX_API_VERSION < 4000000
|
|
||||||
nsIEventQueue *vboxQueue;
|
|
||||||
# else
|
|
||||||
void *vboxQueue;
|
|
||||||
# endif
|
|
||||||
unsigned long version;
|
unsigned long version;
|
||||||
|
|
||||||
/* reference counting of vbox connections */
|
/* reference counting of vbox connections */
|
||||||
@ -548,7 +533,6 @@ typedef struct {
|
|||||||
uint32_t APIVersion;
|
uint32_t APIVersion;
|
||||||
uint32_t XPCOMCVersion;
|
uint32_t XPCOMCVersion;
|
||||||
/* vbox APIs */
|
/* vbox APIs */
|
||||||
int (*initializeDomainEvent)(vboxDriverPtr driver);
|
|
||||||
void (*detachDevices)(vboxDriverPtr driver, IMachine *machine, PRUnichar *hddcnameUtf16);
|
void (*detachDevices)(vboxDriverPtr driver, IMachine *machine, PRUnichar *hddcnameUtf16);
|
||||||
nsresult (*unregisterMachine)(vboxDriverPtr driver, vboxIIDUnion *iidu, IMachine **machine);
|
nsresult (*unregisterMachine)(vboxDriverPtr driver, vboxIIDUnion *iidu, IMachine **machine);
|
||||||
void (*deleteConfig)(IMachine *machine);
|
void (*deleteConfig)(IMachine *machine);
|
||||||
@ -562,7 +546,6 @@ typedef struct {
|
|||||||
int (*attachFloppy)(vboxDriverPtr driver, IMachine *machine, const char *src);
|
int (*attachFloppy)(vboxDriverPtr driver, IMachine *machine, const char *src);
|
||||||
int (*detachFloppy)(IMachine *machine);
|
int (*detachFloppy)(IMachine *machine);
|
||||||
int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot *snapshot);
|
int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot *snapshot);
|
||||||
void (*registerDomainEvent)(virHypervisorDriverPtr driver);
|
|
||||||
vboxUniformedPFN UPFN;
|
vboxUniformedPFN UPFN;
|
||||||
vboxUniformedIID UIID;
|
vboxUniformedIID UIID;
|
||||||
vboxUniformedArray UArray;
|
vboxUniformedArray UArray;
|
||||||
@ -593,7 +576,6 @@ typedef struct {
|
|||||||
vboxUniformedIKeyboard UIKeyboard;
|
vboxUniformedIKeyboard UIKeyboard;
|
||||||
uniformedMachineStateChecker machineStateChecker;
|
uniformedMachineStateChecker machineStateChecker;
|
||||||
/* vbox API features */
|
/* vbox API features */
|
||||||
bool domainEventCallbacks;
|
|
||||||
bool chipsetType;
|
bool chipsetType;
|
||||||
bool accelerate2DVideo;
|
bool accelerate2DVideo;
|
||||||
bool oldMediumInterface;
|
bool oldMediumInterface;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user