VirtualBox

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

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

#3551: “Main: Replace remaining collections with safe arrays”
Converted SharedFolderCollection. Approved by dmik. Tested with GUI.

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