tstAPI.cpp revision d66d6bff1611bf92fac8724b3fc548f78a6f8d71
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * tstAPI - test program for our COM/XPCOM interface
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * Copyright (C) 2006 InnoTek Systemberatung GmbH
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * available from http://www.virtualbox.org. This file is free software;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * General Public License as published by the Free Software Foundation,
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * If you received this file as part of a commercial VirtualBox
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * distribution, then only the terms of your commercial VirtualBox
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * license agreement apply instead of the previous paragraph.
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsyncusing namespace com;
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync///////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsyncHRESULT readAndChangeMachineSettings (IMachine *machine, IMachine *readonlyMachine = 0)
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC_RET (machine->COMGETTER(Name) (name.asOutParam()));
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync CHECK_RC (machine->COMGETTER(Id) (guid.asOutParam()));
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync printf ("Guid::toString(): {%s}\n", (const char *) guid.toString());
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySize));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->COMGETTER(State) (&machineState));
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync CHECK_RC (machine->COMGETTER(SettingsModified) (&modified));
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync printf("Changing memory size to %d...\n", memorySizeBig);
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync CHECK_RC (machine->COMSETTER(MemorySize) (memorySizeBig));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting memory size of the counterpart readonly machine...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync printf ("Are any settings modified after discarding?...\n");
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2;
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync printf("Changing memory size to %d...\n", memorySize);
a9e040e11af94d3457b824f2942d11375f16f598vboxsync CHECK_RC_RET (machine->COMSETTER(MemorySize) (memorySize));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Are any settings modified after saving?...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync printf ("Getting memory size of the counterpart readonly machine...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Getting extra data key {%ls}...\n", extraDataKey.raw());
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
9f9f83ee5948916d644046a79836873db40bfc88vboxsync printf ("Extra data value: {%ls}\n", extraData.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync extraData = L"Das ist die Berliner Luft, Luft, Luft...";
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync "Setting extra data key {%ls} to {%ls}...\n",
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC (machine->SetExtraData (extraDataKey, extraData));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting extra data key {%ls} again...\n", extraDataKey.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Extra data value: {%ls}\n", extraData.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync///////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * Initialize the VBox runtime without loading
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * the support driver.
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // scopes all the stuff till shutdown
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC (virtualBox.createLocalObject (CLSID_VirtualBox,
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync "VirtualBoxServer"));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC (session.createInprocObject (CLSID_Session));
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync // IUnknown identity test
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync ////////////////////////////////////////////////////////////////////////////
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync printf ("Creating one more VirtualBox object...\n");
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox,
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync "VirtualBoxServer"));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync printf ("IVirtualBox(virualBox)=%p IVirtualBox(virualBox2)=%p\n",
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync (IVirtualBox *) virtualBox, (IVirtualBox *) virtualBox2);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("IUnknown(virualBox)=%p IUnknown(virualBox2)=%p\n",
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("IVirtualBox(IUnknown(virualBox))=%p IVirtualBox(IUnknown(virualBox2))=%p\n",
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // create the event queue
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // (here it is necessary only to process remaining XPCOM/IPC events
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // after the session is closed)
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // some outdated stuff
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Host DVD drive name: %s\n", driveNameUtf8);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Could not get host DVD drive collection\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Host floppy drive name: %s\n", driveNameUtf8);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Could not get host floppy drive collection\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // IVirtualBoxErrorInfo test
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // RPC calls
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // call a method that will definitely fail
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// com::ErrorInfo info (virtualBox);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// PRINT_ERROR_INFO (info);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // call a method that will definitely succeed
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = virtualBox->COMGETTER(Version) (version.asOutParam());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("virtualBox->COMGETTER(Version)=%08X\n", rc);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // Local calls
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // call a method that will definitely fail
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = session->COMGETTER(Machine)(machine.asOutParam());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// com::ErrorInfo info (virtualBox);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// PRINT_ERROR_INFO (info);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // call a method that will definitely succeed
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // register the existing hard disk image
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr src = L"E:\\develop\\innotek\\images\\NewHardDisk.vdi";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Registerin the existing hard disk '%ls'...\n", src.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, OpenHardDisk (src, hd.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, RegisterHardDisk (hd));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // find and unregister the existing hard disk image
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Unregistering the hard disk '%ls'...\n", src.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, UnregisterHardDisk (id, hd.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // clone the registered hard disk
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr src = L"/mnt/hugaida/common/develop/innotek/images/freedos-linux.vdi";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr src = L"E:/develop/innotek/images/freedos.vdi";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTPrintf ("Cloning '%ls' to '%ls'...\n", src.raw(), dst.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (hd, CloneToImage (dst, vdi.asOutParam(), progress.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTPrintf ("Actual clone path is '%ls'\n", dst.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // access the machine in read-only mode
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting a machine object named '%ls'...\n", name.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// printf ("Accessing the machine in read-only mode:\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// readAndChangeMachineSettings (machine);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync// if (argc != 2)
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// printf("Error: a string has to be supplied!\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// Bstr secureLabel = argv[1];
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// machine->COMSETTER(ExtraData)(L"VBoxSDL/SecureLabel", secureLabel);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // create a new machine (w/o registering it)
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ///////////////////////////////////////////////////////////////////////////
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync printf ("Creating a new machine object (base dir '%ls', name '%ls')...\n",
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_ERROR_BREAK (virtualBox, CreateMachine (baseDir, name,
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync CHECK_ERROR_BREAK (machine, COMGETTER(Name) (name.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (machine, COMGETTER(SettingsModified) (&modified));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync name = L"Kakaya prekrasnaya virtual'naya mashina!";
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Setting new name ({%ls})...\n", name.raw());
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR_BREAK (machine, COMSETTER(Name) (name));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR_BREAK (machine, COMSETTER(MemorySize) (111));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR_BREAK (virtualBox, FindGuestOSType (type, guestOSType.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync // enumerate host DVD drives
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ///////////////////////////////////////////////////////////////////////////
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (host->COMGETTER(DVDDrives) (coll.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (enumerator->GetNext (drive.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Host DVD drive: name={%ls}\n", name.raw());
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR (enumerator, GetNext (drive.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR (coll, GetItemAt (1000, drive.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR (coll, FindByName (Bstr ("R:"), drive.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Found by name: name={%ls}\n", name.raw());
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync // enumerate hard disks & dvd images
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ///////////////////////////////////////////////////////////////////////////
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (virtualBox->COMGETTER(HardDisks) (coll.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (enumerator->GetNext (disk.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (disk->COMGETTER(Id) (id.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (disk->COMGETTER(FilePath) (path.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync virtualBox->GetHardDiskUsage (id, ResourceUsage_AllUsage,
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync printf (" used by VM: {%s}\n", mid.toString().raw());
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync CHECK_RC_BREAK (virtualBox->COMGETTER(DVDImages) (coll.asOutParam()));
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (enumerator->GetNext (image.asOutParam()));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync CHECK_RC_BREAK (image->COMGETTER(Id) (id.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (image->COMGETTER(FilePath) (path.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync virtualBox->GetDVDImageUsage (id, ResourceUsage_AllUsage,
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync // open a (direct) session
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync ///////////////////////////////////////////////////////////////////////////
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync printf ("Getting a machine object named '%ls'...\n", name.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Opening a session for this machine...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (virtualBox->OpenSession (session, guid));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Accessing the machine within the session:\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync readAndChangeMachineSettings (sessionMachine, machine);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Discarding the current machine state...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_ERROR_BREAK (console, DiscardCurrentState (progress.asOutParam()));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_ERROR_BREAK (progress, COMGETTER(Initiator) (initiator.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("initiator(unk) = %p\n", (IUnknown *) initiator);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("console(unk) = %p\n", (IUnknown *) ComPtr <IUnknown> ((IConsole *) console));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // open a remote session
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
9f9f83ee5948916d644046a79836873db40bfc88vboxsync printf ("Getting a machine object named '%ls'...\n", name.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Opening a remote session for this machine...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("gui"),
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
fdc1cae8a7a45e9299077dd0270c3736b02e4e97vboxsync CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Press enter to pause the VM execution in the remote session...");
7df95d48add893eab9003d793e18c099e126edf9vboxsync // open an existing remote session
7df95d48add893eab9003d793e18c099e126edf9vboxsync ///////////////////////////////////////////////////////////////////////////
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync printf ("Getting a machine object named '%ls'...\n", name.raw());
7df95d48add893eab9003d793e18c099e126edf9vboxsync CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Opening an existing remote session for this machine...\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (virtualBox->OpenExistingSession (session, guid));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync Bstr extraData = "Das kommt jetzt noch viel krasser vom total konkreten API!";
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC (sessionMachine->SetExtraData (extraDataKey, extraData));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Press enter to pause the VM execution in the remote session...");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Press enter to release Session and VirtualBox instances...");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync // end "all-stuff" scope
ccc1001951ecd639b15b3034260c6012423349b3vboxsync ////////////////////////////////////////////////////////////////////////////