diff options
| author | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 1970-01-01 00:00:00 +0000 |
|---|---|---|
| committer | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 1970-01-01 00:00:00 +0000 |
| commit | 96e96718ba88fc2e5d0ac35122c7795477c02922 (patch) | |
| tree | 71ffcded8c1c994fe5a7e377f7640d636981a9e0 /src/VBox/Main/testcase/tstAPI.cpp | |
| download | VirtualBox-svn-96e96718ba88fc2e5d0ac35122c7795477c02922.tar.gz | |
import
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@1 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/Main/testcase/tstAPI.cpp')
| -rw-r--r-- | src/VBox/Main/testcase/tstAPI.cpp | 766 |
1 files changed, 766 insertions, 0 deletions
diff --git a/src/VBox/Main/testcase/tstAPI.cpp b/src/VBox/Main/testcase/tstAPI.cpp new file mode 100644 index 00000000000..7d7454622df --- /dev/null +++ b/src/VBox/Main/testcase/tstAPI.cpp @@ -0,0 +1,766 @@ +/** @file + * + * tstAPI - test program for our COM/XPCOM interface + */ + +/* + * Copyright (C) 2006 InnoTek Systemberatung GmbH + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation, + * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE + * distribution. VirtualBox OSE is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY of any kind. + * + * If you received this file as part of a commercial VirtualBox + * distribution, then only the terms of your commercial VirtualBox + * license agreement apply instead of the previous paragraph. + */ + +#include <stdio.h> +#include <stdlib.h> + +#include <VBox/com/com.h> +#include <VBox/com/string.h> +#include <VBox/com/Guid.h> +#include <VBox/com/ErrorInfo.h> +#include <VBox/com/EventQueue.h> + +#include <VBox/com/VirtualBox.h> + +using namespace com; + +#include <iprt/runtime.h> +#include <iprt/stream.h> + +#define LOG_ENABLED +#define LOG_GROUP LOG_GROUP_MAIN +#define LOG_INSTANCE NULL +#include <VBox/log.h> + +#define printf RTPrintf + +// funcs +/////////////////////////////////////////////////////////////////////////////// + +HRESULT readAndChangeMachineSettings (IMachine *machine, IMachine *readonlyMachine = 0) +{ + HRESULT rc = S_OK; + + Bstr name; + printf ("Getting machine name...\n"); + CHECK_RC_RET (machine->COMGETTER(Name) (name.asOutParam())); + printf ("Name: {%ls}\n", name.raw()); + + printf("Getting machine GUID...\n"); + Guid guid; + CHECK_RC (machine->COMGETTER(Id) (guid.asOutParam())); + if (SUCCEEDED (rc) && !guid.isEmpty()) { + printf ("Guid::toString(): {%s}\n", (const char *) guid.toString()); + } else { + printf ("WARNING: there's no GUID!"); + } + + ULONG memorySize; + printf ("Getting memory size...\n"); + CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySize)); + printf ("Memory size: %d\n", memorySize); + + MachineState_T machineState; + printf ("Getting machine state...\n"); + CHECK_RC_RET (machine->COMGETTER(State) (&machineState)); + printf ("Machine state: %d\n", machineState); + + BOOL modified; + printf ("Are any settings modified?...\n"); + CHECK_RC (machine->COMGETTER(SettingsModified) (&modified)); + if (SUCCEEDED (rc)) + printf ("%s\n", modified ? "yes" : "no"); + + ULONG memorySizeBig = memorySize * 10; + printf("Changing memory size to %d...\n", memorySizeBig); + CHECK_RC (machine->COMSETTER(MemorySize) (memorySizeBig)); + + if (SUCCEEDED (rc)) { + printf ("Are any settings modified now?...\n"); + CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified)); + printf ("%s\n", modified ? "yes" : "no"); + ASSERT_RET (modified, 0); + + ULONG memorySizeGot; + printf ("Getting memory size again...\n"); + CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot)); + printf ("Memory size: %d\n", memorySizeGot); + ASSERT_RET (memorySizeGot == memorySizeBig, 0); + + if (readonlyMachine) { + printf ("Getting memory size of the counterpart readonly machine...\n"); + ULONG memorySizeRO; + readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO); + printf ("Memory size: %d\n", memorySizeRO); + ASSERT_RET (memorySizeRO != memorySizeGot, 0); + } + + printf ("Discarding recent changes...\n"); + CHECK_RC_RET (machine->DiscardSettings()); + printf ("Are any settings modified after discarding?...\n"); + CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified)); + printf ("%s\n", modified ? "yes" : "no"); + ASSERT_RET (!modified, 0); + + printf ("Getting memory size once more...\n"); + CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot)); + printf ("Memory size: %d\n", memorySizeGot); + ASSERT_RET (memorySizeGot == memorySize, 0); + + memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2; + printf("Changing memory size to %d...\n", memorySize); + CHECK_RC_RET (machine->COMSETTER(MemorySize) (memorySize)); + } + + printf ("Saving machine settings...\n"); + CHECK_RC (machine->SaveSettings()); + if (SUCCEEDED (rc)) { + printf ("Are any settings modified after saving?...\n"); + CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified)); + printf ("%s\n", modified ? "yes" : "no"); + ASSERT_RET (!modified, 0); + + if (readonlyMachine) { + printf ("Getting memory size of the counterpart readonly machine...\n"); + ULONG memorySizeRO; + readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO); + printf ("Memory size: %d\n", memorySizeRO); + ASSERT_RET (memorySizeRO == memorySize, 0); + } + } + + Bstr extraDataKey = L"Blafasel"; + Bstr extraData; + printf ("Getting extra data key {%ls}...\n", extraDataKey.raw()); + CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam())); + if (!extraData.isEmpty()) { + printf ("Extra data value: {%ls}\n", extraData.raw()); + } else { + if (extraData.isNull()) + printf ("No extra data exists\n"); + else + printf ("Extra data is empty\n"); + } + + if (extraData.isEmpty()) + extraData = L"Das ist die Berliner Luft, Luft, Luft..."; + else + extraData.setNull(); + printf ( + "Setting extra data key {%ls} to {%ls}...\n", + extraDataKey.raw(), extraData.raw() + ); + CHECK_RC (machine->SetExtraData (extraDataKey, extraData)); + + if (SUCCEEDED (rc)) { + printf ("Getting extra data key {%ls} again...\n", extraDataKey.raw()); + CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam())); + if (!extraData.isEmpty()) { + printf ("Extra data value: {%ls}\n", extraData.raw()); + } else { + if (extraData.isNull()) + printf ("No extra data exists\n"); + else + printf ("Extra data is empty\n"); + } + } + + return rc; +} + +// main +/////////////////////////////////////////////////////////////////////////////// + +int main(int argc, char *argv[]) +{ + /* + * Initialize the VBox runtime without loading + * the support driver. + */ + RTR3Init(false); + + HRESULT rc; + + printf ("Initializing COM...\n"); + + CHECK_RC_RET (com::Initialize()); + + do + { + // scopes all the stuff till shutdown + //////////////////////////////////////////////////////////////////////////// + + ComPtr <IVirtualBox> virtualBox; + ComPtr <ISession> session; + + printf ("Creating VirtualBox object...\n"); + CHECK_RC (virtualBox.createLocalObject (CLSID_VirtualBox, + "VirtualBoxServer")); + if (FAILED (rc)) + { + CHECK_ERROR_NOCALL(); + break; + } + + printf ("Creating Session object...\n"); + CHECK_RC (session.createInprocObject (CLSID_Session)); + if (FAILED (rc)) + { + CHECK_ERROR_NOCALL(); + break; + } + +#if 0 + // IUnknown identity test + //////////////////////////////////////////////////////////////////////////// + { + ComPtr <IVirtualBox> virtualBox2; + + printf ("Creating one more VirtualBox object...\n"); + CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox, + "VirtualBoxServer")); + if (FAILED (rc)) + { + CHECK_ERROR_NOCALL(); + break; + } + + printf ("IVirtualBox(virualBox)=%p IVirtualBox(virualBox2)=%p\n", + (IVirtualBox *) virtualBox, (IVirtualBox *) virtualBox2); + + ComPtr <IUnknown> unk (virtualBox); + ComPtr <IUnknown> unk2; + unk2 = virtualBox2; + + printf ("IUnknown(virualBox)=%p IUnknown(virualBox2)=%p\n", + (IUnknown *) unk, (IUnknown *) unk2); + + ComPtr <IVirtualBox> vb = unk; + ComPtr <IVirtualBox> vb2 = unk; + + printf ("IVirtualBox(IUnknown(virualBox))=%p IVirtualBox(IUnknown(virualBox2))=%p\n", + (IVirtualBox *) vb, (IVirtualBox *) vb2); + + printf ("Will be now released (press Enter)..."); + getchar(); + } +#endif + + // create the event queue + // (here it is necessary only to process remaining XPCOM/IPC events + // after the session is closed) + EventQueue eventQ; + + // some outdated stuff + //////////////////////////////////////////////////////////////////////////// + +#if 0 + printf("Getting IHost interface...\n"); + IHost *host; + rc = virtualBox->GetHost(&host); + if (SUCCEEDED(rc)) + { + IHostDVDDriveCollection *dvdColl; + rc = host->GetHostDVDDrives(&dvdColl); + if (SUCCEEDED(rc)) + { + IHostDVDDrive *dvdDrive = NULL; + dvdColl->GetNextHostDVDDrive(dvdDrive, &dvdDrive); + while (dvdDrive) + { + BSTR driveName; + char *driveNameUtf8; + dvdDrive->GetDriveName(&driveName); + RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName); + printf("Host DVD drive name: %s\n", driveNameUtf8); + RTStrFree(driveNameUtf8); + SysFreeString(driveName); + IHostDVDDrive *dvdDriveTemp = dvdDrive; + dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive); + dvdDriveTemp->Release(); + } + dvdColl->Release(); + } else + { + printf("Could not get host DVD drive collection\n"); + } + + IHostFloppyDriveCollection *floppyColl; + rc = host->GetHostFloppyDrives(&floppyColl); + if (SUCCEEDED(rc)) + { + IHostFloppyDrive *floppyDrive = NULL; + floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive); + while (floppyDrive) + { + BSTR driveName; + char *driveNameUtf8; + floppyDrive->GetDriveName(&driveName); + RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName); + printf("Host floppy drive name: %s\n", driveNameUtf8); + RTStrFree(driveNameUtf8); + SysFreeString(driveName); + IHostFloppyDrive *floppyDriveTemp = floppyDrive; + floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive); + floppyDriveTemp->Release(); + } + floppyColl->Release(); + } else + { + printf("Could not get host floppy drive collection\n"); + } + host->Release(); + } else + { + printf("Call failed\n"); + } + printf ("\n"); +#endif + +#if 0 + // IVirtualBoxErrorInfo test + //////////////////////////////////////////////////////////////////////////// + { + // RPC calls + + // call a method that will definitely fail + Guid uuid; + ComPtr <IHardDisk> hardDisk; + rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam()); + printf ("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc); + +// { +// com::ErrorInfo info (virtualBox); +// PRINT_ERROR_INFO (info); +// } + + // call a method that will definitely succeed + Bstr version; + rc = virtualBox->COMGETTER(Version) (version.asOutParam()); + printf ("virtualBox->COMGETTER(Version)=%08X\n", rc); + + { + com::ErrorInfo info (virtualBox); + PRINT_ERROR_INFO (info); + } + + // Local calls + + // call a method that will definitely fail + ComPtr <IMachine> machine; + rc = session->COMGETTER(Machine)(machine.asOutParam()); + printf ("session->COMGETTER(Machine)=%08X\n", rc); + +// { +// com::ErrorInfo info (virtualBox); +// PRINT_ERROR_INFO (info); +// } + + // call a method that will definitely succeed + SessionState_T state; + rc = session->COMGETTER(State) (&state); + printf ("session->COMGETTER(State)=%08X\n", rc); + + { + com::ErrorInfo info (virtualBox); + PRINT_ERROR_INFO (info); + } + } +#endif + +#if 0 + // register the existing hard disk image + /////////////////////////////////////////////////////////////////////////// + do + { + ComPtr <IHardDisk> hd; + Bstr src = L"E:\\develop\\innotek\\images\\NewHardDisk.vdi"; + printf ("Registerin the existing hard disk '%ls'...\n", src.raw()); + CHECK_ERROR_BREAK (virtualBox, OpenHardDisk (src, hd.asOutParam())); + CHECK_ERROR_BREAK (virtualBox, RegisterHardDisk (hd)); + } + while (FALSE); + printf ("\n"); +#endif + +#if 0 + // find and unregister the existing hard disk image + /////////////////////////////////////////////////////////////////////////// + do + { + ComPtr <IVirtualDiskImage> vdi; + Bstr src = L"CreatorTest.vdi"; + printf ("Unregistering the hard disk '%ls'...\n", src.raw()); + CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam())); + ComPtr <IHardDisk> hd = vdi; + Guid id; + CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam())); + CHECK_ERROR_BREAK (virtualBox, UnregisterHardDisk (id, hd.asOutParam())); + } + while (FALSE); + printf ("\n"); +#endif + +#if 0 + // clone the registered hard disk + /////////////////////////////////////////////////////////////////////////// + do + { +#if defined __LINUX__ + Bstr src = L"/mnt/hugaida/common/develop/innotek/images/freedos-linux.vdi"; +#else + Bstr src = L"E:/develop/innotek/images/freedos.vdi"; +#endif + Bstr dst = L"./clone.vdi"; + RTPrintf ("Cloning '%ls' to '%ls'...\n", src.raw(), dst.raw()); + ComPtr <IVirtualDiskImage> vdi; + CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam())); + ComPtr <IHardDisk> hd = vdi; + ComPtr <IProgress> progress; + CHECK_ERROR_BREAK (hd, CloneToImage (dst, vdi.asOutParam(), progress.asOutParam())); + RTPrintf ("Waiting for completion...\n"); + CHECK_ERROR_BREAK (progress, WaitForCompletion (-1)); + ProgressErrorInfo ei (progress); + if (FAILED (ei.getResultCode())) + { + PRINT_ERROR_INFO (ei); + } + else + { + vdi->COMGETTER(FilePath) (dst.asOutParam()); + RTPrintf ("Actual clone path is '%ls'\n", dst.raw()); + } + } + while (FALSE); + printf ("\n"); +#endif + +#if 0 + // access the machine in read-only mode + /////////////////////////////////////////////////////////////////////////// + do + { + ComPtr <IMachine> machine; + Bstr name = "Windows XP"; + printf ("Getting a machine object named '%ls'...\n", name.raw()); + CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam())); +// printf ("Accessing the machine in read-only mode:\n"); +// readAndChangeMachineSettings (machine); +// if (argc != 2) +// { +// printf("Error: a string has to be supplied!\n"); +// } +// else +// { +// Bstr secureLabel = argv[1]; +// machine->COMSETTER(ExtraData)(L"VBoxSDL/SecureLabel", secureLabel); +// } + } + while (FALSE); + printf ("\n"); +#endif + +#if 1 + // create a new machine (w/o registering it) + /////////////////////////////////////////////////////////////////////////// + ComPtr <IMachine> m; + do + { + ComPtr <IMachine> machine; +#if defined (__LINUX__) + Bstr baseDir = L"/tmp/vbox"; +#else + Bstr baseDir = L"C:\\vbox"; +#endif + Bstr name = L"machina"; + + printf ("Creating a new machine object (base dir '%ls', name '%ls')...\n", + baseDir.raw(), name.raw()); + CHECK_ERROR_BREAK (virtualBox, CreateMachine (baseDir, name, + machine.asOutParam())); + + printf ("Getting name...\n"); + CHECK_ERROR_BREAK (machine, COMGETTER(Name) (name.asOutParam())); + printf ("Name: {%ls}\n", name.raw()); + + BOOL modified = FALSE; + printf ("Are any settings modified?...\n"); + CHECK_ERROR_BREAK (machine, COMGETTER(SettingsModified) (&modified)); + printf ("%s\n", modified ? "yes" : "no"); + + ASSERT_BREAK (modified == TRUE); + + name = L"Kakaya prekrasnaya virtual'naya mashina!"; + printf ("Setting new name ({%ls})...\n", name.raw()); + CHECK_ERROR_BREAK (machine, COMSETTER(Name) (name)); + + printf ("Setting memory size to 111...\n"); + CHECK_ERROR_BREAK (machine, COMSETTER(MemorySize) (111)); + + ComPtr <IGuestOSType> guestOSType; + Bstr type = L"os2warp45"; + CHECK_ERROR_BREAK (virtualBox, FindGuestOSType (type, guestOSType.asOutParam())); + + printf ("Saving new machine settings...\n"); + CHECK_ERROR_BREAK (machine, SaveSettings()); + + printf ("Accessing the newly created machine:\n"); + readAndChangeMachineSettings (machine); +m = machine; + } + while (FALSE); + printf ("\n"); +#endif + +#if 0 + // enumerate host DVD drives + /////////////////////////////////////////////////////////////////////////// + do + { + ComPtr <IHost> host; + CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam())); + + { + ComPtr <IHostDVDDriveCollection> coll; + CHECK_RC_BREAK (host->COMGETTER(DVDDrives) (coll.asOutParam())); + ComPtr <IHostDVDDriveEnumerator> enumerator; + CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam())); + BOOL hasmore; + while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore) + { + ComPtr <IHostDVDDrive> drive; + CHECK_RC_BREAK (enumerator->GetNext (drive.asOutParam())); + Bstr name; + CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam())); + printf ("Host DVD drive: name={%ls}\n", name.raw()); + } + CHECK_RC_BREAK (rc); + + ComPtr <IHostDVDDrive> drive; + CHECK_ERROR (enumerator, GetNext (drive.asOutParam())); + CHECK_ERROR (coll, GetItemAt (1000, drive.asOutParam())); + CHECK_ERROR (coll, FindByName (Bstr ("R:"), drive.asOutParam())); + if (SUCCEEDED (rc)) + { + Bstr name; + CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam())); + printf ("Found by name: name={%ls}\n", name.raw()); + } + } + } + while (FALSE); + printf ("\n"); +#endif + +#if 0 + // enumerate hard disks & dvd images + /////////////////////////////////////////////////////////////////////////// + do + { + { + ComPtr <IHardDiskCollection> coll; + CHECK_RC_BREAK (virtualBox->COMGETTER(HardDisks) (coll.asOutParam())); + ComPtr <IHardDiskEnumerator> enumerator; + CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam())); + BOOL hasmore; + while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore) + { + ComPtr <IHardDisk> disk; + CHECK_RC_BREAK (enumerator->GetNext (disk.asOutParam())); + Guid id; + CHECK_RC_BREAK (disk->COMGETTER(Id) (id.asOutParam())); + Bstr path; + CHECK_RC_BREAK (disk->COMGETTER(FilePath) (path.asOutParam())); + printf ("Hard Disk: id={%s}, path={%ls}\n", + id.toString().raw(), path.raw()); + Guid mid; + CHECK_RC_BREAK ( + virtualBox->GetHardDiskUsage (id, ResourceUsage_AllUsage, + mid.asOutParam()) + ); + if (mid.isEmpty()) + printf (" not used\n"); + else + printf (" used by VM: {%s}\n", mid.toString().raw()); + } + CHECK_RC_BREAK (rc); + } + + { + ComPtr <IDVDImageCollection> coll; + CHECK_RC_BREAK (virtualBox->COMGETTER(DVDImages) (coll.asOutParam())); + ComPtr <IDVDImageEnumerator> enumerator; + CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam())); + BOOL hasmore; + while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore) + { + ComPtr <IDVDImage> image; + CHECK_RC_BREAK (enumerator->GetNext (image.asOutParam())); + Guid id; + CHECK_RC_BREAK (image->COMGETTER(Id) (id.asOutParam())); + Bstr path; + CHECK_RC_BREAK (image->COMGETTER(FilePath) (path.asOutParam())); + printf ("CD/DVD Image: id={%s}, path={%ls}\n", + id.toString().raw(), path.raw()); + Bstr mIDs; + CHECK_RC_BREAK ( + virtualBox->GetDVDImageUsage (id, ResourceUsage_AllUsage, + mIDs.asOutParam()) + ); + if (mIDs.isNull()) + printf (" not used\n"); + else + printf (" used by VMs: {%ls}\n", mIDs.raw()); + } + CHECK_RC_BREAK (rc); + } + } + while (FALSE); + printf ("\n"); +#endif + +#if 0 + // open a (direct) session + /////////////////////////////////////////////////////////////////////////// + do + { + ComPtr <IMachine> machine; + Bstr name = L"dos"; + printf ("Getting a machine object named '%ls'...\n", name.raw()); + CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam())); + Guid guid; + CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam())); + printf ("Opening a session for this machine...\n"); + CHECK_RC_BREAK (virtualBox->OpenSession (session, guid)); +#if 0 + ComPtr <IMachine> sessionMachine; + printf ("Getting sessioned machine object...\n"); + CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam())); + printf ("Accessing the machine within the session:\n"); + readAndChangeMachineSettings (sessionMachine, machine); +#endif +#if 0 + ComPtr <IConsole> console; + printf ("Getting the console object...\n"); + CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam())); + printf ("Discarding the current machine state...\n"); + ComPtr <IProgress> progress; + CHECK_ERROR_BREAK (console, DiscardCurrentState (progress.asOutParam())); + printf ("Waiting for completion...\n"); + CHECK_ERROR_BREAK (progress, WaitForCompletion (-1)); + ProgressErrorInfo ei (progress); + if (FAILED (ei.getResultCode())) + { + PRINT_ERROR_INFO (ei); + + ComPtr <IUnknown> initiator; + CHECK_ERROR_BREAK (progress, COMGETTER(Initiator) (initiator.asOutParam())); + + printf ("initiator(unk) = %p\n", (IUnknown *) initiator); + printf ("console(unk) = %p\n", (IUnknown *) ComPtr <IUnknown> ((IConsole *) console)); + printf ("console = %p\n", (IConsole *) console); + } +#endif + session->Close(); + } + while (FALSE); + printf ("\n"); +#endif + +#if 0 + // open a remote session + /////////////////////////////////////////////////////////////////////////// + do + { + ComPtr <IMachine> machine; + Bstr name = L"dos"; + printf ("Getting a machine object named '%ls'...\n", name.raw()); + CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam())); + Guid guid; + CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam())); + printf ("Opening a remote session for this machine...\n"); + ComPtr <IProgress> progress; + CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("gui"), + progress.asOutParam())); + printf ("Waiting for the session to open...\n"); + CHECK_RC_BREAK (progress->WaitForCompletion (-1)); + ComPtr <IMachine> sessionMachine; + printf ("Getting sessioned machine object...\n"); + CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam())); + ComPtr <IConsole> console; + printf ("Getting console object...\n"); + CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam())); + printf ("Press enter to pause the VM execution in the remote session..."); + getchar(); + CHECK_RC (console->Pause()); + printf ("Press enter to close this session..."); + getchar(); + session->Close(); + } + while (FALSE); + printf ("\n"); +#endif + +#if 0 + // open an existing remote session + /////////////////////////////////////////////////////////////////////////// + do + { + ComPtr <IMachine> machine; + Bstr name = "dos"; + printf ("Getting a machine object named '%ls'...\n", name.raw()); + CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam())); + Guid guid; + CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam())); + printf ("Opening an existing remote session for this machine...\n"); + CHECK_RC_BREAK (virtualBox->OpenExistingSession (session, guid)); + ComPtr <IMachine> sessionMachine; + printf ("Getting sessioned machine object...\n"); + CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam())); + +#if 0 + Bstr extraDataKey = "VBoxSDL/SecureLabel"; + Bstr extraData = "Das kommt jetzt noch viel krasser vom total konkreten API!"; + CHECK_RC (sessionMachine->SetExtraData (extraDataKey, extraData)); +#endif +#if 0 + ComPtr <IConsole> console; + printf ("Getting console object...\n"); + CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam())); + printf ("Press enter to pause the VM execution in the remote session..."); + getchar(); + CHECK_RC (console->Pause()); + printf ("Press enter to close this session..."); + getchar(); +#endif + session->Close(); + } + while (FALSE); + printf ("\n"); +#endif + + printf ("Press enter to release Session and VirtualBox instances..."); + getchar(); + + // end "all-stuff" scope + //////////////////////////////////////////////////////////////////////////// + } + while (0); + + printf("Press enter to shutdown COM..."); + getchar(); + + com::Shutdown(); + + printf ("tstAPI FINISHED.\n"); + + return rc; +} |
