HostImpl.cpp revision 391cf11262671da62bcc02db361038e7ffbab8f7
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * VirtualBox COM class implementation: Host
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * available from http://www.virtualbox.org. This file is free software;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * you can redistribute it and/or modify it under the terms of the GNU
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * General Public License (GPL) as published by the Free Software
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * additional information or have any questions.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/* bird: This is a hack to work around conflicts between these linux kernel headers
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * and the GLIBC tcpip headers. They have different declarations of the 4
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * standard byte order functions. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync// # include <libhal.h>
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync// /* These are defined by libhal.h and by VBox header files. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync// # undef TRUE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync// # undef FALSE
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif /* RT_OS_LINUX */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif /* RT_OS_SOLARIS */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif /* RT_OS_WINDOWS */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/** @todo the following line becomes obsolete after switching to Mp runtime functions */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync// constructor / destructor
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/////////////////////////////////////////////////////////////////////////////
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync// public initializer/uninitializer for internal purposes only
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/////////////////////////////////////////////////////////////////////////////
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Initializes the host object.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * @param aParent VirtualBox parent object.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Create and initialize the USB Proxy Service.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync# if defined (RT_OS_DARWIN)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mUSBProxyService = new USBProxyServiceDarwin (this);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mUSBProxyService = new USBProxyServiceLinux (this);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mUSBProxyService = new USBProxyServiceSolaris (this);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mUSBProxyService = new USBProxyServiceWindows (this);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif /* VBOX_WITH_USB */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif /* VBOX_WITH_RESOURCE_USAGE_API */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Uninitializes the host object and sets the ready flag to FALSE.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Called either from FinalRelease() or by the parent when it gets destroyed.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync unregisterMetrics (mParent->performanceCollector());
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif /* VBOX_WITH_RESOURCE_USAGE_API */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* wait for USB proxy service to terminate before we uninit all USB
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * devices */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LogFlowThisFunc (("Stopping USB proxy service...\n"));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync LogFlowThisFunc (("Done stopping USB proxy service.\n"));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* uninit all USB device filters still referenced by clients */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync// IHost properties
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/////////////////////////////////////////////////////////////////////////////
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Returns a list of host DVD drives.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * @returns COM status code
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * @param drives address of result pointer
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncSTDMETHODIMP Host::COMGETTER(DVDDrives) (IHostDVDDriveCollection **drives)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync while (*p);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // Not all Solaris versions ship with libhal.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // So use a fallback approach similar to Linux.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cdromDrive = strtok(cdromEnv, ":"); /** @todo use strtok_r. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // this might work on Solaris version older than Nevada.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // check the mounted drives
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!getDVDInfoFromHal(list)) /* Playing with #defines in this way is nasty, I know. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif /* USE_LIBHAL defined */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // On Linux without hal, the situation is much more complex. We will take a
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // heuristical approach and also allow the user to specify a list of host
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // CDROMs using an environment variable.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // The general strategy is to try some known device names and see of they
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // exist. At last, we'll enumerate the /etc/fstab file (luckily there's an
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync // API to parse it) for CDROM devices. Ok, let's start!
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync cdromDrive = strtok(cdromEnv, ":"); /** @todo use strtok_r */
while (cur)
return S_OK;
if (!drives)
return E_POINTER;
CHECK_READY();
#ifdef RT_OS_WINDOWS
driveName[0] = *p;
delete[] hostDrives;
#ifdef VBOX_USE_LIBHAL
char *floppyDrive;
while (floppyDrive)
return S_OK;
#ifdef RT_OS_WINDOWS
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);
&& (!strcmp(szNetProviderName, "innotek GmbH") || !strcmp(szNetProviderName, "Sun Microsystems, Inc.")))
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 E_NOTIMPL;
#ifdef VBOX_WITH_USB
if (!aUSBDeviceFilters)
return E_POINTER;
CHECK_READY();
return rc;
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 E_NOTIMPL;
if (!size)
return E_POINTER;
CHECK_READY();
return E_NOTIMPL;
if (!available)
return E_POINTER;
CHECK_READY();
return E_NOTIMPL;
if (!os)
return E_POINTER;
CHECK_READY();
return E_NOTIMPL;
if (!version)
return E_POINTER;
CHECK_READY();
return E_NOTIMPL;
if (!aUTCTime)
return E_POINTER;
CHECK_READY();
return S_OK;
#ifdef RT_OS_WINDOWS
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;
using namespace settings;
CHECK_READY();
#ifdef VBOX_WITH_USB
action);
return rc;
using namespace settings;
CHECK_READY();
#ifdef VBOX_WITH_USB
++ it;
return S_OK;
#ifdef VBOX_WITH_USB
CHECK_READY();
if (aActiveChanged)
return S_OK;
void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters, VirtualBox::SessionMachineVector *aMachines)
# ifdef VBOX_USE_LIBHAL
bool halSuccess = false;
if (!gLibHalCheckPresence())
if (dbusConnection != 0)
if (halContext != 0)
int numDevices;
if (halDevices != 0)
halSuccess = true;
for (int i = 0; i < numDevices; i++)
#ifdef RT_OS_SOLARIS
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)
#ifndef RT_OS_SOLARIS
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 (!gLibHalCheckPresence())
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;
#ifdef RT_OS_LINUX
if (mtab)
char *mnt_type;
char *mnt_dev;
char *tmp;
if (tmp)
if (mnt_type)
if (tmp)
if (tmp)
if (mnt_dev)
if (tmp)
if (mntFile)
bool retValue = false;
if (!deviceNode)
if (isCDROM)
int fileHandle;
if (fileHandle >= 0)
#ifdef RT_OS_LINUX
retValue = true;
retValue = true;
return retValue;
#ifdef VBOX_WITH_USB
CHECK_READY();
return S_OK;
#ifdef RT_OS_WINDOWS
/* 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;
#ifdef VBOX_WITH_RESOURCE_USAGE_API