add VirtualBox 5 support to vbox_tmpl.c
From 96a6fbaf8bcc6b8ee4e91b23bb5b1f04f2a94a5d Mon Sep 17 00:00:00 2001 From: Martin Pietsch <martin.pietsch@xxxxxxxxxxxxx> Date: Sun, 19 Jun 2016 14:28:25 +0200 Subject: [PATCH 2/7] add VirtualBox 5 support to vbox_tmpl.c --- src/vbox/vbox_tmpl.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 7a8205d..ff547a1 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -69,6 +69,8 @@ # include "vbox_CAPI_v4_3.h" #elif VBOX_API_VERSION == 4003004 # include "vbox_CAPI_v4_3_4.h" +#elif VBOX_API_VERSION == 5000000 +# include "vbox_CAPI_v5_0.h" #else # error "Unsupport VBOX_API_VERSION" #endif @@ -1311,7 +1313,9 @@ _vboxDomainSnapshotRestore(virDomainPtr dom, ISnapshot *snapshot) { vboxGlobalData *data = dom->conn->privateData; +# if VBOX_API_VERSION < 5000000 IConsole *console = NULL; +# endif /*VBOX_API_VERSION < 5000000*/ IProgress *progress = NULL; PRUint32 state; nsresult rc; @@ -1344,8 +1348,10 @@ _vboxDomainSnapshotRestore(virDomainPtr dom, } rc = VBOX_SESSION_OPEN(domiid.value, machine); +# if VBOX_API_VERSION < 5000000 if (NS_SUCCEEDED(rc)) rc = data->vboxSession->vtbl->GetConsole(data->vboxSession, &console); +# endif /*VBOX_API_VERSION < 5000000*/ if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("could not open VirtualBox session with domain %s"), @@ -1353,7 +1359,12 @@ _vboxDomainSnapshotRestore(virDomainPtr dom, goto cleanup; } +# if VBOX_API_VERSION < 5000000 rc = console->vtbl->RestoreSnapshot(console, snapshot, &progress); +# elif VBOX_API_VERSION >= 5000000 /*VBOX_API_VERSION < 5000000*/ + rc = machine->vtbl->RestoreSnapshot(machine, snapshot, &progress); +# endif /*VBOX_API_VERSION >= 5000000*/ + if (NS_FAILED(rc) || !progress) { if (rc == VBOX_E_INVALID_VM_STATE) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -1378,7 +1389,9 @@ _vboxDomainSnapshotRestore(virDomainPtr dom, cleanup: VBOX_RELEASE(progress); +# if VBOX_API_VERSION < 5000000 VBOX_RELEASE(console); +# endif /*VBOX_API_VERSION < 5000000*/ VBOX_SESSION_CLOSE(); vboxIIDUnalloc(&domiid); return ret; @@ -2874,7 +2887,11 @@ _virtualboxCreateHardDisk(IVirtualBox *vboxObj, PRUnichar *format, /* In vbox 2.2 and 3.0, this function will create a IHardDisk object. * In vbox 3.1 and later, this function will create a IMedium object. */ +#if VBOX_API_VERSION < 5000000 return vboxObj->vtbl->CreateHardDisk(vboxObj, format, location, hardDisk); +#elif VBOX_API_VERSION >= 5000000 /*VBOX_API_VERSION >= 5000000*/ + return vboxObj->vtbl->CreateMedium(vboxObj, format, location, AccessMode_ReadWrite, DeviceType_HardDisk, hardDisk); +#endif /*VBOX_API_VERSION >= 5000000*/ } static nsresult @@ -3366,7 +3383,23 @@ _sessionGetMachine(ISession *session, IMachine **machine) static nsresult _consoleSaveState(IConsole *console, IProgress **progress) { +#if VBOX_API_VERSION < 5000000 return console->vtbl->SaveState(console, progress); +#else /*VBOX_API_VERSION < 5000000*/ + IMachine *machine; + nsresult rc; + + rc = console->vtbl->GetMachine(console, &machine); + + if (NS_SUCCEEDED(rc)) + rc = machine->vtbl->SaveState(machine, progress); + else + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to get machine from console. (error %d)"), rc); + + return rc; + +#endif /*VBOX_API_VERSION >= 5000000*/ } static nsresult @@ -3414,7 +3447,25 @@ static nsresult _consoleTakeSnapshot(IConsole *console, PRUnichar *name, PRUnichar *description, IProgress **progress) { +#if VBOX_API_VERSION < 5000000 return console->vtbl->TakeSnapshot(console, name, description, progress); +#else + IMachine *machine; + nsresult rc; + PRUnichar *id = NULL; + bool bpause = true; /*NO live snapshot*/ + + rc = console->vtbl->GetMachine(console, &machine); + + if (NS_SUCCEEDED(rc)) + rc = machine->vtbl->TakeSnapshot(machine, name, description, bpause, &id, progress); + else + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to get machine from console. (error %d)"), rc); + + VBOX_RELEASE(machine); + return rc; +#endif /* VBOX_API_VERSION >= 5000000 */ } static nsresult @@ -3422,9 +3473,24 @@ _consoleDeleteSnapshot(IConsole *console, vboxIIDUnion *iidu, IProgress **progre { #if VBOX_API_VERSION < 3001000 return console->vtbl->DiscardSnapshot(console, IID_MEMBER(value), progress); -#else /* VBOX_API_VERSION >= 3001000 */ +#elif VBOX_API_VERSION >= 3001000 && VBOX_API_VERSION < 5000000 /* VBOX_API_VERSION >= 3001000 */ return console->vtbl->DeleteSnapshot(console, IID_MEMBER(value), progress); -#endif /* VBOX_API_VERSION >= 3001000 */ +#else /* VBOX_API_VERSION >= 5000000 */ + IMachine *machine; + nsresult rc; + + rc = console->vtbl->GetMachine(console, &machine); + + if (NS_SUCCEEDED(rc)) + rc = machine->vtbl->DeleteSnapshot(machine, IID_MEMBER(value), progress); + else + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to get machine from console. (error %d)"), rc); + + VBOX_RELEASE(machine); + + return rc; +#endif /* VBOX_API_VERSION >= 5000000 */ } static nsresult @@ -4342,11 +4408,17 @@ _displayGetScreenResolution(IDisplay *display ATTRIBUTE_UNUSED, #elif VBOX_API_VERSION < 4003000 return display->vtbl->GetScreenResolution(display, screenId, width, height, bitsPerPixel); -#else /* VBOX_API_VERSION >= 4003000 */ +#elif VBOX_API_VERSION < 5000000 /* VBOX_API_VERSION >= 4003000 */ return display->vtbl->GetScreenResolution(display, screenId, width, height, bitsPerPixel, xOrigin, yOrigin); -#endif /* VBOX_API_VERSION >= 4003000 */ +#else /*VBOX_API_VERSION >= 5000000 */ + PRUint32 gms; + + return display->vtbl->GetScreenResolution(display, screenId, width, + height, bitsPerPixel, + xOrigin, yOrigin, &gms); +#endif /* VBOX_API_VERSION >= 5000000 */ } static nsresult @@ -4357,10 +4429,10 @@ _displayTakeScreenShotPNGToArray(IDisplay *display ATTRIBUTE_UNUSED, PRUint32 *screenDataSize ATTRIBUTE_UNUSED, PRUint8** screenData ATTRIBUTE_UNUSED) { -#if VBOX_API_VERSION < 4000000 +#if VBOX_API_VERSION < 4000000 || VBOX_API_VERSION >= 5000000 vboxUnsupported(); return 0; -#else /* VBOX_API_VERSION >= 4000000 */ +#else /* VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 5000000 */ return display->vtbl->TakeScreenShotPNGToArray(display, screenId, width, height, screenDataSize, screenData); -- 2.7.4
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list