HostUSBDeviceImpl.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/** @file
*
* VBox frontends: Basic Frontend (BFE):
* Implementation of HostUSBDevice
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "HostUSBDeviceImpl.h"
#include "USBProxyService.h"
#include "Logging.h"
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
}
{
if (m_pUsb)
{
}
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the USB device object.
*
* @returns COM result indicator
* @param aUsb Pointer to the usb device structure for which the object is to be a wrapper.
* This structure is now fully owned by the HostUSBDevice object and will be
* freed when it is destructed.
* @param aUSBProxyService Pointer to the USB Proxy Service object.
*/
{
/*
* We need a unique ID for this VBoxSVC session.
* The UUID isn't stored anywhere.
*/
RTUuidCreate(&mId);
/*
* Convert from USBDEVICESTATE to USBDeviceState.
*
* Note that not all proxy backend can detect the HELD_BY_PROXY
* and USED_BY_GUEST states. But that shouldn't matter much.
*/
{
default:
break;
break;
break;
case USBDEVICESTATE_UNUSED:
break;
break;
break;
}
/*
* Other data members.
*/
mIgnored = false;
setReady (true);
return S_OK;
}
// IUSBDevice properties
/////////////////////////////////////////////////////////////////////////////
/**
* Returns the GUID.
*
* @returns COM status code
* @param aId Address of result variable.
*/
{
/* AutoLock alock (this); */
CHECK_READY();
return S_OK;
}
/**
* Returns the vendor Id.
*
* @returns COM status code
* @param aVendorId Where to store the vendor id.
*/
{
if (!aVendorId)
return E_INVALIDARG;
CHECK_READY();
return S_OK;
}
/**
* Returns the product Id.
*
* @returns COM status code
* @param aProductId Where to store the product id.
*/
{
if (!aProductId)
return E_INVALIDARG;
CHECK_READY();
return S_OK;
}
/**
* Returns the revision BCD.
*
* @returns COM status code
* @param aRevision Where to store the revision BCD.
*/
{
if (!aRevision)
return E_INVALIDARG;
CHECK_READY();
return S_OK;
}
/**
* Returns the manufacturer string.
*
* @returns COM status code
* @param aManufacturer Where to put the return string.
*/
{
if (!aManufacturer)
return E_INVALIDARG;
CHECK_READY();
return S_OK;
}
/**
* Returns the product string.
*
* @returns COM status code
* @param aProduct Where to put the return string.
*/
{
if (!aProduct)
return E_INVALIDARG;
CHECK_READY();
return S_OK;
}
/**
* Returns the serial number string.
*
* @returns COM status code
* @param aSerialNumber Where to put the return string.
*/
{
if (!aSerialNumber)
return E_INVALIDARG;
CHECK_READY();
return S_OK;
}
/**
* Returns the device address string.
*
* @returns COM status code
* @param aAddress Where to put the returned string.
*/
{
if (!aAddress)
return E_INVALIDARG;
CHECK_READY();
return S_OK;
}
{
if (!aPort)
return E_INVALIDARG;
CHECK_READY();
///@todo implement
aPort = 0;
return S_OK;
}
{
if (!aRemote)
return E_INVALIDARG;
CHECK_READY();
return S_OK;
}
// IHostUSBDevice properties
/////////////////////////////////////////////////////////////////////////////
{
if (!aState)
return E_POINTER;
CHECK_READY();
return S_OK;
}
// public methods only for internal purposes
////////////////////////////////////////////////////////////////////////////////
/** Sets the ignored flag and returns the device to the host */
void HostUSBDevice::setIgnored()
{
AssertReturn (isReady(), (void) 0);
AssertReturn (!mIgnored, (void) 0);
mIgnored = false;
}
/** Requests the capture */
void HostUSBDevice::setCaptured ()
{
Assert (
mState == USBDeviceState_Busy ||
mUSBProxyService->captureDevice (this);
}
/**
* Returns the device back to the host
*
* @returns VBox status code.
*/
int HostUSBDevice::setHostDriven()
{
return mUSBProxyService->releaseDevice (this);
}
/**
* Resets the device as if it were just attached to the host
*
* @returns VBox status code.
*/
int HostUSBDevice::reset()
{
mIgnored = false;
/** @todo this operation might fail and cause the device to the reattached with a different address and all that. */
return mUSBProxyService->resetDevice (this);
}
/**
* Sets the state of the device, as it was reported by the host.
* This method applicable only for devices currently controlled by the host.
*
* @param aState new state
*/
{
aState == USBDeviceState_Busy ||
(void) 0);
mState == USBDeviceState_Busy ||
(void) 0);
{
}
}
/**
* Compares this device with a USBDEVICE and decides which comes first.
*
* @returns < 0 if this should come before pDev2.
* @returns 0 if this and pDev2 are equal.
* @returns > 0 if this should come after pDev2.
*
* @param pDev2 Device 2.
*/
{
}
/**
* Compares two USB devices and decides which comes first.
*
* @returns < 0 if pDev1 should come before pDev2.
* @returns 0 if pDev1 and pDev2 are equal.
* @returns > 0 if pDev1 should come after pDev2.
*
* @param pDev1 Device 1.
* @param pDev2 Device 2.
*/
{
if (iDiff)
return iDiff;
if (iDiff)
return iDiff;
/** @todo Sander, will this work on windows as well? Linux won't reuse an address for quite a while. */
}
/**
* Updates the state of the device.
*
* @returns true if the state has actually changed.
* @returns false if the stat didn't change, or the change might have been cause by VBox.
*
* @param aDev The current device state as seen by the proxy backend.
*/
{
/*
* We have to be pretty conservative here because the proxy backend
* doesn't necessarily know everything that's going on. So, rather
* be overly careful than changing the state once when we shouldn't!
*/
{
default:
return false;
switch (mState)
{
/* the proxy may confuse following states with unavailable */
case USBDeviceState_Held:
case USBDeviceState_Captured:
return false;
default:
LogFlowMember ((" HostUSBDevice::updateState: %d -> %d\n",
return true;
}
break;
switch (mState)
{
case USBDeviceState_Busy:
/* the proxy may confuse following states with capturable */
case USBDeviceState_Held:
case USBDeviceState_Captured:
return false;
default:
LogFlowMember ((" HostUSBDevice::updateState: %d -> %d\n",
return true;
}
break;
case USBDEVICESTATE_UNUSED:
switch (mState)
{
case USBDeviceState_Available:
/* the proxy may confuse following state(s) with available */
case USBDeviceState_Held:
case USBDeviceState_Captured:
return false;
default:
LogFlowMember ((" HostUSBDevice::updateState: %d -> %d\n",
return true;
}
break;
switch (mState)
{
case USBDeviceState_Held:
/* the proxy may confuse following state(s) with held */
case USBDeviceState_Available:
case USBDeviceState_Busy:
case USBDeviceState_Captured:
return false;
default:
LogFlowMember ((" HostUSBDevice::updateState: %d -> %d\n",
return true;
}
break;
switch (mState)
{
case USBDeviceState_Captured:
/* the proxy may confuse following state(s) with captured */
case USBDeviceState_Held:
case USBDeviceState_Available:
case USBDeviceState_Busy:
return false;
default:
LogFlowMember ((" HostUSBDevice::updateState: %d -> %d\n",
return true;
}
break;
}
}