VirtualBox

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

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

3551: “Main: Replace remaining collections with safe arrays”
Converted HostDVDDriveCollection.
Fixed a locking problem that caused hangs in r43495. Tested locally and by lelik.

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