VirtualBox

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

Last change on this file since 1313 was 1128, checked in by vboxsync, 18 years ago

Main/CFGLDR: Fixed: Don't delete DOM objects with |delete| but always use |release()| instead.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.6 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 "VirtualBoxServer"));
219 if (FAILED (rc))
220 {
221 CHECK_ERROR_NOCALL();
222 break;
223 }
224
225 printf ("Creating Session object...\n");
226 CHECK_RC (session.createInprocObject (CLSID_Session));
227 if (FAILED (rc))
228 {
229 CHECK_ERROR_NOCALL();
230 break;
231 }
232
233#if 0
234 // IUnknown identity test
235 ////////////////////////////////////////////////////////////////////////////
236 {
237 ComPtr <IVirtualBox> virtualBox2;
238
239 printf ("Creating one more VirtualBox object...\n");
240 CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox,
241 "VirtualBoxServer"));
242 if (FAILED (rc))
243 {
244 CHECK_ERROR_NOCALL();
245 break;
246 }
247
248 printf ("IVirtualBox(virualBox)=%p IVirtualBox(virualBox2)=%p\n",
249 (IVirtualBox *) virtualBox, (IVirtualBox *) virtualBox2);
250
251 ComPtr <IUnknown> unk (virtualBox);
252 ComPtr <IUnknown> unk2;
253 unk2 = virtualBox2;
254
255 printf ("IUnknown(virualBox)=%p IUnknown(virualBox2)=%p\n",
256 (IUnknown *) unk, (IUnknown *) unk2);
257
258 ComPtr <IVirtualBox> vb = unk;
259 ComPtr <IVirtualBox> vb2 = unk;
260
261 printf ("IVirtualBox(IUnknown(virualBox))=%p IVirtualBox(IUnknown(virualBox2))=%p\n",
262 (IVirtualBox *) vb, (IVirtualBox *) vb2);
263
264 printf ("Will be now released (press Enter)...");
265 getchar();
266 }
267#endif
268
269 // create the event queue
270 // (here it is necessary only to process remaining XPCOM/IPC events
271 // after the session is closed)
272 EventQueue eventQ;
273
274 // some outdated stuff
275 ////////////////////////////////////////////////////////////////////////////
276
277#if 0
278 printf("Getting IHost interface...\n");
279 IHost *host;
280 rc = virtualBox->GetHost(&host);
281 if (SUCCEEDED(rc))
282 {
283 IHostDVDDriveCollection *dvdColl;
284 rc = host->GetHostDVDDrives(&dvdColl);
285 if (SUCCEEDED(rc))
286 {
287 IHostDVDDrive *dvdDrive = NULL;
288 dvdColl->GetNextHostDVDDrive(dvdDrive, &dvdDrive);
289 while (dvdDrive)
290 {
291 BSTR driveName;
292 char *driveNameUtf8;
293 dvdDrive->GetDriveName(&driveName);
294 RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
295 printf("Host DVD drive name: %s\n", driveNameUtf8);
296 RTStrFree(driveNameUtf8);
297 SysFreeString(driveName);
298 IHostDVDDrive *dvdDriveTemp = dvdDrive;
299 dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive);
300 dvdDriveTemp->Release();
301 }
302 dvdColl->Release();
303 } else
304 {
305 printf("Could not get host DVD drive collection\n");
306 }
307
308 IHostFloppyDriveCollection *floppyColl;
309 rc = host->GetHostFloppyDrives(&floppyColl);
310 if (SUCCEEDED(rc))
311 {
312 IHostFloppyDrive *floppyDrive = NULL;
313 floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive);
314 while (floppyDrive)
315 {
316 BSTR driveName;
317 char *driveNameUtf8;
318 floppyDrive->GetDriveName(&driveName);
319 RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
320 printf("Host floppy drive name: %s\n", driveNameUtf8);
321 RTStrFree(driveNameUtf8);
322 SysFreeString(driveName);
323 IHostFloppyDrive *floppyDriveTemp = floppyDrive;
324 floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive);
325 floppyDriveTemp->Release();
326 }
327 floppyColl->Release();
328 } else
329 {
330 printf("Could not get host floppy drive collection\n");
331 }
332 host->Release();
333 } else
334 {
335 printf("Call failed\n");
336 }
337 printf ("\n");
338#endif
339
340#if 0
341 // IVirtualBoxErrorInfo test
342 ////////////////////////////////////////////////////////////////////////////
343 {
344 // RPC calls
345
346 // call a method that will definitely fail
347 Guid uuid;
348 ComPtr <IHardDisk> hardDisk;
349 rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
350 printf ("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc);
351
352// {
353// com::ErrorInfo info (virtualBox);
354// PRINT_ERROR_INFO (info);
355// }
356
357 // call a method that will definitely succeed
358 Bstr version;
359 rc = virtualBox->COMGETTER(Version) (version.asOutParam());
360 printf ("virtualBox->COMGETTER(Version)=%08X\n", rc);
361
362 {
363 com::ErrorInfo info (virtualBox);
364 PRINT_ERROR_INFO (info);
365 }
366
367 // Local calls
368
369 // call a method that will definitely fail
370 ComPtr <IMachine> machine;
371 rc = session->COMGETTER(Machine)(machine.asOutParam());
372 printf ("session->COMGETTER(Machine)=%08X\n", rc);
373
374// {
375// com::ErrorInfo info (virtualBox);
376// PRINT_ERROR_INFO (info);
377// }
378
379 // call a method that will definitely succeed
380 SessionState_T state;
381 rc = session->COMGETTER(State) (&state);
382 printf ("session->COMGETTER(State)=%08X\n", rc);
383
384 {
385 com::ErrorInfo info (virtualBox);
386 PRINT_ERROR_INFO (info);
387 }
388 }
389#endif
390
391#if 0
392 // register the existing hard disk image
393 ///////////////////////////////////////////////////////////////////////////
394 do
395 {
396 ComPtr <IHardDisk> hd;
397 Bstr src = L"E:\\develop\\innotek\\images\\NewHardDisk.vdi";
398 printf ("Registerin the existing hard disk '%ls'...\n", src.raw());
399 CHECK_ERROR_BREAK (virtualBox, OpenHardDisk (src, hd.asOutParam()));
400 CHECK_ERROR_BREAK (virtualBox, RegisterHardDisk (hd));
401 }
402 while (FALSE);
403 printf ("\n");
404#endif
405
406#if 0
407 // find and unregister the existing hard disk image
408 ///////////////////////////////////////////////////////////////////////////
409 do
410 {
411 ComPtr <IVirtualDiskImage> vdi;
412 Bstr src = L"CreatorTest.vdi";
413 printf ("Unregistering the hard disk '%ls'...\n", src.raw());
414 CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
415 ComPtr <IHardDisk> hd = vdi;
416 Guid id;
417 CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam()));
418 CHECK_ERROR_BREAK (virtualBox, UnregisterHardDisk (id, hd.asOutParam()));
419 }
420 while (FALSE);
421 printf ("\n");
422#endif
423
424#if 0
425 // clone the registered hard disk
426 ///////////////////////////////////////////////////////////////////////////
427 do
428 {
429#if defined __LINUX__
430 Bstr src = L"/mnt/hugaida/common/develop/innotek/images/freedos-linux.vdi";
431#else
432 Bstr src = L"E:/develop/innotek/images/freedos.vdi";
433#endif
434 Bstr dst = L"./clone.vdi";
435 RTPrintf ("Cloning '%ls' to '%ls'...\n", src.raw(), dst.raw());
436 ComPtr <IVirtualDiskImage> vdi;
437 CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
438 ComPtr <IHardDisk> hd = vdi;
439 ComPtr <IProgress> progress;
440 CHECK_ERROR_BREAK (hd, CloneToImage (dst, vdi.asOutParam(), progress.asOutParam()));
441 RTPrintf ("Waiting for completion...\n");
442 CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
443 ProgressErrorInfo ei (progress);
444 if (FAILED (ei.getResultCode()))
445 {
446 PRINT_ERROR_INFO (ei);
447 }
448 else
449 {
450 vdi->COMGETTER(FilePath) (dst.asOutParam());
451 RTPrintf ("Actual clone path is '%ls'\n", dst.raw());
452 }
453 }
454 while (FALSE);
455 printf ("\n");
456#endif
457
458#if 0
459 // access the machine in read-only mode
460 ///////////////////////////////////////////////////////////////////////////
461 do
462 {
463 ComPtr <IMachine> machine;
464 Bstr name = "Windows XP";
465 printf ("Getting a machine object named '%ls'...\n", name.raw());
466 CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
467// printf ("Accessing the machine in read-only mode:\n");
468// readAndChangeMachineSettings (machine);
469// if (argc != 2)
470// {
471// printf("Error: a string has to be supplied!\n");
472// }
473// else
474// {
475// Bstr secureLabel = argv[1];
476// machine->COMSETTER(ExtraData)(L"VBoxSDL/SecureLabel", secureLabel);
477// }
478 }
479 while (FALSE);
480 printf ("\n");
481#endif
482
483#if 1
484 // create a new machine (w/o registering it)
485 ///////////////////////////////////////////////////////////////////////////
486 do
487 {
488 ComPtr <IMachine> machine;
489#if defined (__LINUX__)
490 Bstr baseDir = L"/tmp/vbox";
491#else
492 Bstr baseDir = L"C:\\vbox";
493#endif
494 Bstr name = L"machina";
495
496 printf ("Creating a new machine object (base dir '%ls', name '%ls')...\n",
497 baseDir.raw(), name.raw());
498 CHECK_ERROR_BREAK (virtualBox, CreateMachine (baseDir, name,
499 machine.asOutParam()));
500
501 printf ("Getting name...\n");
502 CHECK_ERROR_BREAK (machine, COMGETTER(Name) (name.asOutParam()));
503 printf ("Name: {%ls}\n", name.raw());
504
505 BOOL modified = FALSE;
506 printf ("Are any settings modified?...\n");
507 CHECK_ERROR_BREAK (machine, COMGETTER(SettingsModified) (&modified));
508 printf ("%s\n", modified ? "yes" : "no");
509
510 ASSERT_BREAK (modified == TRUE);
511
512 name = L"Kakaya prekrasnaya virtual'naya mashina!";
513 printf ("Setting new name ({%ls})...\n", name.raw());
514 CHECK_ERROR_BREAK (machine, COMSETTER(Name) (name));
515
516 printf ("Setting memory size to 111...\n");
517 CHECK_ERROR_BREAK (machine, COMSETTER(MemorySize) (111));
518
519 Bstr desc = L"This is an exemplary description.";
520 printf ("Setting description to \"%ls\"...\n", desc.raw());
521 CHECK_ERROR_BREAK (machine, COMSETTER(Description) (desc));
522
523 ComPtr <IGuestOSType> guestOSType;
524 Bstr type = L"os2warp45";
525 CHECK_ERROR_BREAK (virtualBox, FindGuestOSType (type, guestOSType.asOutParam()));
526
527 printf ("Saving new machine settings...\n");
528 CHECK_ERROR_BREAK (machine, SaveSettings());
529
530 printf ("Accessing the newly created machine:\n");
531 readAndChangeMachineSettings (machine);
532 }
533 while (FALSE);
534 printf ("\n");
535#endif
536
537#if 0
538 // enumerate host DVD drives
539 ///////////////////////////////////////////////////////////////////////////
540 do
541 {
542 ComPtr <IHost> host;
543 CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam()));
544
545 {
546 ComPtr <IHostDVDDriveCollection> coll;
547 CHECK_RC_BREAK (host->COMGETTER(DVDDrives) (coll.asOutParam()));
548 ComPtr <IHostDVDDriveEnumerator> enumerator;
549 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
550 BOOL hasmore;
551 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
552 {
553 ComPtr <IHostDVDDrive> drive;
554 CHECK_RC_BREAK (enumerator->GetNext (drive.asOutParam()));
555 Bstr name;
556 CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
557 printf ("Host DVD drive: name={%ls}\n", name.raw());
558 }
559 CHECK_RC_BREAK (rc);
560
561 ComPtr <IHostDVDDrive> drive;
562 CHECK_ERROR (enumerator, GetNext (drive.asOutParam()));
563 CHECK_ERROR (coll, GetItemAt (1000, drive.asOutParam()));
564 CHECK_ERROR (coll, FindByName (Bstr ("R:"), drive.asOutParam()));
565 if (SUCCEEDED (rc))
566 {
567 Bstr name;
568 CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
569 printf ("Found by name: name={%ls}\n", name.raw());
570 }
571 }
572 }
573 while (FALSE);
574 printf ("\n");
575#endif
576
577#if 0
578 // enumerate hard disks & dvd images
579 ///////////////////////////////////////////////////////////////////////////
580 do
581 {
582 {
583 ComPtr <IHardDiskCollection> coll;
584 CHECK_RC_BREAK (virtualBox->COMGETTER(HardDisks) (coll.asOutParam()));
585 ComPtr <IHardDiskEnumerator> enumerator;
586 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
587 BOOL hasmore;
588 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
589 {
590 ComPtr <IHardDisk> disk;
591 CHECK_RC_BREAK (enumerator->GetNext (disk.asOutParam()));
592 Guid id;
593 CHECK_RC_BREAK (disk->COMGETTER(Id) (id.asOutParam()));
594 Bstr path;
595 CHECK_RC_BREAK (disk->COMGETTER(FilePath) (path.asOutParam()));
596 printf ("Hard Disk: id={%s}, path={%ls}\n",
597 id.toString().raw(), path.raw());
598 Guid mid;
599 CHECK_RC_BREAK (
600 virtualBox->GetHardDiskUsage (id, ResourceUsage_AllUsage,
601 mid.asOutParam())
602 );
603 if (mid.isEmpty())
604 printf (" not used\n");
605 else
606 printf (" used by VM: {%s}\n", mid.toString().raw());
607 }
608 CHECK_RC_BREAK (rc);
609 }
610
611 {
612 ComPtr <IDVDImageCollection> coll;
613 CHECK_RC_BREAK (virtualBox->COMGETTER(DVDImages) (coll.asOutParam()));
614 ComPtr <IDVDImageEnumerator> enumerator;
615 CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
616 BOOL hasmore;
617 while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
618 {
619 ComPtr <IDVDImage> image;
620 CHECK_RC_BREAK (enumerator->GetNext (image.asOutParam()));
621 Guid id;
622 CHECK_RC_BREAK (image->COMGETTER(Id) (id.asOutParam()));
623 Bstr path;
624 CHECK_RC_BREAK (image->COMGETTER(FilePath) (path.asOutParam()));
625 printf ("CD/DVD Image: id={%s}, path={%ls}\n",
626 id.toString().raw(), path.raw());
627 Bstr mIDs;
628 CHECK_RC_BREAK (
629 virtualBox->GetDVDImageUsage (id, ResourceUsage_AllUsage,
630 mIDs.asOutParam())
631 );
632 if (mIDs.isNull())
633 printf (" not used\n");
634 else
635 printf (" used by VMs: {%ls}\n", mIDs.raw());
636 }
637 CHECK_RC_BREAK (rc);
638 }
639 }
640 while (FALSE);
641 printf ("\n");
642#endif
643
644#if 0
645 // open a (direct) session
646 ///////////////////////////////////////////////////////////////////////////
647 do
648 {
649 ComPtr <IMachine> machine;
650 Bstr name = L"dos";
651 printf ("Getting a machine object named '%ls'...\n", name.raw());
652 CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
653 Guid guid;
654 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
655 printf ("Opening a session for this machine...\n");
656 CHECK_RC_BREAK (virtualBox->OpenSession (session, guid));
657#if 0
658 ComPtr <IMachine> sessionMachine;
659 printf ("Getting sessioned machine object...\n");
660 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
661 printf ("Accessing the machine within the session:\n");
662 readAndChangeMachineSettings (sessionMachine, machine);
663#endif
664#if 0
665 ComPtr <IConsole> console;
666 printf ("Getting the console object...\n");
667 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
668 printf ("Discarding the current machine state...\n");
669 ComPtr <IProgress> progress;
670 CHECK_ERROR_BREAK (console, DiscardCurrentState (progress.asOutParam()));
671 printf ("Waiting for completion...\n");
672 CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
673 ProgressErrorInfo ei (progress);
674 if (FAILED (ei.getResultCode()))
675 {
676 PRINT_ERROR_INFO (ei);
677
678 ComPtr <IUnknown> initiator;
679 CHECK_ERROR_BREAK (progress, COMGETTER(Initiator) (initiator.asOutParam()));
680
681 printf ("initiator(unk) = %p\n", (IUnknown *) initiator);
682 printf ("console(unk) = %p\n", (IUnknown *) ComPtr <IUnknown> ((IConsole *) console));
683 printf ("console = %p\n", (IConsole *) console);
684 }
685#endif
686 session->Close();
687 }
688 while (FALSE);
689 printf ("\n");
690#endif
691
692#if 0
693 // open a remote session
694 ///////////////////////////////////////////////////////////////////////////
695 do
696 {
697 ComPtr <IMachine> machine;
698 Bstr name = L"dos";
699 printf ("Getting a machine object named '%ls'...\n", name.raw());
700 CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
701 Guid guid;
702 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
703 printf ("Opening a remote session for this machine...\n");
704 ComPtr <IProgress> progress;
705 CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("gui"),
706 progress.asOutParam()));
707 printf ("Waiting for the session to open...\n");
708 CHECK_RC_BREAK (progress->WaitForCompletion (-1));
709 ComPtr <IMachine> sessionMachine;
710 printf ("Getting sessioned machine object...\n");
711 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
712 ComPtr <IConsole> console;
713 printf ("Getting console object...\n");
714 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
715 printf ("Press enter to pause the VM execution in the remote session...");
716 getchar();
717 CHECK_RC (console->Pause());
718 printf ("Press enter to close this session...");
719 getchar();
720 session->Close();
721 }
722 while (FALSE);
723 printf ("\n");
724#endif
725
726#if 0
727 // open an existing remote session
728 ///////////////////////////////////////////////////////////////////////////
729 do
730 {
731 ComPtr <IMachine> machine;
732 Bstr name = "dos";
733 printf ("Getting a machine object named '%ls'...\n", name.raw());
734 CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
735 Guid guid;
736 CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
737 printf ("Opening an existing remote session for this machine...\n");
738 CHECK_RC_BREAK (virtualBox->OpenExistingSession (session, guid));
739 ComPtr <IMachine> sessionMachine;
740 printf ("Getting sessioned machine object...\n");
741 CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
742
743#if 0
744 Bstr extraDataKey = "VBoxSDL/SecureLabel";
745 Bstr extraData = "Das kommt jetzt noch viel krasser vom total konkreten API!";
746 CHECK_RC (sessionMachine->SetExtraData (extraDataKey, extraData));
747#endif
748#if 0
749 ComPtr <IConsole> console;
750 printf ("Getting console object...\n");
751 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
752 printf ("Press enter to pause the VM execution in the remote session...");
753 getchar();
754 CHECK_RC (console->Pause());
755 printf ("Press enter to close this session...");
756 getchar();
757#endif
758 session->Close();
759 }
760 while (FALSE);
761 printf ("\n");
762#endif
763
764 printf ("Press enter to release Session and VirtualBox instances...");
765 getchar();
766
767 // end "all-stuff" scope
768 ////////////////////////////////////////////////////////////////////////////
769 }
770 while (0);
771
772 printf("Press enter to shutdown COM...");
773 getchar();
774
775 com::Shutdown();
776
777 printf ("tstAPI FINISHED.\n");
778
779 return rc;
780}
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