VirtualBox

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

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

Main,VMM,Frontends,++: Teminology. Added a bind address for the (target) teleporter.

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