tstAPI.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A/** @file
2362N/A *
0N/A * tstAPI - test program for our COM/XPCOM interface
0N/A */
0N/A
0N/A/*
2362N/A * Copyright (C) 2006 InnoTek Systemberatung GmbH
0N/A *
2362N/A * This file is part of VirtualBox Open Source Edition (OSE), as
0N/A * available from http://www.virtualbox.org. This file is free software;
0N/A * you can redistribute it and/or modify it under the terms of the GNU
0N/A * General Public License as published by the Free Software Foundation,
0N/A * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
0N/A * distribution. VirtualBox OSE is distributed in the hope that it will
0N/A * be useful, but WITHOUT ANY WARRANTY of any kind.
0N/A *
0N/A * If you received this file as part of a commercial VirtualBox
0N/A * distribution, then only the terms of your commercial VirtualBox
0N/A * license agreement apply instead of the previous paragraph.
0N/A */
2362N/A
2362N/A#include <stdio.h>
2362N/A#include <stdlib.h>
0N/A
0N/A#include <VBox/com/com.h>
0N/A#include <VBox/com/string.h>
0N/A#include <VBox/com/Guid.h>
0N/A#include <VBox/com/ErrorInfo.h>
0N/A#include <VBox/com/EventQueue.h>
0N/A
0N/A#include <VBox/com/VirtualBox.h>
0N/A
0N/Ausing namespace com;
0N/A
0N/A#include <iprt/runtime.h>
0N/A#include <iprt/stream.h>
0N/A
0N/A#define LOG_ENABLED
0N/A#define LOG_GROUP LOG_GROUP_MAIN
0N/A#define LOG_INSTANCE NULL
0N/A#include <VBox/log.h>
0N/A
0N/A#define printf RTPrintf
0N/A
0N/A// funcs
0N/A///////////////////////////////////////////////////////////////////////////////
0N/A
0N/AHRESULT readAndChangeMachineSettings (IMachine *machine, IMachine *readonlyMachine = 0)
0N/A{
0N/A HRESULT rc = S_OK;
0N/A
0N/A Bstr name;
0N/A printf ("Getting machine name...\n");
0N/A CHECK_RC_RET (machine->COMGETTER(Name) (name.asOutParam()));
0N/A printf ("Name: {%ls}\n", name.raw());
0N/A
0N/A printf("Getting machine GUID...\n");
0N/A Guid guid;
0N/A CHECK_RC (machine->COMGETTER(Id) (guid.asOutParam()));
0N/A if (SUCCEEDED (rc) && !guid.isEmpty()) {
0N/A printf ("Guid::toString(): {%s}\n", (const char *) guid.toString());
0N/A } else {
0N/A printf ("WARNING: there's no GUID!");
0N/A }
0N/A
0N/A ULONG memorySize;
0N/A printf ("Getting memory size...\n");
0N/A CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySize));
0N/A printf ("Memory size: %d\n", memorySize);
0N/A
0N/A MachineState_T machineState;
0N/A printf ("Getting machine state...\n");
0N/A CHECK_RC_RET (machine->COMGETTER(State) (&machineState));
0N/A printf ("Machine state: %d\n", machineState);
0N/A
0N/A BOOL modified;
0N/A printf ("Are any settings modified?...\n");
0N/A CHECK_RC (machine->COMGETTER(SettingsModified) (&modified));
0N/A if (SUCCEEDED (rc))
0N/A printf ("%s\n", modified ? "yes" : "no");
0N/A
0N/A ULONG memorySizeBig = memorySize * 10;
0N/A printf("Changing memory size to %d...\n", memorySizeBig);
0N/A CHECK_RC (machine->COMSETTER(MemorySize) (memorySizeBig));
0N/A
0N/A if (SUCCEEDED (rc)) {
0N/A printf ("Are any settings modified now?...\n");
0N/A CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
0N/A printf ("%s\n", modified ? "yes" : "no");
0N/A ASSERT_RET (modified, 0);
0N/A
0N/A ULONG memorySizeGot;
0N/A printf ("Getting memory size again...\n");
0N/A CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
0N/A printf ("Memory size: %d\n", memorySizeGot);
0N/A ASSERT_RET (memorySizeGot == memorySizeBig, 0);
0N/A
0N/A if (readonlyMachine) {
0N/A printf ("Getting memory size of the counterpart readonly machine...\n");
0N/A ULONG memorySizeRO;
0N/A readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
0N/A printf ("Memory size: %d\n", memorySizeRO);
0N/A ASSERT_RET (memorySizeRO != memorySizeGot, 0);
0N/A }
0N/A
0N/A printf ("Discarding recent changes...\n");
0N/A CHECK_RC_RET (machine->DiscardSettings());
0N/A printf ("Are any settings modified after discarding?...\n");
0N/A CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
0N/A printf ("%s\n", modified ? "yes" : "no");
0N/A ASSERT_RET (!modified, 0);
0N/A
0N/A printf ("Getting memory size once more...\n");
0N/A CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
0N/A printf ("Memory size: %d\n", memorySizeGot);
0N/A ASSERT_RET (memorySizeGot == memorySize, 0);
0N/A
0N/A memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2;
0N/A printf("Changing memory size to %d...\n", memorySize);
0N/A CHECK_RC_RET (machine->COMSETTER(MemorySize) (memorySize));
0N/A }
0N/A
0N/A printf ("Saving machine settings...\n");
0N/A CHECK_RC (machine->SaveSettings());
0N/A if (SUCCEEDED (rc)) {
0N/A printf ("Are any settings modified after saving?...\n");
0N/A CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
0N/A printf ("%s\n", modified ? "yes" : "no");
0N/A ASSERT_RET (!modified, 0);
0N/A
0N/A if (readonlyMachine) {
0N/A printf ("Getting memory size of the counterpart readonly machine...\n");
0N/A ULONG memorySizeRO;
0N/A readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
0N/A printf ("Memory size: %d\n", memorySizeRO);
0N/A ASSERT_RET (memorySizeRO == memorySize, 0);
0N/A }
0N/A }
0N/A
0N/A Bstr extraDataKey = L"Blafasel";
0N/A Bstr extraData;
0N/A printf ("Getting extra data key {%ls}...\n", extraDataKey.raw());
0N/A CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
0N/A if (!extraData.isEmpty()) {
0N/A printf ("Extra data value: {%ls}\n", extraData.raw());
0N/A } else {
0N/A if (extraData.isNull())
0N/A printf ("No extra data exists\n");
0N/A else
0N/A printf ("Extra data is empty\n");
28N/A }
0N/A
0N/A if (extraData.isEmpty())
0N/A extraData = L"Das ist die Berliner Luft, Luft, Luft...";
0N/A else
0N/A extraData.setNull();
0N/A printf (
0N/A "Setting extra data key {%ls} to {%ls}...\n",
0N/A extraDataKey.raw(), extraData.raw()
0N/A );
0N/A CHECK_RC (machine->SetExtraData (extraDataKey, extraData));
0N/A
0N/A if (SUCCEEDED (rc)) {
0N/A printf ("Getting extra data key {%ls} again...\n", extraDataKey.raw());
0N/A CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
0N/A if (!extraData.isEmpty()) {
0N/A printf ("Extra data value: {%ls}\n", extraData.raw());
0N/A } else {
0N/A if (extraData.isNull())
0N/A printf ("No extra data exists\n");
0N/A else
0N/A printf ("Extra data is empty\n");
0N/A }
0N/A }
0N/A
0N/A return rc;
0N/A}
0N/A
0N/A// main
0N/A///////////////////////////////////////////////////////////////////////////////
0N/A
0N/Aint main(int argc, char *argv[])
0N/A{
0N/A /*
0N/A * Initialize the VBox runtime without loading
0N/A * the support driver.
0N/A */
0N/A RTR3Init(false);
0N/A
0N/A HRESULT rc;
0N/A
0N/A printf ("Initializing COM...\n");
0N/A
0N/A CHECK_RC_RET (com::Initialize());
0N/A
0N/A do
0N/A {
0N/A // scopes all the stuff till shutdown
0N/A ////////////////////////////////////////////////////////////////////////////
0N/A
0N/A ComPtr <IVirtualBox> virtualBox;
0N/A ComPtr <ISession> session;
0N/A
0N/A printf ("Creating VirtualBox object...\n");
0N/A CHECK_RC (virtualBox.createLocalObject (CLSID_VirtualBox,
0N/A "VirtualBoxServer"));
0N/A if (FAILED (rc))
0N/A {
0N/A CHECK_ERROR_NOCALL();
0N/A break;
0N/A }
0N/A
0N/A printf ("Creating Session object...\n");
0N/A CHECK_RC (session.createInprocObject (CLSID_Session));
0N/A if (FAILED (rc))
0N/A {
0N/A CHECK_ERROR_NOCALL();
0N/A break;
0N/A }
0N/A
0N/A#if 0
0N/A // IUnknown identity test
0N/A ////////////////////////////////////////////////////////////////////////////
0N/A {
0N/A ComPtr <IVirtualBox> virtualBox2;
0N/A
0N/A printf ("Creating one more VirtualBox object...\n");
0N/A CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox,
0N/A "VirtualBoxServer"));
0N/A if (FAILED (rc))
0N/A {
0N/A CHECK_ERROR_NOCALL();
0N/A break;
0N/A }
0N/A
0N/A printf ("IVirtualBox(virualBox)=%p IVirtualBox(virualBox2)=%p\n",
0N/A (IVirtualBox *) virtualBox, (IVirtualBox *) virtualBox2);
0N/A
0N/A ComPtr <IUnknown> unk (virtualBox);
0N/A ComPtr <IUnknown> unk2;
0N/A unk2 = virtualBox2;
0N/A
0N/A printf ("IUnknown(virualBox)=%p IUnknown(virualBox2)=%p\n",
0N/A (IUnknown *) unk, (IUnknown *) unk2);
0N/A
0N/A ComPtr <IVirtualBox> vb = unk;
0N/A ComPtr <IVirtualBox> vb2 = unk;
0N/A
0N/A printf ("IVirtualBox(IUnknown(virualBox))=%p IVirtualBox(IUnknown(virualBox2))=%p\n",
0N/A (IVirtualBox *) vb, (IVirtualBox *) vb2);
0N/A
0N/A printf ("Will be now released (press Enter)...");
0N/A getchar();
0N/A }
0N/A#endif
0N/A
0N/A // create the event queue
0N/A // (here it is necessary only to process remaining XPCOM/IPC events
0N/A // after the session is closed)
0N/A EventQueue eventQ;
0N/A
0N/A // some outdated stuff
0N/A ////////////////////////////////////////////////////////////////////////////
0N/A
0N/A#if 0
0N/A printf("Getting IHost interface...\n");
0N/A IHost *host;
0N/A rc = virtualBox->GetHost(&host);
0N/A if (SUCCEEDED(rc))
0N/A {
0N/A IHostDVDDriveCollection *dvdColl;
0N/A rc = host->GetHostDVDDrives(&dvdColl);
0N/A if (SUCCEEDED(rc))
0N/A {
0N/A IHostDVDDrive *dvdDrive = NULL;
0N/A dvdColl->GetNextHostDVDDrive(dvdDrive, &dvdDrive);
0N/A while (dvdDrive)
0N/A {
0N/A BSTR driveName;
0N/A char *driveNameUtf8;
0N/A dvdDrive->GetDriveName(&driveName);
0N/A RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
0N/A printf("Host DVD drive name: %s\n", driveNameUtf8);
0N/A RTStrFree(driveNameUtf8);
0N/A SysFreeString(driveName);
0N/A IHostDVDDrive *dvdDriveTemp = dvdDrive;
0N/A dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive);
0N/A dvdDriveTemp->Release();
0N/A }
0N/A dvdColl->Release();
0N/A } else
0N/A {
0N/A printf("Could not get host DVD drive collection\n");
0N/A }
0N/A
0N/A IHostFloppyDriveCollection *floppyColl;
0N/A rc = host->GetHostFloppyDrives(&floppyColl);
0N/A if (SUCCEEDED(rc))
0N/A {
0N/A IHostFloppyDrive *floppyDrive = NULL;
0N/A floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive);
0N/A while (floppyDrive)
0N/A {
0N/A BSTR driveName;
0N/A char *driveNameUtf8;
0N/A floppyDrive->GetDriveName(&driveName);
0N/A RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
0N/A printf("Host floppy drive name: %s\n", driveNameUtf8);
0N/A RTStrFree(driveNameUtf8);
0N/A SysFreeString(driveName);
0N/A IHostFloppyDrive *floppyDriveTemp = floppyDrive;
0N/A floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive);
0N/A floppyDriveTemp->Release();
0N/A }
0N/A floppyColl->Release();
0N/A } else
0N/A {
0N/A printf("Could not get host floppy drive collection\n");
0N/A }
0N/A host->Release();
0N/A } else
0N/A {
0N/A printf("Call failed\n");
0N/A }
0N/A printf ("\n");
0N/A#endif
0N/A
0N/A#if 0
0N/A // IVirtualBoxErrorInfo test
0N/A ////////////////////////////////////////////////////////////////////////////
0N/A {
0N/A // RPC calls
0N/A
0N/A // call a method that will definitely fail
0N/A Guid uuid;
0N/A ComPtr <IHardDisk> hardDisk;
0N/A rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
0N/A printf ("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc);
0N/A
0N/A// {
0N/A// com::ErrorInfo info (virtualBox);
0N/A// PRINT_ERROR_INFO (info);
0N/A// }
0N/A
0N/A // call a method that will definitely succeed
0N/A Bstr version;
0N/A rc = virtualBox->COMGETTER(Version) (version.asOutParam());
0N/A printf ("virtualBox->COMGETTER(Version)=%08X\n", rc);
0N/A
0N/A {
0N/A com::ErrorInfo info (virtualBox);
0N/A PRINT_ERROR_INFO (info);
0N/A }
0N/A
0N/A // Local calls
0N/A
0N/A // call a method that will definitely fail
0N/A ComPtr <IMachine> machine;
0N/A rc = session->COMGETTER(Machine)(machine.asOutParam());
0N/A printf ("session->COMGETTER(Machine)=%08X\n", rc);
0N/A
0N/A// {
0N/A// com::ErrorInfo info (virtualBox);
0N/A// PRINT_ERROR_INFO (info);
0N/A// }
0N/A
0N/A // call a method that will definitely succeed
0N/A SessionState_T state;
0N/A rc = session->COMGETTER(State) (&state);
0N/A printf ("session->COMGETTER(State)=%08X\n", rc);
0N/A
0N/A {
0N/A com::ErrorInfo info (virtualBox);
0N/A PRINT_ERROR_INFO (info);
0N/A }
}
#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;
}