VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp@ 22750

Last change on this file since 22750 was 22145, checked in by vboxsync, 15 years ago

video hw accel: expose to vboxmanage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 77.7 KB
Line 
1/* $Id: VBoxManageInfo.cpp 22145 2009-08-10 20:02:17Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'showvminfo' command and helper routines.
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef VBOX_ONLY_DOCS
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/com/com.h>
28#include <VBox/com/string.h>
29#include <VBox/com/Guid.h>
30#include <VBox/com/array.h>
31#include <VBox/com/ErrorInfo.h>
32#include <VBox/com/errorprint.h>
33
34#include <VBox/com/VirtualBox.h>
35
36#include <VBox/log.h>
37#include <iprt/stream.h>
38#include <iprt/time.h>
39#include <iprt/string.h>
40#include <iprt/getopt.h>
41#include <iprt/ctype.h>
42
43#include "VBoxManage.h"
44using namespace com;
45
46
47// funcs
48///////////////////////////////////////////////////////////////////////////////
49
50void showSnapshots(ComPtr<ISnapshot> rootSnapshot, VMINFO_DETAILS details, const Bstr &prefix /* = ""*/, int level /*= 0*/)
51{
52 /* start with the root */
53 Bstr name;
54 Bstr uuid;
55 rootSnapshot->COMGETTER(Name)(name.asOutParam());
56 rootSnapshot->COMGETTER(Id)(uuid.asOutParam());
57 if (details == VMINFO_MACHINEREADABLE)
58 {
59 /* print with hierarchical numbering */
60 RTPrintf("SnapshotName%lS=\"%lS\"\n", prefix.raw(), name.raw());
61 RTPrintf("SnapshotUUID%lS=\"%s\"\n", prefix.raw(), Utf8Str(uuid).raw());
62 }
63 else
64 {
65 /* print with indentation */
66 RTPrintf(" %lSName: %lS (UUID: %s)\n", prefix.raw(), name.raw(), Utf8Str(uuid).raw());
67 }
68
69 /* get the children */
70 SafeIfaceArray <ISnapshot> coll;
71 rootSnapshot->COMGETTER(Children)(ComSafeArrayAsOutParam(coll));
72 if (!coll.isNull())
73 {
74 for (size_t index = 0; index < coll.size(); ++index)
75 {
76 ComPtr<ISnapshot> snapshot = coll[index];
77 if (snapshot)
78 {
79 Bstr newPrefix;
80 if (details == VMINFO_MACHINEREADABLE)
81 newPrefix = Utf8StrFmt("%lS-%d", prefix.raw(), index + 1);
82 else
83 newPrefix = Utf8StrFmt("%lS ", prefix.raw());
84 /* recursive call */
85 showSnapshots(snapshot, details, newPrefix, level + 1);
86 }
87 }
88 }
89}
90
91static void makeTimeStr (char *s, int cb, int64_t millies)
92{
93 RTTIME t;
94 RTTIMESPEC ts;
95
96 RTTimeSpecSetMilli(&ts, millies);
97
98 RTTimeExplode (&t, &ts);
99
100 RTStrPrintf(s, cb, "%04d/%02d/%02d %02d:%02d:%02d UTC",
101 t.i32Year, t.u8Month, t.u8MonthDay,
102 t.u8Hour, t.u8Minute, t.u8Second);
103}
104
105/* Disable global optimizations for MSC 8.0/64 to make it compile in reasonable
106 time. MSC 7.1/32 doesn't have quite as much trouble with it, but still
107 sufficient to qualify for this hack as well since this code isn't performance
108 critical and probably won't gain much from the extra optimizing in real life. */
109#if defined(_MSC_VER)
110# pragma optimize("g", off)
111#endif
112
113HRESULT showVMInfo (ComPtr<IVirtualBox> virtualBox,
114 ComPtr<IMachine> machine,
115 VMINFO_DETAILS details /*= VMINFO_NONE*/,
116 ComPtr<IConsole> console /*= ComPtr <IConsole> ()*/)
117{
118 HRESULT rc;
119
120 /*
121 * The rules for output in -argdump format:
122 * 1) the key part (the [0-9a-zA-Z_]+ string before the '=' delimiter)
123 * is all lowercase for "VBoxManage modifyvm" parameters. Any
124 * other values printed are in CamelCase.
125 * 2) strings (anything non-decimal) are printed surrounded by
126 * double quotes '"'. If the strings themselves contain double
127 * quotes, these characters are escaped by '\'. Any '\' character
128 * in the original string is also escaped by '\'.
129 * 3) numbers (containing just [0-9\-]) are written out unchanged.
130 */
131
132 /** @todo the quoting is not yet implemented! */
133 /** @todo error checking! */
134
135 BOOL accessible = FALSE;
136 CHECK_ERROR (machine, COMGETTER(Accessible) (&accessible));
137 CheckComRCReturnRC (rc);
138
139 Bstr uuid;
140 rc = machine->COMGETTER(Id) (uuid.asOutParam());
141
142 if (!accessible)
143 {
144 if (details == VMINFO_COMPACT)
145 RTPrintf("\"<inaccessible>\" {%s}\n", Utf8Str(uuid).raw());
146 else
147 {
148 if (details == VMINFO_MACHINEREADABLE)
149 RTPrintf("name=\"<inaccessible>\"\n");
150 else
151 RTPrintf ("Name: <inaccessible!>\n");
152 if (details == VMINFO_MACHINEREADABLE)
153 RTPrintf ("UUID=\"%s\"\n", Utf8Str(uuid).raw());
154 else
155 RTPrintf ("UUID: %s\n", Utf8Str(uuid).raw());
156 if (details != VMINFO_MACHINEREADABLE)
157 {
158 Bstr settingsFilePath;
159 rc = machine->COMGETTER(SettingsFilePath) (settingsFilePath.asOutParam());
160 RTPrintf ("Config file: %lS\n", settingsFilePath.raw());
161 ComPtr<IVirtualBoxErrorInfo> accessError;
162 rc = machine->COMGETTER(AccessError) (accessError.asOutParam());
163 RTPrintf ("Access error details:\n");
164 ErrorInfo ei (accessError);
165 GluePrintErrorInfo(ei);
166 RTPrintf ("\n");
167 }
168 }
169 return S_OK;
170 }
171
172 Bstr machineName;
173 rc = machine->COMGETTER(Name)(machineName.asOutParam());
174
175 if (details == VMINFO_COMPACT)
176 {
177 RTPrintf("\"%lS\" {%s}\n", machineName.raw(), Utf8Str(uuid).raw());
178 return S_OK;
179 }
180
181 if (details == VMINFO_MACHINEREADABLE)
182 RTPrintf("name=\"%lS\"\n", machineName.raw());
183 else
184 RTPrintf("Name: %lS\n", machineName.raw());
185
186 Bstr osTypeId;
187 rc = machine->COMGETTER(OSTypeId)(osTypeId.asOutParam());
188 ComPtr<IGuestOSType> osType;
189 rc = virtualBox->GetGuestOSType (osTypeId, osType.asOutParam());
190 Bstr osName;
191 rc = osType->COMGETTER(Description)(osName.asOutParam());
192 if (details == VMINFO_MACHINEREADABLE)
193 RTPrintf("ostype=\"%lS\"\n", osTypeId.raw());
194 else
195 RTPrintf("Guest OS: %lS\n", osName.raw());
196
197 if (details == VMINFO_MACHINEREADABLE)
198 RTPrintf("UUID=\"%s\"\n", Utf8Str(uuid).raw());
199 else
200 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
201
202 Bstr settingsFilePath;
203 rc = machine->COMGETTER(SettingsFilePath)(settingsFilePath.asOutParam());
204 if (details == VMINFO_MACHINEREADABLE)
205 RTPrintf("CfgFile=\"%lS\"\n", settingsFilePath.raw());
206 else
207 RTPrintf("Config file: %lS\n", settingsFilePath.raw());
208
209 ULONG memorySize;
210 rc = machine->COMGETTER(MemorySize)(&memorySize);
211 if (details == VMINFO_MACHINEREADABLE)
212 RTPrintf("memory=%u\n", memorySize);
213 else
214 RTPrintf("Memory size: %uMB\n", memorySize);
215
216 ULONG vramSize;
217 rc = machine->COMGETTER(VRAMSize)(&vramSize);
218 if (details == VMINFO_MACHINEREADABLE)
219 RTPrintf("vram=%u\n", vramSize);
220 else
221 RTPrintf("VRAM size: %uMB\n", vramSize);
222
223 ULONG numCpus;
224 rc = machine->COMGETTER(CPUCount)(&numCpus);
225 if (details == VMINFO_MACHINEREADABLE)
226 RTPrintf("cpus=%u\n", numCpus);
227 else
228 RTPrintf("Number of CPUs: %u\n", numCpus);
229
230 ComPtr <IBIOSSettings> biosSettings;
231 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
232
233 BIOSBootMenuMode_T bootMenuMode;
234 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
235 const char *pszBootMenu = NULL;
236 switch (bootMenuMode)
237 {
238 case BIOSBootMenuMode_Disabled:
239 pszBootMenu = "disabled";
240 break;
241 case BIOSBootMenuMode_MenuOnly:
242 if (details == VMINFO_MACHINEREADABLE)
243 pszBootMenu = "menuonly";
244 else
245 pszBootMenu = "menu only";
246 break;
247 default:
248 if (details == VMINFO_MACHINEREADABLE)
249 pszBootMenu = "messageandmenu";
250 else
251 pszBootMenu = "message and menu";
252 }
253 if (details == VMINFO_MACHINEREADABLE)
254 RTPrintf("bootmenu=\"%s\"\n", pszBootMenu);
255 else
256 RTPrintf("Boot menu mode: %s\n", pszBootMenu);
257
258 ULONG maxBootPosition = 0;
259 ComPtr<ISystemProperties> systemProperties;
260 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
261 systemProperties->COMGETTER(MaxBootPosition)(&maxBootPosition);
262 for (ULONG i = 1; i <= maxBootPosition; i++)
263 {
264 DeviceType_T bootOrder;
265 machine->GetBootOrder(i, &bootOrder);
266 if (bootOrder == DeviceType_Floppy)
267 {
268 if (details == VMINFO_MACHINEREADABLE)
269 RTPrintf("boot%d=\"floppy\"\n", i);
270 else
271 RTPrintf("Boot Device (%d): Floppy\n", i);
272 }
273 else if (bootOrder == DeviceType_DVD)
274 {
275 if (details == VMINFO_MACHINEREADABLE)
276 RTPrintf("boot%d=\"dvd\"\n", i);
277 else
278 RTPrintf("Boot Device (%d): DVD\n", i);
279 }
280 else if (bootOrder == DeviceType_HardDisk)
281 {
282 if (details == VMINFO_MACHINEREADABLE)
283 RTPrintf("boot%d=\"disk\"\n", i);
284 else
285 RTPrintf("Boot Device (%d): HardDisk\n", i);
286 }
287 else if (bootOrder == DeviceType_Network)
288 {
289 if (details == VMINFO_MACHINEREADABLE)
290 RTPrintf("boot%d=\"net\"\n", i);
291 else
292 RTPrintf("Boot Device (%d): Network\n", i);
293 }
294 else if (bootOrder == DeviceType_USB)
295 {
296 if (details == VMINFO_MACHINEREADABLE)
297 RTPrintf("boot%d=\"usb\"\n", i);
298 else
299 RTPrintf("Boot Device (%d): USB\n", i);
300 }
301 else if (bootOrder == DeviceType_SharedFolder)
302 {
303 if (details == VMINFO_MACHINEREADABLE)
304 RTPrintf("boot%d=\"sharedfolder\"\n", i);
305 else
306 RTPrintf("Boot Device (%d): Shared Folder\n", i);
307 }
308 else
309 {
310 if (details == VMINFO_MACHINEREADABLE)
311 RTPrintf("boot%d=\"none\"\n", i);
312 else
313 RTPrintf("Boot Device (%d): Not Assigned\n", i);
314 }
315 }
316
317 BOOL acpiEnabled;
318 biosSettings->COMGETTER(ACPIEnabled)(&acpiEnabled);
319 if (details == VMINFO_MACHINEREADABLE)
320 RTPrintf("acpi=\"%s\"\n", acpiEnabled ? "on" : "off");
321 else
322 RTPrintf("ACPI: %s\n", acpiEnabled ? "on" : "off");
323
324 BOOL ioapicEnabled;
325 biosSettings->COMGETTER(IOAPICEnabled)(&ioapicEnabled);
326 if (details == VMINFO_MACHINEREADABLE)
327 RTPrintf("ioapic=\"%s\"\n", ioapicEnabled ? "on" : "off");
328 else
329 RTPrintf("IOAPIC: %s\n", ioapicEnabled ? "on" : "off");
330
331 BOOL PAEEnabled;
332 machine->COMGETTER(PAEEnabled)(&PAEEnabled);
333 if (details == VMINFO_MACHINEREADABLE)
334 RTPrintf("pae=\"%s\"\n", PAEEnabled ? "on" : "off");
335 else
336 RTPrintf("PAE: %s\n", PAEEnabled ? "on" : "off");
337
338 LONG64 timeOffset;
339 biosSettings->COMGETTER(TimeOffset)(&timeOffset);
340 if (details == VMINFO_MACHINEREADABLE)
341 RTPrintf("biossystemtimeoffset=%lld\n", timeOffset);
342 else
343 RTPrintf("Time offset: %lld ms\n", timeOffset);
344
345 BOOL hwVirtExEnabled;
346 machine->COMGETTER(HWVirtExEnabled)(&hwVirtExEnabled);
347 if (details == VMINFO_MACHINEREADABLE)
348 RTPrintf("hwvirtex=\"%s\"\n", hwVirtExEnabled ? "on" : "off");
349 else
350 RTPrintf("Hardw. virt.ext: %s\n", hwVirtExEnabled ? "on" : "off");
351 BOOL HWVirtExNestedPagingEnabled;
352 machine->COMGETTER(HWVirtExNestedPagingEnabled)(&HWVirtExNestedPagingEnabled);
353 if (details == VMINFO_MACHINEREADABLE)
354 RTPrintf("nestedpaging=\"%s\"\n", HWVirtExNestedPagingEnabled ? "on" : "off");
355 else
356 RTPrintf("Nested Paging: %s\n", HWVirtExNestedPagingEnabled ? "on" : "off");
357
358 BOOL HWVirtExVPIDEnabled;
359 machine->COMGETTER(HWVirtExVPIDEnabled)(&HWVirtExVPIDEnabled);
360 if (details == VMINFO_MACHINEREADABLE)
361 RTPrintf("vtxvpid=\"%s\"\n", HWVirtExVPIDEnabled ? "on" : "off");
362 else
363 RTPrintf("VT-x VPID: %s\n", HWVirtExVPIDEnabled ? "on" : "off");
364
365 MachineState_T machineState;
366 const char *pszState = NULL;
367 rc = machine->COMGETTER(State)(&machineState);
368 switch (machineState)
369 {
370 case MachineState_PoweredOff:
371 if (details == VMINFO_MACHINEREADABLE)
372 pszState = "poweroff";
373 else
374 pszState = "powered off";
375 break;
376 case MachineState_Saved:
377 pszState = "saved";
378 break;
379 case MachineState_Aborted:
380 pszState = "aborted";
381 break;
382 case MachineState_Running:
383 pszState = "running";
384 break;
385 case MachineState_Paused:
386 pszState = "paused";
387 break;
388 case MachineState_Starting:
389 pszState = "starting";
390 break;
391 case MachineState_Stopping:
392 pszState = "stopping";
393 break;
394 case MachineState_Saving:
395 pszState = "saving";
396 break;
397 case MachineState_Restoring:
398 pszState = "restoring";
399 break;
400 default:
401 pszState = "unknown";
402 break;
403 }
404 LONG64 stateSince;
405 machine->COMGETTER(LastStateChange)(&stateSince);
406 RTTIMESPEC timeSpec;
407 RTTimeSpecSetMilli(&timeSpec, stateSince);
408 char pszTime[30] = {0};
409 RTTimeSpecToString(&timeSpec, pszTime, sizeof(pszTime));
410 if (details == VMINFO_MACHINEREADABLE)
411 {
412 RTPrintf("VMState=\"%s\"\n", pszState);
413 RTPrintf("VMStateChangeTime=\"%s\"\n", pszTime);
414 }
415 else
416 RTPrintf("State: %s (since %s)\n", pszState, pszTime);
417
418 ULONG numMonitors;
419 machine->COMGETTER(MonitorCount)(&numMonitors);
420 if (details == VMINFO_MACHINEREADABLE)
421 RTPrintf("monitorcount=%d\n", numMonitors);
422 else
423 RTPrintf("Monitor count: %d\n", numMonitors);
424
425 BOOL accelerate3d;
426 machine->COMGETTER(Accelerate3DEnabled)(&accelerate3d);
427 if (details == VMINFO_MACHINEREADABLE)
428 RTPrintf("accelerate3d=\"%s\"\n", accelerate3d ? "on" : "off");
429 else
430 RTPrintf("3D Acceleration: %s\n", accelerate3d ? "on" : "off");
431
432#ifdef VBOX_WITH_VIDEOHWACCEL
433 BOOL accelerate2dVideo;
434 machine->COMGETTER(Accelerate2DVideoEnabled)(&accelerate2dVideo);
435 if (details == VMINFO_MACHINEREADABLE)
436 RTPrintf("accelerate2dvideo=\"%s\"\n", accelerate2dVideo ? "on" : "off");
437 else
438 RTPrintf("2D Video Acceleration: %s\n", accelerate2dVideo ? "on" : "off");
439#endif
440
441 ComPtr<IFloppyDrive> floppyDrive;
442 rc = machine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
443 if (SUCCEEDED(rc) && floppyDrive)
444 {
445 BOOL fFloppyEnabled;
446 floppyDrive->COMGETTER(Enabled)(&fFloppyEnabled);
447 Utf8Str pszFloppy = "invalid";
448 if (fFloppyEnabled)
449 {
450 DriveState_T floppyState;
451 floppyDrive->COMGETTER(State)(&floppyState);
452 switch (floppyState)
453 {
454 case DriveState_ImageMounted:
455 {
456 ComPtr<IFloppyImage> floppyImage;
457 rc = floppyDrive->GetImage(floppyImage.asOutParam());
458 if (SUCCEEDED(rc) && floppyImage)
459 {
460 Bstr imagePath;
461 floppyImage->COMGETTER(Location)(imagePath.asOutParam());
462 Bstr imageGuid;
463 floppyImage->COMGETTER(Id)(imageGuid.asOutParam());
464 if (details == VMINFO_MACHINEREADABLE)
465 {
466 RTPrintf("FloppyImageUUID=\"%s\"\n", Utf8Str(imageGuid).raw());
467 pszFloppy = Utf8StrFmt("%lS", imagePath.raw());
468 }
469 else
470 pszFloppy = Utf8StrFmt("%lS (UUID: %s)", imagePath.raw(), Utf8Str(imageGuid).raw());
471 }
472 break;
473 }
474
475 case DriveState_HostDriveCaptured:
476 {
477 ComPtr<IHostFloppyDrive> hostFloppyDrive;
478 rc = floppyDrive->GetHostDrive(hostFloppyDrive.asOutParam());
479 if (SUCCEEDED(rc) && floppyDrive)
480 {
481 Bstr driveName;
482 hostFloppyDrive->COMGETTER(Name)(driveName.asOutParam());
483 if (details == VMINFO_MACHINEREADABLE)
484 pszFloppy = Utf8StrFmt("host:%lS", driveName.raw());
485 else
486 pszFloppy = Utf8StrFmt("Host drive %lS", driveName.raw());
487 }
488 break;
489 }
490
491 case DriveState_NotMounted:
492 {
493 pszFloppy = "empty";
494 break;
495 }
496 }
497 }
498 else
499 {
500 pszFloppy = "disabled";
501 }
502 if (details == VMINFO_MACHINEREADABLE)
503 RTPrintf("floppy=\"%s\"\n", pszFloppy.raw());
504 else
505 RTPrintf("Floppy: %s\n", pszFloppy.raw());
506 }
507
508 /*
509 * SATA.
510 *
511 * Contributed by: James Lucas
512 */
513#ifdef VBOX_WITH_AHCI
514 ComPtr<IStorageController> SataCtl;
515 bool fSataEnabled = false;
516
517 rc = machine->GetStorageControllerByName(Bstr("SATA"), SataCtl.asOutParam());
518 if (SUCCEEDED(rc))
519 fSataEnabled = true;
520
521 if (details == VMINFO_MACHINEREADABLE)
522 RTPrintf("sata=\"%s\"\n", fSataEnabled ? "on" : "off");
523 else
524 RTPrintf("SATA: %s\n", fSataEnabled ? "enabled" : "disabled");
525
526 /*
527 * SATA Hard disks
528 */
529 if (fSataEnabled)
530 {
531 ComPtr<IHardDisk> hardDisk;
532 Bstr filePath;
533 ULONG cSataPorts;
534
535 SataCtl->COMGETTER(PortCount)(&cSataPorts);
536 for (ULONG i = 0; i < cSataPorts; ++ i)
537 {
538 rc = machine->GetHardDisk(Bstr("SATA"), i, 0, hardDisk.asOutParam());
539 if (SUCCEEDED(rc) && hardDisk)
540 {
541 hardDisk->COMGETTER(Location)(filePath.asOutParam());
542 hardDisk->COMGETTER(Id)(uuid.asOutParam());
543 if (details == VMINFO_MACHINEREADABLE)
544 {
545 RTPrintf("sataport%d=\"%lS\"\n", i, filePath.raw());
546 RTPrintf("SataPortImageUUID%d=\"%s\"\n", i, Utf8Str(uuid).raw());
547 }
548 else
549 RTPrintf("SATA %d: %lS (UUID: %s)\n", i, filePath.raw(), Utf8Str(uuid).raw());
550 }
551 else
552 {
553 if (details == VMINFO_MACHINEREADABLE)
554 RTPrintf("sata%d=\"none\"\n",i);
555 }
556 }
557 }
558#endif
559
560 /*
561 * IDE Hard disks
562 */
563 ComPtr<IStorageController> ideController;
564
565 rc = machine->GetStorageControllerByName(Bstr("IDE"), ideController.asOutParam());
566 if (SUCCEEDED(rc) && ideController)
567 {
568 StorageControllerType_T enmIdeController;
569 const char *pszIdeController = NULL;
570
571 rc = ideController->COMGETTER(ControllerType)(&enmIdeController);
572
573 switch (enmIdeController)
574 {
575 case StorageControllerType_PIIX3:
576 pszIdeController = "PIIX3";
577 break;
578 case StorageControllerType_PIIX4:
579 pszIdeController = "PIIX4";
580 break;
581 case StorageControllerType_ICH6:
582 pszIdeController = "ICH6";
583 break;
584 default:
585 pszIdeController = "unknown";
586 }
587 if (details == VMINFO_MACHINEREADABLE)
588 RTPrintf("idecontroller=\"%s\"\n", pszIdeController);
589 else
590 RTPrintf("IDE Controller: %s\n", pszIdeController);
591 }
592
593 ComPtr<IHardDisk> hardDisk;
594 Bstr filePath;
595 rc = machine->GetHardDisk(Bstr("IDE"), 0, 0, hardDisk.asOutParam());
596 if (SUCCEEDED(rc) && hardDisk)
597 {
598 hardDisk->COMGETTER(Location)(filePath.asOutParam());
599 hardDisk->COMGETTER(Id)(uuid.asOutParam());
600 if (details == VMINFO_MACHINEREADABLE)
601 {
602 RTPrintf("hda=\"%lS\"\n", filePath.raw());
603 RTPrintf("HdaImageUUID=\"%s\"\n", Utf8Str(uuid).raw());
604 }
605 else
606 RTPrintf("Primary master: %lS (UUID: %s)\n", filePath.raw(), Utf8Str(uuid).raw());
607 }
608 else
609 {
610 if (details == VMINFO_MACHINEREADABLE)
611 RTPrintf("hda=\"none\"\n");
612 }
613 rc = machine->GetHardDisk(Bstr("IDE"), 0, 1, hardDisk.asOutParam());
614 if (SUCCEEDED(rc) && hardDisk)
615 {
616 hardDisk->COMGETTER(Location)(filePath.asOutParam());
617 hardDisk->COMGETTER(Id)(uuid.asOutParam());
618 if (details == VMINFO_MACHINEREADABLE)
619 {
620 RTPrintf("hdb=\"%lS\"\n", filePath.raw());
621 RTPrintf("HdbImageUUID=\"%s\"\n", Utf8Str(uuid).raw());
622 }
623 else
624 RTPrintf("Primary slave: %lS (UUID: %s)\n", filePath.raw(), Utf8Str(uuid).raw());
625 }
626 else
627 {
628 if (details == VMINFO_MACHINEREADABLE)
629 RTPrintf("hdb=\"none\"\n");
630 }
631 rc = machine->GetHardDisk(Bstr("IDE"), 1, 1, hardDisk.asOutParam());
632 if (SUCCEEDED(rc) && hardDisk)
633 {
634 hardDisk->COMGETTER(Location)(filePath.asOutParam());
635 hardDisk->COMGETTER(Id)(uuid.asOutParam());
636 if (details == VMINFO_MACHINEREADABLE)
637 {
638 RTPrintf("hdd=\"%lS\"\n", filePath.raw());
639 RTPrintf("HddImageUUID=\"%s\"\n", Utf8Str(uuid).raw());
640 }
641 else
642 RTPrintf("Secondary slave: %lS (UUID: %s)\n", filePath.raw(), Utf8Str(uuid).raw());
643 }
644 else
645 {
646 if (details == VMINFO_MACHINEREADABLE)
647 RTPrintf("hdd=\"none\"\n");
648 }
649 ComPtr<IDVDDrive> dvdDrive;
650 rc = machine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
651 if (SUCCEEDED(rc) && dvdDrive)
652 {
653 ComPtr<IDVDImage> dvdImage;
654 rc = dvdDrive->GetImage(dvdImage.asOutParam());
655 if (SUCCEEDED(rc) && dvdImage)
656 {
657 rc = dvdImage->COMGETTER(Location)(filePath.asOutParam());
658 if (SUCCEEDED(rc) && filePath)
659 {
660 rc = dvdImage->COMGETTER(Id)(uuid.asOutParam());
661 if (details == VMINFO_MACHINEREADABLE)
662 {
663 RTPrintf("dvd=\"%lS\"\n", filePath.raw());
664 RTPrintf("DvdImageUUID=\"%s\"\n", Utf8Str(uuid).raw());
665 }
666 else
667 RTPrintf("DVD: %lS (UUID: %s)\n", filePath.raw(), Utf8Str(uuid).raw());
668 }
669 }
670 else
671 {
672 ComPtr<IHostDVDDrive> hostDVDDrive;
673 rc = dvdDrive->GetHostDrive(hostDVDDrive.asOutParam());
674 if (SUCCEEDED(rc) && hostDVDDrive)
675 {
676 Bstr name;
677 hostDVDDrive->COMGETTER(Name)(name.asOutParam());
678 if (details == VMINFO_MACHINEREADABLE)
679 RTPrintf("dvd=\"host:%lS\"\n", name.raw());
680 else
681 RTPrintf("DVD: Host drive %lS", name.raw());
682 }
683 else
684 {
685 if (details == VMINFO_MACHINEREADABLE)
686 RTPrintf("dvd=\"none\"\n");
687 else
688 RTPrintf("DVD: empty");
689 }
690 BOOL fPassthrough;
691 dvdDrive->COMGETTER(Passthrough)(&fPassthrough);
692 if (details == VMINFO_MACHINEREADABLE)
693 {
694 RTPrintf("dvdpassthrough=\"%s\"\n", fPassthrough ? "on" : "off");
695 }
696 else
697 {
698 if (fPassthrough)
699 RTPrintf(" (passthrough enabled)");
700 RTPrintf("\n");
701 }
702 }
703 }
704
705 /* get the maximum amount of NICS */
706 ComPtr<ISystemProperties> sysProps;
707 virtualBox->COMGETTER(SystemProperties)(sysProps.asOutParam());
708 ULONG maxNICs = 0;
709 sysProps->COMGETTER(NetworkAdapterCount)(&maxNICs);
710 for (ULONG currentNIC = 0; currentNIC < maxNICs; currentNIC++)
711 {
712 ComPtr<INetworkAdapter> nic;
713 rc = machine->GetNetworkAdapter(currentNIC, nic.asOutParam());
714 if (SUCCEEDED(rc) && nic)
715 {
716 BOOL fEnabled;
717 nic->COMGETTER(Enabled)(&fEnabled);
718 if (!fEnabled)
719 {
720 if (details == VMINFO_MACHINEREADABLE)
721 RTPrintf("nic%d=\"none\"\n", currentNIC + 1);
722 else
723 RTPrintf("NIC %d: disabled\n", currentNIC + 1);
724 }
725 else
726 {
727 Bstr strMACAddress;
728 nic->COMGETTER(MACAddress)(strMACAddress.asOutParam());
729 Utf8Str strAttachment;
730 NetworkAttachmentType_T attachment;
731 nic->COMGETTER(AttachmentType)(&attachment);
732 switch (attachment)
733 {
734 case NetworkAttachmentType_Null:
735 if (details == VMINFO_MACHINEREADABLE)
736 strAttachment = "null";
737 else
738 strAttachment = "none";
739 break;
740 case NetworkAttachmentType_NAT:
741 {
742 Bstr strNetwork;
743 nic->COMGETTER(NATNetwork)(strNetwork.asOutParam());
744 if (details == VMINFO_MACHINEREADABLE)
745 {
746 RTPrintf("natnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.raw());
747 strAttachment = "nat";
748 }
749 else if (!strNetwork.isEmpty())
750 strAttachment = Utf8StrFmt("NAT (%lS)", strNetwork.raw());
751 else
752 strAttachment = "NAT";
753 break;
754 }
755 case NetworkAttachmentType_Bridged:
756 {
757 Bstr strBridgeAdp;
758 nic->COMGETTER(HostInterface)(strBridgeAdp.asOutParam());
759 if (details == VMINFO_MACHINEREADABLE)
760 {
761 RTPrintf("bridgeadapter%d=\"%lS\"\n", currentNIC + 1, strBridgeAdp.raw());
762 strAttachment = "bridged";
763 }
764 else
765 strAttachment = Utf8StrFmt("Bridged Interface '%lS'", strBridgeAdp.raw());
766 break;
767 }
768 case NetworkAttachmentType_Internal:
769 {
770 Bstr strNetwork;
771 nic->COMGETTER(InternalNetwork)(strNetwork.asOutParam());
772 if (details == VMINFO_MACHINEREADABLE)
773 {
774 RTPrintf("intnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.raw());
775 strAttachment = "intnet";
776 }
777 else
778 strAttachment = Utf8StrFmt("Internal Network '%s'", Utf8Str(strNetwork).raw());
779 break;
780 }
781#if defined(VBOX_WITH_NETFLT)
782 case NetworkAttachmentType_HostOnly:
783 {
784 Bstr strHostonlyAdp;
785 nic->COMGETTER(HostInterface)(strHostonlyAdp.asOutParam());
786 if (details == VMINFO_MACHINEREADABLE)
787 {
788 RTPrintf("hostonlyadapter%d=\"%lS\"\n", currentNIC + 1, strHostonlyAdp.raw());
789 strAttachment = "hostonly";
790 }
791 else
792 strAttachment = Utf8StrFmt("Host-only Interface '%lS'", strHostonlyAdp.raw());
793 break;
794 }
795#endif
796 default:
797 strAttachment = "unknown";
798 break;
799 }
800
801 /* cable connected */
802 BOOL fConnected;
803 nic->COMGETTER(CableConnected)(&fConnected);
804
805 /* trace stuff */
806 BOOL fTraceEnabled;
807 nic->COMGETTER(TraceEnabled)(&fTraceEnabled);
808 Bstr traceFile;
809 nic->COMGETTER(TraceFile)(traceFile.asOutParam());
810
811 /* NIC type */
812 Utf8Str strNICType;
813 NetworkAdapterType_T NICType;
814 nic->COMGETTER(AdapterType)(&NICType);
815 switch (NICType) {
816 case NetworkAdapterType_Am79C970A:
817 strNICType = "Am79C970A";
818 break;
819 case NetworkAdapterType_Am79C973:
820 strNICType = "Am79C973";
821 break;
822#ifdef VBOX_WITH_E1000
823 case NetworkAdapterType_I82540EM:
824 strNICType = "82540EM";
825 break;
826 case NetworkAdapterType_I82543GC:
827 strNICType = "82543GC";
828 break;
829 case NetworkAdapterType_I82545EM:
830 strNICType = "82545EM";
831 break;
832#endif
833 default:
834 strNICType = "unknown";
835 break;
836 }
837
838 /* reported line speed */
839 ULONG ulLineSpeed;
840 nic->COMGETTER(LineSpeed)(&ulLineSpeed);
841
842 if (details == VMINFO_MACHINEREADABLE)
843 {
844 RTPrintf("macaddress%d=\"%lS\"\n", currentNIC + 1, strMACAddress.raw());
845 RTPrintf("cableconnected%d=\"%s\"\n", currentNIC + 1, fConnected ? "on" : "off");
846 RTPrintf("nic%d=\"%s\"\n", currentNIC + 1, strAttachment.raw());
847 }
848 else
849 RTPrintf("NIC %d: MAC: %lS, Attachment: %s, Cable connected: %s, Trace: %s (file: %lS), Type: %s, Reported speed: %d Mbps\n",
850 currentNIC + 1, strMACAddress.raw(), strAttachment.raw(),
851 fConnected ? "on" : "off",
852 fTraceEnabled ? "on" : "off",
853 traceFile.isEmpty() ? Bstr("none").raw() : traceFile.raw(),
854 strNICType.raw(),
855 ulLineSpeed / 1000);
856 }
857 }
858 }
859
860 /* get the maximum amount of UARTs */
861 ULONG maxUARTs = 0;
862 sysProps->COMGETTER(SerialPortCount)(&maxUARTs);
863 for (ULONG currentUART = 0; currentUART < maxUARTs; currentUART++)
864 {
865 ComPtr<ISerialPort> uart;
866 rc = machine->GetSerialPort(currentUART, uart.asOutParam());
867 if (SUCCEEDED(rc) && uart)
868 {
869 BOOL fEnabled;
870 uart->COMGETTER(Enabled)(&fEnabled);
871 if (!fEnabled)
872 {
873 if (details == VMINFO_MACHINEREADABLE)
874 RTPrintf("uart%d=\"off\"\n", currentUART + 1);
875 else
876 RTPrintf("UART %d: disabled\n", currentUART + 1);
877 }
878 else
879 {
880 ULONG ulIRQ, ulIOBase;
881 PortMode_T HostMode;
882 Bstr path;
883 BOOL fServer;
884 uart->COMGETTER(IRQ)(&ulIRQ);
885 uart->COMGETTER(IOBase)(&ulIOBase);
886 uart->COMGETTER(Path)(path.asOutParam());
887 uart->COMGETTER(Server)(&fServer);
888 uart->COMGETTER(HostMode)(&HostMode);
889
890 if (details == VMINFO_MACHINEREADABLE)
891 RTPrintf("uart%d=\"%#06x,%d\"\n", currentUART + 1,
892 ulIOBase, ulIRQ);
893 else
894 RTPrintf("UART %d: I/O base: 0x%04x, IRQ: %d",
895 currentUART + 1, ulIOBase, ulIRQ);
896 switch (HostMode)
897 {
898 default:
899 case PortMode_Disconnected:
900 if (details == VMINFO_MACHINEREADABLE)
901 RTPrintf("uartmode%d=\"disconnected\"\n", currentUART + 1);
902 else
903 RTPrintf(", disconnected\n");
904 break;
905 case PortMode_RawFile:
906 if (details == VMINFO_MACHINEREADABLE)
907 RTPrintf("uartmode%d=\"%lS\"\n", currentUART + 1,
908 path.raw());
909 else
910 RTPrintf(", attached to raw file '%lS'\n",
911 path.raw());
912 break;
913 case PortMode_HostPipe:
914 if (details == VMINFO_MACHINEREADABLE)
915 RTPrintf("uartmode%d=\"%s,%lS\"\n", currentUART + 1,
916 fServer ? "server" : "client", path.raw());
917 else
918 RTPrintf(", attached to pipe (%s) '%lS'\n",
919 fServer ? "server" : "client", path.raw());
920 break;
921 case PortMode_HostDevice:
922 if (details == VMINFO_MACHINEREADABLE)
923 RTPrintf("uartmode%d=\"%lS\"\n", currentUART + 1,
924 path.raw());
925 else
926 RTPrintf(", attached to device '%lS'\n", path.raw());
927 break;
928 }
929 }
930 }
931 }
932
933 ComPtr<IAudioAdapter> AudioAdapter;
934 rc = machine->COMGETTER(AudioAdapter)(AudioAdapter.asOutParam());
935 if (SUCCEEDED(rc))
936 {
937 const char *pszDrv = "Unknown";
938 const char *pszCtrl = "Unknown";
939 BOOL fEnabled;
940 rc = AudioAdapter->COMGETTER(Enabled)(&fEnabled);
941 if (SUCCEEDED(rc) && fEnabled)
942 {
943 AudioDriverType_T enmDrvType;
944 rc = AudioAdapter->COMGETTER(AudioDriver)(&enmDrvType);
945 switch (enmDrvType)
946 {
947 case AudioDriverType_Null:
948 if (details == VMINFO_MACHINEREADABLE)
949 pszDrv = "null";
950 else
951 pszDrv = "Null";
952 break;
953 case AudioDriverType_WinMM:
954 if (details == VMINFO_MACHINEREADABLE)
955 pszDrv = "winmm";
956 else
957 pszDrv = "WINMM";
958 break;
959 case AudioDriverType_DirectSound:
960 if (details == VMINFO_MACHINEREADABLE)
961 pszDrv = "dsound";
962 else
963 pszDrv = "DSOUND";
964 break;
965 case AudioDriverType_OSS:
966 if (details == VMINFO_MACHINEREADABLE)
967 pszDrv = "oss";
968 else
969 pszDrv = "OSS";
970 break;
971 case AudioDriverType_ALSA:
972 if (details == VMINFO_MACHINEREADABLE)
973 pszDrv = "alsa";
974 else
975 pszDrv = "ALSA";
976 break;
977 case AudioDriverType_Pulse:
978 if (details == VMINFO_MACHINEREADABLE)
979 pszDrv = "pulse";
980 else
981 pszDrv = "PulseAudio";
982 break;
983 case AudioDriverType_CoreAudio:
984 if (details == VMINFO_MACHINEREADABLE)
985 pszDrv = "coreaudio";
986 else
987 pszDrv = "CoreAudio";
988 break;
989 case AudioDriverType_SolAudio:
990 if (details == VMINFO_MACHINEREADABLE)
991 pszDrv = "solaudio";
992 else
993 pszDrv = "SolAudio";
994 break;
995 default:
996 if (details == VMINFO_MACHINEREADABLE)
997 pszDrv = "unknown";
998 break;
999 }
1000 AudioControllerType_T enmCtrlType;
1001 rc = AudioAdapter->COMGETTER(AudioController)(&enmCtrlType);
1002 switch (enmCtrlType)
1003 {
1004 case AudioControllerType_AC97:
1005 if (details == VMINFO_MACHINEREADABLE)
1006 pszCtrl = "ac97";
1007 else
1008 pszCtrl = "AC97";
1009 break;
1010 case AudioControllerType_SB16:
1011 if (details == VMINFO_MACHINEREADABLE)
1012 pszCtrl = "sb16";
1013 else
1014 pszCtrl = "SB16";
1015 break;
1016 }
1017 }
1018 else
1019 fEnabled = FALSE;
1020 if (details == VMINFO_MACHINEREADABLE)
1021 {
1022 if (fEnabled)
1023 RTPrintf("audio=\"%s\"\n", pszDrv);
1024 else
1025 RTPrintf("audio=\"none\"\n");
1026 }
1027 else
1028 {
1029 RTPrintf("Audio: %s",
1030 fEnabled ? "enabled" : "disabled");
1031 if (fEnabled)
1032 RTPrintf(" (Driver: %s, Controller: %s)",
1033 pszDrv, pszCtrl);
1034 RTPrintf("\n");
1035 }
1036 }
1037
1038 /* Shared clipboard */
1039 {
1040 const char *psz = "Unknown";
1041 ClipboardMode_T enmMode;
1042 rc = machine->COMGETTER(ClipboardMode)(&enmMode);
1043 switch (enmMode)
1044 {
1045 case ClipboardMode_Disabled:
1046 if (details == VMINFO_MACHINEREADABLE)
1047 psz = "disabled";
1048 else
1049 psz = "disabled";
1050 break;
1051 case ClipboardMode_HostToGuest:
1052 if (details == VMINFO_MACHINEREADABLE)
1053 psz = "hosttoguest";
1054 else
1055 psz = "HostToGuest";
1056 break;
1057 case ClipboardMode_GuestToHost:
1058 if (details == VMINFO_MACHINEREADABLE)
1059 psz = "guesttohost";
1060 else
1061 psz = "GuestToHost";
1062 break;
1063 case ClipboardMode_Bidirectional:
1064 if (details == VMINFO_MACHINEREADABLE)
1065 psz = "bidirectional";
1066 else
1067 psz = "Bidirectional";
1068 break;
1069 default:
1070 if (details == VMINFO_MACHINEREADABLE)
1071 psz = "unknown";
1072 break;
1073 }
1074 if (details == VMINFO_MACHINEREADABLE)
1075 RTPrintf("clipboard=\"%s\"\n", psz);
1076 else
1077 RTPrintf("Clipboard Mode: %s\n", psz);
1078 }
1079
1080 if (console)
1081 {
1082 ComPtr<IDisplay> display;
1083 CHECK_ERROR_RET(console, COMGETTER(Display)(display.asOutParam()), rc);
1084 do
1085 {
1086 ULONG xRes, yRes, bpp;
1087 rc = display->COMGETTER(Width)(&xRes);
1088 if (rc == E_ACCESSDENIED)
1089 break; /* VM not powered up */
1090 if (FAILED(rc))
1091 {
1092 com::ErrorInfo info (display);
1093 GluePrintErrorInfo(info);
1094 return rc;
1095 }
1096 rc = display->COMGETTER(Height)(&yRes);
1097 if (rc == E_ACCESSDENIED)
1098 break; /* VM not powered up */
1099 if (FAILED(rc))
1100 {
1101 com::ErrorInfo info (display);
1102 GluePrintErrorInfo(info);
1103 return rc;
1104 }
1105 rc = display->COMGETTER(BitsPerPixel)(&bpp);
1106 if (rc == E_ACCESSDENIED)
1107 break; /* VM not powered up */
1108 if (FAILED(rc))
1109 {
1110 com::ErrorInfo info (display);
1111 GluePrintErrorInfo(info);
1112 return rc;
1113 }
1114 if (details == VMINFO_MACHINEREADABLE)
1115 RTPrintf("VideoMode=\"%d,%d,%d\"\n", xRes, yRes, bpp);
1116 else
1117 RTPrintf("Video mode: %dx%dx%d\n", xRes, yRes, bpp);
1118 }
1119 while (0);
1120 }
1121
1122 /*
1123 * VRDP
1124 */
1125 ComPtr<IVRDPServer> vrdpServer;
1126 rc = machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1127 if (SUCCEEDED(rc) && vrdpServer)
1128 {
1129 BOOL fEnabled = false;
1130 vrdpServer->COMGETTER(Enabled)(&fEnabled);
1131 if (fEnabled)
1132 {
1133 ULONG port;
1134 vrdpServer->COMGETTER(Port)(&port);
1135 Bstr address;
1136 vrdpServer->COMGETTER(NetAddress)(address.asOutParam());
1137 BOOL fMultiCon;
1138 vrdpServer->COMGETTER(AllowMultiConnection)(&fMultiCon);
1139 BOOL fReuseCon;
1140 vrdpServer->COMGETTER(ReuseSingleConnection)(&fReuseCon);
1141 VRDPAuthType_T vrdpAuthType;
1142 const char *strAuthType;
1143 vrdpServer->COMGETTER(AuthType)(&vrdpAuthType);
1144 switch (vrdpAuthType)
1145 {
1146 case VRDPAuthType_Null:
1147 strAuthType = "null";
1148 break;
1149 case VRDPAuthType_External:
1150 strAuthType = "external";
1151 break;
1152 case VRDPAuthType_Guest:
1153 strAuthType = "guest";
1154 break;
1155 default:
1156 strAuthType = "unknown";
1157 break;
1158 }
1159 if (details == VMINFO_MACHINEREADABLE)
1160 {
1161 RTPrintf("vrdp=\"on\"\n");
1162 RTPrintf("vrdpport=%d\n", port);
1163 RTPrintf("vrdpaddress=\"%lS\"\n", address.raw());
1164 RTPrintf("vrdpauthtype=\"%s\"\n", strAuthType);
1165 RTPrintf("vrdpmulticon=\"%s\"\n", fMultiCon ? "on" : "off");
1166 RTPrintf("vrdpreusecon=\"%s\"\n", fReuseCon ? "on" : "off");
1167 }
1168 else
1169 {
1170 if (address.isEmpty())
1171 address = "0.0.0.0";
1172 RTPrintf("VRDP: enabled (Address %lS, Port %d, MultiConn: %s, ReuseSingleConn: %s, Authentication type: %s)\n", address.raw(), port, fMultiCon ? "on" : "off", fReuseCon ? "on" : "off", strAuthType);
1173 }
1174 }
1175 else
1176 {
1177 if (details == VMINFO_MACHINEREADABLE)
1178 RTPrintf("vrdp=\"off\"\n");
1179 else
1180 RTPrintf("VRDP: disabled\n");
1181 }
1182 }
1183
1184 /*
1185 * USB.
1186 */
1187 ComPtr<IUSBController> USBCtl;
1188 rc = machine->COMGETTER(USBController)(USBCtl.asOutParam());
1189 if (SUCCEEDED(rc))
1190 {
1191 BOOL fEnabled;
1192 rc = USBCtl->COMGETTER(Enabled)(&fEnabled);
1193 if (FAILED(rc))
1194 fEnabled = false;
1195 if (details == VMINFO_MACHINEREADABLE)
1196 RTPrintf("usb=\"%s\"\n", fEnabled ? "on" : "off");
1197 else
1198 RTPrintf("USB: %s\n", fEnabled ? "enabled" : "disabled");
1199
1200 if (details != VMINFO_MACHINEREADABLE)
1201 RTPrintf("\nUSB Device Filters:\n\n");
1202
1203 SafeIfaceArray <IUSBDeviceFilter> Coll;
1204 CHECK_ERROR_RET (USBCtl, COMGETTER(DeviceFilters)(ComSafeArrayAsOutParam(Coll)), rc);
1205
1206 if (Coll.size() == 0)
1207 {
1208 if (details != VMINFO_MACHINEREADABLE)
1209 RTPrintf("<none>\n\n");
1210 }
1211 else
1212 {
1213 for (size_t index = 0; index < Coll.size(); ++index)
1214 {
1215 ComPtr<IUSBDeviceFilter> DevPtr = Coll[index];
1216
1217 /* Query info. */
1218
1219 if (details != VMINFO_MACHINEREADABLE)
1220 RTPrintf("Index: %zu\n", index);
1221
1222 BOOL bActive = FALSE;
1223 CHECK_ERROR_RET (DevPtr, COMGETTER (Active) (&bActive), rc);
1224 if (details == VMINFO_MACHINEREADABLE)
1225 RTPrintf("USBFilterActive%zu=\"%s\"\n", index + 1, bActive ? "on" : "off");
1226 else
1227 RTPrintf("Active: %s\n", bActive ? "yes" : "no");
1228
1229 Bstr bstr;
1230 CHECK_ERROR_RET (DevPtr, COMGETTER (Name) (bstr.asOutParam()), rc);
1231 if (details == VMINFO_MACHINEREADABLE)
1232 RTPrintf("USBFilterName%zu=\"%lS\"\n", index + 1, bstr.raw());
1233 else
1234 RTPrintf("Name: %lS\n", bstr.raw());
1235 CHECK_ERROR_RET (DevPtr, COMGETTER (VendorId) (bstr.asOutParam()), rc);
1236 if (details == VMINFO_MACHINEREADABLE)
1237 RTPrintf("USBFilterVendorId%zu=\"%lS\"\n", index + 1, bstr.raw());
1238 else
1239 RTPrintf("VendorId: %lS\n", bstr.raw());
1240 CHECK_ERROR_RET (DevPtr, COMGETTER (ProductId) (bstr.asOutParam()), rc);
1241 if (details == VMINFO_MACHINEREADABLE)
1242 RTPrintf("USBFilterProductId%zu=\"%lS\"\n", index + 1, bstr.raw());
1243 else
1244 RTPrintf("ProductId: %lS\n", bstr.raw());
1245 CHECK_ERROR_RET (DevPtr, COMGETTER (Revision) (bstr.asOutParam()), rc);
1246 if (details == VMINFO_MACHINEREADABLE)
1247 RTPrintf("USBFilterRevision%zu=\"%lS\"\n", index + 1, bstr.raw());
1248 else
1249 RTPrintf("Revision: %lS\n", bstr.raw());
1250 CHECK_ERROR_RET (DevPtr, COMGETTER (Manufacturer) (bstr.asOutParam()), rc);
1251 if (details == VMINFO_MACHINEREADABLE)
1252 RTPrintf("USBFilterManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1253 else
1254 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1255 CHECK_ERROR_RET (DevPtr, COMGETTER (Product) (bstr.asOutParam()), rc);
1256 if (details == VMINFO_MACHINEREADABLE)
1257 RTPrintf("USBFilterProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1258 else
1259 RTPrintf("Product: %lS\n", bstr.raw());
1260 CHECK_ERROR_RET (DevPtr, COMGETTER (Remote) (bstr.asOutParam()), rc);
1261 if (details == VMINFO_MACHINEREADABLE)
1262 RTPrintf("USBFilterRemote%zu=\"%lS\"\n", index + 1, bstr.raw());
1263 else
1264 RTPrintf("Remote: %lS\n", bstr.raw());
1265 CHECK_ERROR_RET (DevPtr, COMGETTER (SerialNumber) (bstr.asOutParam()), rc);
1266 if (details == VMINFO_MACHINEREADABLE)
1267 RTPrintf("USBFilterSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1268 else
1269 RTPrintf("Serial Number: %lS\n", bstr.raw());
1270 if (details != VMINFO_MACHINEREADABLE)
1271 {
1272 ULONG fMaskedIfs;
1273 CHECK_ERROR_RET (DevPtr, COMGETTER (MaskedInterfaces) (&fMaskedIfs), rc);
1274 if (fMaskedIfs)
1275 RTPrintf("Masked Interfaces: 0x%08x\n", fMaskedIfs);
1276 RTPrintf("\n");
1277 }
1278 }
1279 }
1280
1281 if (console)
1282 {
1283 /* scope */
1284 {
1285 if (details != VMINFO_MACHINEREADABLE)
1286 RTPrintf("Available remote USB devices:\n\n");
1287
1288 SafeIfaceArray <IHostUSBDevice> coll;
1289 CHECK_ERROR_RET (console, COMGETTER(RemoteUSBDevices) (ComSafeArrayAsOutParam(coll)), rc);
1290
1291 if (coll.size() == 0)
1292 {
1293 if (details != VMINFO_MACHINEREADABLE)
1294 RTPrintf("<none>\n\n");
1295 }
1296 else
1297 {
1298 for (size_t index = 0; index < coll.size(); ++index)
1299 {
1300 ComPtr <IHostUSBDevice> dev = coll[index];
1301
1302 /* Query info. */
1303 Bstr id;
1304 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1305 USHORT usVendorId;
1306 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1307 USHORT usProductId;
1308 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1309 USHORT bcdRevision;
1310 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1311
1312 if (details == VMINFO_MACHINEREADABLE)
1313 RTPrintf("USBRemoteUUID%zu=\"%S\"\n"
1314 "USBRemoteVendorId%zu=\"%#06x\"\n"
1315 "USBRemoteProductId%zu=\"%#06x\"\n"
1316 "USBRemoteRevision%zu=\"%#04x%02x\"\n",
1317 index + 1, Utf8Str(id).raw(),
1318 index + 1, usVendorId,
1319 index + 1, usProductId,
1320 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1321 else
1322 RTPrintf("UUID: %S\n"
1323 "VendorId: 0x%04x (%04X)\n"
1324 "ProductId: 0x%04x (%04X)\n"
1325 "Revision: %u.%u (%02u%02u)\n",
1326 Utf8Str(id).raw(),
1327 usVendorId, usVendorId, usProductId, usProductId,
1328 bcdRevision >> 8, bcdRevision & 0xff,
1329 bcdRevision >> 8, bcdRevision & 0xff);
1330
1331 /* optional stuff. */
1332 Bstr bstr;
1333 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1334 if (!bstr.isEmpty())
1335 {
1336 if (details == VMINFO_MACHINEREADABLE)
1337 RTPrintf("USBRemoteManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1338 else
1339 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1340 }
1341 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1342 if (!bstr.isEmpty())
1343 {
1344 if (details == VMINFO_MACHINEREADABLE)
1345 RTPrintf("USBRemoteProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1346 else
1347 RTPrintf("Product: %lS\n", bstr.raw());
1348 }
1349 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1350 if (!bstr.isEmpty())
1351 {
1352 if (details == VMINFO_MACHINEREADABLE)
1353 RTPrintf("USBRemoteSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1354 else
1355 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1356 }
1357 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1358 if (!bstr.isEmpty())
1359 {
1360 if (details == VMINFO_MACHINEREADABLE)
1361 RTPrintf("USBRemoteAddress%zu=\"%lS\"\n", index + 1, bstr.raw());
1362 else
1363 RTPrintf("Address: %lS\n", bstr.raw());
1364 }
1365
1366 if (details != VMINFO_MACHINEREADABLE)
1367 RTPrintf("\n");
1368 }
1369 }
1370 }
1371
1372 /* scope */
1373 {
1374 if (details != VMINFO_MACHINEREADABLE)
1375 RTPrintf ("Currently Attached USB Devices:\n\n");
1376
1377 SafeIfaceArray <IUSBDevice> coll;
1378 CHECK_ERROR_RET (console, COMGETTER(USBDevices) (ComSafeArrayAsOutParam(coll)), rc);
1379
1380 if (coll.size() == 0)
1381 {
1382 if (details != VMINFO_MACHINEREADABLE)
1383 RTPrintf("<none>\n\n");
1384 }
1385 else
1386 {
1387 for (size_t index = 0; index < coll.size(); ++index)
1388 {
1389 ComPtr <IUSBDevice> dev = coll[index];
1390
1391 /* Query info. */
1392 Bstr id;
1393 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1394 USHORT usVendorId;
1395 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1396 USHORT usProductId;
1397 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1398 USHORT bcdRevision;
1399 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1400
1401 if (details == VMINFO_MACHINEREADABLE)
1402 RTPrintf("USBAttachedUUID%zu=\"%S\"\n"
1403 "USBAttachedVendorId%zu=\"%#06x\"\n"
1404 "USBAttachedProductId%zu=\"%#06x\"\n"
1405 "USBAttachedRevision%zu=\"%#04x%02x\"\n",
1406 index + 1, Utf8Str(id).raw(),
1407 index + 1, usVendorId,
1408 index + 1, usProductId,
1409 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1410 else
1411 RTPrintf("UUID: %S\n"
1412 "VendorId: 0x%04x (%04X)\n"
1413 "ProductId: 0x%04x (%04X)\n"
1414 "Revision: %u.%u (%02u%02u)\n",
1415 Utf8Str(id).raw(),
1416 usVendorId, usVendorId, usProductId, usProductId,
1417 bcdRevision >> 8, bcdRevision & 0xff,
1418 bcdRevision >> 8, bcdRevision & 0xff);
1419
1420 /* optional stuff. */
1421 Bstr bstr;
1422 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1423 if (!bstr.isEmpty())
1424 {
1425 if (details == VMINFO_MACHINEREADABLE)
1426 RTPrintf("USBAttachedManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1427 else
1428 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1429 }
1430 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1431 if (!bstr.isEmpty())
1432 {
1433 if (details == VMINFO_MACHINEREADABLE)
1434 RTPrintf("USBAttachedProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1435 else
1436 RTPrintf("Product: %lS\n", bstr.raw());
1437 }
1438 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1439 if (!bstr.isEmpty())
1440 {
1441 if (details == VMINFO_MACHINEREADABLE)
1442 RTPrintf("USBAttachedSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1443 else
1444 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1445 }
1446 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1447 if (!bstr.isEmpty())
1448 {
1449 if (details == VMINFO_MACHINEREADABLE)
1450 RTPrintf("USBAttachedAddress%zu=\"%lS\"\n", index + 1, bstr.raw());
1451 else
1452 RTPrintf("Address: %lS\n", bstr.raw());
1453 }
1454
1455 if (details != VMINFO_MACHINEREADABLE)
1456 RTPrintf("\n");
1457 }
1458 }
1459 }
1460 }
1461 } /* USB */
1462
1463 /*
1464 * Shared folders
1465 */
1466 if (details != VMINFO_MACHINEREADABLE)
1467 RTPrintf("Shared folders: ");
1468 uint32_t numSharedFolders = 0;
1469#if 0 // not yet implemented
1470 /* globally shared folders first */
1471 {
1472 SafeIfaceArray <ISharedFolder> sfColl;
1473 CHECK_ERROR_RET(virtualBox, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sfColl)), rc);
1474 for (size_t i = 0; i < sfColl.size(); ++i)
1475 {
1476 ComPtr<ISharedFolder> sf = sfColl[i];
1477 Bstr name, hostPath;
1478 sf->COMGETTER(Name)(name.asOutParam());
1479 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1480 RTPrintf("Name: '%lS', Host path: '%lS' (global mapping)\n", name.raw(), hostPath.raw());
1481 ++numSharedFolders;
1482 }
1483 }
1484#endif
1485 /* now VM mappings */
1486 {
1487 com::SafeIfaceArray <ISharedFolder> folders;
1488
1489 CHECK_ERROR_RET(machine, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1490
1491 for (size_t i = 0; i < folders.size(); ++i)
1492 {
1493 ComPtr <ISharedFolder> sf = folders[i];
1494
1495 Bstr name, hostPath;
1496 BOOL writable;
1497 sf->COMGETTER(Name)(name.asOutParam());
1498 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1499 sf->COMGETTER(Writable)(&writable);
1500 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1501 RTPrintf("\n\n");
1502 if (details == VMINFO_MACHINEREADABLE)
1503 {
1504 RTPrintf("SharedFolderNameMachineMapping%zu=\"%lS\"\n", i + 1,
1505 name.raw());
1506 RTPrintf("SharedFolderPathMachineMapping%zu=\"%lS\"\n", i + 1,
1507 hostPath.raw());
1508 }
1509 else
1510 RTPrintf("Name: '%lS', Host path: '%lS' (machine mapping), %s\n",
1511 name.raw(), hostPath.raw(), writable ? "writable" : "readonly");
1512 ++numSharedFolders;
1513 }
1514 }
1515 /* transient mappings */
1516 if (console)
1517 {
1518 com::SafeIfaceArray <ISharedFolder> folders;
1519
1520 CHECK_ERROR_RET(console, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1521
1522 for (size_t i = 0; i < folders.size(); ++i)
1523 {
1524 ComPtr <ISharedFolder> sf = folders[i];
1525
1526 Bstr name, hostPath;
1527 sf->COMGETTER(Name)(name.asOutParam());
1528 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1529 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1530 RTPrintf("\n\n");
1531 if (details == VMINFO_MACHINEREADABLE)
1532 {
1533 RTPrintf("SharedFolderNameTransientMapping%zu=\"%lS\"\n", i + 1,
1534 name.raw());
1535 RTPrintf("SharedFolderPathTransientMapping%zu=\"%lS\"\n", i + 1,
1536 hostPath.raw());
1537 }
1538 else
1539 RTPrintf("Name: '%lS', Host path: '%lS' (transient mapping)\n", name.raw(), hostPath.raw());
1540 ++numSharedFolders;
1541 }
1542 }
1543 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1544 RTPrintf("<none>\n");
1545 if (details != VMINFO_MACHINEREADABLE)
1546 RTPrintf("\n");
1547
1548 if (console)
1549 {
1550 /*
1551 * Live VRDP info.
1552 */
1553 ComPtr<IRemoteDisplayInfo> remoteDisplayInfo;
1554 CHECK_ERROR_RET(console, COMGETTER(RemoteDisplayInfo)(remoteDisplayInfo.asOutParam()), rc);
1555 BOOL Active;
1556 ULONG NumberOfClients;
1557 LONG64 BeginTime;
1558 LONG64 EndTime;
1559 ULONG64 BytesSent;
1560 ULONG64 BytesSentTotal;
1561 ULONG64 BytesReceived;
1562 ULONG64 BytesReceivedTotal;
1563 Bstr User;
1564 Bstr Domain;
1565 Bstr ClientName;
1566 Bstr ClientIP;
1567 ULONG ClientVersion;
1568 ULONG EncryptionStyle;
1569
1570 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Active) (&Active), rc);
1571 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(NumberOfClients) (&NumberOfClients), rc);
1572 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BeginTime) (&BeginTime), rc);
1573 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EndTime) (&EndTime), rc);
1574 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSent) (&BytesSent), rc);
1575 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSentTotal) (&BytesSentTotal), rc);
1576 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceived) (&BytesReceived), rc);
1577 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceivedTotal) (&BytesReceivedTotal), rc);
1578 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(User) (User.asOutParam ()), rc);
1579 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Domain) (Domain.asOutParam ()), rc);
1580 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientName) (ClientName.asOutParam ()), rc);
1581 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientIP) (ClientIP.asOutParam ()), rc);
1582 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientVersion) (&ClientVersion), rc);
1583 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EncryptionStyle) (&EncryptionStyle), rc);
1584
1585 if (details == VMINFO_MACHINEREADABLE)
1586 RTPrintf("VRDPActiveConnection=\"%s\"\n", Active ? "on": "off");
1587 else
1588 RTPrintf("VRDP Connection: %s\n", Active? "active": "not active");
1589
1590 if (details == VMINFO_MACHINEREADABLE)
1591 RTPrintf("VRDPClients=%d\n", NumberOfClients);
1592 else
1593 RTPrintf("Clients so far: %d\n", NumberOfClients);
1594
1595 if (NumberOfClients > 0)
1596 {
1597 char timestr[128];
1598
1599 if (Active)
1600 {
1601 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1602 if (details == VMINFO_MACHINEREADABLE)
1603 RTPrintf("VRDPStartTime=\"%s\"\n", timestr);
1604 else
1605 RTPrintf("Start time: %s\n", timestr);
1606 }
1607 else
1608 {
1609 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1610 if (details == VMINFO_MACHINEREADABLE)
1611 RTPrintf("VRDPLastStartTime=\"%s\"\n", timestr);
1612 else
1613 RTPrintf("Last started: %s\n", timestr);
1614 makeTimeStr (timestr, sizeof (timestr), EndTime);
1615 if (details == VMINFO_MACHINEREADABLE)
1616 RTPrintf("VRDPLastEndTime=\"%s\"\n", timestr);
1617 else
1618 RTPrintf("Last ended: %s\n", timestr);
1619 }
1620
1621 uint64_t ThroughputSend = 0;
1622 uint64_t ThroughputReceive = 0;
1623 if (EndTime != BeginTime)
1624 {
1625 ThroughputSend = (BytesSent * 1000) / (EndTime - BeginTime);
1626 ThroughputReceive = (BytesReceived * 1000) / (EndTime - BeginTime);
1627 }
1628
1629 if (details == VMINFO_MACHINEREADABLE)
1630 {
1631 RTPrintf("VRDPBytesSent=%llu\n", BytesSent);
1632 RTPrintf("VRDPThroughputSend=%llu\n", ThroughputSend);
1633 RTPrintf("VRDPBytesSentTotal=%llu\n", BytesSentTotal);
1634
1635 RTPrintf("VRDPBytesReceived=%llu\n", BytesReceived);
1636 RTPrintf("VRDPThroughputReceive=%llu\n", ThroughputReceive);
1637 RTPrintf("VRDPBytesReceivedTotal=%llu\n", BytesReceivedTotal);
1638 }
1639 else
1640 {
1641 RTPrintf("Sent: %llu Bytes\n", BytesSent);
1642 RTPrintf("Average speed: %llu B/s\n", ThroughputSend);
1643 RTPrintf("Sent total: %llu Bytes\n", BytesSentTotal);
1644
1645 RTPrintf("Received: %llu Bytes\n", BytesReceived);
1646 RTPrintf("Speed: %llu B/s\n", ThroughputReceive);
1647 RTPrintf("Received total: %llu Bytes\n", BytesReceivedTotal);
1648 }
1649
1650 if (Active)
1651 {
1652 if (details == VMINFO_MACHINEREADABLE)
1653 {
1654 RTPrintf("VRDPUserName=\"%lS\"\n", User.raw());
1655 RTPrintf("VRDPDomain=\"%lS\"\n", Domain.raw());
1656 RTPrintf("VRDPClientName=\"%lS\"\n", ClientName.raw());
1657 RTPrintf("VRDPClientIP=\"%lS\"\n", ClientIP.raw());
1658 RTPrintf("VRDPClientVersion=%d\n", ClientVersion);
1659 RTPrintf("VRDPEncryption=\"%s\"\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1660 }
1661 else
1662 {
1663 RTPrintf("User name: %lS\n", User.raw());
1664 RTPrintf("Domain: %lS\n", Domain.raw());
1665 RTPrintf("Client name: %lS\n", ClientName.raw());
1666 RTPrintf("Client IP: %lS\n", ClientIP.raw());
1667 RTPrintf("Client version: %d\n", ClientVersion);
1668 RTPrintf("Encryption: %s\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1669 }
1670 }
1671 }
1672
1673 if (details != VMINFO_MACHINEREADABLE)
1674 RTPrintf("\n");
1675 }
1676
1677 if ( details == VMINFO_STANDARD
1678 || details == VMINFO_FULL
1679 || details == VMINFO_MACHINEREADABLE)
1680 {
1681 Bstr description;
1682 machine->COMGETTER(Description)(description.asOutParam());
1683 if (!description.isEmpty())
1684 {
1685 if (details == VMINFO_MACHINEREADABLE)
1686 RTPrintf("description=\"%lS\"\n", description.raw());
1687 else
1688 RTPrintf("Description:\n%lS\n", description.raw());
1689 }
1690 }
1691
1692 ULONG guestVal;
1693 if (details != VMINFO_MACHINEREADABLE)
1694 RTPrintf("Guest:\n\n");
1695
1696#ifdef VBOX_WITH_MEM_BALLOONING
1697 rc = machine->COMGETTER(MemoryBalloonSize)(&guestVal);
1698 if (SUCCEEDED(rc))
1699 {
1700 if (details == VMINFO_MACHINEREADABLE)
1701 RTPrintf("GuestMemoryBalloon=%d\n", guestVal);
1702 else
1703 RTPrintf("Configured memory balloon size: %d MB\n", guestVal);
1704 }
1705#endif
1706 rc = machine->COMGETTER(StatisticsUpdateInterval)(&guestVal);
1707 if (SUCCEEDED(rc))
1708 {
1709 if (details == VMINFO_MACHINEREADABLE)
1710 RTPrintf("GuestStatisticsUpdateInterval=%d\n", guestVal);
1711 else
1712 {
1713 if (guestVal == 0)
1714 RTPrintf("Statistics update: disabled\n");
1715 else
1716 RTPrintf("Statistics update interval: %d seconds\n", guestVal);
1717 }
1718 }
1719 if (details != VMINFO_MACHINEREADABLE)
1720 RTPrintf("\n");
1721
1722 if ( console
1723 && ( details == VMINFO_STATISTICS
1724 || details == VMINFO_FULL
1725 || details == VMINFO_MACHINEREADABLE))
1726 {
1727 ComPtr <IGuest> guest;
1728
1729 rc = console->COMGETTER(Guest)(guest.asOutParam());
1730 if (SUCCEEDED(rc))
1731 {
1732 ULONG statVal;
1733
1734 rc = guest->GetStatistic(0, GuestStatisticType_SampleNumber, &statVal);
1735 if (SUCCEEDED(rc))
1736 {
1737 if (details == VMINFO_MACHINEREADABLE)
1738 RTPrintf("StatGuestSample=%d\n", statVal);
1739 else
1740 RTPrintf("Guest statistics for sample %d:\n\n", statVal);
1741 }
1742
1743 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Idle, &statVal);
1744 if (SUCCEEDED(rc))
1745 {
1746 if (details == VMINFO_MACHINEREADABLE)
1747 RTPrintf("StatGuestLoadIdleCPU%d=%d\n", 0, statVal);
1748 else
1749 RTPrintf("CPU%d: CPU Load Idle %-3d%%\n", 0, statVal);
1750 }
1751
1752 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Kernel, &statVal);
1753 if (SUCCEEDED(rc))
1754 {
1755 if (details == VMINFO_MACHINEREADABLE)
1756 RTPrintf("StatGuestLoadKernelCPU%d=%d\n", 0, statVal);
1757 else
1758 RTPrintf("CPU%d: CPU Load Kernel %-3d%%\n", 0, statVal);
1759 }
1760
1761 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_User, &statVal);
1762 if (SUCCEEDED(rc))
1763 {
1764 if (details == VMINFO_MACHINEREADABLE)
1765 RTPrintf("StatGuestLoadUserCPU%d=%d\n", 0, statVal);
1766 else
1767 RTPrintf("CPU%d: CPU Load User %-3d%%\n", 0, statVal);
1768 }
1769
1770 rc = guest->GetStatistic(0, GuestStatisticType_Threads, &statVal);
1771 if (SUCCEEDED(rc))
1772 {
1773 if (details == VMINFO_MACHINEREADABLE)
1774 RTPrintf("StatGuestThreadsCPU%d=%d\n", 0, statVal);
1775 else
1776 RTPrintf("CPU%d: Threads %d\n", 0, statVal);
1777 }
1778
1779 rc = guest->GetStatistic(0, GuestStatisticType_Processes, &statVal);
1780 if (SUCCEEDED(rc))
1781 {
1782 if (details == VMINFO_MACHINEREADABLE)
1783 RTPrintf("StatGuestProcessesCPU%d=%d\n", 0, statVal);
1784 else
1785 RTPrintf("CPU%d: Processes %d\n", 0, statVal);
1786 }
1787
1788 rc = guest->GetStatistic(0, GuestStatisticType_Handles, &statVal);
1789 if (SUCCEEDED(rc))
1790 {
1791 if (details == VMINFO_MACHINEREADABLE)
1792 RTPrintf("StatGuestHandlesCPU%d=%d\n", 0, statVal);
1793 else
1794 RTPrintf("CPU%d: Handles %d\n", 0, statVal);
1795 }
1796
1797 rc = guest->GetStatistic(0, GuestStatisticType_MemoryLoad, &statVal);
1798 if (SUCCEEDED(rc))
1799 {
1800 if (details == VMINFO_MACHINEREADABLE)
1801 RTPrintf("StatGuestMemoryLoadCPU%d=%d\n", 0, statVal);
1802 else
1803 RTPrintf("CPU%d: Memory Load %d%%\n", 0, statVal);
1804 }
1805
1806 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemTotal, &statVal);
1807 if (SUCCEEDED(rc))
1808 {
1809 if (details == VMINFO_MACHINEREADABLE)
1810 RTPrintf("StatGuestMemoryTotalPhysCPU%d=%d\n", 0, statVal);
1811 else
1812 RTPrintf("CPU%d: Total physical memory %-4d MB\n", 0, statVal);
1813 }
1814
1815 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemAvailable, &statVal);
1816 if (SUCCEEDED(rc))
1817 {
1818 if (details == VMINFO_MACHINEREADABLE)
1819 RTPrintf("StatGuestMemoryFreePhysCPU%d=%d\n", 0, statVal);
1820 else
1821 RTPrintf("CPU%d: Free physical memory %-4d MB\n", 0, statVal);
1822 }
1823
1824#ifdef VBOX_WITH_MEM_BALLOONING
1825 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemBalloon, &statVal);
1826 if (SUCCEEDED(rc))
1827 {
1828 if (details == VMINFO_MACHINEREADABLE)
1829 RTPrintf("StatGuestMemoryBalloonCPU%d=%d\n", 0, statVal);
1830 else
1831 RTPrintf("CPU%d: Memory balloon size %-4d MB\n", 0, statVal);
1832 }
1833#endif
1834 rc = guest->GetStatistic(0, GuestStatisticType_MemCommitTotal, &statVal);
1835 if (SUCCEEDED(rc))
1836 {
1837 if (details == VMINFO_MACHINEREADABLE)
1838 RTPrintf("StatGuestMemoryCommittedCPU%d=%d\n", 0, statVal);
1839 else
1840 RTPrintf("CPU%d: Committed memory %-4d MB\n", 0, statVal);
1841 }
1842
1843 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelTotal, &statVal);
1844 if (SUCCEEDED(rc))
1845 {
1846 if (details == VMINFO_MACHINEREADABLE)
1847 RTPrintf("StatGuestMemoryTotalKernelCPU%d=%d\n", 0, statVal);
1848 else
1849 RTPrintf("CPU%d: Total kernel memory %-4d MB\n", 0, statVal);
1850 }
1851
1852 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelPaged, &statVal);
1853 if (SUCCEEDED(rc))
1854 {
1855 if (details == VMINFO_MACHINEREADABLE)
1856 RTPrintf("StatGuestMemoryPagedKernelCPU%d=%d\n", 0, statVal);
1857 else
1858 RTPrintf("CPU%d: Paged kernel memory %-4d MB\n", 0, statVal);
1859 }
1860
1861 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelNonpaged, &statVal);
1862 if (SUCCEEDED(rc))
1863 {
1864 if (details == VMINFO_MACHINEREADABLE)
1865 RTPrintf("StatGuestMemoryNonpagedKernelCPU%d=%d\n", 0, statVal);
1866 else
1867 RTPrintf("CPU%d: Nonpaged kernel memory %-4d MB\n", 0, statVal);
1868 }
1869
1870 rc = guest->GetStatistic(0, GuestStatisticType_MemSystemCache, &statVal);
1871 if (SUCCEEDED(rc))
1872 {
1873 if (details == VMINFO_MACHINEREADABLE)
1874 RTPrintf("StatGuestSystemCacheSizeCPU%d=%d\n", 0, statVal);
1875 else
1876 RTPrintf("CPU%d: System cache size %-4d MB\n", 0, statVal);
1877 }
1878
1879 rc = guest->GetStatistic(0, GuestStatisticType_PageFileSize, &statVal);
1880 if (SUCCEEDED(rc))
1881 {
1882 if (details == VMINFO_MACHINEREADABLE)
1883 RTPrintf("StatGuestPageFileSizeCPU%d=%d\n", 0, statVal);
1884 else
1885 RTPrintf("CPU%d: Page file size %-4d MB\n", 0, statVal);
1886 }
1887
1888 RTPrintf("\n");
1889 }
1890 else
1891 {
1892 if (details != VMINFO_MACHINEREADABLE)
1893 {
1894 RTPrintf("[!] FAILED calling console->getGuest at line %d!\n", __LINE__);
1895 GluePrintRCMessage(rc);
1896 }
1897 }
1898 }
1899
1900 /*
1901 * snapshots
1902 */
1903 ComPtr<ISnapshot> snapshot;
1904 rc = machine->GetSnapshot(Bstr(), snapshot.asOutParam());
1905 if (SUCCEEDED(rc) && snapshot)
1906 {
1907 if (details != VMINFO_MACHINEREADABLE)
1908 RTPrintf("Snapshots:\n\n");
1909 showSnapshots(snapshot, details);
1910 }
1911
1912 if (details != VMINFO_MACHINEREADABLE)
1913 RTPrintf("\n");
1914 return S_OK;
1915}
1916
1917#if defined(_MSC_VER)
1918# pragma optimize("", on)
1919#endif
1920
1921static const RTGETOPTDEF g_aShowVMInfoOptions[] =
1922{
1923 { "--details", 'D', RTGETOPT_REQ_NOTHING },
1924 { "-details", 'D', RTGETOPT_REQ_NOTHING }, // deprecated
1925 { "--statistics", 'S', RTGETOPT_REQ_NOTHING },
1926 { "-statistics", 'S', RTGETOPT_REQ_NOTHING }, // deprecated
1927 { "--machinereadable", 'M', RTGETOPT_REQ_NOTHING },
1928 { "-machinereadable", 'M', RTGETOPT_REQ_NOTHING }, // deprecated
1929};
1930
1931int handleShowVMInfo(HandlerArg *a)
1932{
1933 HRESULT rc;
1934 const char *VMNameOrUuid = NULL;
1935 bool fDetails = false;
1936 bool fStatistics = false;
1937 bool fMachinereadable = false;
1938
1939 int c;
1940 RTGETOPTUNION ValueUnion;
1941 RTGETOPTSTATE GetState;
1942 // start at 0 because main() has hacked both the argc and argv given to us
1943 RTGetOptInit(&GetState, a->argc, a->argv, g_aShowVMInfoOptions, RT_ELEMENTS(g_aShowVMInfoOptions), 0, 0 /* fFlags */);
1944 while ((c = RTGetOpt(&GetState, &ValueUnion)))
1945 {
1946 switch (c)
1947 {
1948 case 'D': // --details
1949 fDetails = true;
1950 break;
1951
1952 case 'S': // --statistics
1953 fStatistics = true;
1954 break;
1955
1956 case 'M': // --machinereadable
1957 fMachinereadable = true;
1958 break;
1959
1960 case VINF_GETOPT_NOT_OPTION:
1961 if (!VMNameOrUuid)
1962 VMNameOrUuid = ValueUnion.psz;
1963 else
1964 return errorSyntax(USAGE_SHOWVMINFO, "Invalid parameter '%s'", ValueUnion.psz);
1965 break;
1966
1967 default:
1968 if (c > 0)
1969 {
1970 if (RT_C_IS_PRINT(c))
1971 return errorSyntax(USAGE_SHOWVMINFO, "Invalid option -%c", c);
1972 else
1973 return errorSyntax(USAGE_SHOWVMINFO, "Invalid option case %i", c);
1974 }
1975 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
1976 return errorSyntax(USAGE_SHOWVMINFO, "unknown option: %s\n", ValueUnion.psz);
1977 else if (ValueUnion.pDef)
1978 return errorSyntax(USAGE_SHOWVMINFO, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
1979 else
1980 return errorSyntax(USAGE_SHOWVMINFO, "error: %Rrs", c);
1981 }
1982 }
1983
1984 /* check for required options */
1985 if (!VMNameOrUuid)
1986 return errorSyntax(USAGE_SHOWVMINFO, "VM name or UUID required");
1987
1988 /* try to find the given machine */
1989 ComPtr <IMachine> machine;
1990 Bstr uuid (VMNameOrUuid);
1991 if (!Guid (VMNameOrUuid).isEmpty())
1992 {
1993 CHECK_ERROR (a->virtualBox, GetMachine (uuid, machine.asOutParam()));
1994 }
1995 else
1996 {
1997 CHECK_ERROR (a->virtualBox, FindMachine (Bstr(VMNameOrUuid), machine.asOutParam()));
1998 if (SUCCEEDED (rc))
1999 machine->COMGETTER(Id) (uuid.asOutParam());
2000 }
2001 if (FAILED (rc))
2002 return 1;
2003
2004 /* 2nd option can be -details, -statistics or -argdump */
2005 VMINFO_DETAILS details = VMINFO_NONE;
2006 if (fMachinereadable)
2007 details = VMINFO_MACHINEREADABLE;
2008 else
2009 if (fDetails && fStatistics)
2010 details = VMINFO_FULL;
2011 else
2012 if (fDetails)
2013 details = VMINFO_STANDARD;
2014 else
2015 if (fStatistics)
2016 details = VMINFO_STATISTICS;
2017
2018 ComPtr <IConsole> console;
2019
2020 /* open an existing session for the VM */
2021 rc = a->virtualBox->OpenExistingSession (a->session, uuid);
2022 if (SUCCEEDED(rc))
2023 /* get the session machine */
2024 rc = a->session->COMGETTER(Machine)(machine.asOutParam());
2025 if (SUCCEEDED(rc))
2026 /* get the session console */
2027 rc = a->session->COMGETTER(Console)(console.asOutParam());
2028
2029 rc = showVMInfo(a->virtualBox, machine, details, console);
2030
2031 if (console)
2032 a->session->Close();
2033
2034 return SUCCEEDED (rc) ? 0 : 1;
2035}
2036
2037#endif /* !VBOX_ONLY_DOCS */
2038/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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