VirtualBox

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

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

VBoxManage: -Wshadow warnings

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