VirtualBox

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

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

VBoxManage: new option "--log" for showvminfo, printing the specified VM log file

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