VirtualBox

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

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

FE/VBoxManage: add support for VDE networking. Contributed by Renzo Davoli, VirtualSquare?, University of Bologna

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