HostUSBDeviceImpl.h revision fcb7529771e773b085b87eb5f251ed1182a118fb
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/** @file
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * VirtualBox IHostUSBDevice COM interface implementation
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd */
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/*
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Copyright (C) 2006-2007 innotek GmbH
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * This file is part of VirtualBox Open Source Edition (OSE), as
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * available from http://www.virtualbox.org. This file is free software;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * you can redistribute it and/or modify it under the terms of the GNU
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * General Public License as published by the Free Software Foundation,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
2e545ce2450a9953665f701bb05350f0d3f26275nd * distribution. VirtualBox OSE is distributed in the hope that it will
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * be useful, but WITHOUT ANY WARRANTY of any kind.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen *
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * If you received this file as part of a commercial VirtualBox
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * distribution, then only the terms of your commercial VirtualBox
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * license agreement apply instead of the previous paragraph.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifndef ____H_HOSTUSBDEVICEIMPL
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#define ____H_HOSTUSBDEVICEIMPL
3f08db06526d6901aa08c110b5bc7dde6bc39905nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "VirtualBoxBase.h"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "USBDeviceFilterImpl.h"
e609c337f729875bc20e01096c7e610f45356f54nilgun/* #include "USBProxyService.h" circular on Host/HostUSBDevice, the includer
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * must include this. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "Collection.h"
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem#include <VBox/usb.h>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass SessionMachine;
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass USBProxyService;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Object class used to hold Host USB Device properties.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndclass ATL_NO_VTABLE HostUSBDevice :
a78048ccbdb6256da15e6b0e7e95355e480c2301nd public VirtualBoxBaseNEXT,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd public VirtualBoxSupportErrorInfoImpl <HostUSBDevice, IHostUSBDevice>,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd public VirtualBoxSupportTranslation <HostUSBDevice>,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd public IHostUSBDevice
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
a78048ccbdb6256da15e6b0e7e95355e480c2301ndpublic:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostUSBDevice)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd DECLARE_NOT_AGGREGATABLE(HostUSBDevice)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd DECLARE_PROTECT_FINAL_CONSTRUCT()
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd BEGIN_COM_MAP(HostUSBDevice)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd COM_INTERFACE_ENTRY(ISupportErrorInfo)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd COM_INTERFACE_ENTRY(IHostUSBDevice)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd COM_INTERFACE_ENTRY(IUSBDevice)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd END_COM_MAP()
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh NS_DECL_ISUPPORTS
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd DECLARE_EMPTY_CTOR_DTOR (HostUSBDevice)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd HRESULT FinalConstruct();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void FinalRelease();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd // public initializer/uninitializer for internal purposes only
a78048ccbdb6256da15e6b0e7e95355e480c2301nd HRESULT init(PUSBDEVICE aUsb, USBProxyService *aUSBProxyService);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void uninit();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd // IUSBDevice properties
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(VendorId))(USHORT *aVendorId);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(ProductId))(USHORT *aProductId);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(Revision))(USHORT *aRevision);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(Manufacturer))(BSTR *aManufacturer);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(Product))(BSTR *aProduct);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(SerialNumber))(BSTR *aSerialNumber);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(Address))(BSTR *aAddress);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(Port))(USHORT *aPort);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(Remote))(BOOL *aRemote);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd // IHostUSBDevice properties
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STDMETHOD(COMGETTER(State))(USBDeviceState_T *aState);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd // public methods only for internal purposes
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* @note Must be called from under the object read lock. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const Guid &id() const { return mId; }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* @note Must be called from under the object read lock. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd USBDeviceState_T state() const { return mState; }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* @note Must be called from under the object read lock. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd USBDeviceState_T pendingState() const { return mPendingState; }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* @note Must be called from under the object read lock. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ComObjPtr <SessionMachine, ComWeakRef> &machine() { return mMachine; }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* @note Must be called from under the object read lock. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd bool isStatePending() const { return mIsStatePending; }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /* @note Must be called from under the object read lock. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd PCUSBDEVICE usbData() const { return mUsb; }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Utf8Str name();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd bool requestCapture (SessionMachine *aMachine);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void requestRelease();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void requestHold();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void setHeld();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void reset();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void handlePendingStateChange();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void cancelPendingState();
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd bool isMatch (const USBDeviceFilter::Data &aData);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd int compare (PCUSBDEVICE pDev2);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd static int compare (PCUSBDEVICE pDev1, PCUSBDEVICE pDev2);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd bool updateState (PCUSBDEVICE aDev);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd // for VirtualBoxSupportErrorInfoImpl
a78048ccbdb6256da15e6b0e7e95355e480c2301nd static const wchar_t *getComponentName() { return L"HostUSBDevice"; }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndprivate:
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const Guid mId;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd USBDeviceState_T mState;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd USBDeviceState_T mPendingState;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ComObjPtr <SessionMachine, ComWeakRef> mMachine;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd bool mIsStatePending : 1;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /** Pointer to the USB Proxy Service instance. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd USBProxyService *mUSBProxyService;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd /** Pointer to the USB Device structure owned by this device.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Only used for host devices. */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd PUSBDEVICE mUsb;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd};
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndCOM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostUSBDevice)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
e609c337f729875bc20e01096c7e610f45356f54nilgun STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung {
727872d18412fc021f03969b8641810d8896820bhumbedooh Guid idToFind = aId;
0d0ba3a410038e179b695446bb149cce6264e0abnd if (idToFind.isEmpty())
727872d18412fc021f03969b8641810d8896820bhumbedooh return E_INVALIDARG;
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh if (!aDevice)
0d0ba3a410038e179b695446bb149cce6264e0abnd return E_POINTER;
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh
727872d18412fc021f03969b8641810d8896820bhumbedooh *aDevice = NULL;
0d0ba3a410038e179b695446bb149cce6264e0abnd Vector::value_type found;
0d0ba3a410038e179b695446bb149cce6264e0abnd Vector::iterator it = vec.begin();
0d0ba3a410038e179b695446bb149cce6264e0abnd while (!found && it != vec.end())
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh {
0d0ba3a410038e179b695446bb149cce6264e0abnd Guid id;
0d0ba3a410038e179b695446bb149cce6264e0abnd (*it)->COMGETTER(Id) (id.asOutParam());
0d0ba3a410038e179b695446bb149cce6264e0abnd if (id == idToFind)
727872d18412fc021f03969b8641810d8896820bhumbedooh found = *it;
0d0ba3a410038e179b695446bb149cce6264e0abnd ++ it;
0d0ba3a410038e179b695446bb149cce6264e0abnd }
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh
205f749042ed530040a4f0080dbcb47ceae8a374rjung if (!found)
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
0d0ba3a410038e179b695446bb149cce6264e0abnd "Could not find a USB device with UUID {%s}"),
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd idToFind.toString().raw());
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd return found.queryInterfaceTo (aDevice);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IHostUSBDevice **aDevice)
{
if (!aAddress)
return E_INVALIDARG;
if (!aDevice)
return E_POINTER;
*aDevice = NULL;
Vector::value_type found;
Vector::iterator it = vec.begin();
while (!found && it != vec.end())
{
Bstr address;
(*it)->COMGETTER(Address) (address.asOutParam());
if (address == aAddress)
found = *it;
++ it;
}
if (!found)
return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
"Could not find a USB device with address '%ls'"),
aAddress);
return found.queryInterfaceTo (aDevice);
}
COM_DECL_READONLY_ENUM_AND_COLLECTION_END (HostUSBDevice)
#endif // ____H_HOSTUSBDEVICEIMPL