HostImpl.cpp revision 77a3468aac98c3b67018cc8cdeb25b5ecd77c1e9
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VirtualBox COM class implementation
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (C) 2006 InnoTek Systemberatung GmbH
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * available from http://www.virtualbox.org. This file is free software;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * General Public License as published by the Free Software Foundation,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * If you received this file as part of a commercial VirtualBox
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * distribution, then only the terms of your commercial VirtualBox
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * license agreement apply instead of the previous paragraph.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* bird: This is a hack to work around conflicts between these linux kernel headers
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * and the GLIBC tcpip headers. They have different declarations of the 4
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * standard byte order functions. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* These are defined by libhal.h and by VBox header files. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#endif /* __LINUX __ */
#define INITGUID
#include <guiddef.h>
#include <devguid.h>
#include <objbase.h>
#include <setupapi.h>
#include <shlobj.h>
#include <cfgmgr32.h>
#include "HostImpl.h"
#include "HostDVDDriveImpl.h"
#include "HostFloppyDriveImpl.h"
#include "HostUSBDeviceImpl.h"
#include "USBControllerImpl.h"
#include "USBDeviceFilterImpl.h"
#include "USBProxyService.h"
#include "VirtualBoxImpl.h"
#include "MachineImpl.h"
#include "Logging.h"
#ifdef __DARWIN__
#ifdef __WIN__
#include "HostNetworkInterfaceImpl.h"
#include <stdio.h>
#include <algorithm>
return S_OK;
if (isReady())
uninit();
// public initializer/uninitializer for internal purposes only
setReady(true);
return S_OK;
delete mUSBProxyService;
if (!drives)
return E_POINTER;
CHECK_READY();
#if defined(__WIN__)
driveName[0] = *p;
delete[] hostDrives;
#ifdef VBOX_USE_LIBHAL
char *cdromDrive;
while (cdromDrive)
while (cur)
return S_OK;
if (!drives)
return E_POINTER;
CHECK_READY();
#ifdef __WIN__
driveName[0] = *p;
delete[] hostDrives;
#ifdef VBOX_USE_LIBHAL
char *floppyDrive;
while (floppyDrive)
return S_OK;
#ifdef __WIN__
bool ret = false;
status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &hNetcard);
status = RegQueryValueExA(hNetCardGUID, "NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &len);
szNetProductName[0] = 0;
status = RegQueryValueExA(hNetCardGUID, "ProductName", NULL, &dwKeyType, (LPBYTE)szNetProductName, &len);
szNetProviderName[0] = 0;
status = RegQueryValueExA(hNetCardGUID, "ProviderName", NULL, &dwKeyType, (LPBYTE)szNetProviderName, &len);
ret = true;
return ret;
STDMETHODIMP Host::COMGETTER(NetworkInterfaces) (IHostNetworkInterfaceCollection **networkInterfaces)
if (!networkInterfaces)
return E_POINTER;
CHECK_READY();
return S_OK;
#ifdef VBOX_WITH_USB
if (!aUSBDevices)
return E_POINTER;
CHECK_READY();
return S_OK;
return E_NOTIMPL;
STDMETHODIMP Host::COMGETTER(USBDeviceFilters) (IHostUSBDeviceFilterCollection ** aUSBDeviceFilters)
#ifdef VBOX_WITH_USB
if (!aUSBDeviceFilters)
return E_POINTER;
CHECK_READY();
return S_OK;
return E_NOTIMPL;
if (!count)
return E_POINTER;
CHECK_READY();
return S_OK;
if (!speed)
return E_POINTER;
CHECK_READY();
return S_OK;
if (!description)
return E_POINTER;
CHECK_READY();
return S_OK;
if (!size)
return E_POINTER;
CHECK_READY();
return S_OK;
if (!available)
return E_POINTER;
CHECK_READY();
return S_OK;
if (!os)
return E_POINTER;
CHECK_READY();
return S_OK;
if (!version)
return E_POINTER;
CHECK_READY();
return S_OK;
if (!aUTCTime)
return E_POINTER;
CHECK_READY();
return S_OK;
#ifdef __WIN__
return FALSE;
if (!aName)
return E_INVALIDARG;
if (!aHostNetworkInterface)
return E_POINTER;
if (!aProgress)
return E_POINTER;
CHECK_READY();
d (new NetworkInterfaceHelperClientData());
static_cast <void *> (d.get()),
progress);
d.release();
return rc;
if (!aHostNetworkInterface)
return E_POINTER;
if (!aProgress)
return E_POINTER;
CHECK_READY();
d (new NetworkInterfaceHelperClientData());
static_cast <void *> (d.get()),
progress);
d.release();
return rc;
#ifdef VBOX_WITH_USB
if (!aFilter)
return E_POINTER;
return E_INVALIDARG;
CHECK_READY();
return S_OK;
return E_NOTIMPL;
#ifdef VBOX_WITH_USB
if (!aFilter)
return E_INVALIDARG;
CHECK_READY();
if (!filter)
return E_NOTIMPL;
#ifdef VBOX_WITH_USB
if (!aFilter)
return E_POINTER;
CHECK_READY();
return E_NOTIMPL;
CHECK_READY();
if (aActiveChanged)
return S_OK;
CHECK_READY();
unsigned filterCount = 0;
bool active;
action);
return rc;
CHECK_READY();
++ it;
return S_OK;
CHECK_READY();
++ it;
if (!device)
if (!ok)
return S_OK;
CHECK_READY();
++ it;
return rc;
CHECK_READY();
++ it;
return S_OK;
* VM termination (from under the Machine/SessionMachine lock).
CHECK_READY();
++ it;
return S_OK;
#ifdef __LINUX__
# ifdef VBOX_USE_LIBHAL
bool halSuccess = false;
if (dbusConnection != 0)
if (halContext != 0)
int numDevices;
if (halDevices != 0)
halSuccess = true;
for (int i = 0; i < numDevices; i++)
if (devNode != 0)
if (product == 0)
LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
if (vendor != 0)
if (product != 0)
LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
LogRel(("Host::COMGETTER(DVDDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
return halSuccess;
bool halSuccess = false;
if (dbusConnection != 0)
if (halContext != 0)
int numDevices;
if (halDevices != 0)
halSuccess = true;
for (int i = 0; i < numDevices; i++)
if (driveType != 0)
if (devNode != 0)
if (product == 0)
LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
if (vendor != 0)
if (product != 0)
LogRel(("Host::COMGETTER(FloppyDrives): failed to validate the block device %s as a floppy drive\n"));
LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
LogRel(("Host::COMGETTER(FloppyDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
return halSuccess;
if (mtab)
char *mnt_type;
char *mnt_dev;
char *tmp;
if (tmp)
if (mnt_type)
if (tmp)
if (tmp)
if (mnt_dev)
if (tmp)
bool retValue = false;
if (!deviceNode)
if (isCDROM)
int fileHandle;
if (fileHandle >= 0)
retValue = true;
retValue = true;
return retValue;
return S_OK;
return S_OK;
return S_OK;
++ it;
return rc;
return S_OK;
++ it;
/** @todo dmik, is there anything we should do here? For instance if the device now is available? */
#ifdef VBOX_WITH_USB
CHECK_READY();
return S_OK;
return E_NOTIMPL;
#ifdef __WIN__
/* The original source of the VBoxTAP adapter creation/destruction code has the following copyright */
return E_INVALIDARG;
&pidl);
if (pShellFolder)
return hr;
return E_FAIL;
return E_FAIL;
return E_FAIL;
return status;
return S_OK;
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
while (TRUE)
if (!ret)
index++;
sizeof (detailBuf),
NULL))
TCHAR * t;
index ++;
if (!found)
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (ok)
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
KEY_READ);
GetLastError()));
if (destroyList)
return vrc;
SetErrBreak ((
SetErrBreak ((
SetErrBreak ((
if (hkeyConnection)
if (hkeyNetwork)
while (TRUE)
if (!ok)
index++;
NULL,
NULL,
&size);
if (!ok)
index++;
NULL,
size,
NULL);
if (!ok)
index++;
index++;
if (deviceHwid)
if (found)
index++;
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
return vrc;
return S_OK;
switch (d->msgCode)
bool endLoop = false;
while (!endLoop)
switch (reply)
endLoop = true;
endLoop = true;
endLoop = true;
bool endLoop = false;
while (!endLoop)
switch (reply)
endLoop = true;
endLoop = true;
endLoop = true;
if (aVrc)
return rc;
switch (aMsgCode)
return vrc;