VirtualBox

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

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

API/others: Renamed IConsole::discardSavedState to IConsole::forgetSavedState, added parameter. Deleted old IConsole::powerDown, renamed IConsole::powerDownAsync to IConsole::powerDown (as promised for 2.1). Implemented perl sample code for registering a hard disk. Cleaned up constant formatting in the API docs. Updated SDK changelog. Renamed com/errorprint2.h to com/errorprint.h, added a few assertion variants. Eliminated com/errorprint_legacy.h. Adjusted all files using the affected headers and APIs. Renamed tstHeadless2 to tstHeadless.

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