3
* tstAPI - test program for our COM/XPCOM interface
7
* Copyright (C) 2006-2007 innotek GmbH
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License as published by the Free Software Foundation,
13
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14
* distribution. VirtualBox OSE is distributed in the hope that it will
15
* be useful, but WITHOUT ANY WARRANTY of any kind.
21
#include <VBox/com/com.h>
22
#include <VBox/com/string.h>
23
#include <VBox/com/Guid.h>
24
#include <VBox/com/ErrorInfo.h>
25
#include <VBox/com/EventQueue.h>
27
#include <VBox/com/VirtualBox.h>
32
#define LOG_GROUP LOG_GROUP_MAIN
33
#define LOG_INSTANCE NULL
36
#include <iprt/runtime.h>
37
#include <iprt/stream.h>
39
#define printf RTPrintf
42
///////////////////////////////////////////////////////////////////////////////
44
HRESULT readAndChangeMachineSettings (IMachine *machine, IMachine *readonlyMachine = 0)
49
printf ("Getting machine name...\n");
50
CHECK_RC_RET (machine->COMGETTER(Name) (name.asOutParam()));
51
printf ("Name: {%ls}\n", name.raw());
53
printf("Getting machine GUID...\n");
55
CHECK_RC (machine->COMGETTER(Id) (guid.asOutParam()));
56
if (SUCCEEDED (rc) && !guid.isEmpty()) {
57
printf ("Guid::toString(): {%s}\n", (const char *) guid.toString());
59
printf ("WARNING: there's no GUID!");
63
printf ("Getting memory size...\n");
64
CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySize));
65
printf ("Memory size: %d\n", memorySize);
67
MachineState_T machineState;
68
printf ("Getting machine state...\n");
69
CHECK_RC_RET (machine->COMGETTER(State) (&machineState));
70
printf ("Machine state: %d\n", machineState);
73
printf ("Are any settings modified?...\n");
74
CHECK_RC (machine->COMGETTER(SettingsModified) (&modified));
76
printf ("%s\n", modified ? "yes" : "no");
78
ULONG memorySizeBig = memorySize * 10;
79
printf("Changing memory size to %d...\n", memorySizeBig);
80
CHECK_RC (machine->COMSETTER(MemorySize) (memorySizeBig));
84
printf ("Are any settings modified now?...\n");
85
CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
86
printf ("%s\n", modified ? "yes" : "no");
87
ASSERT_RET (modified, 0);
90
printf ("Getting memory size again...\n");
91
CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
92
printf ("Memory size: %d\n", memorySizeGot);
93
ASSERT_RET (memorySizeGot == memorySizeBig, 0);
97
printf ("Getting memory size of the counterpart readonly machine...\n");
99
readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
100
printf ("Memory size: %d\n", memorySizeRO);
101
ASSERT_RET (memorySizeRO != memorySizeGot, 0);
104
printf ("Discarding recent changes...\n");
105
CHECK_RC_RET (machine->DiscardSettings());
106
printf ("Are any settings modified after discarding?...\n");
107
CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
108
printf ("%s\n", modified ? "yes" : "no");
109
ASSERT_RET (!modified, 0);
111
printf ("Getting memory size once more...\n");
112
CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
113
printf ("Memory size: %d\n", memorySizeGot);
114
ASSERT_RET (memorySizeGot == memorySize, 0);
116
memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2;
117
printf("Changing memory size to %d...\n", memorySize);
118
CHECK_RC_RET (machine->COMSETTER(MemorySize) (memorySize));
122
printf ("Getting description...\n");
123
CHECK_ERROR_RET (machine, COMGETTER(Description) (desc.asOutParam()), rc);
124
printf ("Description is: \"%ls\"\n", desc.raw());
126
desc = L"This is an exemplary description (changed).";
127
printf ("Setting description to \"%ls\"...\n", desc.raw());
128
CHECK_ERROR_RET (machine, COMSETTER(Description) (desc), rc);
130
printf ("Saving machine settings...\n");
131
CHECK_RC (machine->SaveSettings());
134
printf ("Are any settings modified after saving?...\n");
135
CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
136
printf ("%s\n", modified ? "yes" : "no");
137
ASSERT_RET (!modified, 0);
139
if (readonlyMachine) {
140
printf ("Getting memory size of the counterpart readonly machine...\n");
142
readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
143
printf ("Memory size: %d\n", memorySizeRO);
144
ASSERT_RET (memorySizeRO == memorySize, 0);
148
Bstr extraDataKey = L"Blafasel";
150
printf ("Getting extra data key {%ls}...\n", extraDataKey.raw());
151
CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
152
if (!extraData.isEmpty()) {
153
printf ("Extra data value: {%ls}\n", extraData.raw());
155
if (extraData.isNull())
156
printf ("No extra data exists\n");
158
printf ("Extra data is empty\n");
161
if (extraData.isEmpty())
162
extraData = L"Das ist die Berliner Luft, Luft, Luft...";
166
"Setting extra data key {%ls} to {%ls}...\n",
167
extraDataKey.raw(), extraData.raw()
169
CHECK_RC (machine->SetExtraData (extraDataKey, extraData));
171
if (SUCCEEDED (rc)) {
172
printf ("Getting extra data key {%ls} again...\n", extraDataKey.raw());
173
CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
174
if (!extraData.isEmpty()) {
175
printf ("Extra data value: {%ls}\n", extraData.raw());
177
if (extraData.isNull())
178
printf ("No extra data exists\n");
180
printf ("Extra data is empty\n");
188
///////////////////////////////////////////////////////////////////////////////
190
int main(int argc, char *argv[])
193
* Initialize the VBox runtime without loading
194
* the support driver.
201
char homeDir [RTPATH_MAX];
202
GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir));
203
printf ("VirtualBox Home Directory = '%s'\n", homeDir);
206
printf ("Initializing COM...\n");
208
CHECK_RC_RET (com::Initialize());
212
// scopes all the stuff till shutdown
213
////////////////////////////////////////////////////////////////////////////
215
ComPtr <IVirtualBox> virtualBox;
216
ComPtr <ISession> session;
220
////////////////////////////////////////////////////////////////////////////
223
printf ("nullUtf8Str='%s'\n", nullUtf8Str.raw());
225
Utf8Str simpleUtf8Str = "simpleUtf8Str";
226
printf ("simpleUtf8Str='%s'\n", simpleUtf8Str.raw());
228
Utf8Str utf8StrFmt = Utf8StrFmt ("[0=%d]%s[1=%d]",
230
printf ("utf8StrFmt='%s'\n", utf8StrFmt.raw());
234
printf ("Creating VirtualBox object...\n");
235
CHECK_RC (virtualBox.createLocalObject (CLSID_VirtualBox));
238
CHECK_ERROR_NOCALL();
242
printf ("Creating Session object...\n");
243
CHECK_RC (session.createInprocObject (CLSID_Session));
246
CHECK_ERROR_NOCALL();
251
// IUnknown identity test
252
////////////////////////////////////////////////////////////////////////////
255
ComPtr <IVirtualBox> virtualBox2;
257
printf ("Creating one more VirtualBox object...\n");
258
CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox));
261
CHECK_ERROR_NOCALL();
265
printf ("IVirtualBox(virualBox)=%p IVirtualBox(virualBox2)=%p\n",
266
(IVirtualBox *) virtualBox, (IVirtualBox *) virtualBox2);
267
Assert ((IVirtualBox *) virtualBox == (IVirtualBox *) virtualBox2);
269
ComPtr <IUnknown> unk (virtualBox);
270
ComPtr <IUnknown> unk2;
273
printf ("IUnknown(virualBox)=%p IUnknown(virualBox2)=%p\n",
274
(IUnknown *) unk, (IUnknown *) unk2);
275
Assert ((IUnknown *) unk == (IUnknown *) unk2);
277
ComPtr <IVirtualBox> vb = unk;
278
ComPtr <IVirtualBox> vb2 = unk;
280
printf ("IVirtualBox(IUnknown(virualBox))=%p IVirtualBox(IUnknown(virualBox2))=%p\n",
281
(IVirtualBox *) vb, (IVirtualBox *) vb2);
282
Assert ((IVirtualBox *) vb == (IVirtualBox *) vb2);
287
CHECK_ERROR_BREAK (virtualBox, COMGETTER(Host)(host.asOutParam()));
288
printf (" IHost(host)=%p\n", (IHost *) host);
289
ComPtr <IUnknown> unk = host;
290
printf (" IUnknown(host)=%p\n", (IUnknown *) unk);
291
ComPtr <IHost> host_copy = unk;
292
printf (" IHost(host_copy)=%p\n", (IHost *) host_copy);
293
ComPtr <IUnknown> unk_copy = host_copy;
294
printf (" IUnknown(host_copy)=%p\n", (IUnknown *) unk_copy);
295
Assert ((IUnknown *) unk == (IUnknown *) unk_copy);
297
/* query IUnknown on IUnknown */
298
ComPtr <IUnknown> unk_copy_copy;
299
unk_copy.queryInterfaceTo (unk_copy_copy.asOutParam());
300
printf (" IUnknown(unk_copy)=%p\n", (IUnknown *) unk_copy_copy);
301
Assert ((IUnknown *) unk_copy == (IUnknown *) unk_copy_copy);
302
/* query IUnknown on IUnknown in the opposite direction */
303
unk_copy_copy.queryInterfaceTo (unk_copy.asOutParam());
304
printf (" IUnknown(unk_copy_copy)=%p\n", (IUnknown *) unk_copy);
305
Assert ((IUnknown *) unk_copy == (IUnknown *) unk_copy_copy);
307
/* query IUnknown again after releasing all previous IUnknown instances
308
* but keeping IHost -- it should remain the same (Identity Rule) */
309
IUnknown *oldUnk = unk;
312
unk_copy_copy.setNull();
314
printf (" IUnknown(host)=%p\n", (IUnknown *) unk);
315
Assert (oldUnk == (IUnknown *) unk);
318
// printf ("Will be now released (press Enter)...");
323
// create the event queue
324
// (here it is necessary only to process remaining XPCOM/IPC events
325
// after the session is closed)
328
// some outdated stuff
329
////////////////////////////////////////////////////////////////////////////
332
printf("Getting IHost interface...\n");
334
rc = virtualBox->GetHost(&host);
337
IHostDVDDriveCollection *dvdColl;
338
rc = host->GetHostDVDDrives(&dvdColl);
341
IHostDVDDrive *dvdDrive = NULL;
342
dvdColl->GetNextHostDVDDrive(dvdDrive, &dvdDrive);
347
dvdDrive->GetDriveName(&driveName);
348
RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
349
printf("Host DVD drive name: %s\n", driveNameUtf8);
350
RTStrFree(driveNameUtf8);
351
SysFreeString(driveName);
352
IHostDVDDrive *dvdDriveTemp = dvdDrive;
353
dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive);
354
dvdDriveTemp->Release();
359
printf("Could not get host DVD drive collection\n");
362
IHostFloppyDriveCollection *floppyColl;
363
rc = host->GetHostFloppyDrives(&floppyColl);
366
IHostFloppyDrive *floppyDrive = NULL;
367
floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive);
372
floppyDrive->GetDriveName(&driveName);
373
RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
374
printf("Host floppy drive name: %s\n", driveNameUtf8);
375
RTStrFree(driveNameUtf8);
376
SysFreeString(driveName);
377
IHostFloppyDrive *floppyDriveTemp = floppyDrive;
378
floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive);
379
floppyDriveTemp->Release();
381
floppyColl->Release();
384
printf("Could not get host floppy drive collection\n");
389
printf("Call failed\n");
395
// IVirtualBoxErrorInfo test
396
////////////////////////////////////////////////////////////////////////////
400
// call a method that will definitely fail
402
ComPtr <IHardDisk> hardDisk;
403
rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
404
printf ("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc);
407
// com::ErrorInfo info (virtualBox);
408
// PRINT_ERROR_INFO (info);
411
// call a method that will definitely succeed
413
rc = virtualBox->COMGETTER(Version) (version.asOutParam());
414
printf ("virtualBox->COMGETTER(Version)=%08X\n", rc);
417
com::ErrorInfo info (virtualBox);
418
PRINT_ERROR_INFO (info);
423
// call a method that will definitely fail
424
ComPtr <IMachine> machine;
425
rc = session->COMGETTER(Machine)(machine.asOutParam());
426
printf ("session->COMGETTER(Machine)=%08X\n", rc);
429
// com::ErrorInfo info (virtualBox);
430
// PRINT_ERROR_INFO (info);
433
// call a method that will definitely succeed
434
SessionState_T state;
435
rc = session->COMGETTER(State) (&state);
436
printf ("session->COMGETTER(State)=%08X\n", rc);
439
com::ErrorInfo info (virtualBox);
440
PRINT_ERROR_INFO (info);
446
// register the existing hard disk image
447
///////////////////////////////////////////////////////////////////////////
450
ComPtr <IHardDisk> hd;
451
Bstr src = L"E:\\develop\\innotek\\images\\NewHardDisk.vdi";
452
printf ("Registerin the existing hard disk '%ls'...\n", src.raw());
453
CHECK_ERROR_BREAK (virtualBox, OpenHardDisk (src, hd.asOutParam()));
454
CHECK_ERROR_BREAK (virtualBox, RegisterHardDisk (hd));
461
// find and unregister the existing hard disk image
462
///////////////////////////////////////////////////////////////////////////
465
ComPtr <IVirtualDiskImage> vdi;
466
Bstr src = L"CreatorTest.vdi";
467
printf ("Unregistering the hard disk '%ls'...\n", src.raw());
468
CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
469
ComPtr <IHardDisk> hd = vdi;
471
CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam()));
472
CHECK_ERROR_BREAK (virtualBox, UnregisterHardDisk (id, hd.asOutParam()));
479
// clone the registered hard disk
480
///////////////////////////////////////////////////////////////////////////
483
#if defined RT_OS_LINUX
484
Bstr src = L"/mnt/hugaida/common/develop/innotek/images/freedos-linux.vdi";
486
Bstr src = L"E:/develop/innotek/images/freedos.vdi";
488
Bstr dst = L"./clone.vdi";
489
RTPrintf ("Cloning '%ls' to '%ls'...\n", src.raw(), dst.raw());
490
ComPtr <IVirtualDiskImage> vdi;
491
CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
492
ComPtr <IHardDisk> hd = vdi;
493
ComPtr <IProgress> progress;
494
CHECK_ERROR_BREAK (hd, CloneToImage (dst, vdi.asOutParam(), progress.asOutParam()));
495
RTPrintf ("Waiting for completion...\n");
496
CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
497
ProgressErrorInfo ei (progress);
498
if (FAILED (ei.getResultCode()))
500
PRINT_ERROR_INFO (ei);
504
vdi->COMGETTER(FilePath) (dst.asOutParam());
505
RTPrintf ("Actual clone path is '%ls'\n", dst.raw());
513
// find a registered hard disk by location
514
///////////////////////////////////////////////////////////////////////////
517
ComPtr <IHardDisk> hd;
518
static const wchar_t *Names[] =
521
L"E:/Develop/innotek/images/thinker/freedos.vdi",
522
L"E:/Develop/innotek/images/thinker/fReeDoS.vDI",
523
L"E:/Develop/innotek/images/vmdk/haiku.vmdk",
525
L"/mnt/host/common/Develop/innotek/images/maggot/freedos.vdi",
526
L"/mnt/host/common/Develop/innotek/images/maggot/fReeDoS.vDI",
529
for (size_t i = 0; i < ELEMENTS (Names); ++ i)
531
Bstr src = Names [i];
532
printf ("Searching for hard disk '%ls'...\n", src.raw());
533
rc = virtualBox->FindHardDisk (src, hd.asOutParam());
538
CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam()));
539
CHECK_ERROR_BREAK (hd, COMGETTER(Location) (location.asOutParam()));
540
printf ("Found, UUID={%Vuuid}, location='%ls'.\n",
541
id.raw(), location.raw());
545
PRINT_ERROR_INFO (com::ErrorInfo (virtualBox));
554
// access the machine in read-only mode
555
///////////////////////////////////////////////////////////////////////////
558
ComPtr <IMachine> machine;
559
Bstr name = argc > 1 ? argv [1] : "dos";
560
printf ("Getting a machine object named '%ls'...\n", name.raw());
561
CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
562
printf ("Accessing the machine in read-only mode:\n");
563
readAndChangeMachineSettings (machine);
567
printf ("Error: a string has to be supplied!\n");
571
Bstr secureLabel = argv[1];
572
machine->COMSETTER(ExtraData)(L"VBoxSDL/SecureLabel", secureLabel);
581
// create a new machine (w/o registering it)
582
///////////////////////////////////////////////////////////////////////////
585
ComPtr <IMachine> machine;
586
#if defined (RT_OS_LINUX)
587
Bstr baseDir = L"/tmp/vbox";
589
Bstr baseDir = L"C:\\vbox";
591
Bstr name = L"machina";
593
printf ("Creating a new machine object (base dir '%ls', name '%ls')...\n",
594
baseDir.raw(), name.raw());
595
CHECK_ERROR_BREAK (virtualBox, CreateMachine (baseDir, name,
596
machine.asOutParam()));
598
printf ("Getting name...\n");
599
CHECK_ERROR_BREAK (machine, COMGETTER(Name) (name.asOutParam()));
600
printf ("Name: {%ls}\n", name.raw());
602
BOOL modified = FALSE;
603
printf ("Are any settings modified?...\n");
604
CHECK_ERROR_BREAK (machine, COMGETTER(SettingsModified) (&modified));
605
printf ("%s\n", modified ? "yes" : "no");
607
ASSERT_BREAK (modified == TRUE);
609
name = L"Kakaya prekrasnaya virtual'naya mashina!";
610
printf ("Setting new name ({%ls})...\n", name.raw());
611
CHECK_ERROR_BREAK (machine, COMSETTER(Name) (name));
613
printf ("Setting memory size to 111...\n");
614
CHECK_ERROR_BREAK (machine, COMSETTER(MemorySize) (111));
616
Bstr desc = L"This is an exemplary description.";
617
printf ("Setting description to \"%ls\"...\n", desc.raw());
618
CHECK_ERROR_BREAK (machine, COMSETTER(Description) (desc));
620
ComPtr <IGuestOSType> guestOSType;
621
Bstr type = L"os2warp45";
622
CHECK_ERROR_BREAK (virtualBox, GetGuestOSType (type, guestOSType.asOutParam()));
624
printf ("Saving new machine settings...\n");
625
CHECK_ERROR_BREAK (machine, SaveSettings());
627
printf ("Accessing the newly created machine:\n");
628
readAndChangeMachineSettings (machine);
635
// enumerate host DVD drives
636
///////////////////////////////////////////////////////////////////////////
640
CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam()));
643
ComPtr <IHostDVDDriveCollection> coll;
644
CHECK_RC_BREAK (host->COMGETTER(DVDDrives) (coll.asOutParam()));
645
ComPtr <IHostDVDDriveEnumerator> enumerator;
646
CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
648
while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
650
ComPtr <IHostDVDDrive> drive;
651
CHECK_RC_BREAK (enumerator->GetNext (drive.asOutParam()));
653
CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
654
printf ("Host DVD drive: name={%ls}\n", name.raw());
658
ComPtr <IHostDVDDrive> drive;
659
CHECK_ERROR (enumerator, GetNext (drive.asOutParam()));
660
CHECK_ERROR (coll, GetItemAt (1000, drive.asOutParam()));
661
CHECK_ERROR (coll, FindByName (Bstr ("R:"), drive.asOutParam()));
665
CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
666
printf ("Found by name: name={%ls}\n", name.raw());
675
// enumerate hard disks & dvd images
676
///////////////////////////////////////////////////////////////////////////
680
ComPtr <IHardDiskCollection> coll;
681
CHECK_RC_BREAK (virtualBox->COMGETTER(HardDisks) (coll.asOutParam()));
682
ComPtr <IHardDiskEnumerator> enumerator;
683
CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
685
while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
687
ComPtr <IHardDisk> disk;
688
CHECK_RC_BREAK (enumerator->GetNext (disk.asOutParam()));
690
CHECK_RC_BREAK (disk->COMGETTER(Id) (id.asOutParam()));
692
CHECK_RC_BREAK (disk->COMGETTER(FilePath) (path.asOutParam()));
693
printf ("Hard Disk: id={%s}, path={%ls}\n",
694
id.toString().raw(), path.raw());
697
virtualBox->GetHardDiskUsage (id, ResourceUsage_AllUsage,
701
printf (" not used\n");
703
printf (" used by VM: {%s}\n", mid.toString().raw());
709
ComPtr <IDVDImageCollection> coll;
710
CHECK_RC_BREAK (virtualBox->COMGETTER(DVDImages) (coll.asOutParam()));
711
ComPtr <IDVDImageEnumerator> enumerator;
712
CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
714
while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
716
ComPtr <IDVDImage> image;
717
CHECK_RC_BREAK (enumerator->GetNext (image.asOutParam()));
719
CHECK_RC_BREAK (image->COMGETTER(Id) (id.asOutParam()));
721
CHECK_RC_BREAK (image->COMGETTER(FilePath) (path.asOutParam()));
722
printf ("CD/DVD Image: id={%s}, path={%ls}\n",
723
id.toString().raw(), path.raw());
726
virtualBox->GetDVDImageUsage (id, ResourceUsage_AllUsage,
730
printf (" not used\n");
732
printf (" used by VMs: {%ls}\n", mIDs.raw());
742
// open a (direct) session
743
///////////////////////////////////////////////////////////////////////////
746
ComPtr <IMachine> machine;
747
Bstr name = argc > 1 ? argv [1] : "dos";
748
printf ("Getting a machine object named '%ls'...\n", name.raw());
749
CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
751
CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
752
printf ("Opening a session for this machine...\n");
753
CHECK_RC_BREAK (virtualBox->OpenSession (session, guid));
755
ComPtr <IMachine> sessionMachine;
756
printf ("Getting sessioned machine object...\n");
757
CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
758
printf ("Accessing the machine within the session:\n");
759
readAndChangeMachineSettings (sessionMachine, machine);
762
printf ("Enabling the VRDP server (must succeed even if the VM is saved):\n");
763
ComPtr <IVRDPServer> vrdp;
764
CHECK_ERROR_BREAK (sessionMachine, COMGETTER(VRDPServer) (vrdp.asOutParam()));
765
if (FAILED (vrdp->COMSETTER(Enabled) (TRUE)))
767
PRINT_ERROR_INFO (com::ErrorInfo (vrdp));
771
BOOL enabled = FALSE;
772
CHECK_ERROR_BREAK (vrdp, COMGETTER(Enabled) (&enabled));
773
printf ("VRDP server is %s\n", enabled ? "enabled" : "disabled");
778
ComPtr <IConsole> console;
779
printf ("Getting the console object...\n");
780
CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
781
printf ("Discarding the current machine state...\n");
782
ComPtr <IProgress> progress;
783
CHECK_ERROR_BREAK (console, DiscardCurrentState (progress.asOutParam()));
784
printf ("Waiting for completion...\n");
785
CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
786
ProgressErrorInfo ei (progress);
787
if (FAILED (ei.getResultCode()))
789
PRINT_ERROR_INFO (ei);
791
ComPtr <IUnknown> initiator;
792
CHECK_ERROR_BREAK (progress, COMGETTER(Initiator) (initiator.asOutParam()));
794
printf ("initiator(unk) = %p\n", (IUnknown *) initiator);
795
printf ("console(unk) = %p\n", (IUnknown *) ComPtr <IUnknown> ((IConsole *) console));
796
printf ("console = %p\n", (IConsole *) console);
799
printf("Press enter to close session...");
808
// open a remote session
809
///////////////////////////////////////////////////////////////////////////
812
ComPtr <IMachine> machine;
814
printf ("Getting a machine object named '%ls'...\n", name.raw());
815
CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
817
CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
818
printf ("Opening a remote session for this machine...\n");
819
ComPtr <IProgress> progress;
820
CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("gui"),
821
NULL, progress.asOutParam()));
822
printf ("Waiting for the session to open...\n");
823
CHECK_RC_BREAK (progress->WaitForCompletion (-1));
824
ComPtr <IMachine> sessionMachine;
825
printf ("Getting sessioned machine object...\n");
826
CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
827
ComPtr <IConsole> console;
828
printf ("Getting console object...\n");
829
CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
830
printf ("Press enter to pause the VM execution in the remote session...");
832
CHECK_RC (console->Pause());
833
printf ("Press enter to close this session...");
842
// open an existing remote session
843
///////////////////////////////////////////////////////////////////////////
846
ComPtr <IMachine> machine;
848
printf ("Getting a machine object named '%ls'...\n", name.raw());
849
CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
851
CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
852
printf ("Opening an existing remote session for this machine...\n");
853
CHECK_RC_BREAK (virtualBox->OpenExistingSession (session, guid));
854
ComPtr <IMachine> sessionMachine;
855
printf ("Getting sessioned machine object...\n");
856
CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
859
Bstr extraDataKey = "VBoxSDL/SecureLabel";
860
Bstr extraData = "Das kommt jetzt noch viel krasser vom total konkreten API!";
861
CHECK_RC (sessionMachine->SetExtraData (extraDataKey, extraData));
864
ComPtr <IConsole> console;
865
printf ("Getting console object...\n");
866
CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
867
printf ("Press enter to pause the VM execution in the remote session...");
869
CHECK_RC (console->Pause());
870
printf ("Press enter to close this session...");
879
printf ("Press enter to release Session and VirtualBox instances...");
882
// end "all-stuff" scope
883
////////////////////////////////////////////////////////////////////////////
887
printf("Press enter to shutdown COM...");
892
printf ("tstAPI FINISHED.\n");