VirtualBox

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

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

VBoxManage: build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 73.1 KB
Line 
1/* $Id: VBoxManageInfo.cpp 14814 2008-11-30 00:14:34Z 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/VBoxHDD.h>
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 PRINT_ERROR_INFO (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<IFloppyImage2> 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<IHardDisk2> 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->GetHardDisk2(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<IHardDisk2> hardDisk;
515 Bstr filePath;
516 rc = machine->GetHardDisk2(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->GetHardDisk2(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->GetHardDisk2(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<IDVDImage2> 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 default:
703 strAttachment = "unknown";
704 break;
705 }
706
707 /* cable connected */
708 BOOL fConnected;
709 nic->COMGETTER(CableConnected)(&fConnected);
710
711 /* trace stuff */
712 BOOL fTraceEnabled;
713 nic->COMGETTER(TraceEnabled)(&fTraceEnabled);
714 Bstr traceFile;
715 nic->COMGETTER(TraceFile)(traceFile.asOutParam());
716
717 /* NIC type */
718 Utf8Str strNICType;
719 NetworkAdapterType_T NICType;
720 nic->COMGETTER(AdapterType)(&NICType);
721 switch (NICType) {
722 case NetworkAdapterType_Am79C970A:
723 strNICType = "Am79C970A";
724 break;
725 case NetworkAdapterType_Am79C973:
726 strNICType = "Am79C973";
727 break;
728#ifdef VBOX_WITH_E1000
729 case NetworkAdapterType_I82540EM:
730 strNICType = "82540EM";
731 break;
732 case NetworkAdapterType_I82543GC:
733 strNICType = "82543GC";
734 break;
735#endif
736 default:
737 strNICType = "unknown";
738 break;
739 }
740
741 /* reported line speed */
742 ULONG ulLineSpeed;
743 nic->COMGETTER(LineSpeed)(&ulLineSpeed);
744
745 if (details == VMINFO_MACHINEREADABLE)
746 {
747 RTPrintf("macaddress%d=\"%lS\"\n", currentNIC + 1, strMACAddress.raw());
748 RTPrintf("cableconnected%d=\"%s\"\n", currentNIC + 1, fConnected ? "on" : "off");
749 RTPrintf("nic%d=\"%s\"\n", currentNIC + 1, strAttachment.raw());
750 }
751 else
752 RTPrintf("NIC %d: MAC: %lS, Attachment: %s, Cable connected: %s, Trace: %s (file: %lS), Type: %s, Reported speed: %d Mbps\n",
753 currentNIC + 1, strMACAddress.raw(), strAttachment.raw(),
754 fConnected ? "on" : "off",
755 fTraceEnabled ? "on" : "off",
756 traceFile.isEmpty() ? Bstr("none").raw() : traceFile.raw(),
757 strNICType.raw(),
758 ulLineSpeed / 1000);
759 }
760 }
761 }
762
763 /* get the maximum amount of UARTs */
764 ULONG maxUARTs = 0;
765 sysProps->COMGETTER(SerialPortCount)(&maxUARTs);
766 for (ULONG currentUART = 0; currentUART < maxUARTs; currentUART++)
767 {
768 ComPtr<ISerialPort> uart;
769 rc = machine->GetSerialPort(currentUART, uart.asOutParam());
770 if (SUCCEEDED(rc) && uart)
771 {
772 BOOL fEnabled;
773 uart->COMGETTER(Enabled)(&fEnabled);
774 if (!fEnabled)
775 {
776 if (details == VMINFO_MACHINEREADABLE)
777 RTPrintf("uart%d=\"off\"\n", currentUART + 1);
778 else
779 RTPrintf("UART %d: disabled\n", currentUART + 1);
780 }
781 else
782 {
783 ULONG ulIRQ, ulIOBase;
784 PortMode_T HostMode;
785 Bstr path;
786 BOOL fServer;
787 uart->COMGETTER(IRQ)(&ulIRQ);
788 uart->COMGETTER(IOBase)(&ulIOBase);
789 uart->COMGETTER(Path)(path.asOutParam());
790 uart->COMGETTER(Server)(&fServer);
791 uart->COMGETTER(HostMode)(&HostMode);
792
793 if (details == VMINFO_MACHINEREADABLE)
794 RTPrintf("uart%d=\"%#06x,%d\"\n", currentUART + 1,
795 ulIOBase, ulIRQ);
796 else
797 RTPrintf("UART %d: I/O base: 0x%04x, IRQ: %d",
798 currentUART + 1, ulIOBase, ulIRQ);
799 switch (HostMode)
800 {
801 default:
802 case PortMode_Disconnected:
803 if (details == VMINFO_MACHINEREADABLE)
804 RTPrintf("uartmode%d=\"disconnected\"\n", currentUART + 1);
805 else
806 RTPrintf(", disconnected\n");
807 break;
808 case PortMode_HostPipe:
809 if (details == VMINFO_MACHINEREADABLE)
810 RTPrintf("uartmode%d=\"%s,%lS\"\n", currentUART + 1,
811 fServer ? "server" : "client", path.raw());
812 else
813 RTPrintf(", attached to pipe (%s) '%lS'\n",
814 fServer ? "server" : "client", path.raw());
815 break;
816 case PortMode_HostDevice:
817 if (details == VMINFO_MACHINEREADABLE)
818 RTPrintf("uartmode%d=\"%lS\"\n", currentUART + 1,
819 path.raw());
820 else
821 RTPrintf(", attached to device '%lS'\n", path.raw());
822 break;
823 }
824 }
825 }
826 }
827
828 ComPtr<IAudioAdapter> AudioAdapter;
829 rc = machine->COMGETTER(AudioAdapter)(AudioAdapter.asOutParam());
830 if (SUCCEEDED(rc))
831 {
832 const char *pszDrv = "Unknown";
833 const char *pszCtrl = "Unknown";
834 BOOL fEnabled;
835 rc = AudioAdapter->COMGETTER(Enabled)(&fEnabled);
836 if (SUCCEEDED(rc) && fEnabled)
837 {
838 AudioDriverType_T enmDrvType;
839 rc = AudioAdapter->COMGETTER(AudioDriver)(&enmDrvType);
840 switch (enmDrvType)
841 {
842 case AudioDriverType_Null:
843 if (details == VMINFO_MACHINEREADABLE)
844 pszDrv = "null";
845 else
846 pszDrv = "Null";
847 break;
848 case AudioDriverType_WinMM:
849 if (details == VMINFO_MACHINEREADABLE)
850 pszDrv = "winmm";
851 else
852 pszDrv = "WINMM";
853 break;
854 case AudioDriverType_DirectSound:
855 if (details == VMINFO_MACHINEREADABLE)
856 pszDrv = "dsound";
857 else
858 pszDrv = "DSOUND";
859 break;
860 case AudioDriverType_OSS:
861 if (details == VMINFO_MACHINEREADABLE)
862 pszDrv = "oss";
863 else
864 pszDrv = "OSS";
865 break;
866 case AudioDriverType_ALSA:
867 if (details == VMINFO_MACHINEREADABLE)
868 pszDrv = "alsa";
869 else
870 pszDrv = "ALSA";
871 break;
872 case AudioDriverType_Pulse:
873 if (details == VMINFO_MACHINEREADABLE)
874 pszDrv = "pulse";
875 else
876 pszDrv = "PulseAudio";
877 break;
878 case AudioDriverType_CoreAudio:
879 if (details == VMINFO_MACHINEREADABLE)
880 pszDrv = "coreaudio";
881 else
882 pszDrv = "CoreAudio";
883 break;
884 case AudioDriverType_SolAudio:
885 if (details == VMINFO_MACHINEREADABLE)
886 pszDrv = "solaudio";
887 else
888 pszDrv = "SolAudio";
889 break;
890 default:
891 if (details == VMINFO_MACHINEREADABLE)
892 pszDrv = "unknown";
893 break;
894 }
895 AudioControllerType_T enmCtrlType;
896 rc = AudioAdapter->COMGETTER(AudioController)(&enmCtrlType);
897 switch (enmCtrlType)
898 {
899 case AudioControllerType_AC97:
900 if (details == VMINFO_MACHINEREADABLE)
901 pszCtrl = "ac97";
902 else
903 pszCtrl = "AC97";
904 break;
905 case AudioControllerType_SB16:
906 if (details == VMINFO_MACHINEREADABLE)
907 pszCtrl = "sb16";
908 else
909 pszCtrl = "SB16";
910 break;
911 }
912 }
913 else
914 fEnabled = FALSE;
915 if (details == VMINFO_MACHINEREADABLE)
916 {
917 if (fEnabled)
918 RTPrintf("audio=\"%s\"\n", pszDrv);
919 else
920 RTPrintf("audio=\"none\"\n");
921 }
922 else
923 RTPrintf("Audio: %s (Driver: %s, Controller: %s)\n",
924 fEnabled ? "enabled" : "disabled", pszDrv, pszCtrl);
925 }
926
927 /* Shared clipboard */
928 {
929 const char *psz = "Unknown";
930 ClipboardMode_T enmMode;
931 rc = machine->COMGETTER(ClipboardMode)(&enmMode);
932 switch (enmMode)
933 {
934 case ClipboardMode_Disabled:
935 if (details == VMINFO_MACHINEREADABLE)
936 psz = "disabled";
937 else
938 psz = "disabled";
939 break;
940 case ClipboardMode_HostToGuest:
941 if (details == VMINFO_MACHINEREADABLE)
942 psz = "hosttoguest";
943 else
944 psz = "HostToGuest";
945 break;
946 case ClipboardMode_GuestToHost:
947 if (details == VMINFO_MACHINEREADABLE)
948 psz = "guesttohost";
949 else
950 psz = "GuestToHost";
951 break;
952 case ClipboardMode_Bidirectional:
953 if (details == VMINFO_MACHINEREADABLE)
954 psz = "bidirectional";
955 else
956 psz = "Bidirectional";
957 break;
958 default:
959 if (details == VMINFO_MACHINEREADABLE)
960 psz = "unknown";
961 break;
962 }
963 if (details == VMINFO_MACHINEREADABLE)
964 RTPrintf("clipboard=\"%s\"\n", psz);
965 else
966 RTPrintf("Clipboard Mode: %s\n", psz);
967 }
968
969 if (console)
970 {
971 ComPtr<IDisplay> display;
972 CHECK_ERROR_RET(console, COMGETTER(Display)(display.asOutParam()), rc);
973 do
974 {
975 ULONG xRes, yRes, bpp;
976 rc = display->COMGETTER(Width)(&xRes);
977 if (rc == E_ACCESSDENIED)
978 break; /* VM not powered up */
979 if (FAILED(rc))
980 {
981 com::ErrorInfo info (display);
982 PRINT_ERROR_INFO (info);
983 return rc;
984 }
985 rc = display->COMGETTER(Height)(&yRes);
986 if (rc == E_ACCESSDENIED)
987 break; /* VM not powered up */
988 if (FAILED(rc))
989 {
990 com::ErrorInfo info (display);
991 PRINT_ERROR_INFO (info);
992 return rc;
993 }
994 rc = display->COMGETTER(BitsPerPixel)(&bpp);
995 if (rc == E_ACCESSDENIED)
996 break; /* VM not powered up */
997 if (FAILED(rc))
998 {
999 com::ErrorInfo info (display);
1000 PRINT_ERROR_INFO (info);
1001 return rc;
1002 }
1003 if (details == VMINFO_MACHINEREADABLE)
1004 RTPrintf("VideoMode=\"%d,%d,%d\"\n", xRes, yRes, bpp);
1005 else
1006 RTPrintf("Video mode: %dx%dx%d\n", xRes, yRes, bpp);
1007 }
1008 while (0);
1009 }
1010
1011 /*
1012 * VRDP
1013 */
1014 ComPtr<IVRDPServer> vrdpServer;
1015 rc = machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1016 if (SUCCEEDED(rc) && vrdpServer)
1017 {
1018 BOOL fEnabled = false;
1019 vrdpServer->COMGETTER(Enabled)(&fEnabled);
1020 if (fEnabled)
1021 {
1022 ULONG port;
1023 vrdpServer->COMGETTER(Port)(&port);
1024 Bstr address;
1025 vrdpServer->COMGETTER(NetAddress)(address.asOutParam());
1026 BOOL fMultiCon;
1027 vrdpServer->COMGETTER(AllowMultiConnection)(&fMultiCon);
1028 BOOL fReuseCon;
1029 vrdpServer->COMGETTER(ReuseSingleConnection)(&fReuseCon);
1030 VRDPAuthType_T vrdpAuthType;
1031 const char *strAuthType;
1032 vrdpServer->COMGETTER(AuthType)(&vrdpAuthType);
1033 switch (vrdpAuthType)
1034 {
1035 case VRDPAuthType_Null:
1036 strAuthType = "null";
1037 break;
1038 case VRDPAuthType_External:
1039 strAuthType = "external";
1040 break;
1041 case VRDPAuthType_Guest:
1042 strAuthType = "guest";
1043 break;
1044 default:
1045 strAuthType = "unknown";
1046 break;
1047 }
1048 if (details == VMINFO_MACHINEREADABLE)
1049 {
1050 RTPrintf("vrdp=\"on\"\n");
1051 RTPrintf("vrdpport=%d\n", port);
1052 RTPrintf("vrdpaddress=\"%lS\"\n", address.raw());
1053 RTPrintf("vrdpauthtype=\"%s\"\n", strAuthType);
1054 RTPrintf("vrdpmulticon=\"%s\"\n", fMultiCon ? "on" : "off");
1055 RTPrintf("vrdpreusecon=\"%s\"\n", fReuseCon ? "on" : "off");
1056 }
1057 else
1058 {
1059 if (address.isEmpty())
1060 address = "0.0.0.0";
1061 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);
1062 }
1063 }
1064 else
1065 {
1066 if (details == VMINFO_MACHINEREADABLE)
1067 RTPrintf("vrdp=\"off\"\n");
1068 else
1069 RTPrintf("VRDP: disabled\n");
1070 }
1071 }
1072
1073 /*
1074 * USB.
1075 */
1076 ComPtr<IUSBController> USBCtl;
1077 rc = machine->COMGETTER(USBController)(USBCtl.asOutParam());
1078 if (SUCCEEDED(rc))
1079 {
1080 BOOL fEnabled;
1081 rc = USBCtl->COMGETTER(Enabled)(&fEnabled);
1082 if (FAILED(rc))
1083 fEnabled = false;
1084 if (details == VMINFO_MACHINEREADABLE)
1085 RTPrintf("usb=\"%s\"\n", fEnabled ? "on" : "off");
1086 else
1087 RTPrintf("USB: %s\n", fEnabled ? "enabled" : "disabled");
1088
1089 if (details != VMINFO_MACHINEREADABLE)
1090 RTPrintf("\nUSB Device Filters:\n\n");
1091
1092 ComPtr<IUSBDeviceFilterCollection> Coll;
1093 CHECK_ERROR_RET (USBCtl, COMGETTER(DeviceFilters)(Coll.asOutParam()), rc);
1094
1095 ComPtr<IUSBDeviceFilterEnumerator> Enum;
1096 CHECK_ERROR_RET (Coll, Enumerate(Enum.asOutParam()), rc);
1097
1098 ULONG index = 0;
1099 BOOL fMore = FALSE;
1100 rc = Enum->HasMore (&fMore);
1101 ASSERT_RET (SUCCEEDED (rc), rc);
1102
1103 if (!fMore)
1104 {
1105 if (details != VMINFO_MACHINEREADABLE)
1106 RTPrintf("<none>\n\n");
1107 }
1108 else
1109 while (fMore)
1110 {
1111 ComPtr<IUSBDeviceFilter> DevPtr;
1112 rc = Enum->GetNext(DevPtr.asOutParam());
1113 ASSERT_RET (SUCCEEDED (rc), rc);
1114
1115 /* Query info. */
1116
1117 if (details != VMINFO_MACHINEREADABLE)
1118 RTPrintf("Index: %lu\n", index);
1119
1120 BOOL bActive = FALSE;
1121 CHECK_ERROR_RET (DevPtr, COMGETTER (Active) (&bActive), rc);
1122 if (details == VMINFO_MACHINEREADABLE)
1123 RTPrintf("USBFilterActive%d=\"%s\"\n", index + 1, bActive ? "on" : "off");
1124 else
1125 RTPrintf("Active: %s\n", bActive ? "yes" : "no");
1126
1127 Bstr bstr;
1128 CHECK_ERROR_RET (DevPtr, COMGETTER (Name) (bstr.asOutParam()), rc);
1129 if (details == VMINFO_MACHINEREADABLE)
1130 RTPrintf("USBFilterName%d=\"%lS\"\n", index + 1, bstr.raw());
1131 else
1132 RTPrintf("Name: %lS\n", bstr.raw());
1133 CHECK_ERROR_RET (DevPtr, COMGETTER (VendorId) (bstr.asOutParam()), rc);
1134 if (details == VMINFO_MACHINEREADABLE)
1135 RTPrintf("USBFilterVendorId%d=\"%lS\"\n", index + 1, bstr.raw());
1136 else
1137 RTPrintf("VendorId: %lS\n", bstr.raw());
1138 CHECK_ERROR_RET (DevPtr, COMGETTER (ProductId) (bstr.asOutParam()), rc);
1139 if (details == VMINFO_MACHINEREADABLE)
1140 RTPrintf("USBFilterProductId%d=\"%lS\"\n", index + 1, bstr.raw());
1141 else
1142 RTPrintf("ProductId: %lS\n", bstr.raw());
1143 CHECK_ERROR_RET (DevPtr, COMGETTER (Revision) (bstr.asOutParam()), rc);
1144 if (details == VMINFO_MACHINEREADABLE)
1145 RTPrintf("USBFilterRevision%d=\"%lS\"\n", index + 1, bstr.raw());
1146 else
1147 RTPrintf("Revision: %lS\n", bstr.raw());
1148 CHECK_ERROR_RET (DevPtr, COMGETTER (Manufacturer) (bstr.asOutParam()), rc);
1149 if (details == VMINFO_MACHINEREADABLE)
1150 RTPrintf("USBFilterManufacturer%d=\"%lS\"\n", index + 1, bstr.raw());
1151 else
1152 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1153 CHECK_ERROR_RET (DevPtr, COMGETTER (Product) (bstr.asOutParam()), rc);
1154 if (details == VMINFO_MACHINEREADABLE)
1155 RTPrintf("USBFilterProduct%d=\"%lS\"\n", index + 1, bstr.raw());
1156 else
1157 RTPrintf("Product: %lS\n", bstr.raw());
1158 CHECK_ERROR_RET (DevPtr, COMGETTER (Remote) (bstr.asOutParam()), rc);
1159 if (details == VMINFO_MACHINEREADABLE)
1160 RTPrintf("USBFilterRemote%d=\"%lS\"\n", index + 1, bstr.raw());
1161 else
1162 RTPrintf("Remote: %lS\n", bstr.raw());
1163 CHECK_ERROR_RET (DevPtr, COMGETTER (SerialNumber) (bstr.asOutParam()), rc);
1164 if (details == VMINFO_MACHINEREADABLE)
1165 RTPrintf("USBFilterSerialNumber%d=\"%lS\"\n", index + 1, bstr.raw());
1166 else
1167 RTPrintf("Serial Number: %lS\n", bstr.raw());
1168 if (details != VMINFO_MACHINEREADABLE)
1169 {
1170 ULONG fMaskedIfs;
1171 CHECK_ERROR_RET (DevPtr, COMGETTER (MaskedInterfaces) (&fMaskedIfs), rc);
1172 if (fMaskedIfs)
1173 RTPrintf("Masked Interfaces: 0x%08x\n", fMaskedIfs);
1174 RTPrintf("\n");
1175 }
1176
1177 rc = Enum->HasMore (&fMore);
1178 ASSERT_RET (SUCCEEDED (rc), rc);
1179
1180 index ++;
1181 }
1182
1183 if (console)
1184 {
1185 index = 0;
1186 /* scope */
1187 {
1188 if (details != VMINFO_MACHINEREADABLE)
1189 RTPrintf("Available remote USB devices:\n\n");
1190
1191 ComPtr<IHostUSBDeviceCollection> coll;
1192 CHECK_ERROR_RET (console, COMGETTER(RemoteUSBDevices) (coll.asOutParam()), rc);
1193
1194 ComPtr <IHostUSBDeviceEnumerator> en;
1195 CHECK_ERROR_RET (coll, Enumerate (en.asOutParam()), rc);
1196
1197 BOOL more = FALSE;
1198 rc = en->HasMore (&more);
1199 ASSERT_RET (SUCCEEDED (rc), rc);
1200
1201 if (!more)
1202 {
1203 if (details != VMINFO_MACHINEREADABLE)
1204 RTPrintf("<none>\n\n");
1205 }
1206 else
1207 while (more)
1208 {
1209 ComPtr <IHostUSBDevice> dev;
1210 rc = en->GetNext (dev.asOutParam());
1211 ASSERT_RET (SUCCEEDED (rc), rc);
1212
1213 /* Query info. */
1214 Guid id;
1215 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1216 USHORT usVendorId;
1217 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1218 USHORT usProductId;
1219 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1220 USHORT bcdRevision;
1221 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1222
1223 if (details == VMINFO_MACHINEREADABLE)
1224 RTPrintf("USBRemoteUUID%d=\"%S\"\n"
1225 "USBRemoteVendorId%d=\"%#06x\"\n"
1226 "USBRemoteProductId%d=\"%#06x\"\n"
1227 "USBRemoteRevision%d=\"%#04x%02x\"\n",
1228 index + 1, id.toString().raw(),
1229 index + 1, usVendorId,
1230 index + 1, usProductId,
1231 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1232 else
1233 RTPrintf("UUID: %S\n"
1234 "VendorId: 0x%04x (%04X)\n"
1235 "ProductId: 0x%04x (%04X)\n"
1236 "Revision: %u.%u (%02u%02u)\n",
1237 id.toString().raw(),
1238 usVendorId, usVendorId, usProductId, usProductId,
1239 bcdRevision >> 8, bcdRevision & 0xff,
1240 bcdRevision >> 8, bcdRevision & 0xff);
1241
1242 /* optional stuff. */
1243 Bstr bstr;
1244 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1245 if (!bstr.isEmpty())
1246 {
1247 if (details == VMINFO_MACHINEREADABLE)
1248 RTPrintf("USBRemoteManufacturer%d=\"%lS\"\n", index + 1, bstr.raw());
1249 else
1250 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1251 }
1252 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1253 if (!bstr.isEmpty())
1254 {
1255 if (details == VMINFO_MACHINEREADABLE)
1256 RTPrintf("USBRemoteProduct%d=\"%lS\"\n", index + 1, bstr.raw());
1257 else
1258 RTPrintf("Product: %lS\n", bstr.raw());
1259 }
1260 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1261 if (!bstr.isEmpty())
1262 {
1263 if (details == VMINFO_MACHINEREADABLE)
1264 RTPrintf("USBRemoteSerialNumber%d=\"%lS\"\n", index + 1, bstr.raw());
1265 else
1266 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1267 }
1268 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1269 if (!bstr.isEmpty())
1270 {
1271 if (details == VMINFO_MACHINEREADABLE)
1272 RTPrintf("USBRemoteAddress%d=\"%lS\"\n", index + 1, bstr.raw());
1273 else
1274 RTPrintf("Address: %lS\n", bstr.raw());
1275 }
1276
1277 if (details != VMINFO_MACHINEREADABLE)
1278 RTPrintf("\n");
1279
1280 rc = en->HasMore (&more);
1281 ASSERT_RET (SUCCEEDED (rc), rc);
1282
1283 index ++;
1284 }
1285 }
1286
1287 index = 0;
1288 /* scope */
1289 {
1290 if (details != VMINFO_MACHINEREADABLE)
1291 RTPrintf ("Currently Attached USB Devices:\n\n");
1292
1293 ComPtr <IUSBDeviceCollection> coll;
1294 CHECK_ERROR_RET (console, COMGETTER(USBDevices) (coll.asOutParam()), rc);
1295
1296 ComPtr <IUSBDeviceEnumerator> en;
1297 CHECK_ERROR_RET (coll, Enumerate (en.asOutParam()), rc);
1298
1299 BOOL more = FALSE;
1300 rc = en->HasMore (&more);
1301 ASSERT_RET (SUCCEEDED (rc), rc);
1302
1303 if (!more)
1304 {
1305 if (details != VMINFO_MACHINEREADABLE)
1306 RTPrintf("<none>\n\n");
1307 }
1308 else
1309 while (more)
1310 {
1311 ComPtr <IUSBDevice> dev;
1312 rc = en->GetNext (dev.asOutParam());
1313 ASSERT_RET (SUCCEEDED (rc), rc);
1314
1315 /* Query info. */
1316 Guid id;
1317 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1318 USHORT usVendorId;
1319 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1320 USHORT usProductId;
1321 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1322 USHORT bcdRevision;
1323 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1324
1325 if (details == VMINFO_MACHINEREADABLE)
1326 RTPrintf("USBAttachedUUID%d=\"%S\"\n"
1327 "USBAttachedVendorId%d=\"%#06x\"\n"
1328 "USBAttachedProductId%d=\"%#06x\"\n"
1329 "USBAttachedRevision%d=\"%#04x%02x\"\n",
1330 index + 1, id.toString().raw(),
1331 index + 1, usVendorId,
1332 index + 1, usProductId,
1333 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1334 else
1335 RTPrintf("UUID: %S\n"
1336 "VendorId: 0x%04x (%04X)\n"
1337 "ProductId: 0x%04x (%04X)\n"
1338 "Revision: %u.%u (%02u%02u)\n",
1339 id.toString().raw(),
1340 usVendorId, usVendorId, usProductId, usProductId,
1341 bcdRevision >> 8, bcdRevision & 0xff,
1342 bcdRevision >> 8, bcdRevision & 0xff);
1343
1344 /* optional stuff. */
1345 Bstr bstr;
1346 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1347 if (!bstr.isEmpty())
1348 {
1349 if (details == VMINFO_MACHINEREADABLE)
1350 RTPrintf("USBAttachedManufacturer%d=\"%lS\"\n", index + 1, bstr.raw());
1351 else
1352 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1353 }
1354 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1355 if (!bstr.isEmpty())
1356 {
1357 if (details == VMINFO_MACHINEREADABLE)
1358 RTPrintf("USBAttachedProduct%d=\"%lS\"\n", index + 1, bstr.raw());
1359 else
1360 RTPrintf("Product: %lS\n", bstr.raw());
1361 }
1362 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1363 if (!bstr.isEmpty())
1364 {
1365 if (details == VMINFO_MACHINEREADABLE)
1366 RTPrintf("USBAttachedSerialNumber%d=\"%lS\"\n", index + 1, bstr.raw());
1367 else
1368 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1369 }
1370 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1371 if (!bstr.isEmpty())
1372 {
1373 if (details == VMINFO_MACHINEREADABLE)
1374 RTPrintf("USBAttachedAddress%d=\"%lS\"\n", index + 1, bstr.raw());
1375 else
1376 RTPrintf("Address: %lS\n", bstr.raw());
1377 }
1378
1379 if (details != VMINFO_MACHINEREADABLE)
1380 RTPrintf("\n");
1381
1382 rc = en->HasMore (&more);
1383 ASSERT_RET (SUCCEEDED (rc), rc);
1384
1385 index ++;
1386 }
1387 }
1388 }
1389 } /* USB */
1390
1391 /*
1392 * Shared folders
1393 */
1394 if (details != VMINFO_MACHINEREADABLE)
1395 RTPrintf("Shared folders: ");
1396 uint32_t numSharedFolders = 0;
1397#if 0 // not yet implemented
1398 /* globally shared folders first */
1399 {
1400 ComPtr<ISharedFolderCollection> sfColl;
1401 ComPtr<ISharedFolderEnumerator> sfEnum;
1402 CHECK_ERROR_RET(virtualBox, COMGETTER(SharedFolders)(sfColl.asOutParam()), rc);
1403 CHECK_ERROR_RET(sfColl, Enumerate(sfEnum.asOutParam()), rc);
1404 BOOL fMore;
1405 sfEnum->HasMore(&fMore);
1406 while (fMore)
1407 {
1408 ComPtr<ISharedFolder> sf;
1409 CHECK_ERROR_RET(sfEnum, GetNext(sf.asOutParam()), rc);
1410 Bstr name, hostPath;
1411 sf->COMGETTER(Name)(name.asOutParam());
1412 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1413 RTPrintf("Name: '%lS', Host path: '%lS' (global mapping)\n", name.raw(), hostPath.raw());
1414 ++numSharedFolders;
1415 CHECK_ERROR_RET(sfEnum, HasMore(&fMore), rc);
1416 }
1417 }
1418#endif
1419 /* now VM mappings */
1420 {
1421 ComPtr<ISharedFolderCollection> sfColl;
1422 ComPtr<ISharedFolderEnumerator> sfEnum;
1423 CHECK_ERROR_RET(machine, COMGETTER(SharedFolders)(sfColl.asOutParam()), rc);
1424 CHECK_ERROR_RET(sfColl, Enumerate(sfEnum.asOutParam()), rc);
1425 ULONG index = 0;
1426 BOOL fMore;
1427 sfEnum->HasMore(&fMore);
1428 while (fMore)
1429 {
1430 ComPtr<ISharedFolder> sf;
1431 CHECK_ERROR_RET(sfEnum, GetNext(sf.asOutParam()), rc);
1432 Bstr name, hostPath;
1433 BOOL writable;
1434 sf->COMGETTER(Name)(name.asOutParam());
1435 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1436 sf->COMGETTER(Writable)(&writable);
1437 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1438 RTPrintf("\n\n");
1439 if (details == VMINFO_MACHINEREADABLE)
1440 {
1441 RTPrintf("SharedFolderNameMachineMapping%d=\"%lS\"\n", index + 1,
1442 name.raw());
1443 RTPrintf("SharedFolderPathMachineMapping%d=\"%lS\"\n", index + 1,
1444 hostPath.raw());
1445 }
1446 else
1447 RTPrintf("Name: '%lS', Host path: '%lS' (machine mapping), %s\n",
1448 name.raw(), hostPath.raw(), writable ? "writable" : "readonly");
1449 ++numSharedFolders;
1450 CHECK_ERROR_RET(sfEnum, HasMore(&fMore), rc);
1451 }
1452 }
1453 /* transient mappings */
1454 if (console)
1455 {
1456 ComPtr<ISharedFolderCollection> sfColl;
1457 ComPtr<ISharedFolderEnumerator> sfEnum;
1458 CHECK_ERROR_RET(console, COMGETTER(SharedFolders)(sfColl.asOutParam()), rc);
1459 CHECK_ERROR_RET(sfColl, Enumerate(sfEnum.asOutParam()), rc);
1460 ULONG index = 0;
1461 BOOL fMore;
1462 sfEnum->HasMore(&fMore);
1463 while (fMore)
1464 {
1465 ComPtr<ISharedFolder> sf;
1466 CHECK_ERROR_RET(sfEnum, GetNext(sf.asOutParam()), rc);
1467 Bstr name, hostPath;
1468 sf->COMGETTER(Name)(name.asOutParam());
1469 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1470 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1471 RTPrintf("\n\n");
1472 if (details == VMINFO_MACHINEREADABLE)
1473 {
1474 RTPrintf("SharedFolderNameTransientMapping%d=\"%lS\"\n", index + 1,
1475 name.raw());
1476 RTPrintf("SharedFolderPathTransientMapping%d=\"%lS\"\n", index + 1,
1477 hostPath.raw());
1478 }
1479 else
1480 RTPrintf("Name: '%lS', Host path: '%lS' (transient mapping)\n", name.raw(), hostPath.raw());
1481 ++numSharedFolders;
1482 CHECK_ERROR_RET(sfEnum, HasMore(&fMore), rc);
1483 }
1484 }
1485 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1486 RTPrintf("<none>\n");
1487 if (details != VMINFO_MACHINEREADABLE)
1488 RTPrintf("\n");
1489
1490 if (console)
1491 {
1492 /*
1493 * Live VRDP info.
1494 */
1495 ComPtr<IRemoteDisplayInfo> remoteDisplayInfo;
1496 CHECK_ERROR_RET(console, COMGETTER(RemoteDisplayInfo)(remoteDisplayInfo.asOutParam()), rc);
1497 BOOL Active;
1498 ULONG NumberOfClients;
1499 LONG64 BeginTime;
1500 LONG64 EndTime;
1501 ULONG64 BytesSent;
1502 ULONG64 BytesSentTotal;
1503 ULONG64 BytesReceived;
1504 ULONG64 BytesReceivedTotal;
1505 Bstr User;
1506 Bstr Domain;
1507 Bstr ClientName;
1508 Bstr ClientIP;
1509 ULONG ClientVersion;
1510 ULONG EncryptionStyle;
1511
1512 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Active) (&Active), rc);
1513 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(NumberOfClients) (&NumberOfClients), rc);
1514 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BeginTime) (&BeginTime), rc);
1515 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EndTime) (&EndTime), rc);
1516 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSent) (&BytesSent), rc);
1517 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSentTotal) (&BytesSentTotal), rc);
1518 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceived) (&BytesReceived), rc);
1519 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceivedTotal) (&BytesReceivedTotal), rc);
1520 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(User) (User.asOutParam ()), rc);
1521 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Domain) (Domain.asOutParam ()), rc);
1522 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientName) (ClientName.asOutParam ()), rc);
1523 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientIP) (ClientIP.asOutParam ()), rc);
1524 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientVersion) (&ClientVersion), rc);
1525 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EncryptionStyle) (&EncryptionStyle), rc);
1526
1527 if (details == VMINFO_MACHINEREADABLE)
1528 RTPrintf("VRDPActiveConnection=\"%s\"\n", Active ? "on": "off");
1529 else
1530 RTPrintf("VRDP Connection: %s\n", Active? "active": "not active");
1531
1532 if (details == VMINFO_MACHINEREADABLE)
1533 RTPrintf("VRDPClients=%d\n", NumberOfClients);
1534 else
1535 RTPrintf("Clients so far: %d\n", NumberOfClients);
1536
1537 if (NumberOfClients > 0)
1538 {
1539 char timestr[128];
1540
1541 if (Active)
1542 {
1543 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1544 if (details == VMINFO_MACHINEREADABLE)
1545 RTPrintf("VRDPStartTime=\"%s\"\n", timestr);
1546 else
1547 RTPrintf("Start time: %s\n", timestr);
1548 }
1549 else
1550 {
1551 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1552 if (details == VMINFO_MACHINEREADABLE)
1553 RTPrintf("VRDPLastStartTime=\"%s\"\n", timestr);
1554 else
1555 RTPrintf("Last started: %s\n", timestr);
1556 makeTimeStr (timestr, sizeof (timestr), EndTime);
1557 if (details == VMINFO_MACHINEREADABLE)
1558 RTPrintf("VRDPLastEndTime=\"%s\"\n", timestr);
1559 else
1560 RTPrintf("Last ended: %s\n", timestr);
1561 }
1562
1563 uint64_t ThroughputSend = 0;
1564 uint64_t ThroughputReceive = 0;
1565 if (EndTime != BeginTime)
1566 {
1567 ThroughputSend = (BytesSent * 1000) / (EndTime - BeginTime);
1568 ThroughputReceive = (BytesReceived * 1000) / (EndTime - BeginTime);
1569 }
1570
1571 if (details == VMINFO_MACHINEREADABLE)
1572 {
1573 RTPrintf("VRDPBytesSent=%llu\n", BytesSent);
1574 RTPrintf("VRDPThroughputSend=%llu\n", ThroughputSend);
1575 RTPrintf("VRDPBytesSentTotal=%llu\n", BytesSentTotal);
1576
1577 RTPrintf("VRDPBytesReceived=%llu\n", BytesReceived);
1578 RTPrintf("VRDPThroughputReceive=%llu\n", ThroughputReceive);
1579 RTPrintf("VRDPBytesReceivedTotal=%llu\n", BytesReceivedTotal);
1580 }
1581 else
1582 {
1583 RTPrintf("Sent: %llu Bytes\n", BytesSent);
1584 RTPrintf("Average speed: %llu B/s\n", ThroughputSend);
1585 RTPrintf("Sent total: %llu Bytes\n", BytesSentTotal);
1586
1587 RTPrintf("Received: %llu Bytes\n", BytesReceived);
1588 RTPrintf("Speed: %llu B/s\n", ThroughputReceive);
1589 RTPrintf("Received total: %llu Bytes\n", BytesReceivedTotal);
1590 }
1591
1592 if (Active)
1593 {
1594 if (details == VMINFO_MACHINEREADABLE)
1595 {
1596 RTPrintf("VRDPUserName=\"%lS\"\n", User.raw());
1597 RTPrintf("VRDPDomain=\"%lS\"\n", Domain.raw());
1598 RTPrintf("VRDPClientName=\"%lS\"\n", ClientName.raw());
1599 RTPrintf("VRDPClientIP=\"%lS\"\n", ClientIP.raw());
1600 RTPrintf("VRDPClientVersion=%d\n", ClientVersion);
1601 RTPrintf("VRDPEncryption=\"%s\"\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1602 }
1603 else
1604 {
1605 RTPrintf("User name: %lS\n", User.raw());
1606 RTPrintf("Domain: %lS\n", Domain.raw());
1607 RTPrintf("Client name: %lS\n", ClientName.raw());
1608 RTPrintf("Client IP: %lS\n", ClientIP.raw());
1609 RTPrintf("Client version: %d\n", ClientVersion);
1610 RTPrintf("Encryption: %s\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1611 }
1612 }
1613 }
1614
1615 if (details != VMINFO_MACHINEREADABLE)
1616 RTPrintf("\n");
1617 }
1618
1619 if ( details == VMINFO_STANDARD
1620 || details == VMINFO_FULL
1621 || details == VMINFO_MACHINEREADABLE)
1622 {
1623 Bstr description;
1624 machine->COMGETTER(Description)(description.asOutParam());
1625 if (!description.isEmpty())
1626 {
1627 if (details == VMINFO_MACHINEREADABLE)
1628 RTPrintf("description=\"%lS\"\n", description.raw());
1629 else
1630 RTPrintf("Description:\n%lS\n", description.raw());
1631 }
1632 }
1633
1634 ULONG guestVal;
1635 if (details != VMINFO_MACHINEREADABLE)
1636 RTPrintf("Guest:\n\n");
1637
1638#ifdef VBOX_WITH_MEM_BALLOONING
1639 rc = machine->COMGETTER(MemoryBalloonSize)(&guestVal);
1640 if (SUCCEEDED(rc))
1641 {
1642 if (details == VMINFO_MACHINEREADABLE)
1643 RTPrintf("GuestMemoryBalloon=%d\n", guestVal);
1644 else
1645 RTPrintf("Configured memory balloon size: %d MB\n", guestVal);
1646 }
1647#endif
1648 rc = machine->COMGETTER(StatisticsUpdateInterval)(&guestVal);
1649 if (SUCCEEDED(rc))
1650 {
1651 if (details == VMINFO_MACHINEREADABLE)
1652 RTPrintf("GuestStatisticsUpdateInterval=%d\n", guestVal);
1653 else
1654 {
1655 if (guestVal == 0)
1656 RTPrintf("Statistics update: disabled\n");
1657 else
1658 RTPrintf("Statistics update interval: %d seconds\n", guestVal);
1659 }
1660 }
1661 if (details != VMINFO_MACHINEREADABLE)
1662 RTPrintf("\n");
1663
1664 if ( console
1665 && ( details == VMINFO_STATISTICS
1666 || details == VMINFO_FULL
1667 || details == VMINFO_MACHINEREADABLE))
1668 {
1669 ComPtr <IGuest> guest;
1670
1671 rc = console->COMGETTER(Guest)(guest.asOutParam());
1672 if (SUCCEEDED(rc))
1673 {
1674 ULONG statVal;
1675
1676 rc = guest->GetStatistic(0, GuestStatisticType_SampleNumber, &statVal);
1677 if (details == VMINFO_MACHINEREADABLE)
1678 RTPrintf("StatGuestSample=%d\n", statVal);
1679 else
1680 RTPrintf("Guest statistics for sample %d:\n\n", statVal);
1681
1682 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Idle, &statVal);
1683 if (SUCCEEDED(rc))
1684 {
1685 if (details == VMINFO_MACHINEREADABLE)
1686 RTPrintf("StatGuestLoadIdleCPU%d=%d\n", 0, statVal);
1687 else
1688 RTPrintf("CPU%d: CPU Load Idle %-3d%%\n", 0, statVal);
1689 }
1690
1691 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Kernel, &statVal);
1692 if (SUCCEEDED(rc))
1693 {
1694 if (details == VMINFO_MACHINEREADABLE)
1695 RTPrintf("StatGuestLoadKernelCPU%d=%d\n", 0, statVal);
1696 else
1697 RTPrintf("CPU%d: CPU Load Kernel %-3d%%\n", 0, statVal);
1698 }
1699
1700 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_User, &statVal);
1701 if (SUCCEEDED(rc))
1702 {
1703 if (details == VMINFO_MACHINEREADABLE)
1704 RTPrintf("StatGuestLoadUserCPU%d=%d\n", 0, statVal);
1705 else
1706 RTPrintf("CPU%d: CPU Load User %-3d%%\n", 0, statVal);
1707 }
1708
1709 rc = guest->GetStatistic(0, GuestStatisticType_Threads, &statVal);
1710 if (SUCCEEDED(rc))
1711 {
1712 if (details == VMINFO_MACHINEREADABLE)
1713 RTPrintf("StatGuestThreadsCPU%d=%d\n", 0, statVal);
1714 else
1715 RTPrintf("CPU%d: Threads %d\n", 0, statVal);
1716 }
1717
1718 rc = guest->GetStatistic(0, GuestStatisticType_Processes, &statVal);
1719 if (SUCCEEDED(rc))
1720 {
1721 if (details == VMINFO_MACHINEREADABLE)
1722 RTPrintf("StatGuestProcessesCPU%d=%d\n", 0, statVal);
1723 else
1724 RTPrintf("CPU%d: Processes %d\n", 0, statVal);
1725 }
1726
1727 rc = guest->GetStatistic(0, GuestStatisticType_Handles, &statVal);
1728 if (SUCCEEDED(rc))
1729 {
1730 if (details == VMINFO_MACHINEREADABLE)
1731 RTPrintf("StatGuestHandlesCPU%d=%d\n", 0, statVal);
1732 else
1733 RTPrintf("CPU%d: Handles %d\n", 0, statVal);
1734 }
1735
1736 rc = guest->GetStatistic(0, GuestStatisticType_MemoryLoad, &statVal);
1737 if (SUCCEEDED(rc))
1738 {
1739 if (details == VMINFO_MACHINEREADABLE)
1740 RTPrintf("StatGuestMemoryLoadCPU%d=%d\n", 0, statVal);
1741 else
1742 RTPrintf("CPU%d: Memory Load %d%%\n", 0, statVal);
1743 }
1744
1745 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemTotal, &statVal);
1746 if (SUCCEEDED(rc))
1747 {
1748 if (details == VMINFO_MACHINEREADABLE)
1749 RTPrintf("StatGuestMemoryTotalPhysCPU%d=%d\n", 0, statVal);
1750 else
1751 RTPrintf("CPU%d: Total physical memory %-4d MB\n", 0, statVal);
1752 }
1753
1754 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemAvailable, &statVal);
1755 if (SUCCEEDED(rc))
1756 {
1757 if (details == VMINFO_MACHINEREADABLE)
1758 RTPrintf("StatGuestMemoryFreePhysCPU%d=%d\n", 0, statVal);
1759 else
1760 RTPrintf("CPU%d: Free physical memory %-4d MB\n", 0, statVal);
1761 }
1762
1763#ifdef VBOX_WITH_MEM_BALLOONING
1764 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemBalloon, &statVal);
1765 if (SUCCEEDED(rc))
1766 {
1767 if (details == VMINFO_MACHINEREADABLE)
1768 RTPrintf("StatGuestMemoryBalloonCPU%d=%d\n", 0, statVal);
1769 else
1770 RTPrintf("CPU%d: Memory balloon size %-4d MB\n", 0, statVal);
1771 }
1772#endif
1773 rc = guest->GetStatistic(0, GuestStatisticType_MemCommitTotal, &statVal);
1774 if (SUCCEEDED(rc))
1775 {
1776 if (details == VMINFO_MACHINEREADABLE)
1777 RTPrintf("StatGuestMemoryCommittedCPU%d=%d\n", 0, statVal);
1778 else
1779 RTPrintf("CPU%d: Committed memory %-4d MB\n", 0, statVal);
1780 }
1781
1782 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelTotal, &statVal);
1783 if (SUCCEEDED(rc))
1784 {
1785 if (details == VMINFO_MACHINEREADABLE)
1786 RTPrintf("StatGuestMemoryTotalKernelCPU%d=%d\n", 0, statVal);
1787 else
1788 RTPrintf("CPU%d: Total kernel memory %-4d MB\n", 0, statVal);
1789 }
1790
1791 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelPaged, &statVal);
1792 if (SUCCEEDED(rc))
1793 {
1794 if (details == VMINFO_MACHINEREADABLE)
1795 RTPrintf("StatGuestMemoryPagedKernelCPU%d=%d\n", 0, statVal);
1796 else
1797 RTPrintf("CPU%d: Paged kernel memory %-4d MB\n", 0, statVal);
1798 }
1799
1800 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelNonpaged, &statVal);
1801 if (SUCCEEDED(rc))
1802 {
1803 if (details == VMINFO_MACHINEREADABLE)
1804 RTPrintf("StatGuestMemoryNonpagedKernelCPU%d=%d\n", 0, statVal);
1805 else
1806 RTPrintf("CPU%d: Nonpaged kernel memory %-4d MB\n", 0, statVal);
1807 }
1808
1809 rc = guest->GetStatistic(0, GuestStatisticType_MemSystemCache, &statVal);
1810 if (SUCCEEDED(rc))
1811 {
1812 if (details == VMINFO_MACHINEREADABLE)
1813 RTPrintf("StatGuestSystemCacheSizeCPU%d=%d\n", 0, statVal);
1814 else
1815 RTPrintf("CPU%d: System cache size %-4d MB\n", 0, statVal);
1816 }
1817
1818 rc = guest->GetStatistic(0, GuestStatisticType_PageFileSize, &statVal);
1819 if (SUCCEEDED(rc))
1820 {
1821 if (details == VMINFO_MACHINEREADABLE)
1822 RTPrintf("StatGuestPageFileSizeCPU%d=%d\n", 0, statVal);
1823 else
1824 RTPrintf("CPU%d: Page file size %-4d MB\n", 0, statVal);
1825 }
1826
1827 RTPrintf("\n");
1828 }
1829 else
1830 {
1831 if (details != VMINFO_MACHINEREADABLE)
1832 {
1833 RTPrintf("[!] FAILED calling console->getGuest at line %d!\n", __LINE__);
1834 PRINT_RC_MESSAGE(rc);
1835 }
1836 }
1837 }
1838
1839 /*
1840 * snapshots
1841 */
1842 ComPtr<ISnapshot> snapshot;
1843 rc = machine->GetSnapshot(Guid(), snapshot.asOutParam());
1844 if (SUCCEEDED(rc) && snapshot)
1845 {
1846 if (details != VMINFO_MACHINEREADABLE)
1847 RTPrintf("Snapshots:\n\n");
1848 showSnapshots(snapshot, details);
1849 }
1850
1851 if (details != VMINFO_MACHINEREADABLE)
1852 RTPrintf("\n");
1853 return S_OK;
1854}
1855
1856#if defined(_MSC_VER)
1857# pragma optimize("", on)
1858#endif
1859
1860int handleShowVMInfo(int argc, char *argv[],
1861 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
1862{
1863 HRESULT rc;
1864
1865 /* at least one option: the UUID or name of the VM */
1866 if (argc < 1)
1867 return errorSyntax(USAGE_SHOWVMINFO, "Incorrect number of parameters");
1868
1869 /* try to find the given machine */
1870 ComPtr <IMachine> machine;
1871 Guid uuid (argv[0]);
1872 if (!uuid.isEmpty())
1873 {
1874 CHECK_ERROR (virtualBox, GetMachine (uuid, machine.asOutParam()));
1875 }
1876 else
1877 {
1878 CHECK_ERROR (virtualBox, FindMachine (Bstr(argv[0]), machine.asOutParam()));
1879 if (SUCCEEDED (rc))
1880 machine->COMGETTER(Id) (uuid.asOutParam());
1881 }
1882 if (FAILED (rc))
1883 return 1;
1884
1885 /* 2nd option can be -details, -statistics or -argdump */
1886 VMINFO_DETAILS details = VMINFO_NONE;
1887 bool fDetails = false;
1888 bool fStatistics = false;
1889 bool fMachinereadable = false;
1890 for (int i=1;i<argc;i++)
1891 {
1892 if (!strcmp(argv[i], "-details"))
1893 fDetails = true;
1894 else
1895 if (!strcmp(argv[i], "-statistics"))
1896 fStatistics = true;
1897 if (!strcmp(argv[1], "-machinereadable"))
1898 fMachinereadable = true;
1899 }
1900 if (fMachinereadable)
1901 details = VMINFO_MACHINEREADABLE;
1902 else
1903 if (fDetails && fStatistics)
1904 details = VMINFO_FULL;
1905 else
1906 if (fDetails)
1907 details = VMINFO_STANDARD;
1908 else
1909 if (fStatistics)
1910 details = VMINFO_STATISTICS;
1911
1912 ComPtr <IConsole> console;
1913
1914 /* open an existing session for the VM */
1915 rc = virtualBox->OpenExistingSession (session, uuid);
1916 if (SUCCEEDED(rc))
1917 /* get the session machine */
1918 rc = session->COMGETTER(Machine)(machine.asOutParam());
1919 if (SUCCEEDED(rc))
1920 /* get the session console */
1921 rc = session->COMGETTER(Console)(console.asOutParam());
1922
1923 rc = showVMInfo (virtualBox, machine, console, details);
1924
1925 if (console)
1926 session->Close();
1927
1928 return SUCCEEDED (rc) ? 0 : 1;
1929}
1930
1931#endif /* !VBOX_ONLY_DOCS */
1932
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