VirtualBox

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

Last change on this file since 23454 was 23223, checked in by vboxsync, 15 years ago

API: big medium handling change and lots of assorted other cleanups and fixes

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