HostImpl.cpp revision c1eabfdd25befbe50456ee60bf512e437558559e
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync * VirtualBox COM class implementation: Host
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * available from http://www.virtualbox.org. This file is free software;
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * additional information or have any questions.
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync/* bird: This is a hack to work around conflicts between these linux kernel headers
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync * and the GLIBC tcpip headers. They have different declarations of the 4
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync * standard byte order functions. */
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync// # include <libhal.h>
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync// /* These are defined by libhal.h and by VBox header files. */
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync// # undef TRUE
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync// # undef FALSE
4d939f327b6fe2b8201ab00e2d7e7d12b6d47d23vboxsync#endif /* RT_OS_LINUX */
#ifdef RT_OS_SOLARIS
# include <fcntl.h>
# include <unistd.h>
# include <stropts.h>
# include <errno.h>
# include <limits.h>
# include <stdio.h>
# ifdef VBOX_USE_LIBHAL
# include "vbox-libhal.h"
#ifdef RT_OS_WINDOWS
# define _WIN32_DCOM
# include <windows.h>
# include <shellapi.h>
# 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"
#ifdef VBOX_WITH_USB
# include "HostUSBDeviceImpl.h"
# include "USBDeviceFilterImpl.h"
# include "USBProxyService.h"
#include "VirtualBoxImpl.h"
#include "MachineImpl.h"
#include "Logging.h"
#ifdef RT_OS_DARWIN
#ifdef RT_OS_WINDOWS
# include "HostNetworkInterfaceImpl.h"
#ifdef RT_OS_SOLARIS
#include <stdio.h>
#include <algorithm>
return S_OK;
if (isReady())
uninit();
// public initializer/uninitializer for internal purposes only
#ifdef VBOX_WITH_USB
# if defined (RT_OS_DARWIN)
#ifdef VBOX_WITH_RESOURCE_USAGE_API
UsageSamplerCallback, this);
return E_FAIL;
setReady(true);
return S_OK;
#ifdef VBOX_WITH_USB
delete mUSBProxyService;
#ifdef VBOX_WITH_USB
#ifdef VBOX_WITH_RESOURCE_USAGE_API
if (!drives)
return E_POINTER;
CHECK_READY();
#if defined(RT_OS_WINDOWS)
driveName[0] = *p;
delete[] hostDrives;
# ifdef VBOX_USE_LIBHAL
char *cdromDrive;
while (cdromDrive)
#ifdef VBOX_USE_LIBHAL
char *cdromDrive;
while (cdromDrive)
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 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 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;
#ifdef VBOX_WITH_RESOURCE_USAGE_API
return E_POINTER;
return S_OK;
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