VirtualBox

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

Last change on this file since 684 was 437, checked in by vboxsync, 18 years ago

Main: Fixed compiler warnings.

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