VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp@ 34913

Last change on this file since 34913 was 34244, checked in by vboxsync, 14 years ago

Main,Config.kmk,VBoxManage,ExtPacks: Moved the VRDE bits from IVirtualBox to the extension packs; changed ISystemProperties and IVRDEServer to talk about VRDE extension packs instead of VRDE libraries.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.2 KB
Line 
1/* $Id: VBoxManageList.cpp 34244 2010-11-22 14:31:02Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
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/string.h>
35#include <iprt/time.h>
36#include <iprt/getopt.h>
37#include <iprt/ctype.h>
38
39#include "VBoxManage.h"
40using namespace com;
41
42#ifdef VBOX_WITH_HOSTNETIF_API
43static const char *getHostIfMediumTypeText(HostNetworkInterfaceMediumType_T enmType)
44{
45 switch (enmType)
46 {
47 case HostNetworkInterfaceMediumType_Ethernet: return "Ethernet";
48 case HostNetworkInterfaceMediumType_PPP: return "PPP";
49 case HostNetworkInterfaceMediumType_SLIP: return "SLIP";
50 }
51 return "Unknown";
52}
53
54static const char *getHostIfStatusText(HostNetworkInterfaceStatus_T enmStatus)
55{
56 switch (enmStatus)
57 {
58 case HostNetworkInterfaceStatus_Up: return "Up";
59 case HostNetworkInterfaceStatus_Down: return "Down";
60 }
61 return "Unknown";
62}
63#endif /* VBOX_WITH_HOSTNETIF_API */
64
65static const char*getDeviceTypeText(DeviceType_T enmType)
66{
67 switch (enmType)
68 {
69 case DeviceType_HardDisk: return "HardDisk";
70 case DeviceType_DVD: return "DVD";
71 case DeviceType_Floppy: return "Floppy";
72 }
73 return "Unknown";
74}
75
76static void listMedia(const ComPtr<IVirtualBox> aVirtualBox,
77 const com::SafeIfaceArray<IMedium> &aMedia,
78 const char *pszParentUUIDStr)
79{
80 HRESULT rc;
81 for (size_t i = 0; i < aMedia.size(); ++i)
82 {
83 ComPtr<IMedium> pMedium = aMedia[i];
84 Bstr uuid;
85 pMedium->COMGETTER(Id)(uuid.asOutParam());
86 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
87 if (pszParentUUIDStr)
88 RTPrintf("Parent UUID: %s\n", pszParentUUIDStr);
89 Bstr format;
90 pMedium->COMGETTER(Format)(format.asOutParam());
91 RTPrintf("Format: %lS\n", format.raw());
92 Bstr filepath;
93 pMedium->COMGETTER(Location)(filepath.asOutParam());
94 RTPrintf("Location: %lS\n", filepath.raw());
95
96 MediumState_T enmState;
97 pMedium->RefreshState(&enmState);
98 const char *stateStr = "unknown";
99 switch (enmState)
100 {
101 case MediumState_NotCreated:
102 stateStr = "not created";
103 break;
104 case MediumState_Created:
105 stateStr = "created";
106 break;
107 case MediumState_LockedRead:
108 stateStr = "locked read";
109 break;
110 case MediumState_LockedWrite:
111 stateStr = "locked write";
112 break;
113 case MediumState_Inaccessible:
114 stateStr = "inaccessible";
115 break;
116 case MediumState_Creating:
117 stateStr = "creating";
118 break;
119 case MediumState_Deleting:
120 stateStr = "deleting";
121 break;
122 }
123 RTPrintf("State: %s\n", stateStr);
124
125 MediumType_T type;
126 pMedium->COMGETTER(Type)(&type);
127 const char *typeStr = "unknown";
128 switch (type)
129 {
130 case MediumType_Normal:
131 typeStr = "normal";
132 break;
133 case MediumType_Immutable:
134 typeStr = "immutable";
135 break;
136 case MediumType_Writethrough:
137 typeStr = "writethrough";
138 break;
139 case MediumType_Shareable:
140 typeStr = "shareable";
141 break;
142 case MediumType_Readonly:
143 typeStr = "readonly";
144 break;
145 }
146 RTPrintf("Type: %s\n", typeStr);
147
148 com::SafeArray<BSTR> machineIds;
149 pMedium->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
150 for (size_t j = 0; j < machineIds.size(); ++j)
151 {
152 ComPtr<IMachine> machine;
153 CHECK_ERROR(aVirtualBox, FindMachine(machineIds[j], machine.asOutParam()));
154 ASSERT(machine);
155 Bstr name;
156 machine->COMGETTER(Name)(name.asOutParam());
157 RTPrintf("%s%lS (UUID: %lS)",
158 j == 0 ? "Usage: " : " ",
159 name.raw(), machineIds[j]);
160 com::SafeArray<BSTR> snapshotIds;
161 pMedium->GetSnapshotIds(machineIds[j],
162 ComSafeArrayAsOutParam(snapshotIds));
163 for (size_t k = 0; k < snapshotIds.size(); ++k)
164 {
165 ComPtr<ISnapshot> snapshot;
166 machine->FindSnapshot(snapshotIds[k], snapshot.asOutParam());
167 if (snapshot)
168 {
169 Bstr snapshotName;
170 snapshot->COMGETTER(Name)(snapshotName.asOutParam());
171 RTPrintf(" [%lS (UUID: %lS)]", snapshotName.raw(), snapshotIds[k]);
172 }
173 }
174 RTPrintf("\n");
175 }
176 RTPrintf("\n");
177
178 com::SafeIfaceArray<IMedium> children;
179 CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
180 if (children.size() > 0)
181 {
182 // depth first listing of child media
183 listMedia(aVirtualBox, children, Utf8Str(uuid).c_str());
184 }
185 }
186}
187
188
189/**
190 * List extension packs.
191 *
192 * @returns See produceList.
193 * @param rptrVirtualBox Reference to the IVirtualBox smart pointer.
194 */
195static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &rptrVirtualBox)
196{
197 ComObjPtr<IExtPackManager> ptrExtPackMgr;
198 CHECK_ERROR2_RET(rptrVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
199
200 SafeIfaceArray<IExtPack> extPacks;
201 CHECK_ERROR2_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
202 RTPrintf("Extension Packs: %u\n", extPacks.size());
203
204 HRESULT hrc = S_OK;
205 for (size_t i = 0; i < extPacks.size(); i++)
206 {
207 /* Read all the properties. */
208 Bstr bstrName;
209 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
210 Bstr bstrDesc;
211 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
212 Bstr bstrVersion;
213 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
214 ULONG uRevision;
215 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
216 Bstr bstrVrdeModule;
217 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(VRDEModule)(bstrVrdeModule.asOutParam()),hrc=hrcCheck; bstrVrdeModule.setNull());
218 BOOL fUsable;
219 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
220 Bstr bstrWhy;
221 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
222
223 /* Display them. */
224 if (i)
225 RTPrintf("\n");
226 RTPrintf("Pack no.%2zu: %lS\n"
227 "Version: %lS\n"
228 "Revision: %u\n"
229 "Description: %lS\n"
230 "VRDE Module: %lS\n"
231 "Usable: %RTbool\n"
232 "Why unusable: %lS\n",
233 i, bstrName.raw(),
234 bstrVersion.raw(),
235 uRevision,
236 bstrDesc.raw(),
237 bstrVrdeModule.raw(),
238 fUsable != FALSE,
239 bstrWhy.raw());
240
241 /* Query plugins and display them. */
242 }
243 return hrc;
244}
245
246
247/**
248 * The type of lists we can produce.
249 */
250enum enmListType
251{
252 kListNotSpecified = 1000,
253 kListVMs,
254 kListRunningVMs,
255 kListOsTypes,
256 kListHostDvds,
257 kListHostFloppies,
258 kListBridgedInterfaces,
259#if defined(VBOX_WITH_NETFLT)
260 kListHostOnlyInterfaces,
261#endif
262 kListHostCpuIDs,
263 kListHostInfo,
264 kListHddBackends,
265 kListHdds,
266 kListDvds,
267 kListFloppies,
268 kListUsbHost,
269 kListUsbFilters,
270 kListSystemProperties,
271 kListDhcpServers,
272 kListExtPacks
273};
274
275
276/**
277 * Produces the specified listing.
278 *
279 * @returns S_OK or some COM error code that has been reported in full.
280 * @param enmList The list to produce.
281 * @param fOptLong Long (@c true) or short list format.
282 * @param rptrVirtualBox Reference to the IVirtualBox smart pointer.
283 */
284static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, const ComPtr<IVirtualBox> &rptrVirtualBox)
285{
286 HRESULT rc = S_OK;
287 switch (enmCommand)
288 {
289 case kListNotSpecified:
290 AssertFailed();
291 return E_FAIL;
292
293 case kListVMs:
294 {
295 /*
296 * Get the list of all registered VMs
297 */
298 com::SafeIfaceArray<IMachine> machines;
299 rc = rptrVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
300 if (SUCCEEDED(rc))
301 {
302 /*
303 * Iterate through the collection
304 */
305 for (size_t i = 0; i < machines.size(); ++i)
306 {
307 if (machines[i])
308 rc = showVMInfo(rptrVirtualBox, machines[i], fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
309 }
310 }
311 break;
312 }
313
314 case kListRunningVMs:
315 {
316 /*
317 * Get the list of all _running_ VMs
318 */
319 com::SafeIfaceArray<IMachine> machines;
320 rc = rptrVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
321 if (SUCCEEDED(rc))
322 {
323 /*
324 * Iterate through the collection
325 */
326 for (size_t i = 0; i < machines.size(); ++i)
327 {
328 if (machines[i])
329 {
330 MachineState_T machineState;
331 rc = machines[i]->COMGETTER(State)(&machineState);
332 if (SUCCEEDED(rc))
333 {
334 switch (machineState)
335 {
336 case MachineState_Running:
337 case MachineState_Teleporting:
338 case MachineState_LiveSnapshotting:
339 case MachineState_Paused:
340 case MachineState_TeleportingPausedVM:
341 rc = showVMInfo(rptrVirtualBox, machines[i], fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
342 break;
343 }
344 }
345 }
346 }
347 }
348 break;
349 }
350
351 case kListOsTypes:
352 {
353 com::SafeIfaceArray<IGuestOSType> coll;
354 rc = rptrVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
355 if (SUCCEEDED(rc))
356 {
357 /*
358 * Iterate through the collection.
359 */
360 for (size_t i = 0; i < coll.size(); ++i)
361 {
362 ComPtr<IGuestOSType> guestOS;
363 guestOS = coll[i];
364 Bstr guestId;
365 guestOS->COMGETTER(Id)(guestId.asOutParam());
366 RTPrintf("ID: %lS\n", guestId.raw());
367 Bstr guestDescription;
368 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
369 RTPrintf("Description: %lS\n\n", guestDescription.raw());
370 }
371 }
372 break;
373 }
374
375 case kListHostDvds:
376 {
377 ComPtr<IHost> host;
378 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
379 com::SafeIfaceArray<IMedium> coll;
380 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
381 if (SUCCEEDED(rc))
382 {
383 for (size_t i = 0; i < coll.size(); ++i)
384 {
385 ComPtr<IMedium> dvdDrive = coll[i];
386 Bstr uuid;
387 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
388 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
389 Bstr name;
390 dvdDrive->COMGETTER(Name)(name.asOutParam());
391 RTPrintf("Name: %lS\n\n", name.raw());
392 }
393 }
394 break;
395 }
396
397 case kListHostFloppies:
398 {
399 ComPtr<IHost> host;
400 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
401 com::SafeIfaceArray<IMedium> coll;
402 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
403 if (SUCCEEDED(rc))
404 {
405 for (size_t i = 0; i < coll.size(); ++i)
406 {
407 ComPtr<IMedium> floppyDrive = coll[i];
408 Bstr uuid;
409 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
410 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
411 Bstr name;
412 floppyDrive->COMGETTER(Name)(name.asOutParam());
413 RTPrintf("Name: %lS\n\n", name.raw());
414 }
415 }
416 break;
417 }
418
419 /** @todo function. */
420 case kListBridgedInterfaces:
421#if defined(VBOX_WITH_NETFLT)
422 case kListHostOnlyInterfaces:
423#endif
424 {
425 ComPtr<IHost> host;
426 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
427 com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
428#if defined(VBOX_WITH_NETFLT)
429 if (enmCommand == kListBridgedInterfaces)
430 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
431 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
432 else
433 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
434 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
435#else
436 CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
437#endif
438 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
439 {
440 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
441#ifndef VBOX_WITH_HOSTNETIF_API
442 Bstr interfaceName;
443 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
444 RTPrintf("Name: %lS\n", interfaceName.raw());
445 Guid interfaceGuid;
446 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
447 RTPrintf("GUID: %lS\n\n", Bstr(interfaceGuid.toString()).raw());
448#else /* VBOX_WITH_HOSTNETIF_API */
449 Bstr interfaceName;
450 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
451 RTPrintf("Name: %lS\n", interfaceName.raw());
452 Bstr interfaceGuid;
453 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
454 RTPrintf("GUID: %lS\n", interfaceGuid.raw());
455 BOOL bDhcpEnabled;
456 networkInterface->COMGETTER(DhcpEnabled)(&bDhcpEnabled);
457 RTPrintf("Dhcp: %s\n", bDhcpEnabled ? "Enabled" : "Disabled");
458
459 Bstr IPAddress;
460 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
461 RTPrintf("IPAddress: %lS\n", IPAddress.raw());
462 Bstr NetworkMask;
463 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
464 RTPrintf("NetworkMask: %lS\n", NetworkMask.raw());
465 Bstr IPV6Address;
466 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
467 RTPrintf("IPV6Address: %lS\n", IPV6Address.raw());
468 ULONG IPV6NetworkMaskPrefixLength;
469 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
470 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
471 Bstr HardwareAddress;
472 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
473 RTPrintf("HardwareAddress: %lS\n", HardwareAddress.raw());
474 HostNetworkInterfaceMediumType_T Type;
475 networkInterface->COMGETTER(MediumType)(&Type);
476 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
477 HostNetworkInterfaceStatus_T Status;
478 networkInterface->COMGETTER(Status)(&Status);
479 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
480 Bstr netName;
481 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
482 RTPrintf("VBoxNetworkName: %lS\n\n", netName.raw());
483#endif
484 }
485 break;
486 }
487
488 /** @todo function. */
489 case kListHostInfo:
490 {
491 ComPtr<IHost> Host;
492 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()));
493
494 RTPrintf("Host Information:\n\n");
495
496 LONG64 u64UtcTime = 0;
497 CHECK_ERROR(Host, COMGETTER(UTCTime)(&u64UtcTime));
498 RTTIMESPEC timeSpec;
499 char szTime[32];
500 RTPrintf("Host time: %s\n", RTTimeSpecToString(RTTimeSpecSetMilli(&timeSpec, u64UtcTime), szTime, sizeof(szTime)));
501
502 ULONG processorOnlineCount = 0;
503 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
504 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
505 ULONG processorCount = 0;
506 CHECK_ERROR(Host, COMGETTER(ProcessorCount)(&processorCount));
507 RTPrintf("Processor count: %lu\n", processorCount);
508 ULONG processorSpeed = 0;
509 Bstr processorDescription;
510 for (ULONG i = 0; i < processorCount; i++)
511 {
512 CHECK_ERROR(Host, GetProcessorSpeed(i, &processorSpeed));
513 if (processorSpeed)
514 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
515 else
516 RTPrintf("Processor#%u speed: unknown\n", i, processorSpeed);
517 CHECK_ERROR(Host, GetProcessorDescription(i, processorDescription.asOutParam()));
518 RTPrintf("Processor#%u description: %lS\n", i, processorDescription.raw());
519 }
520
521 ULONG memorySize = 0;
522 CHECK_ERROR(Host, COMGETTER(MemorySize)(&memorySize));
523 RTPrintf("Memory size: %lu MByte\n", memorySize);
524
525 ULONG memoryAvailable = 0;
526 CHECK_ERROR(Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
527 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
528
529 Bstr operatingSystem;
530 CHECK_ERROR(Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
531 RTPrintf("Operating system: %lS\n", operatingSystem.raw());
532
533 Bstr oSVersion;
534 CHECK_ERROR(Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
535 RTPrintf("Operating system version: %lS\n", oSVersion.raw());
536 break;
537 }
538
539 case kListHostCpuIDs:
540 {
541 ComPtr<IHost> Host;
542 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()));
543
544 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
545 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
546 static uint32_t const s_auCpuIdRanges[] =
547 {
548 UINT32_C(0x00000000), UINT32_C(0x0000007f),
549 UINT32_C(0x80000000), UINT32_C(0x8000007f),
550 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
551 };
552 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
553 {
554 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
555 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
556 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
557 continue;
558 cLeafs++;
559 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
560 {
561 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
562 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
563 }
564 }
565 break;
566 }
567
568 /** @todo function. */
569 case kListHddBackends:
570 {
571 ComPtr<ISystemProperties> systemProperties;
572 CHECK_ERROR(rptrVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
573 com::SafeIfaceArray<IMediumFormat> mediumFormats;
574 CHECK_ERROR(systemProperties, COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
575
576 RTPrintf("Supported hard disk backends:\n\n");
577 for (size_t i = 0; i < mediumFormats.size(); ++i)
578 {
579 /* General information */
580 Bstr id;
581 CHECK_ERROR(mediumFormats[i], COMGETTER(Id)(id.asOutParam()));
582
583 Bstr description;
584 CHECK_ERROR(mediumFormats[i],
585 COMGETTER(Id)(description.asOutParam()));
586
587 ULONG caps;
588 CHECK_ERROR(mediumFormats[i],
589 COMGETTER(Capabilities)(&caps));
590
591 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
592 i, id.raw(), description.raw(), caps);
593
594 /* File extensions */
595 com::SafeArray <BSTR> fileExtensions;
596 com::SafeArray <DeviceType_T> deviceTypes;
597 CHECK_ERROR(mediumFormats[i],
598 DescribeFileExtensions(ComSafeArrayAsOutParam(fileExtensions), ComSafeArrayAsOutParam(deviceTypes)));
599 for (size_t j = 0; j < fileExtensions.size(); ++j)
600 {
601 RTPrintf("%ls (%s)", Bstr(fileExtensions[j]).raw(), getDeviceTypeText(deviceTypes[j]));
602 if (j != fileExtensions.size()-1)
603 RTPrintf(",");
604 }
605 RTPrintf("'");
606
607 /* Configuration keys */
608 com::SafeArray <BSTR> propertyNames;
609 com::SafeArray <BSTR> propertyDescriptions;
610 com::SafeArray <DataType_T> propertyTypes;
611 com::SafeArray <ULONG> propertyFlags;
612 com::SafeArray <BSTR> propertyDefaults;
613 CHECK_ERROR(mediumFormats[i],
614 DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
615 ComSafeArrayAsOutParam(propertyDescriptions),
616 ComSafeArrayAsOutParam(propertyTypes),
617 ComSafeArrayAsOutParam(propertyFlags),
618 ComSafeArrayAsOutParam(propertyDefaults)));
619
620 RTPrintf(" properties=(");
621 if (propertyNames.size() > 0)
622 {
623 for (size_t j = 0; j < propertyNames.size(); ++j)
624 {
625 RTPrintf("\n name='%ls' desc='%ls' type=",
626 Bstr(propertyNames[j]).raw(), Bstr(propertyDescriptions[j]).raw());
627 switch (propertyTypes[j])
628 {
629 case DataType_Int32: RTPrintf("int"); break;
630 case DataType_Int8: RTPrintf("byte"); break;
631 case DataType_String: RTPrintf("string"); break;
632 }
633 RTPrintf(" flags=%#04x", propertyFlags[j]);
634 RTPrintf(" default='%ls'", Bstr(propertyDefaults[j]).raw());
635 if (j != propertyNames.size()-1)
636 RTPrintf(", ");
637 }
638 }
639 RTPrintf(")\n");
640 }
641 break;
642 }
643
644 case kListHdds:
645 {
646 com::SafeIfaceArray<IMedium> hdds;
647 CHECK_ERROR(rptrVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
648 listMedia(rptrVirtualBox, hdds, "base");
649 break;
650 }
651
652 case kListDvds:
653 {
654 com::SafeIfaceArray<IMedium> dvds;
655 CHECK_ERROR(rptrVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
656 listMedia(rptrVirtualBox, dvds, NULL);
657 break;
658 }
659
660 case kListFloppies:
661 {
662 com::SafeIfaceArray<IMedium> floppies;
663 CHECK_ERROR(rptrVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
664 listMedia(rptrVirtualBox, floppies, NULL);
665 break;
666 }
667
668 /** @todo function. */
669 case kListUsbHost:
670 {
671 ComPtr<IHost> Host;
672 CHECK_ERROR_RET(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
673
674 SafeIfaceArray<IHostUSBDevice> CollPtr;
675 CHECK_ERROR_RET(Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
676
677 RTPrintf("Host USB Devices:\n\n");
678
679 if (CollPtr.size() == 0)
680 {
681 RTPrintf("<none>\n\n");
682 }
683 else
684 {
685 for (size_t i = 0; i < CollPtr.size(); ++i)
686 {
687 ComPtr <IHostUSBDevice> dev = CollPtr[i];
688
689 /* Query info. */
690 Bstr id;
691 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), 1);
692 USHORT usVendorId;
693 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), 1);
694 USHORT usProductId;
695 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), 1);
696 USHORT bcdRevision;
697 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), 1);
698
699 RTPrintf("UUID: %S\n"
700 "VendorId: %#06x (%04X)\n"
701 "ProductId: %#06x (%04X)\n"
702 "Revision: %u.%u (%02u%02u)\n",
703 Utf8Str(id).c_str(),
704 usVendorId, usVendorId, usProductId, usProductId,
705 bcdRevision >> 8, bcdRevision & 0xff,
706 bcdRevision >> 8, bcdRevision & 0xff);
707
708 /* optional stuff. */
709 Bstr bstr;
710 CHECK_ERROR_RET(dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
711 if (!bstr.isEmpty())
712 RTPrintf("Manufacturer: %lS\n", bstr.raw());
713 CHECK_ERROR_RET(dev, COMGETTER(Product)(bstr.asOutParam()), 1);
714 if (!bstr.isEmpty())
715 RTPrintf("Product: %lS\n", bstr.raw());
716 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
717 if (!bstr.isEmpty())
718 RTPrintf("SerialNumber: %lS\n", bstr.raw());
719 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
720 if (!bstr.isEmpty())
721 RTPrintf("Address: %lS\n", bstr.raw());
722
723 /* current state */
724 USBDeviceState_T state;
725 CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
726 const char *pszState = "?";
727 switch (state)
728 {
729 case USBDeviceState_NotSupported:
730 pszState = "Not supported";
731 break;
732 case USBDeviceState_Unavailable:
733 pszState = "Unavailable";
734 break;
735 case USBDeviceState_Busy:
736 pszState = "Busy";
737 break;
738 case USBDeviceState_Available:
739 pszState = "Available";
740 break;
741 case USBDeviceState_Held:
742 pszState = "Held";
743 break;
744 case USBDeviceState_Captured:
745 pszState = "Captured";
746 break;
747 default:
748 ASSERT(false);
749 break;
750 }
751 RTPrintf("Current State: %s\n\n", pszState);
752 }
753 }
754 break;
755 }
756
757 /** @todo function. */
758 case kListUsbFilters:
759 {
760 RTPrintf("Global USB Device Filters:\n\n");
761
762 ComPtr<IHost> host;
763 CHECK_ERROR_RET(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()), 1);
764
765 SafeIfaceArray<IHostUSBDeviceFilter> coll;
766 CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
767
768 if (coll.size() == 0)
769 {
770 RTPrintf("<none>\n\n");
771 }
772 else
773 {
774 for (size_t index = 0; index < coll.size(); ++index)
775 {
776 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
777
778 /* Query info. */
779
780 RTPrintf("Index: %zu\n", index);
781
782 BOOL active = FALSE;
783 CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
784 RTPrintf("Active: %s\n", active ? "yes" : "no");
785
786 USBDeviceFilterAction_T action;
787 CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
788 const char *pszAction = "<invalid>";
789 switch (action)
790 {
791 case USBDeviceFilterAction_Ignore:
792 pszAction = "Ignore";
793 break;
794 case USBDeviceFilterAction_Hold:
795 pszAction = "Hold";
796 break;
797 default:
798 break;
799 }
800 RTPrintf("Action: %s\n", pszAction);
801
802 Bstr bstr;
803 CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
804 RTPrintf("Name: %lS\n", bstr.raw());
805 CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
806 RTPrintf("VendorId: %lS\n", bstr.raw());
807 CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
808 RTPrintf("ProductId: %lS\n", bstr.raw());
809 CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
810 RTPrintf("Revision: %lS\n", bstr.raw());
811 CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
812 RTPrintf("Manufacturer: %lS\n", bstr.raw());
813 CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
814 RTPrintf("Product: %lS\n", bstr.raw());
815 CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
816 RTPrintf("Serial Number: %lS\n\n", bstr.raw());
817 }
818 }
819 break;
820 }
821
822 /** @todo function. */
823 case kListSystemProperties:
824 {
825 ComPtr<ISystemProperties> systemProperties;
826 rptrVirtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
827
828 Bstr str;
829 ULONG ulValue;
830 LONG64 i64Value;
831
832 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
833 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
834 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
835 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
836 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
837 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
838 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
839 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
840 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
841 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
842 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
843 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
844 systemProperties->COMGETTER(InfoVDSize)(&i64Value);
845 RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
846 systemProperties->COMGETTER(NetworkAdapterCount)(&ulValue);
847 RTPrintf("Maximum Network Adapter count: %u\n", ulValue);
848 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
849 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
850 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
851 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
852 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
853 RTPrintf("Maximum Boot Position: %u\n", ulValue);
854 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_IDE, &ulValue);
855 RTPrintf("Maximum PIIX3 IDE Controllers: %u\n", ulValue);
856 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_IDE, &ulValue);
857 RTPrintf("Maximum ICH9 IDE Controllers: %u\n", ulValue);
858 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
859 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
860 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
861 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
862 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SATA, &ulValue);
863 RTPrintf("Maximum PIIX3 SATA Controllers: %u\n", ulValue);
864 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SATA, &ulValue);
865 RTPrintf("Maximum ICH9 SATA Controllers: %u\n", ulValue);
866 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
867 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
868 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
869 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
870 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SCSI, &ulValue);
871 RTPrintf("Maximum PIIX3 SCSI Controllers: %u\n", ulValue);
872 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SCSI, &ulValue);
873 RTPrintf("Maximum ICH9 SCSI Controllers: %u\n", ulValue);
874 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
875 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
876 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
877 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
878 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SAS, &ulValue);
879 RTPrintf("Maximum SAS PIIX3 Controllers: %u\n", ulValue);
880 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SAS, &ulValue);
881 RTPrintf("Maximum SAS ICH9 Controllers: %u\n", ulValue);
882 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
883 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
884 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
885 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
886 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_Floppy, &ulValue);
887 RTPrintf("Maximum PIIX3 Floppy Controllers:%u\n", ulValue);
888 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_Floppy, &ulValue);
889 RTPrintf("Maximum ICH9 Floppy Controllers: %u\n", ulValue);
890 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
891 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
892 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
893 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
894 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
895 RTPrintf("Default machine folder: %lS\n", str.raw());
896 systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
897 RTPrintf("VRDE auth library: %lS\n", str.raw());
898 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
899 RTPrintf("Webservice auth. library: %lS\n", str.raw());
900 systemProperties->COMGETTER(DefaultVRDEExtPack)(str.asOutParam());
901 RTPrintf("Remote desktop ExtPack: %lS\n", str.raw());
902 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
903 RTPrintf("Log history count: %u\n", ulValue);
904 break;
905 }
906
907 case kListDhcpServers:
908 {
909 com::SafeIfaceArray<IDHCPServer> svrs;
910 CHECK_ERROR(rptrVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)));
911 for (size_t i = 0; i < svrs.size(); ++i)
912 {
913 ComPtr<IDHCPServer> svr = svrs[i];
914 Bstr netName;
915 svr->COMGETTER(NetworkName)(netName.asOutParam());
916 RTPrintf("NetworkName: %lS\n", netName.raw());
917 Bstr ip;
918 svr->COMGETTER(IPAddress)(ip.asOutParam());
919 RTPrintf("IP: %lS\n", ip.raw());
920 Bstr netmask;
921 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
922 RTPrintf("NetworkMask: %lS\n", netmask.raw());
923 Bstr lowerIp;
924 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
925 RTPrintf("lowerIPAddress: %lS\n", lowerIp.raw());
926 Bstr upperIp;
927 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
928 RTPrintf("upperIPAddress: %lS\n", upperIp.raw());
929 BOOL fEnabled;
930 svr->COMGETTER(Enabled)(&fEnabled);
931 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
932 RTPrintf("\n");
933 }
934 break;
935 }
936
937 case kListExtPacks:
938 rc = listExtensionPacks(rptrVirtualBox);
939 break;
940
941 /* No default here, want gcc warnings. */
942
943 } /* end switch */
944
945 return rc;
946}
947
948/**
949 * Handles the 'list' command.
950 *
951 * @returns Appropriate exit code.
952 * @param a Handler argument.
953 */
954int handleList(HandlerArg *a)
955{
956 bool fOptLong = false;
957 bool fOptMultiple = false;
958 enum enmListType enmOptCommand = kListNotSpecified;
959
960 static const RTGETOPTDEF s_aListOptions[] =
961 {
962 { "--long", 'l', RTGETOPT_REQ_NOTHING },
963 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
964 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
965 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
966 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
967 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
968 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
969 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
970 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
971#if defined(VBOX_WITH_NETFLT)
972 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
973#endif
974 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
975 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
976 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
977 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
978 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
979 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
980 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
981 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
982 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
983 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
984 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
985 };
986
987 int ch;
988 RTGETOPTUNION ValueUnion;
989 RTGETOPTSTATE GetState;
990 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
991 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
992 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
993 {
994 switch (ch)
995 {
996 case 'l': /* --long */
997 fOptLong = true;
998 break;
999
1000 case 'm':
1001 fOptMultiple = true;
1002 if (enmOptCommand == kListNotSpecified)
1003 break;
1004 ch = enmOptCommand;
1005 /* fall thru */
1006
1007 case kListVMs:
1008 case kListRunningVMs:
1009 case kListOsTypes:
1010 case kListHostDvds:
1011 case kListHostFloppies:
1012 case kListBridgedInterfaces:
1013#if defined(VBOX_WITH_NETFLT)
1014 case kListHostOnlyInterfaces:
1015#endif
1016 case kListHostInfo:
1017 case kListHostCpuIDs:
1018 case kListHddBackends:
1019 case kListHdds:
1020 case kListDvds:
1021 case kListFloppies:
1022 case kListUsbHost:
1023 case kListUsbFilters:
1024 case kListSystemProperties:
1025 case kListDhcpServers:
1026 case kListExtPacks:
1027 enmOptCommand = (enum enmListType)ch;
1028 if (fOptMultiple)
1029 {
1030 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, a->virtualBox);
1031 if (FAILED(hrc))
1032 return 1;
1033 }
1034 break;
1035
1036 case VINF_GETOPT_NOT_OPTION:
1037 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
1038
1039 default:
1040 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
1041 }
1042 }
1043
1044 /*
1045 * If not in multiple list mode, we have to produce the list now.
1046 */
1047 if (enmOptCommand == kListNotSpecified)
1048 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
1049 if (!fOptMultiple)
1050 {
1051 HRESULT hrc = produceList(enmOptCommand, fOptLong, a->virtualBox);
1052 if (FAILED(hrc))
1053 return 1;
1054 }
1055
1056 return 0;
1057}
1058
1059#endif /* !VBOX_ONLY_DOCS */
1060/* 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