HostUSBDeviceImpl.h revision 60e0f5a98bb6781dfe5c134512c314f525501e48
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/** @file
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync *
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * VirtualBox IHostUSBDevice COM interface implementation
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/*
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * Copyright (C) 2006 InnoTek Systemberatung GmbH
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync *
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * available from http://www.virtualbox.org. This file is free software;
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * General Public License as published by the Free Software Foundation,
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync *
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * If you received this file as part of a commercial VirtualBox
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * distribution, then only the terms of your commercial VirtualBox
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * license agreement apply instead of the previous paragraph.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#ifndef ____H_HOSTUSBDEVICEIMPL
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#define ____H_HOSTUSBDEVICEIMPL
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#include "VirtualBoxBase.h"
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#include "USBDeviceFilterImpl.h"
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/* #include "USBProxyService.h" circular on Host/HostUSBDevice, the includer
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * must include this. */
5ff3fa0492332325f57e80636321619e2224027evboxsync#include "Collection.h"
5ff3fa0492332325f57e80636321619e2224027evboxsync
5ff3fa0492332325f57e80636321619e2224027evboxsync#include <VBox/usb.h>
5ff3fa0492332325f57e80636321619e2224027evboxsync
d440eb388d1459ffc6f581ff0c786ef3f048dc39vboxsyncclass SessionMachine;
482a222498aae619afda0255a7edf4ebda97268cvboxsyncclass USBProxyService;
482a222498aae619afda0255a7edf4ebda97268cvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/**
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * Object class used to hold Host USB Device properties.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsyncclass ATL_NO_VTABLE HostUSBDevice :
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync public VirtualBoxBaseNEXT,
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync public VirtualBoxSupportErrorInfoImpl <HostUSBDevice, IHostUSBDevice>,
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync public VirtualBoxSupportTranslation <HostUSBDevice>,
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync public IHostUSBDevice
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync{
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsyncpublic:
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostUSBDevice)
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync DECLARE_NOT_AGGREGATABLE(HostUSBDevice)
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync DECLARE_PROTECT_FINAL_CONSTRUCT()
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync BEGIN_COM_MAP(HostUSBDevice)
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync COM_INTERFACE_ENTRY(ISupportErrorInfo)
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync COM_INTERFACE_ENTRY(IHostUSBDevice)
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync COM_INTERFACE_ENTRY(IUSBDevice)
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync END_COM_MAP()
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync NS_DECL_ISUPPORTS
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync DECLARE_EMPTY_CTOR_DTOR (HostUSBDevice)
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync HRESULT FinalConstruct();
ee5869bb73f07de9c139dc6a608836a7b5767933vboxsync void FinalRelease();
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync // public initializer/uninitializer for internal purposes only
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync HRESULT init(PUSBDEVICE aUsb, USBProxyService *aUSBProxyService);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync void uninit();
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync // IUSBDevice properties
ee5869bb73f07de9c139dc6a608836a7b5767933vboxsync STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
f6dde23cd488aee26203b38ec67220270f5c4273vboxsync STDMETHOD(COMGETTER(VendorId))(USHORT *aVendorId);
f6dde23cd488aee26203b38ec67220270f5c4273vboxsync STDMETHOD(COMGETTER(ProductId))(USHORT *aProductId);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync STDMETHOD(COMGETTER(Revision))(USHORT *aRevision);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync STDMETHOD(COMGETTER(Manufacturer))(BSTR *aManufacturer);
ee5869bb73f07de9c139dc6a608836a7b5767933vboxsync STDMETHOD(COMGETTER(Product))(BSTR *aProduct);
ee5869bb73f07de9c139dc6a608836a7b5767933vboxsync STDMETHOD(COMGETTER(SerialNumber))(BSTR *aSerialNumber);
a96ed55e8e1b248965a3d29d6e4c3116979e887bvboxsync STDMETHOD(COMGETTER(Address))(BSTR *aAddress);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync STDMETHOD(COMGETTER(Port))(USHORT *aPort);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync STDMETHOD(COMGETTER(Remote))(BOOL *aRemote);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync // IHostUSBDevice properties
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync STDMETHOD(COMGETTER(State))(USBDeviceState_T *aState);
482a222498aae619afda0255a7edf4ebda97268cvboxsync
482a222498aae619afda0255a7edf4ebda97268cvboxsync // public methods only for internal purposes
482a222498aae619afda0255a7edf4ebda97268cvboxsync
a96ed55e8e1b248965a3d29d6e4c3116979e887bvboxsync /* @note Must be called from under the object read lock. */
a96ed55e8e1b248965a3d29d6e4c3116979e887bvboxsync const Guid &id() const { return mId; }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync /* @note Must be called from under the object read lock. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync USBDeviceState_T state() const { return mState; }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync /** Same as state() except you don't need to lock any thing. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync USBDeviceState_T stateUnlocked() const
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync {
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync AutoReaderLock (this);
d91dc86210d602f51a4701762488a5e696c80a45vboxsync return state();
d91dc86210d602f51a4701762488a5e696c80a45vboxsync }
a96ed55e8e1b248965a3d29d6e4c3116979e887bvboxsync
a96ed55e8e1b248965a3d29d6e4c3116979e887bvboxsync /* @note Must be called from under the object read lock. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync USBDeviceState_T pendingState() const { return mPendingState; }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync /** Same as pendingState() except you don't need to lock any thing. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync USBDeviceState_T pendingStateUnlocked() const
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync {
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync AutoReaderLock (this);
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync return pendingState();
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync }
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync /* @note Must be called from under the object read lock. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync ComObjPtr <SessionMachine, ComWeakRef> &machine() { return mMachine; }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/// @todo remove
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#if 0
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync /* @note Must be called from under the object read lock. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync bool isIgnored() { return mIgnored; }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#endif
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync /* @note Must be called from under the object read lock. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync bool isStatePending() const { return mIsStatePending; }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync /** Same as isStatePending() except you don't need to lock any thing. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync bool isStatePendingUnlocked() const
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync {
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync AutoReaderLock (this);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync return isStatePending();
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync /* @note Must be called from under the object read lock. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync PCUSBDEVICE usbData() const { return mUsb; }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync Utf8Str name();
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/// @todo remove
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#if 0
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync void setIgnored();
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#endif
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync bool setCaptured (SessionMachine *aMachine);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync int setHostDriven();
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync int reset();
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/// @todo remove
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#if 0
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync void setHostState (USBDeviceState_T aState);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync#endif
23ab2e25f17cdd6af9c0448ee70905a8c1c82896vboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync bool isMatch (const USBDeviceFilter::Data &aData);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
f6dde23cd488aee26203b38ec67220270f5c4273vboxsync int compare (PCUSBDEVICE pDev2);
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync static int compare (PCUSBDEVICE pDev1, PCUSBDEVICE pDev2);
f6dde23cd488aee26203b38ec67220270f5c4273vboxsync
43e9355f77c0463e7ace350984bb5a09fb8c50a1vboxsync bool updateState (PCUSBDEVICE aDev);
43e9355f77c0463e7ace350984bb5a09fb8c50a1vboxsync
6f25e64d3d98b4f23e7ef0faaa225cb980d6abe8vboxsync // for VirtualBoxSupportErrorInfoImpl
f6dde23cd488aee26203b38ec67220270f5c4273vboxsync static const wchar_t *getComponentName() { return L"HostUSBDevice"; }
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
611af5c9fc04865215e86b6e4906c9dfdfb6a381vboxsyncprivate:
611af5c9fc04865215e86b6e4906c9dfdfb6a381vboxsync
611af5c9fc04865215e86b6e4906c9dfdfb6a381vboxsync const Guid mId;
611af5c9fc04865215e86b6e4906c9dfdfb6a381vboxsync USBDeviceState_T mState;
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync USBDeviceState_T mPendingState;
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync ComObjPtr <SessionMachine, ComWeakRef> mMachine;
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync bool mIsStatePending : 1;
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/// @todo remove
f9cac318205d74ee5b35dabcf2bd39118f6293d7vboxsync#if 0
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync bool mIgnored : 1;
d91dc86210d602f51a4701762488a5e696c80a45vboxsync#endif
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync /** Pointer to the USB Proxy Service instance. */
f9cac318205d74ee5b35dabcf2bd39118f6293d7vboxsync USBProxyService *mUSBProxyService;
611af5c9fc04865215e86b6e4906c9dfdfb6a381vboxsync
611af5c9fc04865215e86b6e4906c9dfdfb6a381vboxsync /** Pointer to the USB Device structure owned by this device.
f9cac318205d74ee5b35dabcf2bd39118f6293d7vboxsync * Only used for host devices. */
4831e82ecaa3c813398d2f343e9d38ee34a3acf4vboxsync PUSBDEVICE mUsb;
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync};
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsyncCOM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostUSBDevice)
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync STDMETHOD(FindById) (INPTR GUIDPARAM aId, IHostUSBDevice **aDevice)
{
Guid idToFind = aId;
if (idToFind.isEmpty())
return E_INVALIDARG;
if (!aDevice)
return E_POINTER;
*aDevice = NULL;
Vector::value_type found;
Vector::iterator it = vec.begin();
while (!found && it != vec.end())
{
Guid id;
(*it)->COMGETTER(Id) (id.asOutParam());
if (id == idToFind)
found = *it;
++ it;
}
if (!found)
return setError (E_INVALIDARG, HostUSBDeviceCollection::tr (
"Could not find a USB device with UUID {%s}"),
idToFind.toString().raw());
return found.queryInterfaceTo (aDevice);
}
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