VirtualBox

source: vbox/trunk/src/VBox/Main/HostImpl.cpp@ 19796

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

Main: support for using VBox from Python on Windows (still certain limitation apply, such as enum visibility)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 85.4 KB
Line 
1/* $Id: HostImpl.cpp 19239 2009-04-28 13:19:14Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation: Host
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#define __STDC_LIMIT_MACROS
23#define __STDC_CONSTANT_MACROS
24
25#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
26# include <VBox/WinNetConfig.h>
27#endif /* #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT) */
28
29#ifdef RT_OS_LINUX
30// # include <sys/types.h>
31// # include <sys/stat.h>
32// # include <unistd.h>
33# include <sys/ioctl.h>
34// # include <fcntl.h>
35// # include <mntent.h>
36/* bird: This is a hack to work around conflicts between these linux kernel headers
37 * and the GLIBC tcpip headers. They have different declarations of the 4
38 * standard byte order functions. */
39// # define _LINUX_BYTEORDER_GENERIC_H
40// # include <linux/cdrom.h>
41# include <errno.h>
42# include <net/if.h>
43# include <net/if_arp.h>
44#endif /* RT_OS_LINUX */
45
46#ifdef RT_OS_SOLARIS
47# include <fcntl.h>
48# include <unistd.h>
49# include <stropts.h>
50# include <errno.h>
51# include <limits.h>
52# include <stdio.h>
53# ifdef VBOX_SOLARIS_NSL_RESOLVED
54# include <libdevinfo.h>
55# endif
56# include <net/if.h>
57# include <sys/socket.h>
58# include <sys/sockio.h>
59# include <net/if_arp.h>
60# include <net/if.h>
61# include <sys/types.h>
62# include <sys/stat.h>
63# include <sys/cdio.h>
64# include <sys/dkio.h>
65# include <sys/mnttab.h>
66# include <sys/mntent.h>
67/* Dynamic loading of libhal on Solaris hosts */
68# ifdef VBOX_USE_LIBHAL
69# include "vbox-libhal.h"
70extern "C" char *getfullrawname(char *);
71# endif
72# include "solaris/DynLoadLibSolaris.h"
73#endif /* RT_OS_SOLARIS */
74
75#ifdef RT_OS_WINDOWS
76# define _WIN32_DCOM
77# include <windows.h>
78# include <shellapi.h>
79# define INITGUID
80# include <guiddef.h>
81# include <devguid.h>
82# include <objbase.h>
83//# include <setupapi.h>
84# include <shlobj.h>
85# include <cfgmgr32.h>
86
87#endif /* RT_OS_WINDOWS */
88
89
90#include "HostImpl.h"
91#include "HostDVDDriveImpl.h"
92#include "HostFloppyDriveImpl.h"
93#include "HostNetworkInterfaceImpl.h"
94#ifdef VBOX_WITH_USB
95# include "HostUSBDeviceImpl.h"
96# include "USBDeviceFilterImpl.h"
97# include "USBProxyService.h"
98#endif
99#include "VirtualBoxImpl.h"
100#include "MachineImpl.h"
101#include "Logging.h"
102#include "Performance.h"
103
104#ifdef RT_OS_DARWIN
105# include "darwin/iokit.h"
106#endif
107
108
109#include <iprt/asm.h>
110#include <iprt/string.h>
111#include <iprt/mp.h>
112#include <iprt/time.h>
113#include <iprt/param.h>
114#include <iprt/env.h>
115#include <iprt/mem.h>
116#include <iprt/system.h>
117#ifdef RT_OS_SOLARIS
118# include <iprt/path.h>
119# include <iprt/ctype.h>
120#endif
121#ifdef VBOX_WITH_HOSTNETIF_API
122#include "netif.h"
123#endif
124
125#include <VBox/usb.h>
126#include <VBox/x86.h>
127#include <VBox/err.h>
128#include <VBox/settings.h>
129
130#include <stdio.h>
131
132#include <algorithm>
133
134
135
136// constructor / destructor
137/////////////////////////////////////////////////////////////////////////////
138
139HRESULT Host::FinalConstruct()
140{
141 return S_OK;
142}
143
144void Host::FinalRelease()
145{
146 if (isReady())
147 uninit();
148}
149
150// public initializer/uninitializer for internal purposes only
151/////////////////////////////////////////////////////////////////////////////
152
153/**
154 * Initializes the host object.
155 *
156 * @param aParent VirtualBox parent object.
157 */
158HRESULT Host::init (VirtualBox *aParent)
159{
160 LogFlowThisFunc (("isReady=%d\n", isReady()));
161
162 ComAssertRet (aParent, E_INVALIDARG);
163
164 AutoWriteLock alock (this);
165 ComAssertRet (!isReady(), E_FAIL);
166
167 mParent = aParent;
168
169#ifdef VBOX_WITH_USB
170 /*
171 * Create and initialize the USB Proxy Service.
172 */
173# if defined (RT_OS_DARWIN)
174 mUSBProxyService = new USBProxyServiceDarwin (this);
175# elif defined (RT_OS_LINUX)
176 mUSBProxyService = new USBProxyServiceLinux (this);
177# elif defined (RT_OS_OS2)
178 mUSBProxyService = new USBProxyServiceOs2 (this);
179# elif defined (RT_OS_SOLARIS)
180 mUSBProxyService = new USBProxyServiceSolaris (this);
181# elif defined (RT_OS_WINDOWS)
182 mUSBProxyService = new USBProxyServiceWindows (this);
183# else
184 mUSBProxyService = new USBProxyService (this);
185# endif
186 HRESULT hrc = mUSBProxyService->init();
187 AssertComRCReturn(hrc, hrc);
188#endif /* VBOX_WITH_USB */
189
190#ifdef VBOX_WITH_RESOURCE_USAGE_API
191 registerMetrics (aParent->performanceCollector());
192#endif /* VBOX_WITH_RESOURCE_USAGE_API */
193
194#if defined (RT_OS_WINDOWS)
195 mHostPowerService = new HostPowerServiceWin (mParent);
196#elif defined (RT_OS_DARWIN)
197 mHostPowerService = new HostPowerServiceDarwin (mParent);
198#else
199 mHostPowerService = new HostPowerService (mParent);
200#endif
201
202 /* Cache the features reported by GetProcessorFeature. */
203 fVTxAMDVSupported = false;
204 fLongModeSupported = false;
205 fPAESupported = false;
206
207 if (ASMHasCpuId())
208 {
209 uint32_t u32FeaturesECX;
210 uint32_t u32Dummy;
211 uint32_t u32FeaturesEDX;
212 uint32_t u32VendorEBX, u32VendorECX, u32VendorEDX, u32AMDFeatureEDX, u32AMDFeatureECX;
213
214 ASMCpuId (0, &u32Dummy, &u32VendorEBX, &u32VendorECX, &u32VendorEDX);
215 ASMCpuId (1, &u32Dummy, &u32Dummy, &u32FeaturesECX, &u32FeaturesEDX);
216 /* Query AMD features. */
217 ASMCpuId (0x80000001, &u32Dummy, &u32Dummy, &u32AMDFeatureECX, &u32AMDFeatureEDX);
218
219 fLongModeSupported = !!(u32AMDFeatureEDX & X86_CPUID_AMD_FEATURE_EDX_LONG_MODE);
220 fPAESupported = !!(u32FeaturesEDX & X86_CPUID_FEATURE_EDX_PAE);
221
222 if ( u32VendorEBX == X86_CPUID_VENDOR_INTEL_EBX
223 && u32VendorECX == X86_CPUID_VENDOR_INTEL_ECX
224 && u32VendorEDX == X86_CPUID_VENDOR_INTEL_EDX
225 )
226 {
227 if ( (u32FeaturesECX & X86_CPUID_FEATURE_ECX_VMX)
228 && (u32FeaturesEDX & X86_CPUID_FEATURE_EDX_MSR)
229 && (u32FeaturesEDX & X86_CPUID_FEATURE_EDX_FXSR)
230 )
231 fVTxAMDVSupported = true;
232 }
233 else
234 if ( u32VendorEBX == X86_CPUID_VENDOR_AMD_EBX
235 && u32VendorECX == X86_CPUID_VENDOR_AMD_ECX
236 && u32VendorEDX == X86_CPUID_VENDOR_AMD_EDX
237 )
238 {
239 if ( (u32AMDFeatureECX & X86_CPUID_AMD_FEATURE_ECX_SVM)
240 && (u32FeaturesEDX & X86_CPUID_FEATURE_EDX_MSR)
241 && (u32FeaturesEDX & X86_CPUID_FEATURE_EDX_FXSR)
242 )
243 fVTxAMDVSupported = true;
244 }
245 }
246
247 setReady(true);
248 return S_OK;
249}
250
251/**
252 * Uninitializes the host object and sets the ready flag to FALSE.
253 * Called either from FinalRelease() or by the parent when it gets destroyed.
254 */
255void Host::uninit()
256{
257 LogFlowThisFunc (("isReady=%d\n", isReady()));
258
259 AssertReturn (isReady(), (void) 0);
260
261#ifdef VBOX_WITH_RESOURCE_USAGE_API
262 unregisterMetrics (mParent->performanceCollector());
263#endif /* VBOX_WITH_RESOURCE_USAGE_API */
264
265#ifdef VBOX_WITH_USB
266 /* wait for USB proxy service to terminate before we uninit all USB
267 * devices */
268 LogFlowThisFunc (("Stopping USB proxy service...\n"));
269 delete mUSBProxyService;
270 mUSBProxyService = NULL;
271 LogFlowThisFunc (("Done stopping USB proxy service.\n"));
272#endif
273
274 delete mHostPowerService;
275
276 /* uninit all USB device filters still referenced by clients */
277 uninitDependentChildren();
278
279#ifdef VBOX_WITH_USB
280 mUSBDeviceFilters.clear();
281#endif
282
283 setReady (FALSE);
284}
285
286// IHost properties
287/////////////////////////////////////////////////////////////////////////////
288
289/**
290 * Returns a list of host DVD drives.
291 *
292 * @returns COM status code
293 * @param drives address of result pointer
294 */
295STDMETHODIMP Host::COMGETTER(DVDDrives) (ComSafeArrayOut (IHostDVDDrive *, aDrives))
296{
297 CheckComArgOutSafeArrayPointerValid(aDrives);
298 AutoWriteLock alock (this);
299 CHECK_READY();
300 std::list <ComObjPtr <HostDVDDrive> > list;
301 HRESULT rc = S_OK;
302
303#if defined(RT_OS_WINDOWS)
304 int sz = GetLogicalDriveStrings(0, NULL);
305 TCHAR *hostDrives = new TCHAR[sz+1];
306 GetLogicalDriveStrings(sz, hostDrives);
307 wchar_t driveName[3] = { '?', ':', '\0' };
308 TCHAR *p = hostDrives;
309 do
310 {
311 if (GetDriveType(p) == DRIVE_CDROM)
312 {
313 driveName[0] = *p;
314 ComObjPtr <HostDVDDrive> hostDVDDriveObj;
315 hostDVDDriveObj.createObject();
316 hostDVDDriveObj->init (Bstr (driveName));
317 list.push_back (hostDVDDriveObj);
318 }
319 p += _tcslen(p) + 1;
320 }
321 while (*p);
322 delete[] hostDrives;
323
324#elif defined(RT_OS_SOLARIS)
325# ifdef VBOX_USE_LIBHAL
326 if (!getDVDInfoFromHal(list))
327# endif
328 // Not all Solaris versions ship with libhal.
329 // So use a fallback approach similar to Linux.
330 {
331 if (RTEnvGet("VBOX_CDROM"))
332 {
333 char *cdromEnv = strdup(RTEnvGet("VBOX_CDROM"));
334 char *cdromDrive;
335 cdromDrive = strtok(cdromEnv, ":"); /** @todo use strtok_r. */
336 while (cdromDrive)
337 {
338 if (validateDevice(cdromDrive, true))
339 {
340 ComObjPtr <HostDVDDrive> hostDVDDriveObj;
341 hostDVDDriveObj.createObject();
342 hostDVDDriveObj->init (Bstr (cdromDrive));
343 list.push_back (hostDVDDriveObj);
344 }
345 cdromDrive = strtok(NULL, ":");
346 }
347 free(cdromEnv);
348 }
349 else
350 {
351 // this might work on Solaris version older than Nevada.
352 if (validateDevice("/cdrom/cdrom0", true))
353 {
354 ComObjPtr <HostDVDDrive> hostDVDDriveObj;
355 hostDVDDriveObj.createObject();
356 hostDVDDriveObj->init (Bstr ("cdrom/cdrom0"));
357 list.push_back (hostDVDDriveObj);
358 }
359
360 // check the mounted drives
361 parseMountTable(MNTTAB, list);
362 }
363 }
364
365#elif defined(RT_OS_LINUX)
366 if (RT_SUCCESS (mHostDrives.updateDVDs()))
367 for (DriveInfoList::const_iterator it = mHostDrives.DVDBegin();
368 SUCCEEDED (rc) && it != mHostDrives.DVDEnd(); ++it)
369 {
370 ComObjPtr<HostDVDDrive> hostDVDDriveObj;
371 Bstr device (it->mDevice.c_str());
372 Bstr udi (it->mUdi.empty() ? NULL : it->mUdi.c_str());
373 Bstr description (it->mDescription.empty() ? NULL : it->mDescription.c_str());
374 if (device.isNull() || (!it->mUdi.empty() && udi.isNull()) ||
375 (!it->mDescription.empty() && description.isNull()))
376 rc = E_OUTOFMEMORY;
377 if (SUCCEEDED (rc))
378 rc = hostDVDDriveObj.createObject();
379 if (SUCCEEDED (rc))
380 rc = hostDVDDriveObj->init (device, udi, description);
381 if (SUCCEEDED (rc))
382 list.push_back(hostDVDDriveObj);
383 }
384#elif defined(RT_OS_DARWIN)
385 PDARWINDVD cur = DarwinGetDVDDrives();
386 while (cur)
387 {
388 ComObjPtr<HostDVDDrive> hostDVDDriveObj;
389 hostDVDDriveObj.createObject();
390 hostDVDDriveObj->init(Bstr(cur->szName));
391 list.push_back(hostDVDDriveObj);
392
393 /* next */
394 void *freeMe = cur;
395 cur = cur->pNext;
396 RTMemFree(freeMe);
397 }
398
399#else
400 /* PORTME */
401#endif
402
403 SafeIfaceArray <IHostDVDDrive> array (list);
404 array.detachTo(ComSafeArrayOutArg(aDrives));
405 return rc;
406}
407
408/**
409 * Returns a list of host floppy drives.
410 *
411 * @returns COM status code
412 * @param drives address of result pointer
413 */
414STDMETHODIMP Host::COMGETTER(FloppyDrives) (ComSafeArrayOut (IHostFloppyDrive *, aDrives))
415{
416 CheckComArgOutPointerValid(aDrives);
417 AutoWriteLock alock (this);
418 CHECK_READY();
419
420 std::list <ComObjPtr <HostFloppyDrive> > list;
421 HRESULT rc = S_OK;
422
423#ifdef RT_OS_WINDOWS
424 int sz = GetLogicalDriveStrings(0, NULL);
425 TCHAR *hostDrives = new TCHAR[sz+1];
426 GetLogicalDriveStrings(sz, hostDrives);
427 wchar_t driveName[3] = { '?', ':', '\0' };
428 TCHAR *p = hostDrives;
429 do
430 {
431 if (GetDriveType(p) == DRIVE_REMOVABLE)
432 {
433 driveName[0] = *p;
434 ComObjPtr <HostFloppyDrive> hostFloppyDriveObj;
435 hostFloppyDriveObj.createObject();
436 hostFloppyDriveObj->init (Bstr (driveName));
437 list.push_back (hostFloppyDriveObj);
438 }
439 p += _tcslen(p) + 1;
440 }
441 while (*p);
442 delete[] hostDrives;
443#elif defined(RT_OS_LINUX)
444 if (RT_SUCCESS (mHostDrives.updateFloppies()))
445 for (DriveInfoList::const_iterator it = mHostDrives.FloppyBegin();
446 SUCCEEDED (rc) && it != mHostDrives.FloppyEnd(); ++it)
447 {
448 ComObjPtr<HostFloppyDrive> hostFloppyDriveObj;
449 Bstr device (it->mDevice.c_str());
450 Bstr udi (it->mUdi.empty() ? NULL : it->mUdi.c_str());
451 Bstr description (it->mDescription.empty() ? NULL : it->mDescription.c_str());
452 if (device.isNull() || (!it->mUdi.empty() && udi.isNull()) ||
453 (!it->mDescription.empty() && description.isNull()))
454 rc = E_OUTOFMEMORY;
455 if (SUCCEEDED (rc))
456 rc = hostFloppyDriveObj.createObject();
457 if (SUCCEEDED (rc))
458 rc = hostFloppyDriveObj->init (device, udi, description);
459 if (SUCCEEDED (rc))
460 list.push_back(hostFloppyDriveObj);
461 }
462#else
463 /* PORTME */
464#endif
465
466 SafeIfaceArray<IHostFloppyDrive> collection (list);
467 collection.detachTo(ComSafeArrayOutArg (aDrives));
468 return rc;
469}
470
471#ifdef RT_OS_SOLARIS
472static void vboxSolarisAddHostIface(char *pszIface, int Instance, PCRTMAC pMac, void *pvHostNetworkInterfaceList)
473{
474 std::list<ComObjPtr <HostNetworkInterface> > *pList = (std::list<ComObjPtr <HostNetworkInterface> > *)pvHostNetworkInterfaceList;
475 Assert(pList);
476
477 typedef std::map <std::string, std::string> NICMap;
478 typedef std::pair <std::string, std::string> NICPair;
479 static NICMap SolarisNICMap;
480 if (SolarisNICMap.empty())
481 {
482 SolarisNICMap.insert(NICPair("afe", "ADMtek Centaur/Comet Fast Ethernet"));
483 SolarisNICMap.insert(NICPair("aggr", "Link Aggregation Interface"));
484 SolarisNICMap.insert(NICPair("bge", "Broadcom BCM57xx Gigabit Ethernet"));
485 SolarisNICMap.insert(NICPair("ce", "Cassini Gigabit Ethernet"));
486 SolarisNICMap.insert(NICPair("chxge", "Chelsio Ethernet"));
487 SolarisNICMap.insert(NICPair("dmfe", "Davicom Fast Ethernet"));
488 SolarisNICMap.insert(NICPair("dnet", "DEC 21040/41 21140 Ethernet"));
489 SolarisNICMap.insert(NICPair("e1000", "Intel PRO/1000 Gigabit Ethernet"));
490 SolarisNICMap.insert(NICPair("e1000g", "Intel PRO/1000 Gigabit Ethernet"));
491 SolarisNICMap.insert(NICPair("elx", "3COM EtherLink III Ethernet"));
492 SolarisNICMap.insert(NICPair("elxl", "3COM Ethernet"));
493 SolarisNICMap.insert(NICPair("eri", "eri Fast Ethernet"));
494 SolarisNICMap.insert(NICPair("ge", "GEM Gigabit Ethernet"));
495 SolarisNICMap.insert(NICPair("hme", "SUNW,hme Fast-Ethernet"));
496 SolarisNICMap.insert(NICPair("ipge", "PCI-E Gigabit Ethernet"));
497 SolarisNICMap.insert(NICPair("iprb", "Intel 82557/58/59 Ethernet"));
498 SolarisNICMap.insert(NICPair("mxfe", "Macronix 98715 Fast Ethernet"));
499 SolarisNICMap.insert(NICPair("nge", "Nvidia Gigabit Ethernet"));
500 SolarisNICMap.insert(NICPair("pcelx", "3COM EtherLink III PCMCIA Ethernet"));
501 SolarisNICMap.insert(NICPair("pcn", "AMD PCnet Ethernet"));
502 SolarisNICMap.insert(NICPair("qfe", "SUNW,qfe Quad Fast-Ethernet"));
503 SolarisNICMap.insert(NICPair("rge", "Realtek Gigabit Ethernet"));
504 SolarisNICMap.insert(NICPair("rtls", "Realtek 8139 Fast Ethernet"));
505 SolarisNICMap.insert(NICPair("skge", "SksKonnect Gigabit Ethernet"));
506 SolarisNICMap.insert(NICPair("spwr", "SMC EtherPower II 10/100 (9432) Ethernet"));
507 SolarisNICMap.insert(NICPair("vnic", "Virtual Network Interface Ethernet"));
508 SolarisNICMap.insert(NICPair("xge", "Neterior Xframe Gigabit Ethernet"));
509 SolarisNICMap.insert(NICPair("xge", "Neterior Xframe 10Gigabit Ethernet"));
510 }
511
512 /*
513 * Try picking up description from our NIC map.
514 */
515 char szNICInstance[128];
516 RTStrPrintf(szNICInstance, sizeof(szNICInstance), "%s%d", pszIface, Instance);
517 char szNICDesc[256];
518 std::string Description = SolarisNICMap[pszIface];
519 if (Description != "")
520 RTStrPrintf(szNICDesc, sizeof(szNICDesc), "%s - %s", szNICInstance, Description.c_str());
521 else
522 RTStrPrintf(szNICDesc, sizeof(szNICDesc), "%s - Ethernet", szNICInstance);
523
524 /*
525 * Construct UUID with interface name and the MAC address if available.
526 */
527 RTUUID Uuid;
528 RTUuidClear(&Uuid);
529 memcpy(&Uuid, szNICInstance, RT_MIN(strlen(szNICInstance), sizeof(Uuid)));
530 Uuid.Gen.u8ClockSeqHiAndReserved = (Uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80;
531 Uuid.Gen.u16TimeHiAndVersion = (Uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
532 if (pMac)
533 {
534 Uuid.Gen.au8Node[0] = pMac->au8[0];
535 Uuid.Gen.au8Node[1] = pMac->au8[1];
536 Uuid.Gen.au8Node[2] = pMac->au8[2];
537 Uuid.Gen.au8Node[3] = pMac->au8[3];
538 Uuid.Gen.au8Node[4] = pMac->au8[4];
539 Uuid.Gen.au8Node[5] = pMac->au8[5];
540 }
541
542 ComObjPtr<HostNetworkInterface> IfObj;
543 IfObj.createObject();
544 if (SUCCEEDED(IfObj->init(Bstr(szNICDesc), Guid(Uuid), HostNetworkInterfaceType_Bridged)))
545 pList->push_back(IfObj);
546}
547
548static boolean_t vboxSolarisAddLinkHostIface(const char *pszIface, void *pvHostNetworkInterfaceList)
549{
550 /*
551 * Clip off the zone instance number from the interface name (if any).
552 */
553 char szIfaceName[128];
554 strcpy(szIfaceName, pszIface);
555 char *pszColon = (char *)memchr(szIfaceName, ':', sizeof(szIfaceName));
556 if (pszColon)
557 *pszColon = '\0';
558
559 /*
560 * Get the instance number from the interface name, then clip it off.
561 */
562 int cbInstance = 0;
563 int cbIface = strlen(szIfaceName);
564 const char *pszEnd = pszIface + cbIface - 1;
565 for (int i = 0; i < cbIface - 1; i++)
566 {
567 if (!RT_C_IS_DIGIT(*pszEnd))
568 break;
569 cbInstance++;
570 pszEnd--;
571 }
572
573 int Instance = atoi(pszEnd + 1);
574 strncpy(szIfaceName, pszIface, cbIface - cbInstance);
575 szIfaceName[cbIface - cbInstance] = '\0';
576
577 /*
578 * Add the interface.
579 */
580 vboxSolarisAddHostIface(szIfaceName, Instance, NULL, pvHostNetworkInterfaceList);
581
582 /*
583 * Continue walking...
584 */
585 return _B_FALSE;
586}
587
588static bool vboxSolarisSortNICList(const ComObjPtr <HostNetworkInterface> Iface1, const ComObjPtr <HostNetworkInterface> Iface2)
589{
590 Bstr Iface1Str;
591 (*Iface1).COMGETTER(Name) (Iface1Str.asOutParam());
592
593 Bstr Iface2Str;
594 (*Iface2).COMGETTER(Name) (Iface2Str.asOutParam());
595
596 return Iface1Str < Iface2Str;
597}
598
599static bool vboxSolarisSameNIC(const ComObjPtr <HostNetworkInterface> Iface1, const ComObjPtr <HostNetworkInterface> Iface2)
600{
601 Bstr Iface1Str;
602 (*Iface1).COMGETTER(Name) (Iface1Str.asOutParam());
603
604 Bstr Iface2Str;
605 (*Iface2).COMGETTER(Name) (Iface2Str.asOutParam());
606
607 return (Iface1Str == Iface2Str);
608}
609
610# ifdef VBOX_SOLARIS_NSL_RESOLVED
611static int vboxSolarisAddPhysHostIface(di_node_t Node, di_minor_t Minor, void *pvHostNetworkInterfaceList)
612{
613 /*
614 * Skip aggregations.
615 */
616 if (!strcmp(di_driver_name(Node), "aggr"))
617 return DI_WALK_CONTINUE;
618
619 /*
620 * Skip softmacs.
621 */
622 if (!strcmp(di_driver_name(Node), "softmac"))
623 return DI_WALK_CONTINUE;
624
625 vboxSolarisAddHostIface(di_driver_name(Node), di_instance(Node), NULL, pvHostNetworkInterfaceList);
626 return DI_WALK_CONTINUE;
627}
628# endif /* VBOX_SOLARIS_NSL_RESOLVED */
629
630#endif
631
632#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
633# define VBOX_APP_NAME L"VirtualBox"
634
635static int vboxNetWinAddComponent(std::list <ComObjPtr <HostNetworkInterface> > * pPist, INetCfgComponent * pncc)
636{
637 LPWSTR lpszName;
638 GUID IfGuid;
639 HRESULT hr;
640 int rc = VERR_GENERAL_FAILURE;
641
642 hr = pncc->GetDisplayName( &lpszName );
643 Assert(hr == S_OK);
644 if(hr == S_OK)
645 {
646 size_t cUnicodeName = wcslen(lpszName) + 1;
647 size_t uniLen = (cUnicodeName * 2 + sizeof (OLECHAR) - 1) / sizeof (OLECHAR);
648 Bstr name (uniLen + 1 /* extra zero */);
649 wcscpy((wchar_t *) name.mutableRaw(), lpszName);
650
651 hr = pncc->GetInstanceGuid(&IfGuid);
652 Assert(hr == S_OK);
653 if (hr == S_OK)
654 {
655 /* create a new object and add it to the list */
656 ComObjPtr <HostNetworkInterface> iface;
657 iface.createObject();
658 /* remove the curly bracket at the end */
659 if (SUCCEEDED (iface->init (name, Guid (IfGuid), HostNetworkInterfaceType_Bridged)))
660 {
661// iface->setVirtualBox(mParent);
662 pPist->push_back (iface);
663 rc = VINF_SUCCESS;
664 }
665 else
666 {
667 Assert(0);
668 }
669 }
670 CoTaskMemFree(lpszName);
671 }
672
673 return rc;
674}
675#endif /* defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT) */
676/**
677 * Returns a list of host network interfaces.
678 *
679 * @returns COM status code
680 * @param drives address of result pointer
681 */
682STDMETHODIMP Host::COMGETTER(NetworkInterfaces) (ComSafeArrayOut (IHostNetworkInterface *, aNetworkInterfaces))
683{
684#if defined(RT_OS_WINDOWS) || defined(VBOX_WITH_NETFLT) /*|| defined(RT_OS_OS2)*/
685 if (ComSafeArrayOutIsNull (aNetworkInterfaces))
686 return E_POINTER;
687
688 AutoWriteLock alock (this);
689 CHECK_READY();
690
691 std::list <ComObjPtr <HostNetworkInterface> > list;
692
693#ifdef VBOX_WITH_HOSTNETIF_API
694 int rc = NetIfList(list);
695 if (rc)
696 {
697 Log(("Failed to get host network interface list with rc=%Vrc\n", rc));
698 }
699#else
700# if defined(RT_OS_DARWIN)
701 PDARWINETHERNIC pEtherNICs = DarwinGetEthernetControllers();
702 while (pEtherNICs)
703 {
704 ComObjPtr<HostNetworkInterface> IfObj;
705 IfObj.createObject();
706 if (SUCCEEDED(IfObj->init(Bstr(pEtherNICs->szName), Guid(pEtherNICs->Uuid), HostNetworkInterfaceType_Bridged)))
707 list.push_back(IfObj);
708
709 /* next, free current */
710 void *pvFree = pEtherNICs;
711 pEtherNICs = pEtherNICs->pNext;
712 RTMemFree(pvFree);
713 }
714
715# elif defined(RT_OS_SOLARIS)
716
717# ifdef VBOX_SOLARIS_NSL_RESOLVED
718
719 /*
720 * Use libdevinfo for determining all physical interfaces.
721 */
722 di_node_t Root;
723 Root = di_init("/", DINFOCACHE);
724 if (Root != DI_NODE_NIL)
725 {
726 di_walk_minor(Root, DDI_NT_NET, 0, &list, vboxSolarisAddPhysHostIface);
727 di_fini(Root);
728 }
729
730 /*
731 * Use libdlpi for determining all DLPI interfaces.
732 */
733 if (VBoxSolarisLibDlpiFound())
734 g_pfnLibDlpiWalk(vboxSolarisAddLinkHostIface, &list, 0);
735
736# endif /* VBOX_SOLARIS_NSL_RESOLVED */
737
738 /*
739 * This gets only the list of all plumbed logical interfaces.
740 * This is needed for zones which cannot access the device tree
741 * and in this case we just let them use the list of plumbed interfaces
742 * on the zone.
743 */
744 int Sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
745 if (Sock > 0)
746 {
747 struct lifnum IfNum;
748 memset(&IfNum, 0, sizeof(IfNum));
749 IfNum.lifn_family = AF_INET;
750 int rc = ioctl(Sock, SIOCGLIFNUM, &IfNum);
751 if (!rc)
752 {
753 struct lifreq Ifaces[24];
754 struct lifconf IfConfig;
755 memset(&IfConfig, 0, sizeof(IfConfig));
756 IfConfig.lifc_family = AF_INET;
757 IfConfig.lifc_len = sizeof(Ifaces);
758 IfConfig.lifc_buf = (caddr_t)&(Ifaces[0]);
759 rc = ioctl(Sock, SIOCGLIFCONF, &IfConfig);
760 if (!rc)
761 {
762 for (int i = 0; i < IfNum.lifn_count; i++)
763 {
764 /*
765 * Skip loopback interfaces.
766 */
767 if (!strncmp(Ifaces[i].lifr_name, "lo", 2))
768 continue;
769
770#if 0
771 rc = ioctl(Sock, SIOCGLIFADDR, &(Ifaces[i]));
772 if (!rc)
773 {
774 RTMAC Mac;
775 struct arpreq ArpReq;
776 memcpy(&ArpReq.arp_pa, &Ifaces[i].lifr_addr, sizeof(struct sockaddr_in));
777
778 /*
779 * We might fail if the interface has not been assigned an IP address.
780 * That doesn't matter; as long as it's plumbed we can pick it up.
781 * But, if it has not acquired an IP address we cannot obtain it's MAC
782 * address this way, so we just use all zeros there.
783 */
784 rc = ioctl(Sock, SIOCGARP, &ArpReq);
785 if (!rc)
786 memcpy(&Mac, ArpReq.arp_ha.sa_data, sizeof(RTMAC));
787 else
788 memset(&Mac, 0, sizeof(Mac));
789
790 char szNICDesc[LIFNAMSIZ + 256];
791 char *pszIface = Ifaces[i].lifr_name;
792 strcpy(szNICDesc, pszIface);
793
794 vboxSolarisAddLinkHostIface(pszIface, &list);
795 }
796#endif
797
798 char *pszIface = Ifaces[i].lifr_name;
799 vboxSolarisAddLinkHostIface(pszIface, &list);
800 }
801 }
802 }
803 close(Sock);
804 }
805
806 /*
807 * Weed out duplicates caused by dlpi_walk inconsistencies across Nevadas.
808 */
809 list.sort(vboxSolarisSortNICList);
810 list.unique(vboxSolarisSameNIC);
811
812# elif defined RT_OS_WINDOWS
813# ifndef VBOX_WITH_NETFLT
814 hr = E_NOTIMPL;
815# else /* # if defined VBOX_WITH_NETFLT */
816 INetCfg *pNc;
817 INetCfgComponent *pMpNcc;
818 INetCfgComponent *pTcpIpNcc;
819 LPWSTR lpszApp;
820 HRESULT hr;
821 IEnumNetCfgBindingPath *pEnumBp;
822 INetCfgBindingPath *pBp;
823 IEnumNetCfgBindingInterface *pEnumBi;
824 INetCfgBindingInterface *pBi;
825
826 /* we are using the INetCfg API for getting the list of miniports */
827 hr = VBoxNetCfgWinQueryINetCfg( FALSE,
828 VBOX_APP_NAME,
829 &pNc,
830 &lpszApp );
831 Assert(hr == S_OK);
832 if(hr == S_OK)
833 {
834#ifdef VBOX_NETFLT_ONDEMAND_BIND
835 /* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
836 hr = pNc->FindComponent(L"MS_TCPIP", &pTcpIpNcc);
837#else
838 /* for the filter-based approach we get all miniports our filter (sun_VBoxNetFlt)is bound to */
839 hr = pNc->FindComponent(L"sun_VBoxNetFlt", &pTcpIpNcc);
840# ifndef VBOX_WITH_HARDENING
841 if(hr != S_OK)
842 {
843 /* TODO: try to install the netflt from here */
844 }
845# endif
846
847#endif
848
849 if(hr == S_OK)
850 {
851 hr = VBoxNetCfgWinGetBindingPathEnum(pTcpIpNcc, EBP_BELOW, &pEnumBp);
852 Assert(hr == S_OK);
853 if ( hr == S_OK )
854 {
855 hr = VBoxNetCfgWinGetFirstBindingPath(pEnumBp, &pBp);
856 Assert(hr == S_OK || hr == S_FALSE);
857 while( hr == S_OK )
858 {
859 /* S_OK == enabled, S_FALSE == disabled */
860 if(pBp->IsEnabled() == S_OK)
861 {
862 hr = VBoxNetCfgWinGetBindingInterfaceEnum(pBp, &pEnumBi);
863 Assert(hr == S_OK);
864 if ( hr == S_OK )
865 {
866 hr = VBoxNetCfgWinGetFirstBindingInterface(pEnumBi, &pBi);
867 Assert(hr == S_OK);
868 while(hr == S_OK)
869 {
870 hr = pBi->GetLowerComponent( &pMpNcc );
871 Assert(hr == S_OK);
872 if(hr == S_OK)
873 {
874 ULONG uComponentStatus;
875 hr = pMpNcc->GetDeviceStatus(&uComponentStatus);
876 Assert(hr == S_OK);
877 if(hr == S_OK)
878 {
879 if(uComponentStatus == 0)
880 {
881 vboxNetWinAddComponent(&list, pMpNcc);
882 }
883 }
884 VBoxNetCfgWinReleaseRef( pMpNcc );
885 }
886 VBoxNetCfgWinReleaseRef(pBi);
887
888 hr = VBoxNetCfgWinGetNextBindingInterface(pEnumBi, &pBi);
889 }
890 VBoxNetCfgWinReleaseRef(pEnumBi);
891 }
892 }
893 VBoxNetCfgWinReleaseRef(pBp);
894
895 hr = VBoxNetCfgWinGetNextBindingPath(pEnumBp, &pBp);
896 }
897 VBoxNetCfgWinReleaseRef(pEnumBp);
898 }
899 VBoxNetCfgWinReleaseRef(pTcpIpNcc);
900 }
901 else
902 {
903 LogRel(("failed to get the sun_VBoxNetFlt component, error (0x%x)", hr));
904 }
905
906 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE);
907 }
908# endif /* # if defined VBOX_WITH_NETFLT */
909
910
911# elif defined RT_OS_LINUX
912 int sock = socket(AF_INET, SOCK_DGRAM, 0);
913 if (sock >= 0)
914 {
915 char pBuffer[2048];
916 struct ifconf ifConf;
917 ifConf.ifc_len = sizeof(pBuffer);
918 ifConf.ifc_buf = pBuffer;
919 if (ioctl(sock, SIOCGIFCONF, &ifConf) >= 0)
920 {
921 for (struct ifreq *pReq = ifConf.ifc_req; (char*)pReq < pBuffer + ifConf.ifc_len; pReq++)
922 {
923 if (ioctl(sock, SIOCGIFHWADDR, pReq) >= 0)
924 {
925 if (pReq->ifr_hwaddr.sa_family == ARPHRD_ETHER)
926 {
927 RTUUID uuid;
928 Assert(sizeof(uuid) <= sizeof(*pReq));
929 memcpy(&uuid, pReq, sizeof(uuid));
930
931 ComObjPtr<HostNetworkInterface> IfObj;
932 IfObj.createObject();
933 if (SUCCEEDED(IfObj->init(Bstr(pReq->ifr_name), Guid(uuid), HostNetworkInterfaceType_Bridged)))
934 list.push_back(IfObj);
935 }
936 }
937 }
938 }
939 close(sock);
940 }
941# endif /* RT_OS_LINUX */
942#endif
943
944 std::list <ComObjPtr <HostNetworkInterface> >::iterator it;
945 for (it = list.begin(); it != list.end(); ++it)
946 {
947 (*it)->setVirtualBox(mParent);
948 }
949
950
951 SafeIfaceArray <IHostNetworkInterface> networkInterfaces (list);
952 networkInterfaces.detachTo (ComSafeArrayOutArg (aNetworkInterfaces));
953
954 return S_OK;
955
956#else
957 /* Not implemented / supported on this platform. */
958 ReturnComNotImplemented();
959#endif
960}
961
962STDMETHODIMP Host::COMGETTER(USBDevices)(ComSafeArrayOut (IHostUSBDevice *, aUSBDevices))
963{
964#ifdef VBOX_WITH_USB
965 CheckComArgOutSafeArrayPointerValid(aUSBDevices);
966
967 AutoWriteLock alock (this);
968 CHECK_READY();
969
970 MultiResult rc = checkUSBProxyService();
971 CheckComRCReturnRC (rc);
972
973 return mUSBProxyService->getDeviceCollection (ComSafeArrayOutArg(aUSBDevices));
974
975#else
976 /* Note: The GUI depends on this method returning E_NOTIMPL with no
977 * extended error info to indicate that USB is simply not available
978 * (w/o treating it as a failure), for example, as in OSE. */
979 ReturnComNotImplemented();
980#endif
981}
982
983STDMETHODIMP Host::COMGETTER(USBDeviceFilters) (ComSafeArrayOut (IHostUSBDeviceFilter *, aUSBDeviceFilters))
984{
985#ifdef VBOX_WITH_USB
986 CheckComArgOutSafeArrayPointerValid(aUSBDeviceFilters);
987
988 AutoWriteLock alock (this);
989 CHECK_READY();
990
991 MultiResult rc = checkUSBProxyService();
992 CheckComRCReturnRC (rc);
993
994 SafeIfaceArray <IHostUSBDeviceFilter> collection (mUSBDeviceFilters);
995 collection.detachTo (ComSafeArrayOutArg (aUSBDeviceFilters));
996
997 return rc;
998#else
999 /* Note: The GUI depends on this method returning E_NOTIMPL with no
1000 * extended error info to indicate that USB is simply not available
1001 * (w/o treating it as a failure), for example, as in OSE. */
1002 ReturnComNotImplemented();
1003#endif
1004}
1005
1006/**
1007 * Returns the number of installed logical processors
1008 *
1009 * @returns COM status code
1010 * @param count address of result variable
1011 */
1012STDMETHODIMP Host::COMGETTER(ProcessorCount)(ULONG *aCount)
1013{
1014 CheckComArgOutPointerValid(aCount);
1015 AutoWriteLock alock (this);
1016 CHECK_READY();
1017 *aCount = RTMpGetPresentCount();
1018 return S_OK;
1019}
1020
1021/**
1022 * Returns the number of online logical processors
1023 *
1024 * @returns COM status code
1025 * @param count address of result variable
1026 */
1027STDMETHODIMP Host::COMGETTER(ProcessorOnlineCount)(ULONG *aCount)
1028{
1029 CheckComArgOutPointerValid(aCount);
1030 AutoWriteLock alock (this);
1031 CHECK_READY();
1032 *aCount = RTMpGetOnlineCount();
1033 return S_OK;
1034}
1035
1036/**
1037 * Returns the (approximate) maximum speed of the given host CPU in MHz
1038 *
1039 * @returns COM status code
1040 * @param cpu id to get info for.
1041 * @param speed address of result variable, speed is 0 if unknown or aCpuId is invalid.
1042 */
1043STDMETHODIMP Host::GetProcessorSpeed(ULONG aCpuId, ULONG *aSpeed)
1044{
1045 CheckComArgOutPointerValid(aSpeed);
1046 AutoWriteLock alock (this);
1047 CHECK_READY();
1048 *aSpeed = RTMpGetMaxFrequency(aCpuId);
1049 return S_OK;
1050}
1051/**
1052 * Returns a description string for the host CPU
1053 *
1054 * @returns COM status code
1055 * @param cpu id to get info for.
1056 * @param description address of result variable, NULL if known or aCpuId is invalid.
1057 */
1058STDMETHODIMP Host::GetProcessorDescription(ULONG /* aCpuId */, BSTR *aDescription)
1059{
1060 CheckComArgOutPointerValid(aDescription);
1061 AutoWriteLock alock (this);
1062 CHECK_READY();
1063 /** @todo */
1064 ReturnComNotImplemented();
1065}
1066
1067/**
1068 * Returns whether a host processor feature is supported or not
1069 *
1070 * @returns COM status code
1071 * @param Feature to query.
1072 * @param address of supported bool result variable
1073 */
1074STDMETHODIMP Host::GetProcessorFeature(ProcessorFeature_T aFeature, BOOL *aSupported)
1075{
1076 CheckComArgOutPointerValid(aSupported);
1077 AutoWriteLock alock (this);
1078 CHECK_READY();
1079
1080 switch (aFeature)
1081 {
1082 case ProcessorFeature_HWVirtEx:
1083 *aSupported = fVTxAMDVSupported;
1084 break;
1085
1086 case ProcessorFeature_PAE:
1087 *aSupported = fPAESupported;
1088 break;
1089
1090 case ProcessorFeature_LongMode:
1091 *aSupported = fLongModeSupported;
1092 break;
1093
1094 default:
1095 ReturnComNotImplemented();
1096 }
1097 return S_OK;
1098}
1099
1100/**
1101 * Returns the amount of installed system memory in megabytes
1102 *
1103 * @returns COM status code
1104 * @param size address of result variable
1105 */
1106STDMETHODIMP Host::COMGETTER(MemorySize)(ULONG *aSize)
1107{
1108 CheckComArgOutPointerValid(aSize);
1109 AutoWriteLock alock (this);
1110 CHECK_READY();
1111 /* @todo This is an ugly hack. There must be a function in IPRT for that. */
1112 pm::CollectorHAL *hal = pm::createHAL();
1113 if (!hal)
1114 return E_FAIL;
1115 ULONG tmp;
1116 int rc = hal->getHostMemoryUsage(aSize, &tmp, &tmp);
1117 *aSize /= 1024;
1118 delete hal;
1119 return rc;
1120}
1121
1122/**
1123 * Returns the current system memory free space in megabytes
1124 *
1125 * @returns COM status code
1126 * @param available address of result variable
1127 */
1128STDMETHODIMP Host::COMGETTER(MemoryAvailable)(ULONG *aAvailable)
1129{
1130 CheckComArgOutPointerValid(aAvailable);
1131 AutoWriteLock alock (this);
1132 CHECK_READY();
1133 /* @todo This is an ugly hack. There must be a function in IPRT for that. */
1134 pm::CollectorHAL *hal = pm::createHAL();
1135 if (!hal)
1136 return E_FAIL;
1137 ULONG tmp;
1138 int rc = hal->getHostMemoryUsage(&tmp, &tmp, aAvailable);
1139 *aAvailable /= 1024;
1140 delete hal;
1141 return rc;
1142}
1143
1144/**
1145 * Returns the name string of the host operating system
1146 *
1147 * @returns COM status code
1148 * @param os address of result variable
1149 */
1150STDMETHODIMP Host::COMGETTER(OperatingSystem)(BSTR *aOs)
1151{
1152 CheckComArgOutPointerValid(aOs);
1153 AutoWriteLock alock (this);
1154 CHECK_READY();
1155
1156 char szOSName[80];
1157 int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szOSName, sizeof(szOSName));
1158 if (RT_FAILURE(vrc))
1159 return E_FAIL; /** @todo error reporting? */
1160 Bstr (szOSName).cloneTo (aOs);
1161 return S_OK;
1162}
1163
1164/**
1165 * Returns the version string of the host operating system
1166 *
1167 * @returns COM status code
1168 * @param os address of result variable
1169 */
1170STDMETHODIMP Host::COMGETTER(OSVersion)(BSTR *aVersion)
1171{
1172 CheckComArgOutPointerValid(aVersion);
1173 AutoWriteLock alock (this);
1174 CHECK_READY();
1175
1176 /* Get the OS release. Reserve some buffer space for the service pack. */
1177 char szOSRelease[128];
1178 int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szOSRelease, sizeof(szOSRelease) - 32);
1179 if (RT_FAILURE(vrc))
1180 return E_FAIL; /** @todo error reporting? */
1181
1182 /* Append the service pack if present. */
1183 char szOSServicePack[80];
1184 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szOSServicePack, sizeof(szOSServicePack));
1185 if (RT_FAILURE(vrc))
1186 {
1187 if (vrc != VERR_NOT_SUPPORTED)
1188 return E_FAIL; /** @todo error reporting? */
1189 szOSServicePack[0] = '\0';
1190 }
1191 if (szOSServicePack[0] != '\0')
1192 {
1193 char *psz = strchr(szOSRelease, '\0');
1194 RTStrPrintf(psz, &szOSRelease[sizeof(szOSRelease)] - psz, "sp%s", szOSServicePack);
1195 }
1196
1197 Bstr (szOSRelease).cloneTo (aVersion);
1198 return S_OK;
1199}
1200
1201/**
1202 * Returns the current host time in milliseconds since 1970-01-01 UTC.
1203 *
1204 * @returns COM status code
1205 * @param time address of result variable
1206 */
1207STDMETHODIMP Host::COMGETTER(UTCTime)(LONG64 *aUTCTime)
1208{
1209 CheckComArgOutPointerValid(aUTCTime);
1210 AutoWriteLock alock (this);
1211 CHECK_READY();
1212 RTTIMESPEC now;
1213 *aUTCTime = RTTimeSpecGetMilli(RTTimeNow(&now));
1214 return S_OK;
1215}
1216
1217// IHost methods
1218////////////////////////////////////////////////////////////////////////////////
1219STDMETHODIMP
1220Host::CreateHostOnlyNetworkInterface (IHostNetworkInterface **aHostNetworkInterface,
1221 IProgress **aProgress)
1222{
1223 CheckComArgOutPointerValid(aHostNetworkInterface);
1224 CheckComArgOutPointerValid(aProgress);
1225
1226 AutoWriteLock alock (this);
1227 CHECK_READY();
1228
1229 int r = NetIfCreateHostOnlyNetworkInterface (mParent, aHostNetworkInterface, aProgress);
1230 if(RT_SUCCESS(r))
1231 {
1232 return S_OK;
1233 }
1234
1235 return r == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
1236}
1237
1238STDMETHODIMP
1239Host::RemoveHostOnlyNetworkInterface (IN_BSTR aId,
1240 IHostNetworkInterface **aHostNetworkInterface,
1241 IProgress **aProgress)
1242{
1243 CheckComArgOutPointerValid(aHostNetworkInterface);
1244 CheckComArgOutPointerValid(aProgress);
1245
1246 AutoWriteLock alock (this);
1247 CHECK_READY();
1248
1249 /* first check whether an interface with the given name already exists */
1250 {
1251 ComPtr <IHostNetworkInterface> iface;
1252 if (FAILED (FindHostNetworkInterfaceById (aId, iface.asOutParam())))
1253 return setError (VBOX_E_OBJECT_NOT_FOUND,
1254 tr ("Host network interface with UUID {%RTuuid} does not exist"),
1255 Guid (aId).raw());
1256 }
1257
1258 int r = NetIfRemoveHostOnlyNetworkInterface (mParent, Guid(aId), aHostNetworkInterface, aProgress);
1259 if(RT_SUCCESS(r))
1260 {
1261 return S_OK;
1262 }
1263
1264 return r == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
1265}
1266
1267STDMETHODIMP Host::CreateUSBDeviceFilter (IN_BSTR aName, IHostUSBDeviceFilter **aFilter)
1268{
1269#ifdef VBOX_WITH_USB
1270 CheckComArgStrNotEmptyOrNull(aName);
1271 CheckComArgOutPointerValid(aFilter);
1272
1273 AutoWriteLock alock (this);
1274 CHECK_READY();
1275
1276 ComObjPtr <HostUSBDeviceFilter> filter;
1277 filter.createObject();
1278 HRESULT rc = filter->init (this, aName);
1279 ComAssertComRCRet (rc, rc);
1280 rc = filter.queryInterfaceTo (aFilter);
1281 AssertComRCReturn (rc, rc);
1282 return S_OK;
1283#else
1284 /* Note: The GUI depends on this method returning E_NOTIMPL with no
1285 * extended error info to indicate that USB is simply not available
1286 * (w/o treating it as a failure), for example, as in OSE. */
1287 ReturnComNotImplemented();
1288#endif
1289}
1290
1291STDMETHODIMP Host::InsertUSBDeviceFilter (ULONG aPosition, IHostUSBDeviceFilter *aFilter)
1292{
1293#ifdef VBOX_WITH_USB
1294 CheckComArgNotNull(aFilter);
1295
1296 /* Note: HostUSBDeviceFilter and USBProxyService also uses this lock. */
1297 AutoWriteLock alock (this);
1298 CHECK_READY();
1299
1300 MultiResult rc = checkUSBProxyService();
1301 CheckComRCReturnRC (rc);
1302
1303 ComObjPtr <HostUSBDeviceFilter> filter = getDependentChild (aFilter);
1304 if (!filter)
1305 return setError (VBOX_E_INVALID_OBJECT_STATE,
1306 tr ("The given USB device filter is not created within "
1307 "this VirtualBox instance"));
1308
1309 if (filter->mInList)
1310 return setError (E_INVALIDARG,
1311 tr ("The given USB device filter is already in the list"));
1312
1313 /* iterate to the position... */
1314 USBDeviceFilterList::iterator it = mUSBDeviceFilters.begin();
1315 std::advance (it, aPosition);
1316 /* ...and insert */
1317 mUSBDeviceFilters.insert (it, filter);
1318 filter->mInList = true;
1319
1320 /* notify the proxy (only when the filter is active) */
1321 if (mUSBProxyService->isActive() && filter->data().mActive)
1322 {
1323 ComAssertRet (filter->id() == NULL, E_FAIL);
1324 filter->id() = mUSBProxyService->insertFilter (&filter->data().mUSBFilter);
1325 }
1326
1327 /* save the global settings */
1328 alock.unlock();
1329 return rc = mParent->saveSettings();
1330#else
1331 /* Note: The GUI depends on this method returning E_NOTIMPL with no
1332 * extended error info to indicate that USB is simply not available
1333 * (w/o treating it as a failure), for example, as in OSE. */
1334 ReturnComNotImplemented();
1335#endif
1336}
1337
1338STDMETHODIMP Host::RemoveUSBDeviceFilter (ULONG aPosition, IHostUSBDeviceFilter **aFilter)
1339{
1340#ifdef VBOX_WITH_USB
1341 CheckComArgOutPointerValid(aFilter);
1342
1343 /* Note: HostUSBDeviceFilter and USBProxyService also uses this lock. */
1344 AutoWriteLock alock (this);
1345 CHECK_READY();
1346
1347 MultiResult rc = checkUSBProxyService();
1348 CheckComRCReturnRC (rc);
1349
1350 if (!mUSBDeviceFilters.size())
1351 return setError (E_INVALIDARG,
1352 tr ("The USB device filter list is empty"));
1353
1354 if (aPosition >= mUSBDeviceFilters.size())
1355 return setError (E_INVALIDARG,
1356 tr ("Invalid position: %lu (must be in range [0, %lu])"),
1357 aPosition, mUSBDeviceFilters.size() - 1);
1358
1359 ComObjPtr <HostUSBDeviceFilter> filter;
1360 {
1361 /* iterate to the position... */
1362 USBDeviceFilterList::iterator it = mUSBDeviceFilters.begin();
1363 std::advance (it, aPosition);
1364 /* ...get an element from there... */
1365 filter = *it;
1366 /* ...and remove */
1367 filter->mInList = false;
1368 mUSBDeviceFilters.erase (it);
1369 }
1370
1371 filter.queryInterfaceTo (aFilter);
1372
1373 /* notify the proxy (only when the filter is active) */
1374 if (mUSBProxyService->isActive() && filter->data().mActive)
1375 {
1376 ComAssertRet (filter->id() != NULL, E_FAIL);
1377 mUSBProxyService->removeFilter (filter->id());
1378 filter->id() = NULL;
1379 }
1380
1381 /* save the global settings */
1382 alock.unlock();
1383 return rc = mParent->saveSettings();
1384#else
1385 /* Note: The GUI depends on this method returning E_NOTIMPL with no
1386 * extended error info to indicate that USB is simply not available
1387 * (w/o treating it as a failure), for example, as in OSE. */
1388 ReturnComNotImplemented();
1389#endif
1390}
1391
1392// public methods only for internal purposes
1393////////////////////////////////////////////////////////////////////////////////
1394
1395HRESULT Host::loadSettings (const settings::Key &aGlobal)
1396{
1397 using namespace settings;
1398
1399 AutoWriteLock alock (this);
1400 CHECK_READY();
1401
1402 AssertReturn (!aGlobal.isNull(), E_FAIL);
1403
1404 HRESULT rc = S_OK;
1405
1406#ifdef VBOX_WITH_USB
1407 Key::List filters = aGlobal.key ("USBDeviceFilters").keys ("DeviceFilter");
1408 for (Key::List::const_iterator it = filters.begin();
1409 it != filters.end(); ++ it)
1410 {
1411 Bstr name = (*it).stringValue ("name");
1412 bool active = (*it).value <bool> ("active");
1413
1414 Bstr vendorId = (*it).stringValue ("vendorId");
1415 Bstr productId = (*it).stringValue ("productId");
1416 Bstr revision = (*it).stringValue ("revision");
1417 Bstr manufacturer = (*it).stringValue ("manufacturer");
1418 Bstr product = (*it).stringValue ("product");
1419 Bstr serialNumber = (*it).stringValue ("serialNumber");
1420 Bstr port = (*it).stringValue ("port");
1421
1422 USBDeviceFilterAction_T action;
1423 action = USBDeviceFilterAction_Ignore;
1424 const char *actionStr = (*it).stringValue ("action");
1425 if (strcmp (actionStr, "Ignore") == 0)
1426 action = USBDeviceFilterAction_Ignore;
1427 else
1428 if (strcmp (actionStr, "Hold") == 0)
1429 action = USBDeviceFilterAction_Hold;
1430 else
1431 AssertMsgFailed (("Invalid action: '%s'\n", actionStr));
1432
1433 ComObjPtr <HostUSBDeviceFilter> filterObj;
1434 filterObj.createObject();
1435 rc = filterObj->init (this,
1436 name, active, vendorId, productId, revision,
1437 manufacturer, product, serialNumber, port,
1438 action);
1439 /* error info is set by init() when appropriate */
1440 CheckComRCBreakRC (rc);
1441
1442 mUSBDeviceFilters.push_back (filterObj);
1443 filterObj->mInList = true;
1444
1445 /* notify the proxy (only when the filter is active) */
1446 if (filterObj->data().mActive)
1447 {
1448 HostUSBDeviceFilter *flt = filterObj; /* resolve ambiguity */
1449 flt->id() = mUSBProxyService->insertFilter (&filterObj->data().mUSBFilter);
1450 }
1451 }
1452#endif /* VBOX_WITH_USB */
1453
1454 return rc;
1455}
1456
1457HRESULT Host::saveSettings (settings::Key &aGlobal)
1458{
1459 using namespace settings;
1460
1461 AutoWriteLock alock (this);
1462 CHECK_READY();
1463
1464 ComAssertRet (!aGlobal.isNull(), E_FAIL);
1465
1466#ifdef VBOX_WITH_USB
1467 /* first, delete the entry */
1468 Key filters = aGlobal.findKey ("USBDeviceFilters");
1469 if (!filters.isNull())
1470 filters.zap();
1471 /* then, recreate it */
1472 filters = aGlobal.createKey ("USBDeviceFilters");
1473
1474 USBDeviceFilterList::const_iterator it = mUSBDeviceFilters.begin();
1475 while (it != mUSBDeviceFilters.end())
1476 {
1477 AutoWriteLock filterLock (*it);
1478 const HostUSBDeviceFilter::Data &data = (*it)->data();
1479
1480 Key filter = filters.appendKey ("DeviceFilter");
1481
1482 filter.setValue <Bstr> ("name", data.mName);
1483 filter.setValue <bool> ("active", !!data.mActive);
1484
1485 /* all are optional */
1486 Bstr str;
1487 (*it)->COMGETTER (VendorId) (str.asOutParam());
1488 if (!str.isNull())
1489 filter.setValue <Bstr> ("vendorId", str);
1490
1491 (*it)->COMGETTER (ProductId) (str.asOutParam());
1492 if (!str.isNull())
1493 filter.setValue <Bstr> ("productId", str);
1494
1495 (*it)->COMGETTER (Revision) (str.asOutParam());
1496 if (!str.isNull())
1497 filter.setValue <Bstr> ("revision", str);
1498
1499 (*it)->COMGETTER (Manufacturer) (str.asOutParam());
1500 if (!str.isNull())
1501 filter.setValue <Bstr> ("manufacturer", str);
1502
1503 (*it)->COMGETTER (Product) (str.asOutParam());
1504 if (!str.isNull())
1505 filter.setValue <Bstr> ("product", str);
1506
1507 (*it)->COMGETTER (SerialNumber) (str.asOutParam());
1508 if (!str.isNull())
1509 filter.setValue <Bstr> ("serialNumber", str);
1510
1511 (*it)->COMGETTER (Port) (str.asOutParam());
1512 if (!str.isNull())
1513 filter.setValue <Bstr> ("port", str);
1514
1515 /* action is mandatory */
1516 USBDeviceFilterAction_T action = USBDeviceFilterAction_Null;
1517 (*it)->COMGETTER (Action) (&action);
1518 if (action == USBDeviceFilterAction_Ignore)
1519 filter.setStringValue ("action", "Ignore");
1520 else if (action == USBDeviceFilterAction_Hold)
1521 filter.setStringValue ("action", "Hold");
1522 else
1523 AssertMsgFailed (("Invalid action: %d\n", action));
1524
1525 ++ it;
1526 }
1527#endif /* VBOX_WITH_USB */
1528
1529 return S_OK;
1530}
1531
1532#ifdef VBOX_WITH_USB
1533/**
1534 * Called by setter methods of all USB device filters.
1535 */
1536HRESULT Host::onUSBDeviceFilterChange (HostUSBDeviceFilter *aFilter,
1537 BOOL aActiveChanged /* = FALSE */)
1538{
1539 AutoWriteLock alock (this);
1540 CHECK_READY();
1541
1542 if (aFilter->mInList)
1543 {
1544 if (aActiveChanged)
1545 {
1546 // insert/remove the filter from the proxy
1547 if (aFilter->data().mActive)
1548 {
1549 ComAssertRet (aFilter->id() == NULL, E_FAIL);
1550 aFilter->id() = mUSBProxyService->insertFilter (&aFilter->data().mUSBFilter);
1551 }
1552 else
1553 {
1554 ComAssertRet (aFilter->id() != NULL, E_FAIL);
1555 mUSBProxyService->removeFilter (aFilter->id());
1556 aFilter->id() = NULL;
1557 }
1558 }
1559 else
1560 {
1561 if (aFilter->data().mActive)
1562 {
1563 // update the filter in the proxy
1564 ComAssertRet (aFilter->id() != NULL, E_FAIL);
1565 mUSBProxyService->removeFilter (aFilter->id());
1566 aFilter->id() = mUSBProxyService->insertFilter (&aFilter->data().mUSBFilter);
1567 }
1568 }
1569
1570 // save the global settings... yeah, on every single filter property change
1571 alock.unlock();
1572 return mParent->saveSettings();
1573 }
1574
1575 return S_OK;
1576}
1577
1578
1579/**
1580 * Interface for obtaining a copy of the USBDeviceFilterList,
1581 * used by the USBProxyService.
1582 *
1583 * @param aGlobalFilters Where to put the global filter list copy.
1584 * @param aMachines Where to put the machine vector.
1585 */
1586void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters, VirtualBox::SessionMachineVector *aMachines)
1587{
1588 AutoWriteLock alock (this);
1589
1590 mParent->getOpenedMachines (*aMachines);
1591 *aGlobalFilters = mUSBDeviceFilters;
1592}
1593
1594#endif /* VBOX_WITH_USB */
1595
1596// private methods
1597////////////////////////////////////////////////////////////////////////////////
1598
1599#if defined(RT_OS_SOLARIS) && defined(VBOX_USE_LIBHAL)
1600/* Solaris hosts, loading libhal at runtime */
1601
1602/**
1603 * Helper function to query the hal subsystem for information about DVD drives attached to the
1604 * system.
1605 *
1606 * @returns true if information was successfully obtained, false otherwise
1607 * @retval list drives found will be attached to this list
1608 */
1609bool Host::getDVDInfoFromHal(std::list <ComObjPtr <HostDVDDrive> > &list)
1610{
1611 bool halSuccess = false;
1612 DBusError dbusError;
1613 if (!gLibHalCheckPresence())
1614 return false;
1615 gDBusErrorInit (&dbusError);
1616 DBusConnection *dbusConnection = gDBusBusGet(DBUS_BUS_SYSTEM, &dbusError);
1617 if (dbusConnection != 0)
1618 {
1619 LibHalContext *halContext = gLibHalCtxNew();
1620 if (halContext != 0)
1621 {
1622 if (gLibHalCtxSetDBusConnection (halContext, dbusConnection))
1623 {
1624 if (gLibHalCtxInit(halContext, &dbusError))
1625 {
1626 int numDevices;
1627 char **halDevices = gLibHalFindDeviceStringMatch(halContext,
1628 "storage.drive_type", "cdrom",
1629 &numDevices, &dbusError);
1630 if (halDevices != 0)
1631 {
1632 /* Hal is installed and working, so if no devices are reported, assume
1633 that there are none. */
1634 halSuccess = true;
1635 for (int i = 0; i < numDevices; i++)
1636 {
1637 char *devNode = gLibHalDeviceGetPropertyString(halContext,
1638 halDevices[i], "block.device", &dbusError);
1639#ifdef RT_OS_SOLARIS
1640 /* The CD/DVD ioctls work only for raw device nodes. */
1641 char *tmp = getfullrawname(devNode);
1642 gLibHalFreeString(devNode);
1643 devNode = tmp;
1644#endif
1645 if (devNode != 0)
1646 {
1647// if (validateDevice(devNode, true))
1648// {
1649 Utf8Str description;
1650 char *vendor, *product;
1651 /* We do not check the error here, as this field may
1652 not even exist. */
1653 vendor = gLibHalDeviceGetPropertyString(halContext,
1654 halDevices[i], "info.vendor", 0);
1655 product = gLibHalDeviceGetPropertyString(halContext,
1656 halDevices[i], "info.product", &dbusError);
1657 if ((product != 0 && product[0] != 0))
1658 {
1659 if ((vendor != 0) && (vendor[0] != 0))
1660 {
1661 description = Utf8StrFmt ("%s %s",
1662 vendor, product);
1663 }
1664 else
1665 {
1666 description = product;
1667 }
1668 ComObjPtr <HostDVDDrive> hostDVDDriveObj;
1669 hostDVDDriveObj.createObject();
1670 hostDVDDriveObj->init (Bstr (devNode),
1671 Bstr (halDevices[i]),
1672 Bstr (description));
1673 list.push_back (hostDVDDriveObj);
1674 }
1675 else
1676 {
1677 if (product == 0)
1678 {
1679 LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
1680 halDevices[i], dbusError.name, dbusError.message));
1681 gDBusErrorFree(&dbusError);
1682 }
1683 ComObjPtr <HostDVDDrive> hostDVDDriveObj;
1684 hostDVDDriveObj.createObject();
1685 hostDVDDriveObj->init (Bstr (devNode),
1686 Bstr (halDevices[i]));
1687 list.push_back (hostDVDDriveObj);
1688 }
1689 if (vendor != 0)
1690 {
1691 gLibHalFreeString(vendor);
1692 }
1693 if (product != 0)
1694 {
1695 gLibHalFreeString(product);
1696 }
1697// }
1698// else
1699// {
1700// LogRel(("Host::COMGETTER(DVDDrives): failed to validate the block device %s as a DVD drive\n"));
1701// }
1702#ifndef RT_OS_SOLARIS
1703 gLibHalFreeString(devNode);
1704#else
1705 free(devNode);
1706#endif
1707 }
1708 else
1709 {
1710 LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
1711 halDevices[i], dbusError.name, dbusError.message));
1712 gDBusErrorFree(&dbusError);
1713 }
1714 }
1715 gLibHalFreeStringArray(halDevices);
1716 }
1717 else
1718 {
1719 LogRel(("Host::COMGETTER(DVDDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
1720 gDBusErrorFree(&dbusError);
1721 }
1722 if (!gLibHalCtxShutdown(halContext, &dbusError)) /* what now? */
1723 {
1724 LogRel(("Host::COMGETTER(DVDDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
1725 gDBusErrorFree(&dbusError);
1726 }
1727 }
1728 else
1729 {
1730 LogRel(("Host::COMGETTER(DVDDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
1731 gDBusErrorFree(&dbusError);
1732 }
1733 gLibHalCtxFree(halContext);
1734 }
1735 else
1736 {
1737 LogRel(("Host::COMGETTER(DVDDrives): failed to set libhal connection to dbus.\n"));
1738 }
1739 }
1740 else
1741 {
1742 LogRel(("Host::COMGETTER(DVDDrives): failed to get a libhal context - out of memory?\n"));
1743 }
1744 gDBusConnectionUnref(dbusConnection);
1745 }
1746 else
1747 {
1748 LogRel(("Host::COMGETTER(DVDDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
1749 gDBusErrorFree(&dbusError);
1750 }
1751 return halSuccess;
1752}
1753
1754
1755/**
1756 * Helper function to query the hal subsystem for information about floppy drives attached to the
1757 * system.
1758 *
1759 * @returns true if information was successfully obtained, false otherwise
1760 * @retval list drives found will be attached to this list
1761 */
1762bool Host::getFloppyInfoFromHal(std::list <ComObjPtr <HostFloppyDrive> > &list)
1763{
1764 bool halSuccess = false;
1765 DBusError dbusError;
1766 if (!gLibHalCheckPresence())
1767 return false;
1768 gDBusErrorInit (&dbusError);
1769 DBusConnection *dbusConnection = gDBusBusGet(DBUS_BUS_SYSTEM, &dbusError);
1770 if (dbusConnection != 0)
1771 {
1772 LibHalContext *halContext = gLibHalCtxNew();
1773 if (halContext != 0)
1774 {
1775 if (gLibHalCtxSetDBusConnection (halContext, dbusConnection))
1776 {
1777 if (gLibHalCtxInit(halContext, &dbusError))
1778 {
1779 int numDevices;
1780 char **halDevices = gLibHalFindDeviceStringMatch(halContext,
1781 "storage.drive_type", "floppy",
1782 &numDevices, &dbusError);
1783 if (halDevices != 0)
1784 {
1785 /* Hal is installed and working, so if no devices are reported, assume
1786 that there are none. */
1787 halSuccess = true;
1788 for (int i = 0; i < numDevices; i++)
1789 {
1790 char *driveType = gLibHalDeviceGetPropertyString(halContext,
1791 halDevices[i], "storage.drive_type", 0);
1792 if (driveType != 0)
1793 {
1794 if (strcmp(driveType, "floppy") != 0)
1795 {
1796 gLibHalFreeString(driveType);
1797 continue;
1798 }
1799 gLibHalFreeString(driveType);
1800 }
1801 else
1802 {
1803 /* An error occurred. The attribute "storage.drive_type"
1804 probably didn't exist. */
1805 continue;
1806 }
1807 char *devNode = gLibHalDeviceGetPropertyString(halContext,
1808 halDevices[i], "block.device", &dbusError);
1809 if (devNode != 0)
1810 {
1811// if (validateDevice(devNode, false))
1812// {
1813 Utf8Str description;
1814 char *vendor, *product;
1815 /* We do not check the error here, as this field may
1816 not even exist. */
1817 vendor = gLibHalDeviceGetPropertyString(halContext,
1818 halDevices[i], "info.vendor", 0);
1819 product = gLibHalDeviceGetPropertyString(halContext,
1820 halDevices[i], "info.product", &dbusError);
1821 if ((product != 0) && (product[0] != 0))
1822 {
1823 if ((vendor != 0) && (vendor[0] != 0))
1824 {
1825 description = Utf8StrFmt ("%s %s",
1826 vendor, product);
1827 }
1828 else
1829 {
1830 description = product;
1831 }
1832 ComObjPtr <HostFloppyDrive> hostFloppyDrive;
1833 hostFloppyDrive.createObject();
1834 hostFloppyDrive->init (Bstr (devNode),
1835 Bstr (halDevices[i]),
1836 Bstr (description));
1837 list.push_back (hostFloppyDrive);
1838 }
1839 else
1840 {
1841 if (product == 0)
1842 {
1843 LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
1844 halDevices[i], dbusError.name, dbusError.message));
1845 gDBusErrorFree(&dbusError);
1846 }
1847 ComObjPtr <HostFloppyDrive> hostFloppyDrive;
1848 hostFloppyDrive.createObject();
1849 hostFloppyDrive->init (Bstr (devNode),
1850 Bstr (halDevices[i]));
1851 list.push_back (hostFloppyDrive);
1852 }
1853 if (vendor != 0)
1854 {
1855 gLibHalFreeString(vendor);
1856 }
1857 if (product != 0)
1858 {
1859 gLibHalFreeString(product);
1860 }
1861// }
1862// else
1863// {
1864// LogRel(("Host::COMGETTER(FloppyDrives): failed to validate the block device %s as a floppy drive\n"));
1865// }
1866 gLibHalFreeString(devNode);
1867 }
1868 else
1869 {
1870 LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
1871 halDevices[i], dbusError.name, dbusError.message));
1872 gDBusErrorFree(&dbusError);
1873 }
1874 }
1875 gLibHalFreeStringArray(halDevices);
1876 }
1877 else
1878 {
1879 LogRel(("Host::COMGETTER(FloppyDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
1880 gDBusErrorFree(&dbusError);
1881 }
1882 if (!gLibHalCtxShutdown(halContext, &dbusError)) /* what now? */
1883 {
1884 LogRel(("Host::COMGETTER(FloppyDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
1885 gDBusErrorFree(&dbusError);
1886 }
1887 }
1888 else
1889 {
1890 LogRel(("Host::COMGETTER(FloppyDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
1891 gDBusErrorFree(&dbusError);
1892 }
1893 gLibHalCtxFree(halContext);
1894 }
1895 else
1896 {
1897 LogRel(("Host::COMGETTER(FloppyDrives): failed to set libhal connection to dbus.\n"));
1898 }
1899 }
1900 else
1901 {
1902 LogRel(("Host::COMGETTER(FloppyDrives): failed to get a libhal context - out of memory?\n"));
1903 }
1904 gDBusConnectionUnref(dbusConnection);
1905 }
1906 else
1907 {
1908 LogRel(("Host::COMGETTER(FloppyDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
1909 gDBusErrorFree(&dbusError);
1910 }
1911 return halSuccess;
1912}
1913#endif /* RT_OS_SOLARIS and VBOX_USE_HAL */
1914
1915#if defined(RT_OS_SOLARIS)
1916
1917/**
1918 * Helper function to parse the given mount file and add found entries
1919 */
1920void Host::parseMountTable(char *mountTable, std::list <ComObjPtr <HostDVDDrive> > &list)
1921{
1922#ifdef RT_OS_LINUX
1923 FILE *mtab = setmntent(mountTable, "r");
1924 if (mtab)
1925 {
1926 struct mntent *mntent;
1927 char *mnt_type;
1928 char *mnt_dev;
1929 char *tmp;
1930 while ((mntent = getmntent(mtab)))
1931 {
1932 mnt_type = (char*)malloc(strlen(mntent->mnt_type) + 1);
1933 mnt_dev = (char*)malloc(strlen(mntent->mnt_fsname) + 1);
1934 strcpy(mnt_type, mntent->mnt_type);
1935 strcpy(mnt_dev, mntent->mnt_fsname);
1936 // supermount fs case
1937 if (strcmp(mnt_type, "supermount") == 0)
1938 {
1939 tmp = strstr(mntent->mnt_opts, "fs=");
1940 if (tmp)
1941 {
1942 free(mnt_type);
1943 mnt_type = strdup(tmp + strlen("fs="));
1944 if (mnt_type)
1945 {
1946 tmp = strchr(mnt_type, ',');
1947 if (tmp)
1948 *tmp = '\0';
1949 }
1950 }
1951 tmp = strstr(mntent->mnt_opts, "dev=");
1952 if (tmp)
1953 {
1954 free(mnt_dev);
1955 mnt_dev = strdup(tmp + strlen("dev="));
1956 if (mnt_dev)
1957 {
1958 tmp = strchr(mnt_dev, ',');
1959 if (tmp)
1960 *tmp = '\0';
1961 }
1962 }
1963 }
1964 // use strstr here to cover things fs types like "udf,iso9660"
1965 if (strstr(mnt_type, "iso9660") == 0)
1966 {
1967 /** @todo check whether we've already got the drive in our list! */
1968 if (validateDevice(mnt_dev, true))
1969 {
1970 ComObjPtr <HostDVDDrive> hostDVDDriveObj;
1971 hostDVDDriveObj.createObject();
1972 hostDVDDriveObj->init (Bstr (mnt_dev));
1973 list.push_back (hostDVDDriveObj);
1974 }
1975 }
1976 free(mnt_dev);
1977 free(mnt_type);
1978 }
1979 endmntent(mtab);
1980 }
1981#else // RT_OS_SOLARIS
1982 FILE *mntFile = fopen(mountTable, "r");
1983 if (mntFile)
1984 {
1985 struct mnttab mntTab;
1986 while (getmntent(mntFile, &mntTab) == 0)
1987 {
1988 char *mountName = strdup(mntTab.mnt_special);
1989 char *mountPoint = strdup(mntTab.mnt_mountp);
1990 char *mountFSType = strdup(mntTab.mnt_fstype);
1991
1992 // skip devices we are not interested in
1993 if ((*mountName && mountName[0] == '/') && // skip 'fake' devices (like -hosts, proc, fd, swap)
1994 (*mountFSType && (strcmp(mountFSType, "devfs") != 0 && // skip devfs (i.e. /devices)
1995 strcmp(mountFSType, "dev") != 0 && // skip dev (i.e. /dev)
1996 strcmp(mountFSType, "lofs") != 0)) && // skip loop-back file-system (lofs)
1997 (*mountPoint && strcmp(mountPoint, "/") != 0)) // skip point '/' (Can CD/DVD be mounted at '/' ???)
1998 {
1999 char *rawDevName = getfullrawname(mountName);
2000 if (validateDevice(rawDevName, true))
2001 {
2002 ComObjPtr <HostDVDDrive> hostDVDDriveObj;
2003 hostDVDDriveObj.createObject();
2004 hostDVDDriveObj->init (Bstr (rawDevName));
2005 list.push_back (hostDVDDriveObj);
2006 }
2007 free(rawDevName);
2008 }
2009
2010 free(mountName);
2011 free(mountPoint);
2012 free(mountFSType);
2013 }
2014
2015 fclose(mntFile);
2016 }
2017#endif
2018}
2019
2020/**
2021 * Helper function to check whether the given device node is a valid drive
2022 */
2023bool Host::validateDevice(const char *deviceNode, bool isCDROM)
2024{
2025 struct stat statInfo;
2026 bool retValue = false;
2027
2028 // sanity check
2029 if (!deviceNode)
2030 {
2031 return false;
2032 }
2033
2034 // first a simple stat() call
2035 if (stat(deviceNode, &statInfo) < 0)
2036 {
2037 return false;
2038 } else
2039 {
2040 if (isCDROM)
2041 {
2042 if (S_ISCHR(statInfo.st_mode) || S_ISBLK(statInfo.st_mode))
2043 {
2044 int fileHandle;
2045 // now try to open the device
2046 fileHandle = open(deviceNode, O_RDONLY | O_NONBLOCK, 0);
2047 if (fileHandle >= 0)
2048 {
2049 cdrom_subchnl cdChannelInfo;
2050 cdChannelInfo.cdsc_format = CDROM_MSF;
2051 // this call will finally reveal the whole truth
2052#ifdef RT_OS_LINUX
2053 if ((ioctl(fileHandle, CDROMSUBCHNL, &cdChannelInfo) == 0) ||
2054 (errno == EIO) || (errno == ENOENT) ||
2055 (errno == EINVAL) || (errno == ENOMEDIUM))
2056#else
2057 if ((ioctl(fileHandle, CDROMSUBCHNL, &cdChannelInfo) == 0) ||
2058 (errno == EIO) || (errno == ENOENT) ||
2059 (errno == EINVAL))
2060#endif
2061 {
2062 retValue = true;
2063 }
2064 close(fileHandle);
2065 }
2066 }
2067 } else
2068 {
2069 // floppy case
2070 if (S_ISCHR(statInfo.st_mode) || S_ISBLK(statInfo.st_mode))
2071 {
2072 /// @todo do some more testing, maybe a nice IOCTL!
2073 retValue = true;
2074 }
2075 }
2076 }
2077 return retValue;
2078}
2079#endif // RT_OS_SOLARIS
2080
2081#ifdef VBOX_WITH_USB
2082/**
2083 * Checks for the presense and status of the USB Proxy Service.
2084 * Returns S_OK when the Proxy is present and OK, VBOX_E_HOST_ERROR (as a
2085 * warning) if the proxy service is not available due to the way the host is
2086 * configured (at present, that means that usbfs and hal/DBus are not
2087 * available on a Linux host) or E_FAIL and a corresponding error message
2088 * otherwise. Intended to be used by methods that rely on the Proxy Service
2089 * availability.
2090 *
2091 * @note This method may return a warning result code. It is recommended to use
2092 * MultiError to store the return value.
2093 *
2094 * @note Locks this object for reading.
2095 */
2096HRESULT Host::checkUSBProxyService()
2097{
2098 AutoWriteLock alock (this);
2099 CHECK_READY();
2100
2101 AssertReturn (mUSBProxyService, E_FAIL);
2102 if (!mUSBProxyService->isActive())
2103 {
2104 /* disable the USB controller completely to avoid assertions if the
2105 * USB proxy service could not start. */
2106
2107 if (mUSBProxyService->getLastError() == VERR_FILE_NOT_FOUND)
2108 return setWarning (E_FAIL,
2109 tr ("Could not load the Host USB Proxy Service (%Rrc). "
2110 "The service might not be installed on the host computer"),
2111 mUSBProxyService->getLastError());
2112 if (mUSBProxyService->getLastError() == VINF_SUCCESS)
2113#ifdef RT_OS_LINUX
2114 return setWarning (VBOX_E_HOST_ERROR,
2115# ifdef VBOX_WITH_DBUS
2116 tr ("The USB Proxy Service could not be started, because neither the USB file system (usbfs) nor the hardware information service (hal) is available")
2117# else
2118 tr ("The USB Proxy Service could not be started, because the USB file system (usbfs) is not available")
2119# endif
2120 );
2121#else /* !RT_OS_LINUX */
2122 return setWarning (E_FAIL,
2123 tr ("The USB Proxy Service has not yet been ported to this host"));
2124#endif /* !RT_OS_LINUX */
2125 return setWarning (E_FAIL,
2126 tr ("Could not load the Host USB Proxy service (%Rrc)"),
2127 mUSBProxyService->getLastError());
2128 }
2129
2130 return S_OK;
2131}
2132#endif /* VBOX_WITH_USB */
2133
2134#ifdef VBOX_WITH_RESOURCE_USAGE_API
2135void Host::registerMetrics (PerformanceCollector *aCollector)
2136{
2137 pm::CollectorHAL *hal = aCollector->getHAL();
2138 /* Create sub metrics */
2139 pm::SubMetric *cpuLoadUser = new pm::SubMetric ("CPU/Load/User",
2140 "Percentage of processor time spent in user mode.");
2141 pm::SubMetric *cpuLoadKernel = new pm::SubMetric ("CPU/Load/Kernel",
2142 "Percentage of processor time spent in kernel mode.");
2143 pm::SubMetric *cpuLoadIdle = new pm::SubMetric ("CPU/Load/Idle",
2144 "Percentage of processor time spent idling.");
2145 pm::SubMetric *cpuMhzSM = new pm::SubMetric ("CPU/MHz",
2146 "Average of current frequency of all processors.");
2147 pm::SubMetric *ramUsageTotal = new pm::SubMetric ("RAM/Usage/Total",
2148 "Total physical memory installed.");
2149 pm::SubMetric *ramUsageUsed = new pm::SubMetric ("RAM/Usage/Used",
2150 "Physical memory currently occupied.");
2151 pm::SubMetric *ramUsageFree = new pm::SubMetric ("RAM/Usage/Free",
2152 "Physical memory currently available to applications.");
2153 /* Create and register base metrics */
2154 IUnknown *objptr;
2155 ComObjPtr <Host> tmp = this;
2156 tmp.queryInterfaceTo (&objptr);
2157 pm::BaseMetric *cpuLoad = new pm::HostCpuLoadRaw (hal, objptr, cpuLoadUser, cpuLoadKernel,
2158 cpuLoadIdle);
2159 aCollector->registerBaseMetric (cpuLoad);
2160 pm::BaseMetric *cpuMhz = new pm::HostCpuMhz (hal, objptr, cpuMhzSM);
2161 aCollector->registerBaseMetric (cpuMhz);
2162 pm::BaseMetric *ramUsage = new pm::HostRamUsage (hal, objptr, ramUsageTotal, ramUsageUsed,
2163 ramUsageFree);
2164 aCollector->registerBaseMetric (ramUsage);
2165
2166 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser, 0));
2167 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser,
2168 new pm::AggregateAvg()));
2169 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser,
2170 new pm::AggregateMin()));
2171 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser,
2172 new pm::AggregateMax()));
2173
2174 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel, 0));
2175 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel,
2176 new pm::AggregateAvg()));
2177 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel,
2178 new pm::AggregateMin()));
2179 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel,
2180 new pm::AggregateMax()));
2181
2182 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle, 0));
2183 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle,
2184 new pm::AggregateAvg()));
2185 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle,
2186 new pm::AggregateMin()));
2187 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle,
2188 new pm::AggregateMax()));
2189
2190 aCollector->registerMetric (new pm::Metric(cpuMhz, cpuMhzSM, 0));
2191 aCollector->registerMetric (new pm::Metric(cpuMhz, cpuMhzSM,
2192 new pm::AggregateAvg()));
2193 aCollector->registerMetric (new pm::Metric(cpuMhz, cpuMhzSM,
2194 new pm::AggregateMin()));
2195 aCollector->registerMetric (new pm::Metric(cpuMhz, cpuMhzSM,
2196 new pm::AggregateMax()));
2197
2198 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal, 0));
2199 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
2200 new pm::AggregateAvg()));
2201 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
2202 new pm::AggregateMin()));
2203 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
2204 new pm::AggregateMax()));
2205
2206 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed, 0));
2207 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
2208 new pm::AggregateAvg()));
2209 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
2210 new pm::AggregateMin()));
2211 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
2212 new pm::AggregateMax()));
2213
2214 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree, 0));
2215 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
2216 new pm::AggregateAvg()));
2217 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
2218 new pm::AggregateMin()));
2219 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
2220 new pm::AggregateMax()));
2221};
2222
2223void Host::unregisterMetrics (PerformanceCollector *aCollector)
2224{
2225 aCollector->unregisterMetricsFor (this);
2226 aCollector->unregisterBaseMetricsFor (this);
2227};
2228#endif /* VBOX_WITH_RESOURCE_USAGE_API */
2229
2230STDMETHODIMP Host::FindHostDVDDrive(IN_BSTR aName, IHostDVDDrive **aDrive)
2231{
2232 CheckComArgNotNull(aName);
2233 CheckComArgOutPointerValid(aDrive);
2234
2235 *aDrive = NULL;
2236
2237 SafeIfaceArray <IHostDVDDrive> drivevec;
2238 HRESULT rc = COMGETTER(DVDDrives) (ComSafeArrayAsOutParam(drivevec));
2239 CheckComRCReturnRC (rc);
2240
2241 for (size_t i = 0; i < drivevec.size(); ++i)
2242 {
2243 Bstr name;
2244 rc = drivevec[i]->COMGETTER(Name) (name.asOutParam());
2245 CheckComRCReturnRC (rc);
2246 if (name == aName)
2247 {
2248 ComObjPtr<HostDVDDrive> found;
2249 found.createObject();
2250 Bstr udi, description;
2251 rc = drivevec[i]->COMGETTER(Udi) (udi.asOutParam());
2252 CheckComRCReturnRC (rc);
2253 rc = drivevec[i]->COMGETTER(Description) (description.asOutParam());
2254 CheckComRCReturnRC (rc);
2255 found->init(name, udi, description);
2256 return found.queryInterfaceTo(aDrive);
2257 }
2258 }
2259
2260 return setError (VBOX_E_OBJECT_NOT_FOUND, HostDVDDrive::tr (
2261 "The host DVD drive named '%ls' could not be found"), aName);
2262}
2263
2264STDMETHODIMP Host::FindHostFloppyDrive(IN_BSTR aName, IHostFloppyDrive **aDrive)
2265{
2266 CheckComArgNotNull(aName);
2267 CheckComArgOutPointerValid(aDrive);
2268
2269 *aDrive = NULL;
2270
2271 SafeIfaceArray <IHostFloppyDrive> drivevec;
2272 HRESULT rc = COMGETTER(FloppyDrives) (ComSafeArrayAsOutParam(drivevec));
2273 CheckComRCReturnRC (rc);
2274
2275 for (size_t i = 0; i < drivevec.size(); ++i)
2276 {
2277 Bstr name;
2278 rc = drivevec[i]->COMGETTER(Name) (name.asOutParam());
2279 CheckComRCReturnRC (rc);
2280 if (name == aName)
2281 {
2282 ComObjPtr<HostFloppyDrive> found;
2283 found.createObject();
2284 Bstr udi, description;
2285 rc = drivevec[i]->COMGETTER(Udi) (udi.asOutParam());
2286 CheckComRCReturnRC (rc);
2287 rc = drivevec[i]->COMGETTER(Description) (description.asOutParam());
2288 CheckComRCReturnRC (rc);
2289 found->init(name, udi, description);
2290 return found.queryInterfaceTo(aDrive);
2291 }
2292 }
2293
2294 return setError (VBOX_E_OBJECT_NOT_FOUND, HostFloppyDrive::tr (
2295 "The host floppy drive named '%ls' could not be found"), aName);
2296}
2297
2298STDMETHODIMP Host::FindHostNetworkInterfaceByName(IN_BSTR name, IHostNetworkInterface **networkInterface)
2299{
2300#ifndef VBOX_WITH_HOSTNETIF_API
2301 return E_NOTIMPL;
2302#else
2303 if (!name)
2304 return E_INVALIDARG;
2305 if (!networkInterface)
2306 return E_POINTER;
2307
2308 *networkInterface = NULL;
2309 ComObjPtr <HostNetworkInterface> found;
2310 std::list <ComObjPtr <HostNetworkInterface> > list;
2311 int rc = NetIfList(list);
2312 if (RT_FAILURE(rc))
2313 {
2314 Log(("Failed to get host network interface list with rc=%Vrc\n", rc));
2315 return E_FAIL;
2316 }
2317 std::list <ComObjPtr <HostNetworkInterface> >::iterator it;
2318 for (it = list.begin(); it != list.end(); ++it)
2319 {
2320 Bstr n;
2321 (*it)->COMGETTER(Name) (n.asOutParam());
2322 if (n == name)
2323 found = *it;
2324 }
2325
2326 if (!found)
2327 return setError (E_INVALIDARG, HostNetworkInterface::tr (
2328 "The host network interface with the given name could not be found"));
2329
2330 found->setVirtualBox(mParent);
2331
2332 return found.queryInterfaceTo (networkInterface);
2333#endif
2334}
2335
2336STDMETHODIMP Host::FindHostNetworkInterfaceById(IN_BSTR id, IHostNetworkInterface **networkInterface)
2337{
2338#ifndef VBOX_WITH_HOSTNETIF_API
2339 return E_NOTIMPL;
2340#else
2341 if (Guid(id).isEmpty())
2342 return E_INVALIDARG;
2343 if (!networkInterface)
2344 return E_POINTER;
2345
2346 *networkInterface = NULL;
2347 ComObjPtr <HostNetworkInterface> found;
2348 std::list <ComObjPtr <HostNetworkInterface> > list;
2349 int rc = NetIfList(list);
2350 if (RT_FAILURE(rc))
2351 {
2352 Log(("Failed to get host network interface list with rc=%Vrc\n", rc));
2353 return E_FAIL;
2354 }
2355 std::list <ComObjPtr <HostNetworkInterface> >::iterator it;
2356 for (it = list.begin(); it != list.end(); ++it)
2357 {
2358 Bstr g;
2359 (*it)->COMGETTER(Id) (g.asOutParam());
2360 if (g == id)
2361 found = *it;
2362 }
2363
2364 if (!found)
2365 return setError (E_INVALIDARG, HostNetworkInterface::tr (
2366 "The host network interface with the given GUID could not be found"));
2367
2368 found->setVirtualBox(mParent);
2369
2370 return found.queryInterfaceTo (networkInterface);
2371#endif
2372}
2373
2374STDMETHODIMP Host::FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_T type, ComSafeArrayOut (IHostNetworkInterface *, aNetworkInterfaces))
2375{
2376 std::list <ComObjPtr <HostNetworkInterface> > allList;
2377 int rc = NetIfList(allList);
2378 if(RT_FAILURE(rc))
2379 return E_FAIL;
2380
2381 std::list <ComObjPtr <HostNetworkInterface> > resultList;
2382
2383 std::list <ComObjPtr <HostNetworkInterface> >::iterator it;
2384 for (it = allList.begin(); it != allList.end(); ++it)
2385 {
2386 HostNetworkInterfaceType_T t;
2387 HRESULT hr = (*it)->COMGETTER(InterfaceType)(&t);
2388 if(FAILED(hr))
2389 return hr;
2390
2391 if(t == type)
2392 {
2393 (*it)->setVirtualBox(mParent);
2394 resultList.push_back (*it);
2395 }
2396 }
2397
2398 SafeIfaceArray <IHostNetworkInterface> filteredNetworkInterfaces (resultList);
2399 filteredNetworkInterfaces.detachTo (ComSafeArrayOutArg (aNetworkInterfaces));
2400
2401 return S_OK;
2402}
2403
2404STDMETHODIMP Host::FindUSBDeviceByAddress (IN_BSTR aAddress, IHostUSBDevice **aDevice)
2405{
2406#ifdef VBOX_WITH_USB
2407 CheckComArgNotNull(aAddress);
2408 CheckComArgOutPointerValid(aDevice);
2409
2410 *aDevice = NULL;
2411
2412 SafeIfaceArray <IHostUSBDevice> devsvec;
2413 HRESULT rc = COMGETTER(USBDevices) (ComSafeArrayAsOutParam(devsvec));
2414 CheckComRCReturnRC (rc);
2415
2416 for (size_t i = 0; i < devsvec.size(); ++i)
2417 {
2418 Bstr address;
2419 rc = devsvec[i]->COMGETTER(Address) (address.asOutParam());
2420 CheckComRCReturnRC (rc);
2421 if (address == aAddress)
2422 {
2423 return ComObjPtr<IHostUSBDevice> (devsvec[i]).queryInterfaceTo (aDevice);
2424 }
2425 }
2426
2427 return setErrorNoLog (VBOX_E_OBJECT_NOT_FOUND, tr (
2428 "Could not find a USB device with address '%ls'"),
2429 aAddress);
2430
2431#else /* !VBOX_WITH_USB */
2432 return E_NOTIMPL;
2433#endif /* !VBOX_WITH_USB */
2434}
2435
2436STDMETHODIMP Host::FindUSBDeviceById (IN_BSTR aId, IHostUSBDevice **aDevice)
2437{
2438#ifdef VBOX_WITH_USB
2439 CheckComArgExpr(aId, Guid (aId).isEmpty() == false);
2440 CheckComArgOutPointerValid(aDevice);
2441
2442 *aDevice = NULL;
2443
2444 SafeIfaceArray <IHostUSBDevice> devsvec;
2445 HRESULT rc = COMGETTER(USBDevices) (ComSafeArrayAsOutParam(devsvec));
2446 CheckComRCReturnRC (rc);
2447
2448 for (size_t i = 0; i < devsvec.size(); ++i)
2449 {
2450 Bstr id;
2451 rc = devsvec[i]->COMGETTER(Id) (id.asOutParam());
2452 CheckComRCReturnRC (rc);
2453 if (id == aId)
2454 {
2455 return ComObjPtr<IHostUSBDevice> (devsvec[i]).queryInterfaceTo (aDevice);
2456 }
2457 }
2458
2459 return setErrorNoLog (VBOX_E_OBJECT_NOT_FOUND, tr (
2460 "Could not find a USB device with uuid {%RTuuid}"),
2461 Guid (aId).raw());
2462
2463#else /* !VBOX_WITH_USB */
2464 return E_NOTIMPL;
2465#endif /* !VBOX_WITH_USB */
2466}
2467
2468
2469/* 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