VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 63.9 KB
Line 
1/* $Id: tstAPI.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * tstAPI - test program for our COM/XPCOM interface
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#include <stdio.h>
29#include <stdlib.h>
30
31#include <VBox/com/com.h>
32#include <VBox/com/string.h>
33#include <VBox/com/Guid.h>
34#include <VBox/com/ErrorInfo.h>
35#include <VBox/com/errorprint.h>
36
37#include <VBox/com/VirtualBox.h>
38
39using namespace com;
40
41#define LOG_ENABLED
42#define LOG_GROUP LOG_GROUP_MAIN
43#include <VBox/log.h>
44
45#include <iprt/initterm.h>
46#include <iprt/path.h>
47#include <iprt/param.h>
48#include <iprt/stream.h>
49#include <iprt/thread.h>
50
51
52// forward declarations
53///////////////////////////////////////////////////////////////////////////////
54
55#ifdef VBOX_WITH_RESOURCE_USAGE_API
56static Bstr getObjectName(ComPtr<IVirtualBox> aVirtualBox, ComPtr<IUnknown> aObject);
57static void queryMetrics(ComPtr<IVirtualBox> aVirtualBox,
58 ComPtr<IPerformanceCollector> collector,
59 ComSafeArrayIn(IUnknown *, objects));
60static void listAffectedMetrics(ComPtr<IVirtualBox> aVirtualBox,
61 ComSafeArrayIn(IPerformanceMetric*, aMetrics));
62#endif
63
64// funcs
65///////////////////////////////////////////////////////////////////////////////
66
67HRESULT readAndChangeMachineSettings(IMachine *machine, IMachine *readonlyMachine = 0)
68{
69 HRESULT hrc = S_OK;
70
71 Bstr name;
72 RTPrintf("Getting machine name...\n");
73 CHECK_ERROR_RET(machine, COMGETTER(Name)(name.asOutParam()), hrc);
74 RTPrintf("Name: {%ls}\n", name.raw());
75
76 RTPrintf("Getting machine GUID...\n");
77 Bstr guid;
78 CHECK_ERROR(machine, COMGETTER(Id)(guid.asOutParam()));
79 if (SUCCEEDED(hrc) && !guid.isEmpty()) {
80 RTPrintf("Guid::toString(): {%s}\n", Utf8Str(guid).c_str());
81 } else {
82 RTPrintf("WARNING: there's no GUID!");
83 }
84
85 ULONG memorySize;
86 RTPrintf("Getting memory size...\n");
87 CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySize), hrc);
88 RTPrintf("Memory size: %d\n", memorySize);
89
90 MachineState_T machineState;
91 RTPrintf("Getting machine state...\n");
92 CHECK_ERROR_RET(machine, COMGETTER(State)(&machineState), hrc);
93 RTPrintf("Machine state: %d\n", machineState);
94
95 BOOL modified;
96 RTPrintf("Are any settings modified?...\n");
97 CHECK_ERROR(machine, COMGETTER(SettingsModified)(&modified));
98 if (SUCCEEDED(hrc))
99 RTPrintf("%s\n", modified ? "yes" : "no");
100
101 ULONG memorySizeBig = memorySize * 10;
102 RTPrintf("Changing memory size to %d...\n", memorySizeBig);
103 CHECK_ERROR(machine, COMSETTER(MemorySize)(memorySizeBig));
104
105 if (SUCCEEDED(hrc))
106 {
107 RTPrintf("Are any settings modified now?...\n");
108 CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
109 RTPrintf("%s\n", modified ? "yes" : "no");
110 ASSERT_RET(modified, 0);
111
112 ULONG memorySizeGot;
113 RTPrintf("Getting memory size again...\n");
114 CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySizeGot), hrc);
115 RTPrintf("Memory size: %d\n", memorySizeGot);
116 ASSERT_RET(memorySizeGot == memorySizeBig, 0);
117
118 if (readonlyMachine)
119 {
120 RTPrintf("Getting memory size of the counterpart readonly machine...\n");
121 ULONG memorySizeRO;
122 readonlyMachine->COMGETTER(MemorySize)(&memorySizeRO);
123 RTPrintf("Memory size: %d\n", memorySizeRO);
124 ASSERT_RET(memorySizeRO != memorySizeGot, 0);
125 }
126
127 RTPrintf("Discarding recent changes...\n");
128 CHECK_ERROR_RET(machine, DiscardSettings(), hrc);
129 RTPrintf("Are any settings modified after discarding?...\n");
130 CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
131 RTPrintf("%s\n", modified ? "yes" : "no");
132 ASSERT_RET(!modified, 0);
133
134 RTPrintf("Getting memory size once more...\n");
135 CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySizeGot), hrc);
136 RTPrintf("Memory size: %d\n", memorySizeGot);
137 ASSERT_RET(memorySizeGot == memorySize, 0);
138
139 memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2;
140 RTPrintf("Changing memory size to %d...\n", memorySize);
141 CHECK_ERROR_RET(machine, COMSETTER(MemorySize)(memorySize), hrc);
142 }
143
144 Bstr desc;
145 RTPrintf("Getting description...\n");
146 CHECK_ERROR_RET(machine, COMGETTER(Description)(desc.asOutParam()), hrc);
147 RTPrintf("Description is: \"%ls\"\n", desc.raw());
148
149 desc = L"This is an exemplary description (changed).";
150 RTPrintf("Setting description to \"%ls\"...\n", desc.raw());
151 CHECK_ERROR_RET(machine, COMSETTER(Description)(desc.raw()), hrc);
152
153 RTPrintf("Saving machine settings...\n");
154 CHECK_ERROR(machine, SaveSettings());
155 if (SUCCEEDED(hrc))
156 {
157 RTPrintf("Are any settings modified after saving?...\n");
158 CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
159 RTPrintf("%s\n", modified ? "yes" : "no");
160 ASSERT_RET(!modified, 0);
161
162 if (readonlyMachine) {
163 RTPrintf("Getting memory size of the counterpart readonly machine...\n");
164 ULONG memorySizeRO;
165 readonlyMachine->COMGETTER(MemorySize)(&memorySizeRO);
166 RTPrintf("Memory size: %d\n", memorySizeRO);
167 ASSERT_RET(memorySizeRO == memorySize, 0);
168 }
169 }
170
171 Bstr extraDataKey = L"Blafasel";
172 Bstr extraData;
173 RTPrintf("Getting extra data key {%ls}...\n", extraDataKey.raw());
174 CHECK_ERROR_RET(machine, GetExtraData(extraDataKey.raw(), extraData.asOutParam()), hrc);
175 if (!extraData.isEmpty()) {
176 RTPrintf("Extra data value: {%ls}\n", extraData.raw());
177 } else {
178 RTPrintf("No extra data exists\n");
179 }
180
181 if (extraData.isEmpty())
182 extraData = L"Das ist die Berliner Luft, Luft, Luft...";
183 else
184 extraData.setNull();
185 RTPrintf("Setting extra data key {%ls} to {%ls}...\n",
186 extraDataKey.raw(), extraData.raw());
187 CHECK_ERROR(machine, SetExtraData(extraDataKey.raw(), extraData.raw()));
188
189 if (SUCCEEDED(hrc)) {
190 RTPrintf("Getting extra data key {%ls} again...\n", extraDataKey.raw());
191 CHECK_ERROR_RET(machine, GetExtraData(extraDataKey.raw(), extraData.asOutParam()), hrc);
192 if (!extraData.isEmpty()) {
193 RTPrintf("Extra data value: {%ls}\n", extraData.raw());
194 } else {
195 RTPrintf("No extra data exists\n");
196 }
197 }
198
199 return hrc;
200}
201
202// main
203///////////////////////////////////////////////////////////////////////////////
204
205int main(int argc, char *argv[])
206{
207 /*
208 * Initialize the VBox runtime without loading
209 * the support driver.
210 */
211 RTR3InitExe(argc, &argv, 0);
212
213 HRESULT hrc;
214
215 {
216 char homeDir[RTPATH_MAX];
217 GetVBoxUserHomeDirectory(homeDir, sizeof(homeDir));
218 RTPrintf("VirtualBox Home Directory = '%s'\n", homeDir);
219 }
220
221 RTPrintf("Initializing COM...\n");
222
223 hrc = com::Initialize();
224 if (FAILED(hrc))
225 {
226 RTPrintf("ERROR: failed to initialize COM!\n");
227 return hrc;
228 }
229
230 do
231 {
232 // scopes all the stuff till shutdown
233 ////////////////////////////////////////////////////////////////////////////
234
235 ComPtr<IVirtualBoxClient> virtualBoxClient;
236 ComPtr<IVirtualBox> virtualBox;
237 ComPtr<ISession> session;
238
239#if 0
240 // Utf8Str test
241 ////////////////////////////////////////////////////////////////////////////
242
243 Utf8Str nullUtf8Str;
244 RTPrintf("nullUtf8Str='%s'\n", nullUtf8Str.raw());
245
246 Utf8Str simpleUtf8Str = "simpleUtf8Str";
247 RTPrintf("simpleUtf8Str='%s'\n", simpleUtf8Str.raw());
248
249 Utf8Str utf8StrFmt = Utf8StrFmt("[0=%d]%s[1=%d]", 0, "utf8StrFmt", 1);
250 RTPrintf("utf8StrFmt='%s'\n", utf8StrFmt.raw());
251
252#endif
253
254 RTPrintf("Creating VirtualBox object...\n");
255 hrc = virtualBoxClient.createInprocObject(CLSID_VirtualBoxClient);
256 if (SUCCEEDED(hrc))
257 hrc = virtualBoxClient->COMGETTER(VirtualBox)(virtualBox.asOutParam());
258 if (FAILED(hrc))
259 RTPrintf("ERROR: failed to create the VirtualBox object!\n");
260 else
261 {
262 hrc = session.createInprocObject(CLSID_Session);
263 if (FAILED(hrc))
264 RTPrintf("ERROR: failed to create a session object!\n");
265 }
266
267 if (FAILED(hrc))
268 {
269 com::ErrorInfo info;
270 if (!info.isFullAvailable() && !info.isBasicAvailable())
271 {
272 com::GluePrintRCMessage(hrc);
273 RTPrintf("Most likely, the VirtualBox COM server is not running or failed to start.\n");
274 }
275 else
276 com::GluePrintErrorInfo(info);
277 break;
278 }
279
280#if 0
281 // Testing VirtualBox::COMGETTER(ProgressOperations).
282 // This is designed to be tested while running
283 // "./VBoxManage clonehd src.vdi clone.vdi" in parallel.
284 // It will then display the progress every 2 seconds.
285 ////////////////////////////////////////////////////////////////////////////
286 {
287 RTPrintf("Testing VirtualBox::COMGETTER(ProgressOperations)...\n");
288
289 for (;;) {
290 com::SafeIfaceArray<IProgress> operations;
291
292 CHECK_ERROR_BREAK(virtualBox,
293 COMGETTER(ProgressOperations)(ComSafeArrayAsOutParam(operations)));
294
295 RTPrintf("operations: %d\n", operations.size());
296 if (operations.size() == 0)
297 break; // No more operations left.
298
299 for (size_t i = 0; i < operations.size(); ++i) {
300 PRInt32 percent;
301
302 operations[i]->COMGETTER(Percent)(&percent);
303 RTPrintf("operations[%u]: %ld\n", (unsigned)i, (long)percent);
304 }
305 RTThreadSleep(2000); // msec
306 }
307 }
308#endif
309
310#if 0
311 // IUnknown identity test
312 ////////////////////////////////////////////////////////////////////////////
313 {
314 {
315 ComPtr<IVirtualBox> virtualBox2;
316
317 RTPrintf("Creating one more VirtualBox object...\n");
318 CHECK_RC(virtualBoxClient->COMGETTER(virtualBox2.asOutParam()));
319 if (FAILED(rc))
320 {
321 CHECK_ERROR_NOCALL();
322 break;
323 }
324
325 RTPrintf("IVirtualBox(virtualBox)=%p IVirtualBox(virtualBox2)=%p\n",
326 (IVirtualBox *)virtualBox, (IVirtualBox *)virtualBox2);
327 Assert((IVirtualBox *)virtualBox == (IVirtualBox *)virtualBox2);
328
329 ComPtr<IUnknown> unk(virtualBox);
330 ComPtr<IUnknown> unk2;
331 unk2 = virtualBox2;
332
333 RTPrintf("IUnknown(virtualBox)=%p IUnknown(virtualBox2)=%p\n",
334 (IUnknown *)unk, (IUnknown *)unk2);
335 Assert((IUnknown *)unk == (IUnknown *)unk2);
336
337 ComPtr<IVirtualBox> vb = unk;
338 ComPtr<IVirtualBox> vb2 = unk;
339
340 RTPrintf("IVirtualBox(IUnknown(virtualBox))=%p IVirtualBox(IUnknown(virtualBox2))=%p\n",
341 (IVirtualBox *)vb, (IVirtualBox *)vb2);
342 Assert((IVirtualBox *)vb == (IVirtualBox *)vb2);
343 }
344
345 {
346 ComPtr<IHost> host;
347 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
348 RTPrintf(" IHost(host)=%p\n", (IHost *)host);
349 ComPtr<IUnknown> unk = host;
350 RTPrintf(" IUnknown(host)=%p\n", (IUnknown *)unk);
351 ComPtr<IHost> host_copy = unk;
352 RTPrintf(" IHost(host_copy)=%p\n", (IHost *)host_copy);
353 ComPtr<IUnknown> unk_copy = host_copy;
354 RTPrintf(" IUnknown(host_copy)=%p\n", (IUnknown *)unk_copy);
355 Assert((IUnknown *)unk == (IUnknown *)unk_copy);
356
357 /* query IUnknown on IUnknown */
358 ComPtr<IUnknown> unk_copy_copy;
359 unk_copy.queryInterfaceTo(unk_copy_copy.asOutParam());
360 RTPrintf(" IUnknown(unk_copy)=%p\n", (IUnknown *)unk_copy_copy);
361 Assert((IUnknown *)unk_copy == (IUnknown *)unk_copy_copy);
362 /* query IUnknown on IUnknown in the opposite direction */
363 unk_copy_copy.queryInterfaceTo(unk_copy.asOutParam());
364 RTPrintf(" IUnknown(unk_copy_copy)=%p\n", (IUnknown *)unk_copy);
365 Assert((IUnknown *)unk_copy == (IUnknown *)unk_copy_copy);
366
367 /* query IUnknown again after releasing all previous IUnknown instances
368 * but keeping IHost -- it should remain the same (Identity Rule) */
369 IUnknown *oldUnk = unk;
370 unk.setNull();
371 unk_copy.setNull();
372 unk_copy_copy.setNull();
373 unk = host;
374 RTPrintf(" IUnknown(host)=%p\n", (IUnknown *)unk);
375 Assert(oldUnk == (IUnknown *)unk);
376 }
377
378// RTPrintf("Will be now released (press Enter)...");
379// getchar();
380 }
381#endif
382
383#if 0
384 // the simplest COM API test
385 ////////////////////////////////////////////////////////////////////////////
386 {
387 Bstr version;
388 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Version)(version.asOutParam()));
389 RTPrintf("VirtualBox version = %ls\n", version.raw());
390 }
391#endif
392
393#if 0
394 // Array test
395 ////////////////////////////////////////////////////////////////////////////
396 {
397 RTPrintf("Calling IVirtualBox::Machines...\n");
398
399 com::SafeIfaceArray<IMachine> machines;
400 CHECK_ERROR_BREAK(virtualBox,
401 COMGETTER(Machines)(ComSafeArrayAsOutParam(machines)));
402
403 RTPrintf("%u machines registered (machines.isNull()=%d).\n",
404 machines.size(), machines.isNull());
405
406 for (size_t i = 0; i < machines.size(); ++ i)
407 {
408 Bstr name;
409 CHECK_ERROR_BREAK(machines[i], COMGETTER(Name)(name.asOutParam()));
410 RTPrintf("machines[%u]='%s'\n", i, Utf8Str(name).raw());
411 }
412
413#if 0
414 {
415 RTPrintf("Testing [out] arrays...\n");
416 com::SafeGUIDArray uuids;
417 CHECK_ERROR_BREAK(virtualBox,
418 COMGETTER(Uuids)(ComSafeArrayAsOutParam(uuids)));
419
420 for (size_t i = 0; i < uuids.size(); ++ i)
421 RTPrintf("uuids[%u]=%RTuuid\n", i, &uuids[i]);
422 }
423
424 {
425 RTPrintf("Testing [in] arrays...\n");
426 com::SafeGUIDArray uuids(5);
427 for (size_t i = 0; i < uuids.size(); ++ i)
428 {
429 Guid id;
430 id.create();
431 uuids[i] = id;
432 RTPrintf("uuids[%u]=%RTuuid\n", i, &uuids[i]);
433 }
434
435 CHECK_ERROR_BREAK(virtualBox,
436 SetUuids(ComSafeArrayAsInParam(uuids)));
437 }
438#endif
439
440 }
441#endif
442
443#if 0
444 // some outdated stuff
445 ////////////////////////////////////////////////////////////////////////////
446
447 RTPrintf("Getting IHost interface...\n");
448 IHost *host;
449 rc = virtualBox->GetHost(&host);
450 if (SUCCEEDED(rc))
451 {
452 IHostDVDDriveCollection *dvdColl;
453 rc = host->GetHostDVDDrives(&dvdColl);
454 if (SUCCEEDED(rc))
455 {
456 IHostDVDDrive *dvdDrive = NULL;
457 dvdColl->GetNextHostDVDDrive(dvdDrive, &dvdDrive);
458 while (dvdDrive)
459 {
460 BSTR driveName;
461 char *driveNameUtf8;
462 dvdDrive->GetDriveName(&driveName);
463 RTUtf16ToUtf8((PCRTUTF16)driveName, &driveNameUtf8);
464 RTPrintf("Host DVD drive name: %s\n", driveNameUtf8);
465 RTStrFree(driveNameUtf8);
466 SysFreeString(driveName);
467 IHostDVDDrive *dvdDriveTemp = dvdDrive;
468 dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive);
469 dvdDriveTemp->Release();
470 }
471 dvdColl->Release();
472 } else
473 {
474 RTPrintf("Could not get host DVD drive collection\n");
475 }
476
477 IHostFloppyDriveCollection *floppyColl;
478 rc = host->GetHostFloppyDrives(&floppyColl);
479 if (SUCCEEDED(rc))
480 {
481 IHostFloppyDrive *floppyDrive = NULL;
482 floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive);
483 while (floppyDrive)
484 {
485 BSTR driveName;
486 char *driveNameUtf8;
487 floppyDrive->GetDriveName(&driveName);
488 RTUtf16ToUtf8((PCRTUTF16)driveName, &driveNameUtf8);
489 RTPrintf("Host floppy drive name: %s\n", driveNameUtf8);
490 RTStrFree(driveNameUtf8);
491 SysFreeString(driveName);
492 IHostFloppyDrive *floppyDriveTemp = floppyDrive;
493 floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive);
494 floppyDriveTemp->Release();
495 }
496 floppyColl->Release();
497 } else
498 {
499 RTPrintf("Could not get host floppy drive collection\n");
500 }
501 host->Release();
502 } else
503 {
504 RTPrintf("Call failed\n");
505 }
506 RTPrintf("\n");
507#endif
508
509#if 0
510 // IVirtualBoxErrorInfo test
511 ////////////////////////////////////////////////////////////////////////////
512 {
513 // RPC calls
514
515 // call a method that will definitely fail
516 Guid uuid;
517 ComPtr<IHardDisk> hardDisk;
518 rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
519 RTPrintf("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc);
520
521// {
522// com::ErrorInfo info(virtualBox);
523// PRINT_ERROR_INFO(info);
524// }
525
526 // call a method that will definitely succeed
527 Bstr version;
528 rc = virtualBox->COMGETTER(Version)(version.asOutParam());
529 RTPrintf("virtualBox->COMGETTER(Version)=%08X\n", rc);
530
531 {
532 com::ErrorInfo info(virtualBox);
533 PRINT_ERROR_INFO(info);
534 }
535
536 // Local calls
537
538 // call a method that will definitely fail
539 ComPtr<IMachine> machine;
540 rc = session->COMGETTER(Machine)(machine.asOutParam());
541 RTPrintf("session->COMGETTER(Machine)=%08X\n", rc);
542
543// {
544// com::ErrorInfo info(virtualBox);
545// PRINT_ERROR_INFO(info);
546// }
547
548 // call a method that will definitely succeed
549 SessionState_T state;
550 rc = session->COMGETTER(State)(&state);
551 RTPrintf("session->COMGETTER(State)=%08X\n", rc);
552
553 {
554 com::ErrorInfo info(virtualBox);
555 PRINT_ERROR_INFO(info);
556 }
557 }
558#endif
559
560#if 0
561 // register the existing hard disk image
562 ///////////////////////////////////////////////////////////////////////////
563 do
564 {
565 ComPtr<IHardDisk> hd;
566 Bstr src = L"E:\\develop\\innotek\\images\\NewHardDisk.vdi";
567 RTPrintf("Opening the existing hard disk '%ls'...\n", src.raw());
568 CHECK_ERROR_BREAK(virtualBox, OpenHardDisk(src, AccessMode_ReadWrite, hd.asOutParam()));
569 RTPrintf("Enter to continue...\n");
570 getchar();
571 RTPrintf("Registering the existing hard disk '%ls'...\n", src.raw());
572 CHECK_ERROR_BREAK(virtualBox, RegisterHardDisk(hd));
573 RTPrintf("Enter to continue...\n");
574 getchar();
575 }
576 while (FALSE);
577 RTPrintf("\n");
578#endif
579
580#if 0
581 // find and unregister the existing hard disk image
582 ///////////////////////////////////////////////////////////////////////////
583 do
584 {
585 ComPtr<IVirtualDiskImage> vdi;
586 Bstr src = L"CreatorTest.vdi";
587 RTPrintf("Unregistering the hard disk '%ls'...\n", src.raw());
588 CHECK_ERROR_BREAK(virtualBox, FindVirtualDiskImage(src, vdi.asOutParam()));
589 ComPtr<IHardDisk> hd = vdi;
590 Guid id;
591 CHECK_ERROR_BREAK(hd, COMGETTER(Id)(id.asOutParam()));
592 CHECK_ERROR_BREAK(virtualBox, UnregisterHardDisk(id, hd.asOutParam()));
593 }
594 while (FALSE);
595 RTPrintf("\n");
596#endif
597
598#if 0
599 // clone the registered hard disk
600 ///////////////////////////////////////////////////////////////////////////
601 do
602 {
603#if defined RT_OS_LINUX
604 Bstr src = L"/mnt/hugaida/common/develop/innotek/images/freedos-linux.vdi";
605#else
606 Bstr src = L"E:/develop/innotek/images/freedos.vdi";
607#endif
608 Bstr dst = L"./clone.vdi";
609 RTPrintf("Cloning '%ls' to '%ls'...\n", src.raw(), dst.raw());
610 ComPtr<IVirtualDiskImage> vdi;
611 CHECK_ERROR_BREAK(virtualBox, FindVirtualDiskImage(src, vdi.asOutParam()));
612 ComPtr<IHardDisk> hd = vdi;
613 ComPtr<IProgress> progress;
614 CHECK_ERROR_BREAK(hd, CloneToImage(dst, vdi.asOutParam(), progress.asOutParam()));
615 RTPrintf("Waiting for completion...\n");
616 CHECK_ERROR_BREAK(progress, WaitForCompletion(-1));
617 ProgressErrorInfo ei(progress);
618 if (FAILED(ei.getResultCode()))
619 {
620 PRINT_ERROR_INFO(ei);
621 }
622 else
623 {
624 vdi->COMGETTER(FilePath)(dst.asOutParam());
625 RTPrintf("Actual clone path is '%ls'\n", dst.raw());
626 }
627 }
628 while (FALSE);
629 RTPrintf("\n");
630#endif
631
632#if 0
633 // find a registered hard disk by location and get properties
634 ///////////////////////////////////////////////////////////////////////////
635 do
636 {
637 ComPtr<IHardDisk> hd;
638 static const wchar_t *Names[] =
639 {
640#ifndef RT_OS_LINUX
641 L"freedos.vdi",
642 L"MS-DOS.vmdk",
643 L"iscsi",
644 L"some/path/and/disk.vdi",
645#else
646 L"xp.vdi",
647 L"Xp.vDI",
648#endif
649 };
650
651 RTPrintf("\n");
652
653 for (size_t i = 0; i < RT_ELEMENTS(Names); ++ i)
654 {
655 Bstr src = Names[i];
656 RTPrintf("Searching for hard disk '%ls'...\n", src.raw());
657 rc = virtualBox->FindHardDisk(src, hd.asOutParam());
658 if (SUCCEEDED(rc))
659 {
660 Guid id;
661 Bstr location;
662 CHECK_ERROR_BREAK(hd, COMGETTER(Id)(id.asOutParam()));
663 CHECK_ERROR_BREAK(hd, COMGETTER(Location)(location.asOutParam()));
664 RTPrintf("Found, UUID={%RTuuid}, location='%ls'.\n",
665 id.raw(), location.raw());
666
667 com::SafeArray<BSTR> names;
668 com::SafeArray<BSTR> values;
669
670 CHECK_ERROR_BREAK(hd, GetProperties(NULL,
671 ComSafeArrayAsOutParam(names),
672 ComSafeArrayAsOutParam(values)));
673
674 RTPrintf("Properties:\n");
675 for (size_t i = 0; i < names.size(); ++ i)
676 RTPrintf(" %ls = %ls\n", names[i], values[i]);
677
678 if (names.size() == 0)
679 RTPrintf(" <none>\n");
680
681#if 0
682 Bstr name("TargetAddress");
683 Bstr value = Utf8StrFmt("lalala (%llu)", RTTimeMilliTS());
684
685 RTPrintf("Settings property %ls to %ls...\n", name.raw(), value.raw());
686 CHECK_ERROR(hd, SetProperty(name, value));
687#endif
688 }
689 else
690 {
691 com::ErrorInfo info(virtualBox);
692 PRINT_ERROR_INFO(info);
693 }
694 RTPrintf("\n");
695 }
696 }
697 while (FALSE);
698 RTPrintf("\n");
699#endif
700
701#if 0
702 // access the machine in read-only mode
703 ///////////////////////////////////////////////////////////////////////////
704 do
705 {
706 ComPtr<IMachine> machine;
707 Bstr name = argc > 1 ? argv[1] : "dos";
708 RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
709 CHECK_ERROR_BREAK(virtualBox, FindMachine(name, machine.asOutParam()));
710 RTPrintf("Accessing the machine in read-only mode:\n");
711 readAndChangeMachineSettings(machine);
712#if 0
713 if (argc != 2)
714 {
715 RTPrintf("Error: a string has to be supplied!\n");
716 }
717 else
718 {
719 Bstr secureLabel = argv[1];
720 machine->COMSETTER(ExtraData)(L"VBoxSDL/SecureLabel", secureLabel);
721 }
722#endif
723 }
724 while (0);
725 RTPrintf("\n");
726#endif
727
728#if 0
729 // create a new machine (w/o registering it)
730 ///////////////////////////////////////////////////////////////////////////
731 do
732 {
733 ComPtr<IMachine> machine;
734#if defined(RT_OS_LINUX)
735 Bstr baseDir = L"/tmp/vbox";
736#else
737 Bstr baseDir = L"C:\\vbox";
738#endif
739 Bstr name = L"machina";
740
741 RTPrintf("Creating a new machine object(base dir '%ls', name '%ls')...\n",
742 baseDir.raw(), name.raw());
743 CHECK_ERROR_BREAK(virtualBox, CreateMachine(name, L"", baseDir, L"",
744 false,
745 machine.asOutParam()));
746
747 RTPrintf("Getting name...\n");
748 CHECK_ERROR_BREAK(machine, COMGETTER(Name)(name.asOutParam()));
749 RTPrintf("Name: {%ls}\n", name.raw());
750
751 BOOL modified = FALSE;
752 RTPrintf("Are any settings modified?...\n");
753 CHECK_ERROR_BREAK(machine, COMGETTER(SettingsModified)(&modified));
754 RTPrintf("%s\n", modified ? "yes" : "no");
755
756 ASSERT_BREAK(modified == TRUE);
757
758 name = L"Kakaya prekrasnaya virtual'naya mashina!";
759 RTPrintf("Setting new name ({%ls})...\n", name.raw());
760 CHECK_ERROR_BREAK(machine, COMSETTER(Name)(name));
761
762 RTPrintf("Setting memory size to 111...\n");
763 CHECK_ERROR_BREAK(machine, COMSETTER(MemorySize)(111));
764
765 Bstr desc = L"This is an exemplary description.";
766 RTPrintf("Setting description to \"%ls\"...\n", desc.raw());
767 CHECK_ERROR_BREAK(machine, COMSETTER(Description)(desc));
768
769 ComPtr<IGuestOSType> guestOSType;
770 Bstr type = L"os2warp45";
771 CHECK_ERROR_BREAK(virtualBox, GetGuestOSType(type, guestOSType.asOutParam()));
772
773 RTPrintf("Saving new machine settings...\n");
774 CHECK_ERROR_BREAK(machine, SaveSettings());
775
776 RTPrintf("Accessing the newly created machine:\n");
777 readAndChangeMachineSettings(machine);
778 }
779 while (FALSE);
780 RTPrintf("\n");
781#endif
782
783#if 0
784 // enumerate host DVD drives
785 ///////////////////////////////////////////////////////////////////////////
786 do
787 {
788 ComPtr<IHost> host;
789 CHECK_RC_BREAK(virtualBox->COMGETTER(Host)(host.asOutParam()));
790
791 {
792 ComPtr<IHostDVDDriveCollection> coll;
793 CHECK_RC_BREAK(host->COMGETTER(DVDDrives)(coll.asOutParam()));
794 ComPtr<IHostDVDDriveEnumerator> enumerator;
795 CHECK_RC_BREAK(coll->Enumerate(enumerator.asOutParam()));
796 BOOL hasmore;
797 while (SUCCEEDED(enumerator->HasMore(&hasmore)) && hasmore)
798 {
799 ComPtr<IHostDVDDrive> drive;
800 CHECK_RC_BREAK(enumerator->GetNext(drive.asOutParam()));
801 Bstr name;
802 CHECK_RC_BREAK(drive->COMGETTER(Name)(name.asOutParam()));
803 RTPrintf("Host DVD drive: name={%ls}\n", name.raw());
804 }
805 CHECK_RC_BREAK(rc);
806
807 ComPtr<IHostDVDDrive> drive;
808 CHECK_ERROR(enumerator, GetNext(drive.asOutParam()));
809 CHECK_ERROR(coll, GetItemAt(1000, drive.asOutParam()));
810 CHECK_ERROR(coll, FindByName(Bstr("R:"), drive.asOutParam()));
811 if (SUCCEEDED(rc))
812 {
813 Bstr name;
814 CHECK_RC_BREAK(drive->COMGETTER(Name)(name.asOutParam()));
815 RTPrintf("Found by name: name={%ls}\n", name.raw());
816 }
817 }
818 }
819 while (FALSE);
820 RTPrintf("\n");
821#endif
822
823#if 0
824 // check for available hd backends
825 ///////////////////////////////////////////////////////////////////////////
826 {
827 RTPrintf("Supported hard disk backends: --------------------------\n");
828 ComPtr<ISystemProperties> systemProperties;
829 CHECK_ERROR_BREAK(virtualBox,
830 COMGETTER(SystemProperties)(systemProperties.asOutParam()));
831 com::SafeIfaceArray<IHardDiskFormat> hardDiskFormats;
832 CHECK_ERROR_BREAK(systemProperties,
833 COMGETTER(HardDiskFormats)(ComSafeArrayAsOutParam(hardDiskFormats)));
834
835 for (size_t i = 0; i < hardDiskFormats.size(); ++ i)
836 {
837 /* General information */
838 Bstr id;
839 CHECK_ERROR_BREAK(hardDiskFormats[i],
840 COMGETTER(Id)(id.asOutParam()));
841
842 Bstr description;
843 CHECK_ERROR_BREAK(hardDiskFormats[i],
844 COMGETTER(Id)(description.asOutParam()));
845
846 ULONG caps;
847 CHECK_ERROR_BREAK(hardDiskFormats[i],
848 COMGETTER(Capabilities)(&caps));
849
850 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
851 i, id.raw(), description.raw(), caps);
852
853 /* File extensions */
854 com::SafeArray<BSTR> fileExtensions;
855 CHECK_ERROR_BREAK(hardDiskFormats[i],
856 COMGETTER(FileExtensions)(ComSafeArrayAsOutParam(fileExtensions)));
857 for (size_t a = 0; a < fileExtensions.size(); ++ a)
858 {
859 RTPrintf("%ls", Bstr(fileExtensions[a]).raw());
860 if (a != fileExtensions.size()-1)
861 RTPrintf(",");
862 }
863 RTPrintf("'");
864
865 /* Configuration keys */
866 com::SafeArray<BSTR> propertyNames;
867 com::SafeArray<BSTR> propertyDescriptions;
868 com::SafeArray<ULONG> propertyTypes;
869 com::SafeArray<ULONG> propertyFlags;
870 com::SafeArray<BSTR> propertyDefaults;
871 CHECK_ERROR_BREAK(hardDiskFormats[i],
872 DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
873 ComSafeArrayAsOutParam(propertyDescriptions),
874 ComSafeArrayAsOutParam(propertyTypes),
875 ComSafeArrayAsOutParam(propertyFlags),
876 ComSafeArrayAsOutParam(propertyDefaults)));
877
878 RTPrintf(" config=(");
879 if (propertyNames.size() > 0)
880 {
881 for (size_t a = 0; a < propertyNames.size(); ++ a)
882 {
883 RTPrintf("key='%ls' desc='%ls' type=", Bstr(propertyNames[a]).raw(), Bstr(propertyDescriptions[a]).raw());
884 switch (propertyTypes[a])
885 {
886 case DataType_Int32Type: RTPrintf("int"); break;
887 case DataType_Int8Type: RTPrintf("byte"); break;
888 case DataType_StringType: RTPrintf("string"); break;
889 }
890 RTPrintf(" flags=%#04x", propertyFlags[a]);
891 RTPrintf(" default='%ls'", Bstr(propertyDefaults[a]).raw());
892 if (a != propertyNames.size()-1)
893 RTPrintf(",");
894 }
895 }
896 RTPrintf(")\n");
897 }
898 RTPrintf("-------------------------------------------------------\n");
899 }
900#endif
901
902#if 0
903 // enumerate hard disks & dvd images
904 ///////////////////////////////////////////////////////////////////////////
905 do
906 {
907 {
908 com::SafeIfaceArray<IHardDisk> disks;
909 CHECK_ERROR_BREAK(virtualBox,
910 COMGETTER(HardDisks)(ComSafeArrayAsOutParam(disks)));
911
912 RTPrintf("%u base hard disks registered (disks.isNull()=%d).\n",
913 disks.size(), disks.isNull());
914
915 for (size_t i = 0; i < disks.size(); ++ i)
916 {
917 Bstr loc;
918 CHECK_ERROR_BREAK(disks[i], COMGETTER(Location)(loc.asOutParam()));
919 Guid id;
920 CHECK_ERROR_BREAK(disks[i], COMGETTER(Id)(id.asOutParam()));
921 MediaState_T state;
922 CHECK_ERROR_BREAK(disks[i], COMGETTER(State)(&state));
923 Bstr format;
924 CHECK_ERROR_BREAK(disks[i], COMGETTER(Format)(format.asOutParam()));
925
926 RTPrintf(" disks[%u]: '%ls'\n"
927 " UUID: {%RTuuid}\n"
928 " State: %s\n"
929 " Format: %ls\n",
930 i, loc.raw(), id.raw(),
931 state == MediaState_NotCreated ? "Not Created" :
932 state == MediaState_Created ? "Created" :
933 state == MediaState_Inaccessible ? "Inaccessible" :
934 state == MediaState_LockedRead ? "Locked Read" :
935 state == MediaState_LockedWrite ? "Locked Write" :
936 "???",
937 format.raw());
938
939 if (state == MediaState_Inaccessible)
940 {
941 Bstr error;
942 CHECK_ERROR_BREAK(disks[i],
943 COMGETTER(LastAccessError)(error.asOutParam()));
944 RTPrintf(" Access Error: %ls\n", error.raw());
945 }
946
947 /* get usage */
948
949 RTPrintf(" Used by VMs:\n");
950
951 com::SafeGUIDArray ids;
952 CHECK_ERROR_BREAK(disks[i],
953 COMGETTER(MachineIds)(ComSafeArrayAsOutParam(ids)));
954 if (ids.size() == 0)
955 {
956 RTPrintf(" <not used>\n");
957 }
958 else
959 {
960 for (size_t j = 0; j < ids.size(); ++ j)
961 {
962 RTPrintf(" {%RTuuid}\n", &ids[j]);
963 }
964 }
965 }
966 }
967 {
968 com::SafeIfaceArray<IDVDImage> images;
969 CHECK_ERROR_BREAK(virtualBox,
970 COMGETTER(DVDImages)(ComSafeArrayAsOutParam(images)));
971
972 RTPrintf("%u DVD images registered (images.isNull()=%d).\n",
973 images.size(), images.isNull());
974
975 for (size_t i = 0; i < images.size(); ++ i)
976 {
977 Bstr loc;
978 CHECK_ERROR_BREAK(images[i], COMGETTER(Location)(loc.asOutParam()));
979 Guid id;
980 CHECK_ERROR_BREAK(images[i], COMGETTER(Id)(id.asOutParam()));
981 MediaState_T state;
982 CHECK_ERROR_BREAK(images[i], COMGETTER(State)(&state));
983
984 RTPrintf(" images[%u]: '%ls'\n"
985 " UUID: {%RTuuid}\n"
986 " State: %s\n",
987 i, loc.raw(), id.raw(),
988 state == MediaState_NotCreated ? "Not Created" :
989 state == MediaState_Created ? "Created" :
990 state == MediaState_Inaccessible ? "Inaccessible" :
991 state == MediaState_LockedRead ? "Locked Read" :
992 state == MediaState_LockedWrite ? "Locked Write" :
993 "???");
994
995 if (state == MediaState_Inaccessible)
996 {
997 Bstr error;
998 CHECK_ERROR_BREAK(images[i],
999 COMGETTER(LastAccessError)(error.asOutParam()));
1000 RTPrintf(" Access Error: %ls\n", error.raw());
1001 }
1002
1003 /* get usage */
1004
1005 RTPrintf(" Used by VMs:\n");
1006
1007 com::SafeGUIDArray ids;
1008 CHECK_ERROR_BREAK(images[i],
1009 COMGETTER(MachineIds)(ComSafeArrayAsOutParam(ids)));
1010 if (ids.size() == 0)
1011 {
1012 RTPrintf(" <not used>\n");
1013 }
1014 else
1015 {
1016 for (size_t j = 0; j < ids.size(); ++ j)
1017 {
1018 RTPrintf(" {%RTuuid}\n", &ids[j]);
1019 }
1020 }
1021 }
1022 }
1023 }
1024 while (FALSE);
1025 RTPrintf("\n");
1026#endif
1027
1028#if 0
1029 // open a (direct) session
1030 ///////////////////////////////////////////////////////////////////////////
1031 do
1032 {
1033 ComPtr<IMachine> machine;
1034 Bstr name = argc > 1 ? argv[1] : "dos";
1035 RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
1036 CHECK_ERROR_BREAK(virtualBox, FindMachine(name, machine.asOutParam()));
1037 Guid guid;
1038 CHECK_RC_BREAK(machine->COMGETTER(Id)(guid.asOutParam()));
1039 RTPrintf("Opening a session for this machine...\n");
1040 CHECK_RC_BREAK(virtualBox->OpenSession(session, guid));
1041#if 1
1042 ComPtr<IMachine> sessionMachine;
1043 RTPrintf("Getting machine session object...\n");
1044 CHECK_RC_BREAK(session->COMGETTER(Machine)(sessionMachine.asOutParam()));
1045 RTPrintf("Accessing the machine within the session:\n");
1046 readAndChangeMachineSettings(sessionMachine, machine);
1047#if 0
1048 RTPrintf("\n");
1049 RTPrintf("Enabling the VRDE server (must succeed even if the VM is saved):\n");
1050 ComPtr<IVRDEServer> vrdeServer;
1051 CHECK_ERROR_BREAK(sessionMachine, COMGETTER(VRDEServer)(vrdeServer.asOutParam()));
1052 if (FAILED(vrdeServer->COMSETTER(Enabled)(TRUE)))
1053 {
1054 PRINT_ERROR_INFO(com::ErrorInfo(vrdeServer));
1055 }
1056 else
1057 {
1058 BOOL enabled = FALSE;
1059 CHECK_ERROR_BREAK(vrdeServer, COMGETTER(Enabled)(&enabled));
1060 RTPrintf("VRDE server is %s\n", enabled ? "enabled" : "disabled");
1061 }
1062#endif
1063#endif
1064#if 0
1065 ComPtr<IConsole> console;
1066 RTPrintf("Getting the console object...\n");
1067 CHECK_RC_BREAK(session->COMGETTER(Console)(console.asOutParam()));
1068 RTPrintf("Discarding the current machine state...\n");
1069 ComPtr<IProgress> progress;
1070 CHECK_ERROR_BREAK(console, DiscardCurrentState(progress.asOutParam()));
1071 RTPrintf("Waiting for completion...\n");
1072 CHECK_ERROR_BREAK(progress, WaitForCompletion(-1));
1073 ProgressErrorInfo ei(progress);
1074 if (FAILED(ei.getResultCode()))
1075 {
1076 PRINT_ERROR_INFO(ei);
1077
1078 ComPtr<IUnknown> initiator;
1079 CHECK_ERROR_BREAK(progress, COMGETTER(Initiator)(initiator.asOutParam()));
1080
1081 RTPrintf("initiator(unk) = %p\n", (IUnknown *)initiator);
1082 RTPrintf("console(unk) = %p\n", (IUnknown *)ComPtr<IUnknown>((IConsole *)console));
1083 RTPrintf("console = %p\n", (IConsole *)console);
1084 }
1085#endif
1086 RTPrintf("Press enter to close session...");
1087 getchar();
1088 session->Close();
1089 }
1090 while (FALSE);
1091 RTPrintf("\n");
1092#endif
1093
1094#if 0
1095 // open a remote session
1096 ///////////////////////////////////////////////////////////////////////////
1097 do
1098 {
1099 ComPtr<IMachine> machine;
1100 Bstr name = L"dos";
1101 RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
1102 CHECK_RC_BREAK(virtualBox->FindMachine(name, machine.asOutParam()));
1103 Guid guid;
1104 CHECK_RC_BREAK(machine->COMGETTER(Id)(guid.asOutParam()));
1105 RTPrintf("Opening a remote session for this machine...\n");
1106 ComPtr<IProgress> progress;
1107 CHECK_RC_BREAK(virtualBox->OpenRemoteSession(session, guid, Bstr("gui"),
1108 NULL, progress.asOutParam()));
1109 RTPrintf("Waiting for the session to open...\n");
1110 CHECK_RC_BREAK(progress->WaitForCompletion(-1));
1111 ComPtr<IMachine> sessionMachine;
1112 RTPrintf("Getting machine session object...\n");
1113 CHECK_RC_BREAK(session->COMGETTER(Machine)(sessionMachine.asOutParam()));
1114 ComPtr<IConsole> console;
1115 RTPrintf("Getting console object...\n");
1116 CHECK_RC_BREAK(session->COMGETTER(Console)(console.asOutParam()));
1117 RTPrintf("Press enter to pause the VM execution in the remote session...");
1118 getchar();
1119 CHECK_RC(console->Pause());
1120 RTPrintf("Press enter to close this session...");
1121 getchar();
1122 session->Close();
1123 }
1124 while (FALSE);
1125 RTPrintf("\n");
1126#endif
1127
1128#if 0
1129 // open an existing remote session
1130 ///////////////////////////////////////////////////////////////////////////
1131 do
1132 {
1133 ComPtr<IMachine> machine;
1134 Bstr name = "dos";
1135 RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
1136 CHECK_RC_BREAK(virtualBox->FindMachine(name, machine.asOutParam()));
1137 Guid guid;
1138 CHECK_RC_BREAK(machine->COMGETTER(Id)(guid.asOutParam()));
1139 RTPrintf("Opening an existing remote session for this machine...\n");
1140 CHECK_RC_BREAK(virtualBox->OpenExistingSession(session, guid));
1141 ComPtr<IMachine> sessionMachine;
1142 RTPrintf("Getting machine session object...\n");
1143 CHECK_RC_BREAK(session->COMGETTER(Machine)(sessionMachine.asOutParam()));
1144
1145#if 0
1146 Bstr extraDataKey = "VBoxSDL/SecureLabel";
1147 Bstr extraData = "Das kommt jetzt noch viel krasser vom total konkreten API!";
1148 CHECK_RC(sessionMachine->SetExtraData(extraDataKey, extraData));
1149#endif
1150#if 0
1151 ComPtr<IConsole> console;
1152 RTPrintf("Getting console object...\n");
1153 CHECK_RC_BREAK(session->COMGETTER(Console)(console.asOutParam()));
1154 RTPrintf("Press enter to pause the VM execution in the remote session...");
1155 getchar();
1156 CHECK_RC(console->Pause());
1157 RTPrintf("Press enter to close this session...");
1158 getchar();
1159#endif
1160 session->Close();
1161 }
1162 while (FALSE);
1163 RTPrintf("\n");
1164#endif
1165
1166#if 1
1167 do {
1168 // Get host
1169 ComPtr<IHost> host;
1170 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
1171
1172 ULONG uMemSize, uMemAvail;
1173 CHECK_ERROR_BREAK(host, COMGETTER(MemorySize)(&uMemSize));
1174 RTPrintf("Total memory (MB): %u\n", uMemSize);
1175 CHECK_ERROR_BREAK(host, COMGETTER(MemoryAvailable)(&uMemAvail));
1176 RTPrintf("Free memory (MB): %u\n", uMemAvail);
1177 } while (0);
1178#endif
1179
1180#if 0
1181 do {
1182 // Get host
1183 ComPtr<IHost> host;
1184 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
1185
1186 com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
1187 CHECK_ERROR_BREAK(host,
1188 COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
1189 if (hostNetworkInterfaces.size() > 0)
1190 {
1191 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[0];
1192 Bstr interfaceName;
1193 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
1194 RTPrintf("Found %d network interfaces, testing with %ls...\n", hostNetworkInterfaces.size(), interfaceName.raw());
1195 Bstr interfaceGuid;
1196 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
1197 // Find the interface by its name
1198 networkInterface.setNull();
1199 CHECK_ERROR_BREAK(host,
1200 FindHostNetworkInterfaceByName(interfaceName.raw(), networkInterface.asOutParam()));
1201 Bstr interfaceGuid2;
1202 networkInterface->COMGETTER(Id)(interfaceGuid2.asOutParam());
1203 if (interfaceGuid2 != interfaceGuid)
1204 RTPrintf("Failed to retrieve an interface by name %ls.\n", interfaceName.raw());
1205 // Find the interface by its guid
1206 networkInterface.setNull();
1207 CHECK_ERROR_BREAK(host,
1208 FindHostNetworkInterfaceById(interfaceGuid.raw(), networkInterface.asOutParam()));
1209 Bstr interfaceName2;
1210 networkInterface->COMGETTER(Name)(interfaceName2.asOutParam());
1211 if (interfaceName != interfaceName2)
1212 RTPrintf("Failed to retrieve an interface by GUID %ls.\n", interfaceGuid.raw());
1213 }
1214 else
1215 {
1216 RTPrintf("No network interfaces found!\n");
1217 }
1218 } while (0);
1219#endif
1220
1221#if 0
1222 // DNS & Co.
1223 ///////////////////////////////////////////////////////////////////////////
1224 /* XXX: Note it's endless loop */
1225 do
1226 {
1227 ComPtr<IHost> host;
1228 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
1229
1230 {
1231 Bstr domainName;
1232 CHECK_ERROR_BREAK(host,COMGETTER(DomainName)(domainName.asOutParam()));
1233 RTPrintf("Domain name: %ls\n", domainName.raw());
1234 }
1235
1236 com::SafeArray<BSTR> strs;
1237 CHECK_ERROR_BREAK(host, COMGETTER(NameServers)(ComSafeArrayAsOutParam(strs)));
1238
1239 unsigned int i;
1240 for (i = 0; i < strs.size(); ++i)
1241 RTPrintf("Name server[%d]:%s\n", i, com::Utf8Str(strs[i]).c_str());
1242
1243 RTThreadSleep(1000);
1244 }
1245 while (1);
1246 RTPrintf("\n");
1247#endif
1248
1249
1250#if 0 && defined(VBOX_WITH_RESOURCE_USAGE_API)
1251 do {
1252 // Get collector
1253 ComPtr<IPerformanceCollector> collector;
1254 CHECK_ERROR_BREAK(virtualBox,
1255 COMGETTER(PerformanceCollector)(collector.asOutParam()));
1256
1257
1258 // Fill base metrics array
1259 Bstr baseMetricNames[] = { L"Net/eth0/Load" };
1260 com::SafeArray<BSTR> baseMetrics(1);
1261 baseMetricNames[0].cloneTo(&baseMetrics[0]);
1262
1263 // Get host
1264 ComPtr<IHost> host;
1265 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
1266
1267 // Get host network interfaces
1268 // com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
1269 // CHECK_ERROR_BREAK(host,
1270 // COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
1271
1272 // Setup base metrics
1273 // Note that one needs to set up metrics after a session is open for a machine.
1274 com::SafeIfaceArray<IPerformanceMetric> affectedMetrics;
1275 com::SafeIfaceArray<IUnknown> objects(1);
1276 host.queryInterfaceTo(&objects[0]);
1277 CHECK_ERROR_BREAK(collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics),
1278 ComSafeArrayAsInParam(objects), 1u, 10u,
1279 ComSafeArrayAsOutParam(affectedMetrics)));
1280 listAffectedMetrics(virtualBox,
1281 ComSafeArrayAsInParam(affectedMetrics));
1282 affectedMetrics.setNull();
1283
1284 RTPrintf("Sleeping for 5 seconds...\n");
1285 RTThreadSleep(5000); // Sleep for 5 seconds
1286
1287 RTPrintf("\nMetrics collected: --------------------\n");
1288 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
1289 } while (false);
1290#endif /* VBOX_WITH_RESOURCE_USAGE_API */
1291#if 0 && defined(VBOX_WITH_RESOURCE_USAGE_API)
1292 do {
1293 // Get collector
1294 ComPtr<IPerformanceCollector> collector;
1295 CHECK_ERROR_BREAK(virtualBox,
1296 COMGETTER(PerformanceCollector)(collector.asOutParam()));
1297
1298
1299 // Fill base metrics array
1300 //Bstr baseMetricNames[] = { L"CPU/Load,RAM/Usage" };
1301 Bstr baseMetricNames[] = { L"RAM/VMM" };
1302 com::SafeArray<BSTR> baseMetrics(1);
1303 baseMetricNames[0].cloneTo(&baseMetrics[0]);
1304
1305 // Get host
1306 ComPtr<IHost> host;
1307 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
1308
1309 // Get machine
1310 ComPtr<IMachine> machine;
1311 Bstr name = argc > 1 ? argv[1] : "dsl";
1312 Bstr sessionType = argc > 2 ? argv[2] : "headless";
1313 RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
1314 CHECK_ERROR_BREAK(virtualBox, FindMachine(name.raw(), machine.asOutParam()));
1315
1316 // Open session
1317 ComPtr<IProgress> progress;
1318 RTPrintf("Launching VM process...\n");
1319 CHECK_ERROR_BREAK(machine, LaunchVMProcess(session, sessionType.raw(),
1320 ComSafeArrayNullInParam(), progress.asOutParam()));
1321 RTPrintf("Waiting for the VM to power on...\n");
1322 CHECK_ERROR_BREAK(progress, WaitForCompletion(-1));
1323
1324 // ComPtr<IMachine> sessionMachine;
1325 // RTPrintf("Getting machine session object...\n");
1326 // CHECK_ERROR_BREAK(session, COMGETTER(Machine)(sessionMachine.asOutParam()));
1327
1328 // Setup base metrics
1329 // Note that one needs to set up metrics after a session is open for a machine.
1330 com::SafeIfaceArray<IPerformanceMetric> affectedMetrics;
1331 com::SafeIfaceArray<IUnknown> objects(1);
1332 host.queryInterfaceTo(&objects[0]);
1333 //machine.queryInterfaceTo(&objects[1]);
1334 CHECK_ERROR_BREAK(collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics),
1335 ComSafeArrayAsInParam(objects), 1u, 10u,
1336 ComSafeArrayAsOutParam(affectedMetrics)));
1337 listAffectedMetrics(virtualBox,
1338 ComSafeArrayAsInParam(affectedMetrics));
1339 affectedMetrics.setNull();
1340
1341 // Get console
1342 ComPtr<IConsole> console;
1343 RTPrintf("Getting console object...\n");
1344 CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
1345
1346 RTThreadSleep(5000); // Sleep for 5 seconds
1347
1348 RTPrintf("\nMetrics collected with VM running: --------------------\n");
1349 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
1350
1351 // Pause
1352 //RTPrintf("Press enter to pause the VM execution in the remote session...");
1353 //getchar();
1354 CHECK_ERROR_BREAK(console, Pause());
1355
1356 RTThreadSleep(5000); // Sleep for 5 seconds
1357
1358 RTPrintf("\nMetrics collected with VM paused: ---------------------\n");
1359 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
1360
1361 RTPrintf("\nDrop collected metrics: ----------------------------------------\n");
1362 CHECK_ERROR_BREAK(collector,
1363 SetupMetrics(ComSafeArrayAsInParam(baseMetrics),
1364 ComSafeArrayAsInParam(objects),
1365 1u, 5u, ComSafeArrayAsOutParam(affectedMetrics)));
1366 listAffectedMetrics(virtualBox,
1367 ComSafeArrayAsInParam(affectedMetrics));
1368 affectedMetrics.setNull();
1369 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
1370
1371 com::SafeIfaceArray<IUnknown> vmObject(1);
1372 machine.queryInterfaceTo(&vmObject[0]);
1373
1374 RTPrintf("\nDisable collection of VM metrics: ------------------------------\n");
1375 CHECK_ERROR_BREAK(collector,
1376 DisableMetrics(ComSafeArrayAsInParam(baseMetrics),
1377 ComSafeArrayAsInParam(vmObject),
1378 ComSafeArrayAsOutParam(affectedMetrics)));
1379 listAffectedMetrics(virtualBox,
1380 ComSafeArrayAsInParam(affectedMetrics));
1381 affectedMetrics.setNull();
1382 RTThreadSleep(5000); // Sleep for 5 seconds
1383 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
1384
1385 RTPrintf("\nRe-enable collection of all metrics: ---------------------------\n");
1386 CHECK_ERROR_BREAK(collector,
1387 EnableMetrics(ComSafeArrayAsInParam(baseMetrics),
1388 ComSafeArrayAsInParam(objects),
1389 ComSafeArrayAsOutParam(affectedMetrics)));
1390 listAffectedMetrics(virtualBox,
1391 ComSafeArrayAsInParam(affectedMetrics));
1392 affectedMetrics.setNull();
1393 RTThreadSleep(5000); // Sleep for 5 seconds
1394 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
1395
1396 // Power off
1397 RTPrintf("Press enter to power off VM...");
1398 getchar();
1399 CHECK_ERROR_BREAK(console, PowerDown(progress.asOutParam()));
1400 RTPrintf("Waiting for the VM to power down...\n");
1401 CHECK_ERROR_BREAK(progress, WaitForCompletion(-1));
1402 RTPrintf("Press enter to close this session...");
1403 getchar();
1404 session->UnlockMachine();
1405 } while (false);
1406#endif /* VBOX_WITH_RESOURCE_USAGE_API */
1407#if 0
1408 // check of OVF appliance handling
1409 ///////////////////////////////////////////////////////////////////////////
1410 do
1411 {
1412 Bstr ovf = argc > 1 ? argv[1] : "someOVF.ovf";
1413 RTPrintf("Try to open %ls ...\n", ovf.raw());
1414
1415 ComPtr<IAppliance> appliance;
1416 CHECK_ERROR_BREAK(virtualBox,
1417 CreateAppliance(appliance.asOutParam()));
1418 CHECK_ERROR_BREAK(appliance, Read(ovf));
1419 Bstr path;
1420 CHECK_ERROR_BREAK(appliance, COMGETTER(Path)(path.asOutParam()));
1421 RTPrintf("Successfully opened %ls.\n", path.raw());
1422 CHECK_ERROR_BREAK(appliance, Interpret());
1423 RTPrintf("Successfully interpreted %ls.\n", path.raw());
1424 RTPrintf("Appliance:\n");
1425 // Fetch all disks
1426 com::SafeArray<BSTR> retDisks;
1427 CHECK_ERROR_BREAK(appliance,
1428 COMGETTER(Disks)(ComSafeArrayAsOutParam(retDisks)));
1429 if (retDisks.size() > 0)
1430 {
1431 RTPrintf("Disks:");
1432 for (unsigned i = 0; i < retDisks.size(); i++)
1433 RTPrintf(" %ls", Bstr(retDisks[i]).raw());
1434 RTPrintf("\n");
1435 }
1436 /* Fetch all virtual system descriptions */
1437 com::SafeIfaceArray<IVirtualSystemDescription> retVSD;
1438 CHECK_ERROR_BREAK(appliance,
1439 COMGETTER(VirtualSystemDescriptions)(ComSafeArrayAsOutParam(retVSD)));
1440 if (retVSD.size() > 0)
1441 {
1442 for (unsigned i = 0; i < retVSD.size(); ++i)
1443 {
1444 com::SafeArray<VirtualSystemDescriptionType_T> retTypes;
1445 com::SafeArray<BSTR> retRefValues;
1446 com::SafeArray<BSTR> retOrigValues;
1447 com::SafeArray<BSTR> retAutoValues;
1448 com::SafeArray<BSTR> retConfiguration;
1449 CHECK_ERROR_BREAK(retVSD[i],
1450 GetDescription(ComSafeArrayAsOutParam(retTypes),
1451 ComSafeArrayAsOutParam(retRefValues),
1452 ComSafeArrayAsOutParam(retOrigValues),
1453 ComSafeArrayAsOutParam(retAutoValues),
1454 ComSafeArrayAsOutParam(retConfiguration)));
1455
1456 RTPrintf("VirtualSystemDescription:\n");
1457 for (unsigned a = 0; a < retTypes.size(); ++a)
1458 {
1459 RTPrintf(" %d %ls %ls %ls\n",
1460 retTypes[a],
1461 Bstr(retOrigValues[a]).raw(),
1462 Bstr(retAutoValues[a]).raw(),
1463 Bstr(retConfiguration[a]).raw());
1464 }
1465 /* Show warnings from interpret */
1466 com::SafeArray<BSTR> retWarnings;
1467 CHECK_ERROR_BREAK(retVSD[i],
1468 GetWarnings(ComSafeArrayAsOutParam(retWarnings)));
1469 if (retWarnings.size() > 0)
1470 {
1471 RTPrintf("The following warnings occurs on interpret:\n");
1472 for (unsigned r = 0; r < retWarnings.size(); ++r)
1473 RTPrintf("%ls\n", Bstr(retWarnings[r]).raw());
1474 RTPrintf("\n");
1475 }
1476 }
1477 RTPrintf("\n");
1478 }
1479 RTPrintf("Try to import the appliance ...\n");
1480 ComPtr<IProgress> progress;
1481 CHECK_ERROR_BREAK(appliance,
1482 ImportMachines(progress.asOutParam()));
1483 CHECK_ERROR(progress, WaitForCompletion(-1));
1484 if (SUCCEEDED(rc))
1485 {
1486 /* Check if the import was successfully */
1487 progress->COMGETTER(ResultCode)(&rc);
1488 if (FAILED(rc))
1489 {
1490 com::ProgressErrorInfo info(progress);
1491 if (info.isBasicAvailable())
1492 RTPrintf("Error: failed to import appliance. Error message: %ls\n", info.getText().raw());
1493 else
1494 RTPrintf("Error: failed to import appliance. No error message available!\n");
1495 }
1496 else
1497 RTPrintf("Successfully imported the appliance.\n");
1498 }
1499
1500 }
1501 while (FALSE);
1502 RTPrintf("\n");
1503#endif
1504#if 0
1505 // check of network bandwidth control
1506 ///////////////////////////////////////////////////////////////////////////
1507 do
1508 {
1509 Bstr name = argc > 1 ? argv[1] : "ubuntu";
1510 Bstr sessionType = argc > 2 ? argv[2] : "headless";
1511 Bstr grpName = "tstAPI";
1512 {
1513 // Get machine
1514 ComPtr<IMachine> machine;
1515 ComPtr<IBandwidthControl> bwCtrl;
1516 ComPtr<IBandwidthGroup> bwGroup;
1517 ComPtr<INetworkAdapter> nic;
1518 RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
1519 CHECK_ERROR_BREAK(virtualBox, FindMachine(name.raw(), machine.asOutParam()));
1520 /* open a session for the VM (new or shared) */
1521 CHECK_ERROR_BREAK(machine, LockMachine(session, LockType_Shared));
1522 SessionType_T st;
1523 CHECK_ERROR_BREAK(session, COMGETTER(Type)(&st));
1524 bool fRunTime = (st == SessionType_Shared);
1525 if (fRunTime)
1526 {
1527 RTPrintf("Machine %ls must not be running!\n");
1528 break;
1529 }
1530 /* get the mutable session machine */
1531 session->COMGETTER(Machine)(machine.asOutParam());
1532 CHECK_ERROR_BREAK(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
1533
1534 RTPrintf("Creating bandwidth group named '%ls'...\n", grpName.raw());
1535 CHECK_ERROR_BREAK(bwCtrl, CreateBandwidthGroup(grpName.raw(), BandwidthGroupType_Network, 123));
1536
1537
1538 CHECK_ERROR_BREAK(bwCtrl, GetBandwidthGroup(grpName.raw(), bwGroup.asOutParam()));
1539 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(0, nic.asOutParam()));
1540 RTPrintf("Assigning the group to the first network adapter...\n");
1541 CHECK_ERROR_BREAK(nic, COMSETTER(BandwidthGroup)(bwGroup));
1542 CHECK_ERROR_BREAK(machine, SaveSettings());
1543 RTPrintf("Press enter to close this session...");
1544 getchar();
1545 session->UnlockMachine();
1546 }
1547 {
1548 // Get machine
1549 ComPtr<IMachine> machine;
1550 ComPtr<IBandwidthControl> bwCtrl;
1551 ComPtr<IBandwidthGroup> bwGroup;
1552 Bstr grpNameReadFromNic;
1553 ComPtr<INetworkAdapter> nic;
1554 RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
1555 CHECK_ERROR_BREAK(virtualBox, FindMachine(name.raw(), machine.asOutParam()));
1556 /* open a session for the VM (new or shared) */
1557 CHECK_ERROR_BREAK(machine, LockMachine(session, LockType_Shared));
1558 /* get the mutable session machine */
1559 session->COMGETTER(Machine)(machine.asOutParam());
1560 CHECK_ERROR_BREAK(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
1561 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(0, nic.asOutParam()));
1562
1563 RTPrintf("Reading the group back from the first network adapter...\n");
1564 CHECK_ERROR_BREAK(nic, COMGETTER(BandwidthGroup)(bwGroup.asOutParam()));
1565 if (bwGroup.isNull())
1566 RTPrintf("Error: Bandwidth group is null at the first network adapter!\n");
1567 else
1568 {
1569 CHECK_ERROR_BREAK(bwGroup, COMGETTER(Name)(grpNameReadFromNic.asOutParam()));
1570 if (grpName != grpNameReadFromNic)
1571 RTPrintf("Error: Bandwidth group names do not match (%ls != %ls)!\n", grpName.raw(), grpNameReadFromNic.raw());
1572 else
1573 RTPrintf("Successfully retrieved bandwidth group attribute from NIC (name=%ls)\n", grpNameReadFromNic.raw());
1574 ComPtr<IBandwidthGroup> bwGroupEmpty;
1575 RTPrintf("Assigning an empty group to the first network adapter...\n");
1576 CHECK_ERROR_BREAK(nic, COMSETTER(BandwidthGroup)(bwGroupEmpty));
1577 }
1578 RTPrintf("Removing bandwidth group named '%ls'...\n", grpName.raw());
1579 CHECK_ERROR_BREAK(bwCtrl, DeleteBandwidthGroup(grpName.raw()));
1580 CHECK_ERROR_BREAK(machine, SaveSettings());
1581 RTPrintf("Press enter to close this session...");
1582 getchar();
1583 session->UnlockMachine();
1584 }
1585 } while (FALSE);
1586 RTPrintf("\n");
1587#endif
1588
1589 RTPrintf("Press enter to release Session and VirtualBox instances...");
1590 getchar();
1591
1592 // end "all-stuff" scope
1593 ////////////////////////////////////////////////////////////////////////////
1594 }
1595 while (0);
1596
1597 RTPrintf("Press enter to shutdown COM...");
1598 getchar();
1599
1600 com::Shutdown();
1601
1602 RTPrintf("tstAPI FINISHED.\n");
1603
1604 return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
1605}
1606
1607#ifdef VBOX_WITH_RESOURCE_USAGE_API
1608
1609static void queryMetrics(ComPtr<IVirtualBox> aVirtualBox,
1610 ComPtr<IPerformanceCollector> collector,
1611 ComSafeArrayIn(IUnknown *, objects))
1612{
1613 HRESULT rc;
1614
1615 //Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg,RAM/Usage/Total,RAM/Usage/Used:avg" };
1616 Bstr metricNames[] = { L"*" };
1617 com::SafeArray<BSTR> metrics(1);
1618 metricNames[0].cloneTo(&metrics[0]);
1619 com::SafeArray<BSTR> retNames;
1620 com::SafeIfaceArray<IUnknown> retObjects;
1621 com::SafeArray<BSTR> retUnits;
1622 com::SafeArray<ULONG> retScales;
1623 com::SafeArray<ULONG> retSequenceNumbers;
1624 com::SafeArray<ULONG> retIndices;
1625 com::SafeArray<ULONG> retLengths;
1626 com::SafeArray<LONG> retData;
1627 CHECK_ERROR(collector, QueryMetricsData(ComSafeArrayAsInParam(metrics),
1628 ComSafeArrayInArg(objects),
1629 ComSafeArrayAsOutParam(retNames),
1630 ComSafeArrayAsOutParam(retObjects),
1631 ComSafeArrayAsOutParam(retUnits),
1632 ComSafeArrayAsOutParam(retScales),
1633 ComSafeArrayAsOutParam(retSequenceNumbers),
1634 ComSafeArrayAsOutParam(retIndices),
1635 ComSafeArrayAsOutParam(retLengths),
1636 ComSafeArrayAsOutParam(retData)));
1637 RTPrintf("Object Metric Values\n"
1638 "---------- -------------------- --------------------------------------------\n");
1639 for (unsigned i = 0; i < retNames.size(); i++)
1640 {
1641 Bstr metricUnit(retUnits[i]);
1642 Bstr metricName(retNames[i]);
1643 RTPrintf("%-10ls %-20ls ", getObjectName(aVirtualBox, retObjects[i]).raw(), metricName.raw());
1644 const char *separator = "";
1645 for (unsigned j = 0; j < retLengths[i]; j++)
1646 {
1647 if (retScales[i] == 1)
1648 RTPrintf("%s%d %ls", separator, retData[retIndices[i] + j], metricUnit.raw());
1649 else
1650 RTPrintf("%s%d.%02d%ls", separator, retData[retIndices[i] + j] / retScales[i],
1651 (retData[retIndices[i] + j] * 100 / retScales[i]) % 100, metricUnit.raw());
1652 separator = ", ";
1653 }
1654 RTPrintf("\n");
1655 }
1656}
1657
1658static Bstr getObjectName(ComPtr<IVirtualBox> aVirtualBox,
1659 ComPtr<IUnknown> aObject)
1660{
1661 HRESULT rc;
1662
1663 ComPtr<IHost> host = aObject;
1664 if (!host.isNull())
1665 return Bstr("host");
1666
1667 ComPtr<IMachine> machine = aObject;
1668 if (!machine.isNull())
1669 {
1670 Bstr name;
1671 CHECK_ERROR(machine, COMGETTER(Name)(name.asOutParam()));
1672 if (SUCCEEDED(rc))
1673 return name;
1674 }
1675 return Bstr("unknown");
1676}
1677
1678static void listAffectedMetrics(ComPtr<IVirtualBox> aVirtualBox,
1679 ComSafeArrayIn(IPerformanceMetric*, aMetrics))
1680{
1681 HRESULT rc;
1682 com::SafeIfaceArray<IPerformanceMetric> metrics(ComSafeArrayInArg(aMetrics));
1683 if (metrics.size())
1684 {
1685 ComPtr<IUnknown> object;
1686 Bstr metricName;
1687 RTPrintf("The following metrics were modified:\n\n"
1688 "Object Metric\n"
1689 "---------- --------------------\n");
1690 for (size_t i = 0; i < metrics.size(); i++)
1691 {
1692 CHECK_ERROR(metrics[i], COMGETTER(Object)(object.asOutParam()));
1693 CHECK_ERROR(metrics[i], COMGETTER(MetricName)(metricName.asOutParam()));
1694 RTPrintf("%-10ls %-20ls\n",
1695 getObjectName(aVirtualBox, object).raw(), metricName.raw());
1696 }
1697 RTPrintf("\n");
1698 }
1699 else
1700 {
1701 RTPrintf("No metrics match the specified filter!\n");
1702 }
1703}
1704
1705#endif /* VBOX_WITH_RESOURCE_USAGE_API */
1706/* vim: set shiftwidth=4 tabstop=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use