VirtualBox

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

Last change on this file since 18131 was 18108, checked in by vboxsync, 16 years ago

VBoxManage: clean up various places which use RTGetOpt, fix error handling to deal with changed RTGetOpt semantics, make the double-dash options the recommended ones, updated help

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 33.1 KB
Line 
1/* $Id: VBoxManageList.cpp 18108 2009-03-20 11:04:44Z 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/errorprint2.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 <IHostDVDDrive> 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<IHostDVDDrive> dvdDrive = coll[i];
279 Bstr name;
280 dvdDrive->COMGETTER(Name)(name.asOutParam());
281 RTPrintf("Name: %lS\n\n", name.raw());
282 }
283 }
284 }
285 break;
286
287 case LISTHOSTFLOPPIES:
288 {
289 ComPtr<IHost> host;
290 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
291 com::SafeIfaceArray <IHostFloppyDrive> coll;
292 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
293 if (SUCCEEDED(rc))
294 {
295 for (size_t i = 0; i < coll.size(); ++i)
296 {
297 ComPtr<IHostFloppyDrive> floppyDrive = coll[i];
298 Bstr name;
299 floppyDrive->COMGETTER(Name)(name.asOutParam());
300 RTPrintf("Name: %lS\n\n", name.raw());
301 }
302 }
303 }
304 break;
305
306 case LISTBRIDGEDIFS:
307#if defined(VBOX_WITH_NETFLT)
308 case LISTHOSTONLYIFS:
309#endif
310 {
311 ComPtr<IHost> host;
312 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
313 com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
314#if defined(VBOX_WITH_NETFLT)
315 CHECK_ERROR(host,
316 FindHostNetworkInterfacesOfType (
317 command == LISTBRIDGEDIFS ? HostNetworkInterfaceType_Bridged : HostNetworkInterfaceType_HostOnly,
318 ComSafeArrayAsOutParam (hostNetworkInterfaces)));
319#else
320 CHECK_ERROR(host,
321 COMGETTER(NetworkInterfaces) (ComSafeArrayAsOutParam (hostNetworkInterfaces)));
322#endif
323 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
324 {
325 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
326#ifndef VBOX_WITH_HOSTNETIF_API
327 Bstr interfaceName;
328 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
329 RTPrintf("Name: %lS\n", interfaceName.raw());
330 Guid interfaceGuid;
331 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
332 RTPrintf("GUID: %lS\n\n", Bstr(interfaceGuid.toString()).raw());
333#else /* 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", Bstr(interfaceGuid.toString()).raw());
340 BOOL bDhcpEnabled;
341 networkInterface->COMGETTER(DhcpEnabled)(&bDhcpEnabled);
342 RTPrintf("Dhcp: %s\n", bDhcpEnabled ? "Enabled" : "Disabled");
343
344 Bstr IPAddress;
345 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
346 RTPrintf("IPAddress: %lS\n", IPAddress.raw());
347 Bstr NetworkMask;
348 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
349 RTPrintf("NetworkMask: %lS\n", NetworkMask.raw());
350 Bstr IPV6Address;
351 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
352 RTPrintf("IPV6Address: %lS\n", IPV6Address.raw());
353 ULONG IPV6NetworkMaskPrefixLength;
354 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
355 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
356 Bstr HardwareAddress;
357 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
358 RTPrintf("HardwareAddress: %lS\n", HardwareAddress.raw());
359 HostNetworkInterfaceMediumType_T Type;
360 networkInterface->COMGETTER(MediumType)(&Type);
361 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
362 HostNetworkInterfaceStatus_T Status;
363 networkInterface->COMGETTER(Status)(&Status);
364 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
365 Bstr netName;
366 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
367 RTPrintf("VBoxNetworkName: %lS\n\n", netName.raw());
368
369#endif
370 }
371 }
372 break;
373
374 case LISTHOSTINFO:
375 {
376 ComPtr<IHost> Host;
377 CHECK_ERROR (a->virtualBox, COMGETTER(Host)(Host.asOutParam()));
378
379 RTPrintf("Host Information:\n\n");
380
381 LONG64 uTCTime = 0;
382 CHECK_ERROR (Host, COMGETTER(UTCTime)(&uTCTime));
383 RTTIMESPEC timeSpec;
384 RTTimeSpecSetMilli(&timeSpec, uTCTime);
385 char pszTime[30] = {0};
386 RTTimeSpecToString(&timeSpec, pszTime, sizeof(pszTime));
387 RTPrintf("Host time: %s\n", pszTime);
388
389 ULONG processorOnlineCount = 0;
390 CHECK_ERROR (Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
391 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
392 ULONG processorCount = 0;
393 CHECK_ERROR (Host, COMGETTER(ProcessorCount)(&processorCount));
394 RTPrintf("Processor count: %lu\n", processorCount);
395 ULONG processorSpeed = 0;
396 Bstr processorDescription;
397 for (ULONG i = 0; i < processorCount; i++)
398 {
399 CHECK_ERROR (Host, GetProcessorSpeed(i, &processorSpeed));
400 if (processorSpeed)
401 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
402 else
403 RTPrintf("Processor#%u speed: unknown\n", i, processorSpeed);
404#if 0 /* not yet implemented in Main */
405 CHECK_ERROR (Host, GetProcessorDescription(i, processorDescription.asOutParam()));
406 RTPrintf("Processor#%u description: %lS\n", i, processorDescription.raw());
407#endif
408 }
409
410#if 0 /* not yet implemented in Main */
411 ULONG memorySize = 0;
412 CHECK_ERROR (Host, COMGETTER(MemorySize)(&memorySize));
413 RTPrintf("Memory size: %lu MByte\n", memorySize);
414
415 ULONG memoryAvailable = 0;
416 CHECK_ERROR (Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
417 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
418
419 Bstr operatingSystem;
420 CHECK_ERROR (Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
421 RTPrintf("Operating system: %lS\n", operatingSystem.raw());
422
423 Bstr oSVersion;
424 CHECK_ERROR (Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
425 RTPrintf("Operating system version: %lS\n", oSVersion.raw());
426#endif
427 }
428 break;
429
430 case LISTHDDBACKENDS:
431 {
432 ComPtr<ISystemProperties> systemProperties;
433 CHECK_ERROR(a->virtualBox,
434 COMGETTER(SystemProperties) (systemProperties.asOutParam()));
435 com::SafeIfaceArray <IHardDiskFormat> hardDiskFormats;
436 CHECK_ERROR(systemProperties,
437 COMGETTER(HardDiskFormats) (ComSafeArrayAsOutParam (hardDiskFormats)));
438
439 RTPrintf("Supported hard disk backends:\n\n");
440 for (size_t i = 0; i < hardDiskFormats.size(); ++ i)
441 {
442 /* General information */
443 Bstr id;
444 CHECK_ERROR(hardDiskFormats [i],
445 COMGETTER(Id) (id.asOutParam()));
446
447 Bstr description;
448 CHECK_ERROR(hardDiskFormats [i],
449 COMGETTER(Id) (description.asOutParam()));
450
451 ULONG caps;
452 CHECK_ERROR(hardDiskFormats [i],
453 COMGETTER(Capabilities) (&caps));
454
455 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
456 i, id.raw(), description.raw(), caps);
457
458 /* File extensions */
459 com::SafeArray <BSTR> fileExtensions;
460 CHECK_ERROR(hardDiskFormats [i],
461 COMGETTER(FileExtensions) (ComSafeArrayAsOutParam (fileExtensions)));
462 for (size_t a = 0; a < fileExtensions.size(); ++ a)
463 {
464 RTPrintf ("%ls", Bstr (fileExtensions [a]).raw());
465 if (a != fileExtensions.size()-1)
466 RTPrintf (",");
467 }
468 RTPrintf ("'");
469
470 /* Configuration keys */
471 com::SafeArray <BSTR> propertyNames;
472 com::SafeArray <BSTR> propertyDescriptions;
473 com::SafeArray <DataType_T> propertyTypes;
474 com::SafeArray <ULONG> propertyFlags;
475 com::SafeArray <BSTR> propertyDefaults;
476 CHECK_ERROR(hardDiskFormats [i],
477 DescribeProperties (ComSafeArrayAsOutParam (propertyNames),
478 ComSafeArrayAsOutParam (propertyDescriptions),
479 ComSafeArrayAsOutParam (propertyTypes),
480 ComSafeArrayAsOutParam (propertyFlags),
481 ComSafeArrayAsOutParam (propertyDefaults)));
482
483 RTPrintf (" properties=(");
484 if (propertyNames.size() > 0)
485 {
486 for (size_t a = 0; a < propertyNames.size(); ++ a)
487 {
488 RTPrintf ("\n name='%ls' desc='%ls' type=",
489 Bstr (propertyNames [a]).raw(), Bstr (propertyDescriptions [a]).raw());
490 switch (propertyTypes [a])
491 {
492 case DataType_Int32: RTPrintf ("int"); break;
493 case DataType_Int8: RTPrintf ("byte"); break;
494 case DataType_String: RTPrintf ("string"); break;
495 }
496 RTPrintf (" flags=%#04x", propertyFlags [a]);
497 RTPrintf (" default='%ls'", Bstr (propertyDefaults [a]).raw());
498 if (a != propertyNames.size()-1)
499 RTPrintf (", ");
500 }
501 }
502 RTPrintf (")\n");
503 }
504 }
505 break;
506
507 case LISTHDDS:
508 {
509 com::SafeIfaceArray<IHardDisk> hdds;
510 CHECK_ERROR(a->virtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam (hdds)));
511 for (size_t i = 0; i < hdds.size(); ++ i)
512 {
513 ComPtr<IHardDisk> hdd = hdds[i];
514 Guid uuid;
515 hdd->COMGETTER(Id)(uuid.asOutParam());
516 RTPrintf("UUID: %s\n", uuid.toString().raw());
517 Bstr format;
518 hdd->COMGETTER(Format)(format.asOutParam());
519 RTPrintf("Format: %lS\n", format.raw());
520 Bstr filepath;
521 hdd->COMGETTER(Location)(filepath.asOutParam());
522 RTPrintf("Location: %lS\n", filepath.raw());
523 MediaState_T enmState;
524 /// @todo NEWMEDIA check accessibility of all parents
525 /// @todo NEWMEDIA print the full state value
526 hdd->COMGETTER(State)(&enmState);
527 RTPrintf("Accessible: %s\n", enmState != MediaState_Inaccessible ? "yes" : "no");
528 com::SafeGUIDArray machineIds;
529 hdd->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
530 for (size_t j = 0; j < machineIds.size(); ++ j)
531 {
532 ComPtr<IMachine> machine;
533 CHECK_ERROR(a->virtualBox, GetMachine(machineIds[j], machine.asOutParam()));
534 ASSERT(machine);
535 Bstr name;
536 machine->COMGETTER(Name)(name.asOutParam());
537 machine->COMGETTER(Id)(uuid.asOutParam());
538 RTPrintf("%s%lS (UUID: %RTuuid)\n",
539 j == 0 ? "Usage: " : " ",
540 name.raw(), &machineIds[j]);
541 }
542 /// @todo NEWMEDIA check usage in snapshots too
543 /// @todo NEWMEDIA also list children and say 'differencing' for
544 /// hard disks with the parent or 'base' otherwise.
545 RTPrintf("\n");
546 }
547 }
548 break;
549
550 case LISTDVDS:
551 {
552 com::SafeIfaceArray<IDVDImage> dvds;
553 CHECK_ERROR(a->virtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
554 for (size_t i = 0; i < dvds.size(); ++ i)
555 {
556 ComPtr<IDVDImage> dvdImage = dvds[i];
557 Guid uuid;
558 dvdImage->COMGETTER(Id)(uuid.asOutParam());
559 RTPrintf("UUID: %s\n", uuid.toString().raw());
560 Bstr filePath;
561 dvdImage->COMGETTER(Location)(filePath.asOutParam());
562 RTPrintf("Path: %lS\n", filePath.raw());
563 MediaState_T enmState;
564 dvdImage->COMGETTER(State)(&enmState);
565 RTPrintf("Accessible: %s\n", enmState != MediaState_Inaccessible ? "yes" : "no");
566 /** @todo usage */
567 RTPrintf("\n");
568 }
569 }
570 break;
571
572 case LISTFLOPPIES:
573 {
574 com::SafeIfaceArray<IFloppyImage> floppies;
575 CHECK_ERROR(a->virtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
576 for (size_t i = 0; i < floppies.size(); ++ i)
577 {
578 ComPtr<IFloppyImage> floppyImage = floppies[i];
579 Guid uuid;
580 floppyImage->COMGETTER(Id)(uuid.asOutParam());
581 RTPrintf("UUID: %s\n", uuid.toString().raw());
582 Bstr filePath;
583 floppyImage->COMGETTER(Location)(filePath.asOutParam());
584 RTPrintf("Path: %lS\n", filePath.raw());
585 MediaState_T enmState;
586 floppyImage->COMGETTER(State)(&enmState);
587 RTPrintf("Accessible: %s\n", enmState != MediaState_Inaccessible ? "yes" : "no");
588 /** @todo usage */
589 RTPrintf("\n");
590 }
591 }
592 break;
593
594 case LISTUSBHOST:
595 {
596 ComPtr<IHost> Host;
597 CHECK_ERROR_RET (a->virtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
598
599 SafeIfaceArray <IHostUSBDevice> CollPtr;
600 CHECK_ERROR_RET (Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
601
602 RTPrintf("Host USB Devices:\n\n");
603
604 if (CollPtr.size() == 0)
605 {
606 RTPrintf("<none>\n\n");
607 }
608 else
609 {
610 for (size_t i = 0; i < CollPtr.size(); ++i)
611 {
612 ComPtr <IHostUSBDevice> dev = CollPtr[i];
613
614 /* Query info. */
615 Guid id;
616 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), 1);
617 USHORT usVendorId;
618 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), 1);
619 USHORT usProductId;
620 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), 1);
621 USHORT bcdRevision;
622 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), 1);
623
624 RTPrintf("UUID: %S\n"
625 "VendorId: 0x%04x (%04X)\n"
626 "ProductId: 0x%04x (%04X)\n"
627 "Revision: %u.%u (%02u%02u)\n",
628 id.toString().raw(),
629 usVendorId, usVendorId, usProductId, usProductId,
630 bcdRevision >> 8, bcdRevision & 0xff,
631 bcdRevision >> 8, bcdRevision & 0xff);
632
633 /* optional stuff. */
634 Bstr bstr;
635 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
636 if (!bstr.isEmpty())
637 RTPrintf("Manufacturer: %lS\n", bstr.raw());
638 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), 1);
639 if (!bstr.isEmpty())
640 RTPrintf("Product: %lS\n", bstr.raw());
641 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
642 if (!bstr.isEmpty())
643 RTPrintf("SerialNumber: %lS\n", bstr.raw());
644 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), 1);
645 if (!bstr.isEmpty())
646 RTPrintf("Address: %lS\n", bstr.raw());
647
648 /* current state */
649 USBDeviceState_T state;
650 CHECK_ERROR_RET (dev, COMGETTER(State)(&state), 1);
651 const char *pszState = "?";
652 switch (state)
653 {
654 case USBDeviceState_NotSupported:
655 pszState = "Not supported"; break;
656 case USBDeviceState_Unavailable:
657 pszState = "Unavailable"; break;
658 case USBDeviceState_Busy:
659 pszState = "Busy"; break;
660 case USBDeviceState_Available:
661 pszState = "Available"; break;
662 case USBDeviceState_Held:
663 pszState = "Held"; break;
664 case USBDeviceState_Captured:
665 pszState = "Captured"; break;
666 default:
667 ASSERT (false);
668 break;
669 }
670 RTPrintf("Current State: %s\n\n", pszState);
671 }
672 }
673 }
674 break;
675
676 case LISTUSBFILTERS:
677 {
678 RTPrintf("Global USB Device Filters:\n\n");
679
680 ComPtr <IHost> host;
681 CHECK_ERROR_RET (a->virtualBox, COMGETTER(Host) (host.asOutParam()), 1);
682
683 SafeIfaceArray <IHostUSBDeviceFilter> coll;
684 CHECK_ERROR_RET (host, COMGETTER (USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
685
686 if (coll.size() == 0)
687 {
688 RTPrintf("<none>\n\n");
689 }
690 else
691 {
692 for (size_t index = 0; index < coll.size(); ++index)
693 {
694 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
695
696 /* Query info. */
697
698 RTPrintf("Index: %zu\n", index);
699
700 BOOL active = FALSE;
701 CHECK_ERROR_RET (flt, COMGETTER (Active) (&active), 1);
702 RTPrintf("Active: %s\n", active ? "yes" : "no");
703
704 USBDeviceFilterAction_T action;
705 CHECK_ERROR_RET (flt, COMGETTER (Action) (&action), 1);
706 const char *pszAction = "<invalid>";
707 switch (action)
708 {
709 case USBDeviceFilterAction_Ignore:
710 pszAction = "Ignore";
711 break;
712 case USBDeviceFilterAction_Hold:
713 pszAction = "Hold";
714 break;
715 default:
716 break;
717 }
718 RTPrintf("Action: %s\n", pszAction);
719
720 Bstr bstr;
721 CHECK_ERROR_RET (flt, COMGETTER (Name) (bstr.asOutParam()), 1);
722 RTPrintf("Name: %lS\n", bstr.raw());
723 CHECK_ERROR_RET (flt, COMGETTER (VendorId) (bstr.asOutParam()), 1);
724 RTPrintf("VendorId: %lS\n", bstr.raw());
725 CHECK_ERROR_RET (flt, COMGETTER (ProductId) (bstr.asOutParam()), 1);
726 RTPrintf("ProductId: %lS\n", bstr.raw());
727 CHECK_ERROR_RET (flt, COMGETTER (Revision) (bstr.asOutParam()), 1);
728 RTPrintf("Revision: %lS\n", bstr.raw());
729 CHECK_ERROR_RET (flt, COMGETTER (Manufacturer) (bstr.asOutParam()), 1);
730 RTPrintf("Manufacturer: %lS\n", bstr.raw());
731 CHECK_ERROR_RET (flt, COMGETTER (Product) (bstr.asOutParam()), 1);
732 RTPrintf("Product: %lS\n", bstr.raw());
733 CHECK_ERROR_RET (flt, COMGETTER (SerialNumber) (bstr.asOutParam()), 1);
734 RTPrintf("Serial Number: %lS\n\n", bstr.raw());
735 }
736 }
737 }
738 break;
739
740 case LISTSYSTEMPROPERTIES:
741 {
742 ComPtr<ISystemProperties> systemProperties;
743 a->virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
744
745 Bstr str;
746 ULONG ulValue;
747 ULONG64 ul64Value;
748 BOOL flag;
749
750 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
751 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
752 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
753 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
754 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
755 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
756 systemProperties->COMGETTER(MaxVDISize)(&ul64Value);
757 RTPrintf("Maximum VDI size: %lu Megabytes\n", ul64Value);
758 systemProperties->COMGETTER(DefaultHardDiskFolder)(str.asOutParam());
759 RTPrintf("Default hard disk folder: %lS\n", str.raw());
760 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
761 RTPrintf("Default machine folder: %lS\n", str.raw());
762 systemProperties->COMGETTER(RemoteDisplayAuthLibrary)(str.asOutParam());
763 RTPrintf("VRDP authentication library: %lS\n", str.raw());
764 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
765 RTPrintf("Webservice auth. library: %lS\n", str.raw());
766 systemProperties->COMGETTER(HWVirtExEnabled)(&flag);
767 RTPrintf("Hardware virt. extensions: %s\n", flag ? "yes" : "no");
768 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
769 RTPrintf("Log history count: %u\n", ulValue);
770
771 }
772 break;
773 case LISTDHCPSERVERS:
774 {
775 com::SafeIfaceArray<IDHCPServer> svrs;
776 CHECK_ERROR(a->virtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam (svrs)));
777 for (size_t i = 0; i < svrs.size(); ++ i)
778 {
779 ComPtr<IDHCPServer> svr = svrs[i];
780 Bstr netName;
781 svr->COMGETTER(NetworkName)(netName.asOutParam());
782 RTPrintf("NetworkName: %lS\n", netName.raw());
783 Bstr ip;
784 svr->COMGETTER(IPAddress)(ip.asOutParam());
785 RTPrintf("IP: %lS\n", ip.raw());
786 Bstr netmask;
787 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
788 RTPrintf("NetworkMask: %lS\n", netmask.raw());
789 Bstr lowerIp;
790 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
791 RTPrintf("lowerIPAddress: %lS\n", lowerIp.raw());
792 Bstr upperIp;
793 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
794 RTPrintf("upperIPAddress: %lS\n", upperIp.raw());
795 BOOL bEnabled;
796 svr->COMGETTER(Enabled)(&bEnabled);
797 RTPrintf("Enabled: %s\n", bEnabled ? "Yes" : "No");
798 RTPrintf("\n");
799 }
800 }
801 break;
802 } // end switch
803
804 return SUCCEEDED(rc) ? 0 : 1;
805}
806
807#endif /* !VBOX_ONLY_DOCS */
808/* 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