VirtualBox

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

Last change on this file since 23569 was 23561, checked in by vboxsync, 15 years ago

VBoxManage: comment

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette