VirtualBox

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

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

*: RTGetOpt cleanup related to --help and --version (now standard option). Use RTGetOptPrintError.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.0 KB
Line 
1/* $Id: VBoxManageList.cpp 26517 2010-02-14 21:39:00Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef VBOX_ONLY_DOCS
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/com/com.h>
28#include <VBox/com/string.h>
29#include <VBox/com/Guid.h>
30#include <VBox/com/array.h>
31#include <VBox/com/ErrorInfo.h>
32#include <VBox/com/errorprint.h>
33
34#include <VBox/com/VirtualBox.h>
35
36#include <VBox/log.h>
37#include <iprt/stream.h>
38#include <iprt/string.h>
39#include <iprt/time.h>
40#include <iprt/getopt.h>
41#include <iprt/ctype.h>
42
43#include "VBoxManage.h"
44using namespace com;
45
46#ifdef VBOX_WITH_HOSTNETIF_API
47static const char *getHostIfMediumTypeText(HostNetworkInterfaceMediumType_T enmType)
48{
49 switch (enmType)
50 {
51 case HostNetworkInterfaceMediumType_Ethernet: return "Ethernet";
52 case HostNetworkInterfaceMediumType_PPP: return "PPP";
53 case HostNetworkInterfaceMediumType_SLIP: return "SLIP";
54 }
55 return "Unknown";
56}
57
58static const char *getHostIfStatusText(HostNetworkInterfaceStatus_T enmStatus)
59{
60 switch (enmStatus)
61 {
62 case HostNetworkInterfaceStatus_Up: return "Up";
63 case HostNetworkInterfaceStatus_Down: return "Down";
64 }
65 return "Unknown";
66}
67#endif
68
69enum enOptionCodes
70{
71 LISTVMS = 1000,
72 LISTRUNNINGVMS,
73 LISTOSTYPES,
74 LISTHOSTDVDS,
75 LISTHOSTFLOPPIES,
76 LISTBRIDGEDIFS,
77#if defined(VBOX_WITH_NETFLT)
78 LISTHOSTONLYIFS,
79#endif
80 LISTHOSTCPUIDS,
81 LISTHOSTINFO,
82 LISTHDDBACKENDS,
83 LISTHDDS,
84 LISTDVDS,
85 LISTFLOPPIES,
86 LISTUSBHOST,
87 LISTUSBFILTERS,
88 LISTSYSTEMPROPERTIES,
89 LISTDHCPSERVERS
90};
91
92static const RTGETOPTDEF g_aListOptions[]
93 = {
94 { "--long", 'l', RTGETOPT_REQ_NOTHING },
95 { "vms", LISTVMS, RTGETOPT_REQ_NOTHING },
96 { "runningvms", LISTRUNNINGVMS, RTGETOPT_REQ_NOTHING },
97 { "ostypes", LISTOSTYPES, RTGETOPT_REQ_NOTHING },
98 { "hostdvds", LISTHOSTDVDS, RTGETOPT_REQ_NOTHING },
99 { "hostfloppies", LISTHOSTFLOPPIES, RTGETOPT_REQ_NOTHING },
100 { "hostifs", LISTBRIDGEDIFS, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
101 { "bridgedifs", LISTBRIDGEDIFS, RTGETOPT_REQ_NOTHING },
102#if defined(VBOX_WITH_NETFLT)
103 { "hostonlyifs", LISTHOSTONLYIFS, RTGETOPT_REQ_NOTHING },
104#endif
105 { "hostinfo", LISTHOSTINFO, RTGETOPT_REQ_NOTHING },
106 { "hostcpuids", LISTHOSTCPUIDS, RTGETOPT_REQ_NOTHING },
107 { "hddbackends", LISTHDDBACKENDS, RTGETOPT_REQ_NOTHING },
108 { "hdds", LISTHDDS, RTGETOPT_REQ_NOTHING },
109 { "dvds", LISTDVDS, RTGETOPT_REQ_NOTHING },
110 { "floppies", LISTFLOPPIES, RTGETOPT_REQ_NOTHING },
111 { "usbhost", LISTUSBHOST, RTGETOPT_REQ_NOTHING },
112 { "usbfilters", LISTUSBFILTERS, RTGETOPT_REQ_NOTHING },
113 { "systemproperties", LISTSYSTEMPROPERTIES, RTGETOPT_REQ_NOTHING },
114 { "dhcpservers", LISTDHCPSERVERS, RTGETOPT_REQ_NOTHING }
115 };
116
117int handleList(HandlerArg *a)
118{
119 HRESULT rc = S_OK;
120
121 bool fOptLong = false;
122
123 int command = 0;
124 int c;
125
126 RTGETOPTUNION ValueUnion;
127 RTGETOPTSTATE GetState;
128 RTGetOptInit(&GetState, a->argc, a->argv, g_aListOptions, RT_ELEMENTS(g_aListOptions),
129 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
130 while ((c = RTGetOpt(&GetState, &ValueUnion)))
131 {
132 switch (c)
133 {
134 case 'l': // --long
135 fOptLong = true;
136 break;
137
138 case LISTVMS:
139 case LISTRUNNINGVMS:
140 case LISTOSTYPES:
141 case LISTHOSTDVDS:
142 case LISTHOSTFLOPPIES:
143 case LISTBRIDGEDIFS:
144#if defined(VBOX_WITH_NETFLT)
145 case LISTHOSTONLYIFS:
146#endif
147 case LISTHOSTINFO:
148 case LISTHOSTCPUIDS:
149 case LISTHDDBACKENDS:
150 case LISTHDDS:
151 case LISTDVDS:
152 case LISTFLOPPIES:
153 case LISTUSBHOST:
154 case LISTUSBFILTERS:
155 case LISTSYSTEMPROPERTIES:
156 case LISTDHCPSERVERS:
157 if (command)
158 return errorSyntax(USAGE_LIST, "Too many subcommands for \"list\" command.\n");
159
160 command = c;
161 break;
162
163 case VINF_GETOPT_NOT_OPTION:
164 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
165 break;
166
167 default:
168 if (c > 0)
169 {
170 if (RT_C_IS_GRAPH(c))
171 return errorSyntax(USAGE_LIST, "unhandled option: -%c", c);
172 else
173 return errorSyntax(USAGE_LIST, "unhandled option: %i", c);
174 }
175 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
176 return errorSyntax(USAGE_LIST, "unknown option: %s", ValueUnion.psz);
177 else if (ValueUnion.pDef)
178 return errorSyntax(USAGE_LIST, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
179 else
180 return errorSyntax(USAGE_LIST, "%Rrs", c);
181 }
182 }
183
184 if (!command)
185 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
186
187 /* which object? */
188 switch (command)
189 {
190 case LISTVMS:
191 {
192 /*
193 * Get the list of all registered VMs
194 */
195 com::SafeIfaceArray <IMachine> machines;
196 rc = a->virtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam (machines));
197 if (SUCCEEDED(rc))
198 {
199 /*
200 * Iterate through the collection
201 */
202 for (size_t i = 0; i < machines.size(); ++ i)
203 {
204 if (machines[i])
205 rc = showVMInfo(a->virtualBox,
206 machines[i],
207 (fOptLong) ? VMINFO_STANDARD : VMINFO_COMPACT);
208 }
209 }
210 }
211 break;
212
213 case LISTRUNNINGVMS:
214 {
215 /*
216 * Get the list of all _running_ VMs
217 */
218 com::SafeIfaceArray <IMachine> machines;
219 rc = a->virtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam (machines));
220 if (SUCCEEDED(rc))
221 {
222 /*
223 * Iterate through the collection
224 */
225 for (size_t i = 0; i < machines.size(); ++ i)
226 {
227 if (machines[i])
228 {
229 MachineState_T machineState;
230 rc = machines [i]->COMGETTER(State)(&machineState);
231 if (SUCCEEDED(rc))
232 {
233 switch (machineState)
234 {
235 case MachineState_Running:
236 case MachineState_Teleporting:
237 case MachineState_LiveSnapshotting:
238 case MachineState_Paused:
239 case MachineState_TeleportingPausedVM:
240 rc = showVMInfo(a->virtualBox,
241 machines[i],
242 (fOptLong) ? VMINFO_STANDARD : VMINFO_COMPACT);
243 }
244 }
245 }
246 }
247 }
248 }
249 break;
250
251 case LISTOSTYPES:
252 {
253 com::SafeIfaceArray <IGuestOSType> coll;
254 rc = a->virtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
255 if (SUCCEEDED(rc))
256 {
257 /*
258 * Iterate through the collection.
259 */
260 for (size_t i = 0; i < coll.size(); ++ i)
261 {
262 ComPtr<IGuestOSType> guestOS;
263 guestOS = coll[i];
264 Bstr guestId;
265 guestOS->COMGETTER(Id)(guestId.asOutParam());
266 RTPrintf("ID: %lS\n", guestId.raw());
267 Bstr guestDescription;
268 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
269 RTPrintf("Description: %lS\n\n", guestDescription.raw());
270 }
271 }
272 }
273 break;
274
275 case LISTHOSTDVDS:
276 {
277 ComPtr<IHost> host;
278 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
279 com::SafeIfaceArray <IMedium> coll;
280 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
281 if (SUCCEEDED(rc))
282 {
283 for (size_t i = 0; i < coll.size(); ++ i)
284 {
285 ComPtr<IMedium> dvdDrive = coll[i];
286 Bstr uuid;
287 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
288 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
289 Bstr name;
290 dvdDrive->COMGETTER(Name)(name.asOutParam());
291 RTPrintf("Name: %lS\n\n", name.raw());
292 }
293 }
294 }
295 break;
296
297 case LISTHOSTFLOPPIES:
298 {
299 ComPtr<IHost> host;
300 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
301 com::SafeIfaceArray <IMedium> coll;
302 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
303 if (SUCCEEDED(rc))
304 {
305 for (size_t i = 0; i < coll.size(); ++i)
306 {
307 ComPtr<IMedium> floppyDrive = coll[i];
308 Bstr uuid;
309 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
310 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
311 Bstr name;
312 floppyDrive->COMGETTER(Name)(name.asOutParam());
313 RTPrintf("Name: %lS\n\n", name.raw());
314 }
315 }
316 }
317 break;
318
319 case LISTBRIDGEDIFS:
320#if defined(VBOX_WITH_NETFLT)
321 case LISTHOSTONLYIFS:
322#endif
323 {
324 ComPtr<IHost> host;
325 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
326 com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
327#if defined(VBOX_WITH_NETFLT)
328 if (command == LISTBRIDGEDIFS)
329 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
330 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
331 else
332 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
333 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
334#else
335 CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
336#endif
337 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
338 {
339 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
340#ifndef VBOX_WITH_HOSTNETIF_API
341 Bstr interfaceName;
342 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
343 RTPrintf("Name: %lS\n", interfaceName.raw());
344 Guid interfaceGuid;
345 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
346 RTPrintf("GUID: %lS\n\n", Bstr(interfaceGuid.toString()).raw());
347#else /* VBOX_WITH_HOSTNETIF_API */
348 Bstr interfaceName;
349 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
350 RTPrintf("Name: %lS\n", interfaceName.raw());
351 Bstr interfaceGuid;
352 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
353 RTPrintf("GUID: %lS\n", interfaceGuid.raw());
354 BOOL bDhcpEnabled;
355 networkInterface->COMGETTER(DhcpEnabled)(&bDhcpEnabled);
356 RTPrintf("Dhcp: %s\n", bDhcpEnabled ? "Enabled" : "Disabled");
357
358 Bstr IPAddress;
359 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
360 RTPrintf("IPAddress: %lS\n", IPAddress.raw());
361 Bstr NetworkMask;
362 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
363 RTPrintf("NetworkMask: %lS\n", NetworkMask.raw());
364 Bstr IPV6Address;
365 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
366 RTPrintf("IPV6Address: %lS\n", IPV6Address.raw());
367 ULONG IPV6NetworkMaskPrefixLength;
368 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
369 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
370 Bstr HardwareAddress;
371 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
372 RTPrintf("HardwareAddress: %lS\n", HardwareAddress.raw());
373 HostNetworkInterfaceMediumType_T Type;
374 networkInterface->COMGETTER(MediumType)(&Type);
375 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
376 HostNetworkInterfaceStatus_T Status;
377 networkInterface->COMGETTER(Status)(&Status);
378 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
379 Bstr netName;
380 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
381 RTPrintf("VBoxNetworkName: %lS\n\n", netName.raw());
382
383#endif
384 }
385 }
386 break;
387
388 case LISTHOSTINFO:
389 {
390 ComPtr<IHost> Host;
391 CHECK_ERROR (a->virtualBox, COMGETTER(Host)(Host.asOutParam()));
392
393 RTPrintf("Host Information:\n\n");
394
395 LONG64 uTCTime = 0;
396 CHECK_ERROR (Host, COMGETTER(UTCTime)(&uTCTime));
397 RTTIMESPEC timeSpec;
398 RTTimeSpecSetMilli(&timeSpec, uTCTime);
399 char szTime[32] = {0};
400 RTTimeSpecToString(&timeSpec, szTime, sizeof(szTime));
401 RTPrintf("Host time: %s\n", szTime);
402
403 ULONG processorOnlineCount = 0;
404 CHECK_ERROR (Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
405 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
406 ULONG processorCount = 0;
407 CHECK_ERROR (Host, COMGETTER(ProcessorCount)(&processorCount));
408 RTPrintf("Processor count: %lu\n", processorCount);
409 ULONG processorSpeed = 0;
410 Bstr processorDescription;
411 for (ULONG i = 0; i < processorCount; i++)
412 {
413 CHECK_ERROR (Host, GetProcessorSpeed(i, &processorSpeed));
414 if (processorSpeed)
415 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
416 else
417 RTPrintf("Processor#%u speed: unknown\n", i, processorSpeed);
418 CHECK_ERROR (Host, GetProcessorDescription(i, processorDescription.asOutParam()));
419 RTPrintf("Processor#%u description: %lS\n", i, processorDescription.raw());
420 }
421
422 ULONG memorySize = 0;
423 CHECK_ERROR (Host, COMGETTER(MemorySize)(&memorySize));
424 RTPrintf("Memory size: %lu MByte\n", memorySize);
425
426 ULONG memoryAvailable = 0;
427 CHECK_ERROR (Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
428 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
429
430 Bstr operatingSystem;
431 CHECK_ERROR (Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
432 RTPrintf("Operating system: %lS\n", operatingSystem.raw());
433
434 Bstr oSVersion;
435 CHECK_ERROR (Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
436 RTPrintf("Operating system version: %lS\n", oSVersion.raw());
437 }
438 break;
439
440 case LISTHOSTCPUIDS:
441 {
442 ComPtr<IHost> Host;
443 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(Host.asOutParam()));
444
445 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
446 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
447 static uint32_t const s_auCpuIdRanges[] =
448 {
449 UINT32_C(0x00000000), UINT32_C(0x0000007f),
450 UINT32_C(0x80000000), UINT32_C(0x8000007f),
451 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
452 };
453 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
454 {
455 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
456 CHECK_ERROR(Host, GetProcessorCpuIdLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
457 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
458 continue;
459 cLeafs++;
460 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
461 {
462 CHECK_ERROR(Host, GetProcessorCpuIdLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
463 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
464 }
465 }
466 }
467 break;
468
469 case LISTHDDBACKENDS:
470 {
471 ComPtr<ISystemProperties> systemProperties;
472 CHECK_ERROR(a->virtualBox,
473 COMGETTER(SystemProperties) (systemProperties.asOutParam()));
474 com::SafeIfaceArray <IMediumFormat> mediumFormats;
475 CHECK_ERROR(systemProperties,
476 COMGETTER(MediumFormats) (ComSafeArrayAsOutParam (mediumFormats)));
477
478 RTPrintf("Supported hard disk backends:\n\n");
479 for (size_t i = 0; i < mediumFormats.size(); ++ i)
480 {
481 /* General information */
482 Bstr id;
483 CHECK_ERROR(mediumFormats [i],
484 COMGETTER(Id) (id.asOutParam()));
485
486 Bstr description;
487 CHECK_ERROR(mediumFormats [i],
488 COMGETTER(Id) (description.asOutParam()));
489
490 ULONG caps;
491 CHECK_ERROR(mediumFormats [i],
492 COMGETTER(Capabilities) (&caps));
493
494 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
495 i, id.raw(), description.raw(), caps);
496
497 /* File extensions */
498 com::SafeArray <BSTR> fileExtensions;
499 CHECK_ERROR(mediumFormats [i],
500 COMGETTER(FileExtensions) (ComSafeArrayAsOutParam (fileExtensions)));
501 for (size_t j = 0; j < fileExtensions.size(); ++ j)
502 {
503 RTPrintf ("%ls", Bstr (fileExtensions [j]).raw());
504 if (j != fileExtensions.size()-1)
505 RTPrintf (",");
506 }
507 RTPrintf ("'");
508
509 /* Configuration keys */
510 com::SafeArray <BSTR> propertyNames;
511 com::SafeArray <BSTR> propertyDescriptions;
512 com::SafeArray <DataType_T> propertyTypes;
513 com::SafeArray <ULONG> propertyFlags;
514 com::SafeArray <BSTR> propertyDefaults;
515 CHECK_ERROR(mediumFormats [i],
516 DescribeProperties (ComSafeArrayAsOutParam (propertyNames),
517 ComSafeArrayAsOutParam (propertyDescriptions),
518 ComSafeArrayAsOutParam (propertyTypes),
519 ComSafeArrayAsOutParam (propertyFlags),
520 ComSafeArrayAsOutParam (propertyDefaults)));
521
522 RTPrintf (" properties=(");
523 if (propertyNames.size() > 0)
524 {
525 for (size_t j = 0; j < propertyNames.size(); ++ j)
526 {
527 RTPrintf ("\n name='%ls' desc='%ls' type=",
528 Bstr (propertyNames [j]).raw(), Bstr (propertyDescriptions [j]).raw());
529 switch (propertyTypes [j])
530 {
531 case DataType_Int32: RTPrintf ("int"); break;
532 case DataType_Int8: RTPrintf ("byte"); break;
533 case DataType_String: RTPrintf ("string"); break;
534 }
535 RTPrintf (" flags=%#04x", propertyFlags [j]);
536 RTPrintf (" default='%ls'", Bstr (propertyDefaults [j]).raw());
537 if (j != propertyNames.size()-1)
538 RTPrintf (", ");
539 }
540 }
541 RTPrintf (")\n");
542 }
543 }
544 break;
545
546 case LISTHDDS:
547 {
548 com::SafeIfaceArray<IMedium> hdds;
549 CHECK_ERROR(a->virtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam (hdds)));
550 for (size_t i = 0; i < hdds.size(); ++ i)
551 {
552 ComPtr<IMedium> hdd = hdds[i];
553 Bstr uuid;
554 hdd->COMGETTER(Id)(uuid.asOutParam());
555 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
556 Bstr format;
557 hdd->COMGETTER(Format)(format.asOutParam());
558 RTPrintf("Format: %lS\n", format.raw());
559 Bstr filepath;
560 hdd->COMGETTER(Location)(filepath.asOutParam());
561 RTPrintf("Location: %lS\n", filepath.raw());
562 MediumState_T enmState;
563 /// @todo NEWMEDIA check accessibility of all parents
564 /// @todo NEWMEDIA print the full state value
565 hdd->RefreshState(&enmState);
566 RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
567
568 MediumType_T type;
569 hdd->COMGETTER(Type)(&type);
570 const char *typeStr = "unknown";
571 switch (type)
572 {
573 case MediumType_Normal:
574 typeStr = "normal";
575 break;
576 case MediumType_Immutable:
577 typeStr = "immutable";
578 break;
579 case MediumType_Writethrough:
580 typeStr = "writethrough";
581 break;
582 }
583 RTPrintf("Type: %s\n", typeStr);
584
585 com::SafeArray<BSTR> machineIds;
586 hdd->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
587 for (size_t j = 0; j < machineIds.size(); ++ j)
588 {
589 ComPtr<IMachine> machine;
590 CHECK_ERROR(a->virtualBox, GetMachine(machineIds[j], machine.asOutParam()));
591 ASSERT(machine);
592 Bstr name;
593 machine->COMGETTER(Name)(name.asOutParam());
594 machine->COMGETTER(Id)(uuid.asOutParam());
595 RTPrintf("%s%lS (UUID: %lS)\n",
596 j == 0 ? "Usage: " : " ",
597 name.raw(), machineIds[j]);
598 }
599 /// @todo NEWMEDIA check usage in snapshots too
600 /// @todo NEWMEDIA also list children and say 'differencing' for
601 /// hard disks with the parent or 'base' otherwise.
602 RTPrintf("\n");
603 }
604 }
605 break;
606
607 case LISTDVDS:
608 {
609 com::SafeIfaceArray<IMedium> dvds;
610 CHECK_ERROR(a->virtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
611 for (size_t i = 0; i < dvds.size(); ++ i)
612 {
613 ComPtr<IMedium> dvdImage = dvds[i];
614 Bstr uuid;
615 dvdImage->COMGETTER(Id)(uuid.asOutParam());
616 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
617 Bstr filePath;
618 dvdImage->COMGETTER(Location)(filePath.asOutParam());
619 RTPrintf("Path: %lS\n", filePath.raw());
620 MediumState_T enmState;
621 dvdImage->RefreshState(&enmState);
622 RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
623
624 com::SafeArray<BSTR> machineIds;
625 dvdImage->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
626 for (size_t j = 0; j < machineIds.size(); ++ j)
627 {
628 ComPtr<IMachine> machine;
629 CHECK_ERROR(a->virtualBox, GetMachine(machineIds[j], machine.asOutParam()));
630 ASSERT(machine);
631 Bstr name;
632 machine->COMGETTER(Name)(name.asOutParam());
633 machine->COMGETTER(Id)(uuid.asOutParam());
634 RTPrintf("%s%lS (UUID: %lS)\n",
635 j == 0 ? "Usage: " : " ",
636 name.raw(), machineIds[j]);
637 }
638 RTPrintf("\n");
639 }
640 }
641 break;
642
643 case LISTFLOPPIES:
644 {
645 com::SafeIfaceArray<IMedium> floppies;
646 CHECK_ERROR(a->virtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
647 for (size_t i = 0; i < floppies.size(); ++ i)
648 {
649 ComPtr<IMedium> floppyImage = floppies[i];
650 Bstr uuid;
651 floppyImage->COMGETTER(Id)(uuid.asOutParam());
652 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
653 Bstr filePath;
654 floppyImage->COMGETTER(Location)(filePath.asOutParam());
655 RTPrintf("Path: %lS\n", filePath.raw());
656 MediumState_T enmState;
657 floppyImage->RefreshState(&enmState);
658 RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
659
660 com::SafeArray<BSTR> machineIds;
661 floppyImage->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
662 for (size_t j = 0; j < machineIds.size(); ++ j)
663 {
664 ComPtr<IMachine> machine;
665 CHECK_ERROR(a->virtualBox, GetMachine(machineIds[j], machine.asOutParam()));
666 ASSERT(machine);
667 Bstr name;
668 machine->COMGETTER(Name)(name.asOutParam());
669 machine->COMGETTER(Id)(uuid.asOutParam());
670 RTPrintf("%s%lS (UUID: %lS)\n",
671 j == 0 ? "Usage: " : " ",
672 name.raw(), machineIds[j]);
673 }
674 RTPrintf("\n");
675 }
676 }
677 break;
678
679 case LISTUSBHOST:
680 {
681 ComPtr<IHost> Host;
682 CHECK_ERROR_RET (a->virtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
683
684 SafeIfaceArray <IHostUSBDevice> CollPtr;
685 CHECK_ERROR_RET (Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
686
687 RTPrintf("Host USB Devices:\n\n");
688
689 if (CollPtr.size() == 0)
690 {
691 RTPrintf("<none>\n\n");
692 }
693 else
694 {
695 for (size_t i = 0; i < CollPtr.size(); ++i)
696 {
697 ComPtr <IHostUSBDevice> dev = CollPtr[i];
698
699 /* Query info. */
700 Bstr id;
701 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), 1);
702 USHORT usVendorId;
703 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), 1);
704 USHORT usProductId;
705 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), 1);
706 USHORT bcdRevision;
707 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), 1);
708
709 RTPrintf("UUID: %S\n"
710 "VendorId: 0x%04x (%04X)\n"
711 "ProductId: 0x%04x (%04X)\n"
712 "Revision: %u.%u (%02u%02u)\n",
713 Utf8Str(id).raw(),
714 usVendorId, usVendorId, usProductId, usProductId,
715 bcdRevision >> 8, bcdRevision & 0xff,
716 bcdRevision >> 8, bcdRevision & 0xff);
717
718 /* optional stuff. */
719 Bstr bstr;
720 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
721 if (!bstr.isEmpty())
722 RTPrintf("Manufacturer: %lS\n", bstr.raw());
723 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), 1);
724 if (!bstr.isEmpty())
725 RTPrintf("Product: %lS\n", bstr.raw());
726 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
727 if (!bstr.isEmpty())
728 RTPrintf("SerialNumber: %lS\n", bstr.raw());
729 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), 1);
730 if (!bstr.isEmpty())
731 RTPrintf("Address: %lS\n", bstr.raw());
732
733 /* current state */
734 USBDeviceState_T state;
735 CHECK_ERROR_RET (dev, COMGETTER(State)(&state), 1);
736 const char *pszState = "?";
737 switch (state)
738 {
739 case USBDeviceState_NotSupported:
740 pszState = "Not supported"; break;
741 case USBDeviceState_Unavailable:
742 pszState = "Unavailable"; break;
743 case USBDeviceState_Busy:
744 pszState = "Busy"; break;
745 case USBDeviceState_Available:
746 pszState = "Available"; break;
747 case USBDeviceState_Held:
748 pszState = "Held"; break;
749 case USBDeviceState_Captured:
750 pszState = "Captured"; break;
751 default:
752 ASSERT (false);
753 break;
754 }
755 RTPrintf("Current State: %s\n\n", pszState);
756 }
757 }
758 }
759 break;
760
761 case LISTUSBFILTERS:
762 {
763 RTPrintf("Global USB Device Filters:\n\n");
764
765 ComPtr <IHost> host;
766 CHECK_ERROR_RET (a->virtualBox, COMGETTER(Host) (host.asOutParam()), 1);
767
768 SafeIfaceArray <IHostUSBDeviceFilter> coll;
769 CHECK_ERROR_RET (host, COMGETTER (USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
770
771 if (coll.size() == 0)
772 {
773 RTPrintf("<none>\n\n");
774 }
775 else
776 {
777 for (size_t index = 0; index < coll.size(); ++index)
778 {
779 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
780
781 /* Query info. */
782
783 RTPrintf("Index: %zu\n", index);
784
785 BOOL active = FALSE;
786 CHECK_ERROR_RET (flt, COMGETTER (Active) (&active), 1);
787 RTPrintf("Active: %s\n", active ? "yes" : "no");
788
789 USBDeviceFilterAction_T action;
790 CHECK_ERROR_RET (flt, COMGETTER (Action) (&action), 1);
791 const char *pszAction = "<invalid>";
792 switch (action)
793 {
794 case USBDeviceFilterAction_Ignore:
795 pszAction = "Ignore";
796 break;
797 case USBDeviceFilterAction_Hold:
798 pszAction = "Hold";
799 break;
800 default:
801 break;
802 }
803 RTPrintf("Action: %s\n", pszAction);
804
805 Bstr bstr;
806 CHECK_ERROR_RET (flt, COMGETTER (Name) (bstr.asOutParam()), 1);
807 RTPrintf("Name: %lS\n", bstr.raw());
808 CHECK_ERROR_RET (flt, COMGETTER (VendorId) (bstr.asOutParam()), 1);
809 RTPrintf("VendorId: %lS\n", bstr.raw());
810 CHECK_ERROR_RET (flt, COMGETTER (ProductId) (bstr.asOutParam()), 1);
811 RTPrintf("ProductId: %lS\n", bstr.raw());
812 CHECK_ERROR_RET (flt, COMGETTER (Revision) (bstr.asOutParam()), 1);
813 RTPrintf("Revision: %lS\n", bstr.raw());
814 CHECK_ERROR_RET (flt, COMGETTER (Manufacturer) (bstr.asOutParam()), 1);
815 RTPrintf("Manufacturer: %lS\n", bstr.raw());
816 CHECK_ERROR_RET (flt, COMGETTER (Product) (bstr.asOutParam()), 1);
817 RTPrintf("Product: %lS\n", bstr.raw());
818 CHECK_ERROR_RET (flt, COMGETTER (SerialNumber) (bstr.asOutParam()), 1);
819 RTPrintf("Serial Number: %lS\n\n", bstr.raw());
820 }
821 }
822 }
823 break;
824
825 case LISTSYSTEMPROPERTIES:
826 {
827 ComPtr<ISystemProperties> systemProperties;
828 a->virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
829
830 Bstr str;
831 ULONG ulValue;
832 ULONG64 ul64Value;
833 BOOL flag;
834
835 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
836 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
837 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
838 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
839 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
840 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
841 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
842 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
843 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
844 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
845 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
846 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
847 systemProperties->COMGETTER(MaxVDISize)(&ul64Value);
848 RTPrintf("Maximum VDI size: %lu Megabytes\n", ul64Value);
849 systemProperties->COMGETTER(NetworkAdapterCount)(&ulValue);
850 RTPrintf("Maximum Network Adapter count: %u\n", ulValue);
851 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
852 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
853 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
854 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
855 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
856 RTPrintf("Maximum Boot Position: %u\n", ulValue);
857 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_IDE, &ulValue);
858 RTPrintf("Maximum IDE Controllers: %u\n", ulValue);
859 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
860 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
861 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
862 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
863 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SATA, &ulValue);
864 RTPrintf("Maximum SATA Controllers: %u\n", ulValue);
865 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
866 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
867 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
868 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
869 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SCSI, &ulValue);
870 RTPrintf("Maximum SCSI Controllers: %u\n", ulValue);
871 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
872 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
873 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
874 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
875 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_Floppy, &ulValue);
876 RTPrintf("Maximum Floppy Controllers: %u\n", ulValue);
877 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
878 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
879 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
880 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
881 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
882 RTPrintf("Default machine folder: %lS\n", str.raw());
883 systemProperties->COMGETTER(DefaultHardDiskFolder)(str.asOutParam());
884 RTPrintf("Default hard disk folder: %lS\n", str.raw());
885 systemProperties->COMGETTER(RemoteDisplayAuthLibrary)(str.asOutParam());
886 RTPrintf("VRDP authentication library: %lS\n", str.raw());
887 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
888 RTPrintf("Webservice auth. library: %lS\n", str.raw());
889 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
890 RTPrintf("Log history count: %u\n", ulValue);
891
892 }
893 break;
894 case LISTDHCPSERVERS:
895 {
896 com::SafeIfaceArray<IDHCPServer> svrs;
897 CHECK_ERROR(a->virtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam (svrs)));
898 for (size_t i = 0; i < svrs.size(); ++ i)
899 {
900 ComPtr<IDHCPServer> svr = svrs[i];
901 Bstr netName;
902 svr->COMGETTER(NetworkName)(netName.asOutParam());
903 RTPrintf("NetworkName: %lS\n", netName.raw());
904 Bstr ip;
905 svr->COMGETTER(IPAddress)(ip.asOutParam());
906 RTPrintf("IP: %lS\n", ip.raw());
907 Bstr netmask;
908 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
909 RTPrintf("NetworkMask: %lS\n", netmask.raw());
910 Bstr lowerIp;
911 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
912 RTPrintf("lowerIPAddress: %lS\n", lowerIp.raw());
913 Bstr upperIp;
914 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
915 RTPrintf("upperIPAddress: %lS\n", upperIp.raw());
916 BOOL bEnabled;
917 svr->COMGETTER(Enabled)(&bEnabled);
918 RTPrintf("Enabled: %s\n", bEnabled ? "Yes" : "No");
919 RTPrintf("\n");
920 }
921 }
922 break;
923 } // end switch
924
925 return SUCCEEDED(rc) ? 0 : 1;
926}
927
928#endif /* !VBOX_ONLY_DOCS */
929/* 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