VirtualBox

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

Last change on this file since 1507 was 1471, checked in by vboxsync, 18 years ago

Main: XPCOM: Initial implementation of auto-startable "out-of-proc" VirtualBox component (VBoxSVC).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.5 KB
Line 
1/** @file
2 *
3 * tstAPI - test program for our COM/XPCOM interface
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 0
457 // access the machine in read-only mode
458 ///////////////////////////////////////////////////////////////////////////
459 do
460 {
461 ComPtr <IMachine> machine;
462 Bstr name = "Windows XP";
463 printf ("Getting a machine object named '%ls'...\n", name.raw());
464 CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
465// printf ("Accessing the machine in read-only mode:\n");
466// readAndChangeMachineSettings (machine);
467// if (argc != 2)
468// {
469// printf("Error: a string has to be supplied!\n");
470// }
471// else
472// {
473// Bstr secureLabel = argv[1];
474// machine->COMSETTER(ExtraData)(L"VBoxSDL/SecureLabel", secureLabel);
475// }
476 }
477 while (FALSE);
478 printf ("\n");
479#endif
480
481#if 0
482 // create a new machine (w/o registering it)
483 ///////////////////////////////////////////////////////////////////////////
484 do
485 {
486 ComPtr <IMachine> machine;
487#if defined (__LINUX__)
488 Bstr baseDir = L"/tmp/vbox";
489#else
490 Bstr baseDir = L"C:\\vbox";
491#endif
492 Bstr name = L"machina";
493
494 printf ("Creating a new machine object (base dir '%ls', name '%ls')...\n",
495 baseDir.raw(), name.raw());
496 CHECK_ERROR_BREAK (virtualBox, CreateMachine (baseDir, name,
497 machine.asOutParam()));
498
499 printf ("Getting name...\n");
500 CHECK_ERROR_BREAK (machine, COMGETTER(Name) (name.asOutParam()));
501 printf ("Name: {%ls}\n", name.raw());
502
503 BOOL modified = FALSE;
504 printf ("Are any settings modified?...\n");
505 CHECK_ERROR_BREAK (machine, COMGETTER(SettingsModified) (&modified));
506 printf ("%s\n", modified ? "yes" : "no");
507
508 ASSERT_BREAK (modified == TRUE);
509
510 name = L"Kakaya prekrasnaya virtual'naya mashina!";
511 printf ("Setting new name ({%ls})...\n", name.raw());
512 CHECK_ERROR_BREAK (machine, COMSETTER(Name) (name));
513
514 printf ("Setting memory size to 111...\n");
515 CHECK_ERROR_BREAK (machine, COMSETTER(MemorySize) (111));
516
517 Bstr desc = L"This is an exemplary description.";
518 printf ("Setting description to \"%ls\"...\n", desc.raw());
519 CHECK_ERROR_BREAK (machine, COMSETTER(Description) (desc));
520
521 ComPtr <IGuestOSType> guestOSType;
522 Bstr type = L"os2warp45";
523 CHECK_ERROR_BREAK (virtualBox, FindGuestOSType (type, guestOSType.asOutParam()));
524
525 printf ("Saving new machine settings...\n");
526 CHECK_ERROR_BREAK (machine, SaveSettings());
527
528 printf ("Accessing the newly created machine:\n");
529 readAndChangeMachineSettings (machine);
530 }
531 while (FALSE);
532 printf ("\n");
533#endif
534
535#if 0
536 // enumerate host DVD drives
537 ///////////////////////////////////////////////////////////////////////////
538 do
539 {
540 ComPtr <IHost> host;
541 CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam()));
542
543 {
544 ComPtr <IHostDVDDriveCollection> coll;
545 CHECK_RC_BREAK (host->COMGETTER(DVDDrives) (coll.asOutParam()));
546 ComPtr <IHostDVDDriveEnumerator> enumerator;
547 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
548 BOOL hasmore;
549 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
550 {
551 ComPtr <IHostDVDDrive> drive;
552 CHECK_RC_BREAK (enumerator->GetNext (drive.asOutParam()));
553 Bstr name;
554 CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
555 printf ("Host DVD drive: name={%ls}\n", name.raw());
556 }
557 CHECK_RC_BREAK (rc);
558
559 ComPtr <IHostDVDDrive> drive;
560 CHECK_ERROR (enumerator, GetNext (drive.asOutParam()));
561 CHECK_ERROR (coll, GetItemAt (1000, drive.asOutParam()));
562 CHECK_ERROR (coll, FindByName (Bstr ("R:"), drive.asOutParam()));
563 if (SUCCEEDED (rc))
564 {
565 Bstr name;
566 CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
567 printf ("Found by name: name={%ls}\n", name.raw());
568 }
569 }
570 }
571 while (FALSE);
572 printf ("\n");
573#endif
574
575#if 0
576 // enumerate hard disks & dvd images
577 ///////////////////////////////////////////////////////////////////////////
578 do
579 {
580 {
581 ComPtr <IHardDiskCollection> coll;
582 CHECK_RC_BREAK (virtualBox->COMGETTER(HardDisks) (coll.asOutParam()));
583 ComPtr <IHardDiskEnumerator> enumerator;
584 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
585 BOOL hasmore;
586 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
587 {
588 ComPtr <IHardDisk> disk;
589 CHECK_RC_BREAK (enumerator->GetNext (disk.asOutParam()));
590 Guid id;
591 CHECK_RC_BREAK (disk->COMGETTER(Id) (id.asOutParam()));
592 Bstr path;
593 CHECK_RC_BREAK (disk->COMGETTER(FilePath) (path.asOutParam()));
594 printf ("Hard Disk: id={%s}, path={%ls}\n",
595 id.toString().raw(), path.raw());
596 Guid mid;
597 CHECK_RC_BREAK (
598 virtualBox->GetHardDiskUsage (id, ResourceUsage_AllUsage,
599 mid.asOutParam())
600 );
601 if (mid.isEmpty())
602 printf (" not used\n");
603 else
604 printf (" used by VM: {%s}\n", mid.toString().raw());
605 }
606 CHECK_RC_BREAK (rc);
607 }
608
609 {
610 ComPtr <IDVDImageCollection> coll;
611 CHECK_RC_BREAK (virtualBox->COMGETTER(DVDImages) (coll.asOutParam()));
612 ComPtr <IDVDImageEnumerator> enumerator;
613 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
614 BOOL hasmore;
615 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
616 {
617 ComPtr <IDVDImage> image;
618 CHECK_RC_BREAK (enumerator->GetNext (image.asOutParam()));
619 Guid id;
620 CHECK_RC_BREAK (image->COMGETTER(Id) (id.asOutParam()));
621 Bstr path;
622 CHECK_RC_BREAK (image->COMGETTER(FilePath) (path.asOutParam()));
623 printf ("CD/DVD Image: id={%s}, path={%ls}\n",
624 id.toString().raw(), path.raw());
625 Bstr mIDs;
626 CHECK_RC_BREAK (
627 virtualBox->GetDVDImageUsage (id, ResourceUsage_AllUsage,
628 mIDs.asOutParam())
629 );
630 if (mIDs.isNull())
631 printf (" not used\n");
632 else
633 printf (" used by VMs: {%ls}\n", mIDs.raw());
634 }
635 CHECK_RC_BREAK (rc);
636 }
637 }
638 while (FALSE);
639 printf ("\n");
640#endif
641
642#if 0
643 // open a (direct) session
644 ///////////////////////////////////////////////////////////////////////////
645 do
646 {
647 ComPtr <IMachine> machine;
648 Bstr name = L"dos";
649 printf ("Getting a machine object named '%ls'...\n", name.raw());
650 CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
651 Guid guid;
652 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
653 printf ("Opening a session for this machine...\n");
654 CHECK_RC_BREAK (virtualBox->OpenSession (session, guid));
655#if 0
656 ComPtr <IMachine> sessionMachine;
657 printf ("Getting sessioned machine object...\n");
658 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
659 printf ("Accessing the machine within the session:\n");
660 readAndChangeMachineSettings (sessionMachine, machine);
661#endif
662#if 0
663 ComPtr <IConsole> console;
664 printf ("Getting the console object...\n");
665 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
666 printf ("Discarding the current machine state...\n");
667 ComPtr <IProgress> progress;
668 CHECK_ERROR_BREAK (console, DiscardCurrentState (progress.asOutParam()));
669 printf ("Waiting for completion...\n");
670 CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
671 ProgressErrorInfo ei (progress);
672 if (FAILED (ei.getResultCode()))
673 {
674 PRINT_ERROR_INFO (ei);
675
676 ComPtr <IUnknown> initiator;
677 CHECK_ERROR_BREAK (progress, COMGETTER(Initiator) (initiator.asOutParam()));
678
679 printf ("initiator(unk) = %p\n", (IUnknown *) initiator);
680 printf ("console(unk) = %p\n", (IUnknown *) ComPtr <IUnknown> ((IConsole *) console));
681 printf ("console = %p\n", (IConsole *) console);
682 }
683#endif
684 session->Close();
685 }
686 while (FALSE);
687 printf ("\n");
688#endif
689
690#if 0
691 // open a remote session
692 ///////////////////////////////////////////////////////////////////////////
693 do
694 {
695 ComPtr <IMachine> machine;
696 Bstr name = L"dos";
697 printf ("Getting a machine object named '%ls'...\n", name.raw());
698 CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
699 Guid guid;
700 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
701 printf ("Opening a remote session for this machine...\n");
702 ComPtr <IProgress> progress;
703 CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("gui"),
704 progress.asOutParam()));
705 printf ("Waiting for the session to open...\n");
706 CHECK_RC_BREAK (progress->WaitForCompletion (-1));
707 ComPtr <IMachine> sessionMachine;
708 printf ("Getting sessioned machine object...\n");
709 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
710 ComPtr <IConsole> console;
711 printf ("Getting console object...\n");
712 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
713 printf ("Press enter to pause the VM execution in the remote session...");
714 getchar();
715 CHECK_RC (console->Pause());
716 printf ("Press enter to close this session...");
717 getchar();
718 session->Close();
719 }
720 while (FALSE);
721 printf ("\n");
722#endif
723
724#if 0
725 // open an existing remote session
726 ///////////////////////////////////////////////////////////////////////////
727 do
728 {
729 ComPtr <IMachine> machine;
730 Bstr name = "dos";
731 printf ("Getting a machine object named '%ls'...\n", name.raw());
732 CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
733 Guid guid;
734 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
735 printf ("Opening an existing remote session for this machine...\n");
736 CHECK_RC_BREAK (virtualBox->OpenExistingSession (session, guid));
737 ComPtr <IMachine> sessionMachine;
738 printf ("Getting sessioned machine object...\n");
739 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
740
741#if 0
742 Bstr extraDataKey = "VBoxSDL/SecureLabel";
743 Bstr extraData = "Das kommt jetzt noch viel krasser vom total konkreten API!";
744 CHECK_RC (sessionMachine->SetExtraData (extraDataKey, extraData));
745#endif
746#if 0
747 ComPtr <IConsole> console;
748 printf ("Getting console object...\n");
749 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
750 printf ("Press enter to pause the VM execution in the remote session...");
751 getchar();
752 CHECK_RC (console->Pause());
753 printf ("Press enter to close this session...");
754 getchar();
755#endif
756 session->Close();
757 }
758 while (FALSE);
759 printf ("\n");
760#endif
761
762 printf ("Press enter to release Session and VirtualBox instances...");
763 getchar();
764
765 // end "all-stuff" scope
766 ////////////////////////////////////////////////////////////////////////////
767 }
768 while (0);
769
770 printf("Press enter to shutdown COM...");
771 getchar();
772
773 com::Shutdown();
774
775 printf ("tstAPI FINISHED.\n");
776
777 return rc;
778}
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