VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstAPI.cpp@ 3123

Last change on this file since 3123 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.8 KB
Line 
1/** @file
2 *
3 * tstAPI - test program for our COM/XPCOM interface
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
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.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#include <stdio.h>
23#include <stdlib.h>
24
25#include <VBox/com/com.h>
26#include <VBox/com/string.h>
27#include <VBox/com/Guid.h>
28#include <VBox/com/ErrorInfo.h>
29#include <VBox/com/EventQueue.h>
30
31#include <VBox/com/VirtualBox.h>
32
33using namespace com;
34
35#define LOG_ENABLED
36#define LOG_GROUP LOG_GROUP_MAIN
37#define LOG_INSTANCE NULL
38#include <VBox/log.h>
39
40#include <iprt/runtime.h>
41#include <iprt/stream.h>
42
43#define printf RTPrintf
44
45// funcs
46///////////////////////////////////////////////////////////////////////////////
47
48HRESULT readAndChangeMachineSettings (IMachine *machine, IMachine *readonlyMachine = 0)
49{
50 HRESULT rc = S_OK;
51
52 Bstr name;
53 printf ("Getting machine name...\n");
54 CHECK_RC_RET (machine->COMGETTER(Name) (name.asOutParam()));
55 printf ("Name: {%ls}\n", name.raw());
56
57 printf("Getting machine GUID...\n");
58 Guid guid;
59 CHECK_RC (machine->COMGETTER(Id) (guid.asOutParam()));
60 if (SUCCEEDED (rc) && !guid.isEmpty()) {
61 printf ("Guid::toString(): {%s}\n", (const char *) guid.toString());
62 } else {
63 printf ("WARNING: there's no GUID!");
64 }
65
66 ULONG memorySize;
67 printf ("Getting memory size...\n");
68 CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySize));
69 printf ("Memory size: %d\n", memorySize);
70
71 MachineState_T machineState;
72 printf ("Getting machine state...\n");
73 CHECK_RC_RET (machine->COMGETTER(State) (&machineState));
74 printf ("Machine state: %d\n", machineState);
75
76 BOOL modified;
77 printf ("Are any settings modified?...\n");
78 CHECK_RC (machine->COMGETTER(SettingsModified) (&modified));
79 if (SUCCEEDED (rc))
80 printf ("%s\n", modified ? "yes" : "no");
81
82 ULONG memorySizeBig = memorySize * 10;
83 printf("Changing memory size to %d...\n", memorySizeBig);
84 CHECK_RC (machine->COMSETTER(MemorySize) (memorySizeBig));
85
86 if (SUCCEEDED (rc))
87 {
88 printf ("Are any settings modified now?...\n");
89 CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
90 printf ("%s\n", modified ? "yes" : "no");
91 ASSERT_RET (modified, 0);
92
93 ULONG memorySizeGot;
94 printf ("Getting memory size again...\n");
95 CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
96 printf ("Memory size: %d\n", memorySizeGot);
97 ASSERT_RET (memorySizeGot == memorySizeBig, 0);
98
99 if (readonlyMachine)
100 {
101 printf ("Getting memory size of the counterpart readonly machine...\n");
102 ULONG memorySizeRO;
103 readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
104 printf ("Memory size: %d\n", memorySizeRO);
105 ASSERT_RET (memorySizeRO != memorySizeGot, 0);
106 }
107
108 printf ("Discarding recent changes...\n");
109 CHECK_RC_RET (machine->DiscardSettings());
110 printf ("Are any settings modified after discarding?...\n");
111 CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
112 printf ("%s\n", modified ? "yes" : "no");
113 ASSERT_RET (!modified, 0);
114
115 printf ("Getting memory size once more...\n");
116 CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
117 printf ("Memory size: %d\n", memorySizeGot);
118 ASSERT_RET (memorySizeGot == memorySize, 0);
119
120 memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2;
121 printf("Changing memory size to %d...\n", memorySize);
122 CHECK_RC_RET (machine->COMSETTER(MemorySize) (memorySize));
123 }
124
125 Bstr desc;
126 printf ("Getting description...\n");
127 CHECK_ERROR_RET (machine, COMGETTER(Description) (desc.asOutParam()), rc);
128 printf ("Description is: \"%ls\"\n", desc.raw());
129
130 desc = L"This is an exemplary description (changed).";
131 printf ("Setting description to \"%ls\"...\n", desc.raw());
132 CHECK_ERROR_RET (machine, COMSETTER(Description) (desc), rc);
133
134 printf ("Saving machine settings...\n");
135 CHECK_RC (machine->SaveSettings());
136 if (SUCCEEDED (rc))
137 {
138 printf ("Are any settings modified after saving?...\n");
139 CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
140 printf ("%s\n", modified ? "yes" : "no");
141 ASSERT_RET (!modified, 0);
142
143 if (readonlyMachine) {
144 printf ("Getting memory size of the counterpart readonly machine...\n");
145 ULONG memorySizeRO;
146 readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
147 printf ("Memory size: %d\n", memorySizeRO);
148 ASSERT_RET (memorySizeRO == memorySize, 0);
149 }
150 }
151
152 Bstr extraDataKey = L"Blafasel";
153 Bstr extraData;
154 printf ("Getting extra data key {%ls}...\n", extraDataKey.raw());
155 CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
156 if (!extraData.isEmpty()) {
157 printf ("Extra data value: {%ls}\n", extraData.raw());
158 } else {
159 if (extraData.isNull())
160 printf ("No extra data exists\n");
161 else
162 printf ("Extra data is empty\n");
163 }
164
165 if (extraData.isEmpty())
166 extraData = L"Das ist die Berliner Luft, Luft, Luft...";
167 else
168 extraData.setNull();
169 printf (
170 "Setting extra data key {%ls} to {%ls}...\n",
171 extraDataKey.raw(), extraData.raw()
172 );
173 CHECK_RC (machine->SetExtraData (extraDataKey, extraData));
174
175 if (SUCCEEDED (rc)) {
176 printf ("Getting extra data key {%ls} again...\n", extraDataKey.raw());
177 CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
178 if (!extraData.isEmpty()) {
179 printf ("Extra data value: {%ls}\n", extraData.raw());
180 } else {
181 if (extraData.isNull())
182 printf ("No extra data exists\n");
183 else
184 printf ("Extra data is empty\n");
185 }
186 }
187
188 return rc;
189}
190
191// main
192///////////////////////////////////////////////////////////////////////////////
193
194int main(int argc, char *argv[])
195{
196 /*
197 * Initialize the VBox runtime without loading
198 * the support driver.
199 */
200 RTR3Init(false);
201
202 HRESULT rc;
203
204 printf ("Initializing COM...\n");
205
206 CHECK_RC_RET (com::Initialize());
207
208 do
209 {
210 // scopes all the stuff till shutdown
211 ////////////////////////////////////////////////////////////////////////////
212
213 ComPtr <IVirtualBox> virtualBox;
214 ComPtr <ISession> session;
215
216 printf ("Creating VirtualBox object...\n");
217 CHECK_RC (virtualBox.createLocalObject (CLSID_VirtualBox));
218 if (FAILED (rc))
219 {
220 CHECK_ERROR_NOCALL();
221 break;
222 }
223
224 printf ("Creating Session object...\n");
225 CHECK_RC (session.createInprocObject (CLSID_Session));
226 if (FAILED (rc))
227 {
228 CHECK_ERROR_NOCALL();
229 break;
230 }
231
232#if 0
233 // IUnknown identity test
234 ////////////////////////////////////////////////////////////////////////////
235 {
236 ComPtr <IVirtualBox> virtualBox2;
237
238 printf ("Creating one more VirtualBox object...\n");
239 CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox));
240 if (FAILED (rc))
241 {
242 CHECK_ERROR_NOCALL();
243 break;
244 }
245
246 printf ("IVirtualBox(virualBox)=%p IVirtualBox(virualBox2)=%p\n",
247 (IVirtualBox *) virtualBox, (IVirtualBox *) virtualBox2);
248
249 ComPtr <IUnknown> unk (virtualBox);
250 ComPtr <IUnknown> unk2;
251 unk2 = virtualBox2;
252
253 printf ("IUnknown(virualBox)=%p IUnknown(virualBox2)=%p\n",
254 (IUnknown *) unk, (IUnknown *) unk2);
255
256 ComPtr <IVirtualBox> vb = unk;
257 ComPtr <IVirtualBox> vb2 = unk;
258
259 printf ("IVirtualBox(IUnknown(virualBox))=%p IVirtualBox(IUnknown(virualBox2))=%p\n",
260 (IVirtualBox *) vb, (IVirtualBox *) vb2);
261
262 printf ("Will be now released (press Enter)...");
263 getchar();
264 }
265#endif
266
267 // create the event queue
268 // (here it is necessary only to process remaining XPCOM/IPC events
269 // after the session is closed)
270 EventQueue eventQ;
271
272 // some outdated stuff
273 ////////////////////////////////////////////////////////////////////////////
274
275#if 0
276 printf("Getting IHost interface...\n");
277 IHost *host;
278 rc = virtualBox->GetHost(&host);
279 if (SUCCEEDED(rc))
280 {
281 IHostDVDDriveCollection *dvdColl;
282 rc = host->GetHostDVDDrives(&dvdColl);
283 if (SUCCEEDED(rc))
284 {
285 IHostDVDDrive *dvdDrive = NULL;
286 dvdColl->GetNextHostDVDDrive(dvdDrive, &dvdDrive);
287 while (dvdDrive)
288 {
289 BSTR driveName;
290 char *driveNameUtf8;
291 dvdDrive->GetDriveName(&driveName);
292 RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
293 printf("Host DVD drive name: %s\n", driveNameUtf8);
294 RTStrFree(driveNameUtf8);
295 SysFreeString(driveName);
296 IHostDVDDrive *dvdDriveTemp = dvdDrive;
297 dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive);
298 dvdDriveTemp->Release();
299 }
300 dvdColl->Release();
301 } else
302 {
303 printf("Could not get host DVD drive collection\n");
304 }
305
306 IHostFloppyDriveCollection *floppyColl;
307 rc = host->GetHostFloppyDrives(&floppyColl);
308 if (SUCCEEDED(rc))
309 {
310 IHostFloppyDrive *floppyDrive = NULL;
311 floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive);
312 while (floppyDrive)
313 {
314 BSTR driveName;
315 char *driveNameUtf8;
316 floppyDrive->GetDriveName(&driveName);
317 RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
318 printf("Host floppy drive name: %s\n", driveNameUtf8);
319 RTStrFree(driveNameUtf8);
320 SysFreeString(driveName);
321 IHostFloppyDrive *floppyDriveTemp = floppyDrive;
322 floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive);
323 floppyDriveTemp->Release();
324 }
325 floppyColl->Release();
326 } else
327 {
328 printf("Could not get host floppy drive collection\n");
329 }
330 host->Release();
331 } else
332 {
333 printf("Call failed\n");
334 }
335 printf ("\n");
336#endif
337
338#if 0
339 // IVirtualBoxErrorInfo test
340 ////////////////////////////////////////////////////////////////////////////
341 {
342 // RPC calls
343
344 // call a method that will definitely fail
345 Guid uuid;
346 ComPtr <IHardDisk> hardDisk;
347 rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
348 printf ("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc);
349
350// {
351// com::ErrorInfo info (virtualBox);
352// PRINT_ERROR_INFO (info);
353// }
354
355 // call a method that will definitely succeed
356 Bstr version;
357 rc = virtualBox->COMGETTER(Version) (version.asOutParam());
358 printf ("virtualBox->COMGETTER(Version)=%08X\n", rc);
359
360 {
361 com::ErrorInfo info (virtualBox);
362 PRINT_ERROR_INFO (info);
363 }
364
365 // Local calls
366
367 // call a method that will definitely fail
368 ComPtr <IMachine> machine;
369 rc = session->COMGETTER(Machine)(machine.asOutParam());
370 printf ("session->COMGETTER(Machine)=%08X\n", rc);
371
372// {
373// com::ErrorInfo info (virtualBox);
374// PRINT_ERROR_INFO (info);
375// }
376
377 // call a method that will definitely succeed
378 SessionState_T state;
379 rc = session->COMGETTER(State) (&state);
380 printf ("session->COMGETTER(State)=%08X\n", rc);
381
382 {
383 com::ErrorInfo info (virtualBox);
384 PRINT_ERROR_INFO (info);
385 }
386 }
387#endif
388
389#if 0
390 // register the existing hard disk image
391 ///////////////////////////////////////////////////////////////////////////
392 do
393 {
394 ComPtr <IHardDisk> hd;
395 Bstr src = L"E:\\develop\\innotek\\images\\NewHardDisk.vdi";
396 printf ("Registerin the existing hard disk '%ls'...\n", src.raw());
397 CHECK_ERROR_BREAK (virtualBox, OpenHardDisk (src, hd.asOutParam()));
398 CHECK_ERROR_BREAK (virtualBox, RegisterHardDisk (hd));
399 }
400 while (FALSE);
401 printf ("\n");
402#endif
403
404#if 0
405 // find and unregister the existing hard disk image
406 ///////////////////////////////////////////////////////////////////////////
407 do
408 {
409 ComPtr <IVirtualDiskImage> vdi;
410 Bstr src = L"CreatorTest.vdi";
411 printf ("Unregistering the hard disk '%ls'...\n", src.raw());
412 CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
413 ComPtr <IHardDisk> hd = vdi;
414 Guid id;
415 CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam()));
416 CHECK_ERROR_BREAK (virtualBox, UnregisterHardDisk (id, hd.asOutParam()));
417 }
418 while (FALSE);
419 printf ("\n");
420#endif
421
422#if 0
423 // clone the registered hard disk
424 ///////////////////////////////////////////////////////////////////////////
425 do
426 {
427#if defined __LINUX__
428 Bstr src = L"/mnt/hugaida/common/develop/innotek/images/freedos-linux.vdi";
429#else
430 Bstr src = L"E:/develop/innotek/images/freedos.vdi";
431#endif
432 Bstr dst = L"./clone.vdi";
433 RTPrintf ("Cloning '%ls' to '%ls'...\n", src.raw(), dst.raw());
434 ComPtr <IVirtualDiskImage> vdi;
435 CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
436 ComPtr <IHardDisk> hd = vdi;
437 ComPtr <IProgress> progress;
438 CHECK_ERROR_BREAK (hd, CloneToImage (dst, vdi.asOutParam(), progress.asOutParam()));
439 RTPrintf ("Waiting for completion...\n");
440 CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
441 ProgressErrorInfo ei (progress);
442 if (FAILED (ei.getResultCode()))
443 {
444 PRINT_ERROR_INFO (ei);
445 }
446 else
447 {
448 vdi->COMGETTER(FilePath) (dst.asOutParam());
449 RTPrintf ("Actual clone path is '%ls'\n", dst.raw());
450 }
451 }
452 while (FALSE);
453 printf ("\n");
454#endif
455
456#if 1
457 // find a registered hard disk by location
458 ///////////////////////////////////////////////////////////////////////////
459 do
460 {
461 ComPtr <IHardDisk> hd;
462 static const wchar_t *Names[] =
463 {
464#ifndef __LINUX__
465 L"E:/Develop/innotek/images/thinker/freedos.vdi",
466 L"E:/Develop/innotek/images/thinker/fReeDoS.vDI",
467 L"E:/Develop/innotek/images/vmdk/haiku.vmdk",
468#else
469 L"/mnt/host/common/Develop/innotek/images/maggot/freedos.vdi",
470 L"/mnt/host/common/Develop/innotek/images/maggot/fReeDoS.vDI",
471#endif
472 };
473 for (size_t i = 0; i < ELEMENTS (Names); ++ i)
474 {
475 Bstr src = Names [i];
476 printf ("Searching for hard disk '%ls'...\n", src.raw());
477 rc = virtualBox->FindHardDisk (src, hd.asOutParam());
478 if (SUCCEEDED (rc))
479 {
480 Guid id;
481 Bstr location;
482 CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam()));
483 CHECK_ERROR_BREAK (hd, COMGETTER(Location) (location.asOutParam()));
484 printf ("Found, UUID={%Vuuid}, location='%ls'.\n",
485 id.raw(), location.raw());
486 }
487 else
488 {
489 PRINT_ERROR_INFO (com::ErrorInfo (virtualBox));
490 }
491 }
492 }
493 while (FALSE);
494 printf ("\n");
495#endif
496
497#if 0
498 // access the machine in read-only mode
499 ///////////////////////////////////////////////////////////////////////////
500 do
501 {
502 ComPtr <IMachine> machine;
503 Bstr name = "Windows XP";
504 printf ("Getting a machine object named '%ls'...\n", name.raw());
505 CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
506// printf ("Accessing the machine in read-only mode:\n");
507// readAndChangeMachineSettings (machine);
508// if (argc != 2)
509// {
510// printf("Error: a string has to be supplied!\n");
511// }
512// else
513// {
514// Bstr secureLabel = argv[1];
515// machine->COMSETTER(ExtraData)(L"VBoxSDL/SecureLabel", secureLabel);
516// }
517 }
518 while (FALSE);
519 printf ("\n");
520#endif
521
522#if 0
523 // create a new machine (w/o registering it)
524 ///////////////////////////////////////////////////////////////////////////
525 do
526 {
527 ComPtr <IMachine> machine;
528#if defined (__LINUX__)
529 Bstr baseDir = L"/tmp/vbox";
530#else
531 Bstr baseDir = L"C:\\vbox";
532#endif
533 Bstr name = L"machina";
534
535 printf ("Creating a new machine object (base dir '%ls', name '%ls')...\n",
536 baseDir.raw(), name.raw());
537 CHECK_ERROR_BREAK (virtualBox, CreateMachine (baseDir, name,
538 machine.asOutParam()));
539
540 printf ("Getting name...\n");
541 CHECK_ERROR_BREAK (machine, COMGETTER(Name) (name.asOutParam()));
542 printf ("Name: {%ls}\n", name.raw());
543
544 BOOL modified = FALSE;
545 printf ("Are any settings modified?...\n");
546 CHECK_ERROR_BREAK (machine, COMGETTER(SettingsModified) (&modified));
547 printf ("%s\n", modified ? "yes" : "no");
548
549 ASSERT_BREAK (modified == TRUE);
550
551 name = L"Kakaya prekrasnaya virtual'naya mashina!";
552 printf ("Setting new name ({%ls})...\n", name.raw());
553 CHECK_ERROR_BREAK (machine, COMSETTER(Name) (name));
554
555 printf ("Setting memory size to 111...\n");
556 CHECK_ERROR_BREAK (machine, COMSETTER(MemorySize) (111));
557
558 Bstr desc = L"This is an exemplary description.";
559 printf ("Setting description to \"%ls\"...\n", desc.raw());
560 CHECK_ERROR_BREAK (machine, COMSETTER(Description) (desc));
561
562 ComPtr <IGuestOSType> guestOSType;
563 Bstr type = L"os2warp45";
564 CHECK_ERROR_BREAK (virtualBox, GetGuestOSType (type, guestOSType.asOutParam()));
565
566 printf ("Saving new machine settings...\n");
567 CHECK_ERROR_BREAK (machine, SaveSettings());
568
569 printf ("Accessing the newly created machine:\n");
570 readAndChangeMachineSettings (machine);
571 }
572 while (FALSE);
573 printf ("\n");
574#endif
575
576#if 0
577 // enumerate host DVD drives
578 ///////////////////////////////////////////////////////////////////////////
579 do
580 {
581 ComPtr <IHost> host;
582 CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam()));
583
584 {
585 ComPtr <IHostDVDDriveCollection> coll;
586 CHECK_RC_BREAK (host->COMGETTER(DVDDrives) (coll.asOutParam()));
587 ComPtr <IHostDVDDriveEnumerator> enumerator;
588 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
589 BOOL hasmore;
590 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
591 {
592 ComPtr <IHostDVDDrive> drive;
593 CHECK_RC_BREAK (enumerator->GetNext (drive.asOutParam()));
594 Bstr name;
595 CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
596 printf ("Host DVD drive: name={%ls}\n", name.raw());
597 }
598 CHECK_RC_BREAK (rc);
599
600 ComPtr <IHostDVDDrive> drive;
601 CHECK_ERROR (enumerator, GetNext (drive.asOutParam()));
602 CHECK_ERROR (coll, GetItemAt (1000, drive.asOutParam()));
603 CHECK_ERROR (coll, FindByName (Bstr ("R:"), drive.asOutParam()));
604 if (SUCCEEDED (rc))
605 {
606 Bstr name;
607 CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
608 printf ("Found by name: name={%ls}\n", name.raw());
609 }
610 }
611 }
612 while (FALSE);
613 printf ("\n");
614#endif
615
616#if 0
617 // enumerate hard disks & dvd images
618 ///////////////////////////////////////////////////////////////////////////
619 do
620 {
621 {
622 ComPtr <IHardDiskCollection> coll;
623 CHECK_RC_BREAK (virtualBox->COMGETTER(HardDisks) (coll.asOutParam()));
624 ComPtr <IHardDiskEnumerator> enumerator;
625 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
626 BOOL hasmore;
627 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
628 {
629 ComPtr <IHardDisk> disk;
630 CHECK_RC_BREAK (enumerator->GetNext (disk.asOutParam()));
631 Guid id;
632 CHECK_RC_BREAK (disk->COMGETTER(Id) (id.asOutParam()));
633 Bstr path;
634 CHECK_RC_BREAK (disk->COMGETTER(FilePath) (path.asOutParam()));
635 printf ("Hard Disk: id={%s}, path={%ls}\n",
636 id.toString().raw(), path.raw());
637 Guid mid;
638 CHECK_RC_BREAK (
639 virtualBox->GetHardDiskUsage (id, ResourceUsage_AllUsage,
640 mid.asOutParam())
641 );
642 if (mid.isEmpty())
643 printf (" not used\n");
644 else
645 printf (" used by VM: {%s}\n", mid.toString().raw());
646 }
647 CHECK_RC_BREAK (rc);
648 }
649
650 {
651 ComPtr <IDVDImageCollection> coll;
652 CHECK_RC_BREAK (virtualBox->COMGETTER(DVDImages) (coll.asOutParam()));
653 ComPtr <IDVDImageEnumerator> enumerator;
654 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
655 BOOL hasmore;
656 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
657 {
658 ComPtr <IDVDImage> image;
659 CHECK_RC_BREAK (enumerator->GetNext (image.asOutParam()));
660 Guid id;
661 CHECK_RC_BREAK (image->COMGETTER(Id) (id.asOutParam()));
662 Bstr path;
663 CHECK_RC_BREAK (image->COMGETTER(FilePath) (path.asOutParam()));
664 printf ("CD/DVD Image: id={%s}, path={%ls}\n",
665 id.toString().raw(), path.raw());
666 Bstr mIDs;
667 CHECK_RC_BREAK (
668 virtualBox->GetDVDImageUsage (id, ResourceUsage_AllUsage,
669 mIDs.asOutParam())
670 );
671 if (mIDs.isNull())
672 printf (" not used\n");
673 else
674 printf (" used by VMs: {%ls}\n", mIDs.raw());
675 }
676 CHECK_RC_BREAK (rc);
677 }
678 }
679 while (FALSE);
680 printf ("\n");
681#endif
682
683#if 0
684 // open a (direct) session
685 ///////////////////////////////////////////////////////////////////////////
686 do
687 {
688 ComPtr <IMachine> machine;
689 Bstr name = L"dos";
690 printf ("Getting a machine object named '%ls'...\n", name.raw());
691 CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
692 Guid guid;
693 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
694 printf ("Opening a session for this machine...\n");
695 CHECK_RC_BREAK (virtualBox->OpenSession (session, guid));
696#if 0
697 ComPtr <IMachine> sessionMachine;
698 printf ("Getting sessioned machine object...\n");
699 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
700 printf ("Accessing the machine within the session:\n");
701 readAndChangeMachineSettings (sessionMachine, machine);
702#endif
703#if 0
704 ComPtr <IConsole> console;
705 printf ("Getting the console object...\n");
706 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
707 printf ("Discarding the current machine state...\n");
708 ComPtr <IProgress> progress;
709 CHECK_ERROR_BREAK (console, DiscardCurrentState (progress.asOutParam()));
710 printf ("Waiting for completion...\n");
711 CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
712 ProgressErrorInfo ei (progress);
713 if (FAILED (ei.getResultCode()))
714 {
715 PRINT_ERROR_INFO (ei);
716
717 ComPtr <IUnknown> initiator;
718 CHECK_ERROR_BREAK (progress, COMGETTER(Initiator) (initiator.asOutParam()));
719
720 printf ("initiator(unk) = %p\n", (IUnknown *) initiator);
721 printf ("console(unk) = %p\n", (IUnknown *) ComPtr <IUnknown> ((IConsole *) console));
722 printf ("console = %p\n", (IConsole *) console);
723 }
724#endif
725 session->Close();
726 }
727 while (FALSE);
728 printf ("\n");
729#endif
730
731#if 0
732 // open a remote session
733 ///////////////////////////////////////////////////////////////////////////
734 do
735 {
736 ComPtr <IMachine> machine;
737 Bstr name = L"dos";
738 printf ("Getting a machine object named '%ls'...\n", name.raw());
739 CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
740 Guid guid;
741 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
742 printf ("Opening a remote session for this machine...\n");
743 ComPtr <IProgress> progress;
744 CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("gui"),
745 progress.asOutParam()));
746 printf ("Waiting for the session to open...\n");
747 CHECK_RC_BREAK (progress->WaitForCompletion (-1));
748 ComPtr <IMachine> sessionMachine;
749 printf ("Getting sessioned machine object...\n");
750 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
751 ComPtr <IConsole> console;
752 printf ("Getting console object...\n");
753 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
754 printf ("Press enter to pause the VM execution in the remote session...");
755 getchar();
756 CHECK_RC (console->Pause());
757 printf ("Press enter to close this session...");
758 getchar();
759 session->Close();
760 }
761 while (FALSE);
762 printf ("\n");
763#endif
764
765#if 0
766 // open an existing remote session
767 ///////////////////////////////////////////////////////////////////////////
768 do
769 {
770 ComPtr <IMachine> machine;
771 Bstr name = "dos";
772 printf ("Getting a machine object named '%ls'...\n", name.raw());
773 CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
774 Guid guid;
775 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
776 printf ("Opening an existing remote session for this machine...\n");
777 CHECK_RC_BREAK (virtualBox->OpenExistingSession (session, guid));
778 ComPtr <IMachine> sessionMachine;
779 printf ("Getting sessioned machine object...\n");
780 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
781
782#if 0
783 Bstr extraDataKey = "VBoxSDL/SecureLabel";
784 Bstr extraData = "Das kommt jetzt noch viel krasser vom total konkreten API!";
785 CHECK_RC (sessionMachine->SetExtraData (extraDataKey, extraData));
786#endif
787#if 0
788 ComPtr <IConsole> console;
789 printf ("Getting console object...\n");
790 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
791 printf ("Press enter to pause the VM execution in the remote session...");
792 getchar();
793 CHECK_RC (console->Pause());
794 printf ("Press enter to close this session...");
795 getchar();
796#endif
797 session->Close();
798 }
799 while (FALSE);
800 printf ("\n");
801#endif
802
803 printf ("Press enter to release Session and VirtualBox instances...");
804 getchar();
805
806 // end "all-stuff" scope
807 ////////////////////////////////////////////////////////////////////////////
808 }
809 while (0);
810
811 printf("Press enter to shutdown COM...");
812 getchar();
813
814 com::Shutdown();
815
816 printf ("tstAPI FINISHED.\n");
817
818 return rc;
819}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette