VirtualBox

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

Last change on this file since 16024 was 15918, checked in by vboxsync, 16 years ago

cosmetical issue

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