HostUSBDeviceImpl.h revision b9769010e0bf9346865942a20da204bd1dbc8cb6
039cd2c4871a00e51af909222a34695d9cec3000vboxsync/** @file
039cd2c4871a00e51af909222a34695d9cec3000vboxsync *
039cd2c4871a00e51af909222a34695d9cec3000vboxsync * VirtualBox IHostUSBDevice COM interface implementation
039cd2c4871a00e51af909222a34695d9cec3000vboxsync */
039cd2c4871a00e51af909222a34695d9cec3000vboxsync
039cd2c4871a00e51af909222a34695d9cec3000vboxsync/*
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 innotek GmbH
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
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 as published by the Free Software Foundation,
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * If you received this file as part of a commercial VirtualBox
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * distribution, then only the terms of your commercial VirtualBox
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * license agreement apply instead of the previous paragraph.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync */
039cd2c4871a00e51af909222a34695d9cec3000vboxsync
12cd783de945853c8fc377095e8d0bbd4c97d8a1vboxsync#ifndef ____H_HOSTUSBDEVICEIMPL
12cd783de945853c8fc377095e8d0bbd4c97d8a1vboxsync#define ____H_HOSTUSBDEVICEIMPL
12cd783de945853c8fc377095e8d0bbd4c97d8a1vboxsync
12cd783de945853c8fc377095e8d0bbd4c97d8a1vboxsync#include "VirtualBoxBase.h"
12cd783de945853c8fc377095e8d0bbd4c97d8a1vboxsync#include "USBDeviceFilterImpl.h"
12cd783de945853c8fc377095e8d0bbd4c97d8a1vboxsync/* #include "USBProxyService.h" circular on Host/HostUSBDevice, the includer
27537ffef7291d0bb3a24e459a6b94c65586defevboxsync * must include this. */
039cd2c4871a00e51af909222a34695d9cec3000vboxsync#include "Collection.h"
19edb133387698f301b529248daa3719fe0d7389vboxsync
945c5fd81197e316e8bcfd9f29e06c6b8ff3508dvboxsync#include <VBox/usb.h>
945c5fd81197e316e8bcfd9f29e06c6b8ff3508dvboxsync
039cd2c4871a00e51af909222a34695d9cec3000vboxsyncclass SessionMachine;
039cd2c4871a00e51af909222a34695d9cec3000vboxsyncclass USBProxyService;
7203f6c17d0f467b2735c4cf235948225e73c2cevboxsync
19edb133387698f301b529248daa3719fe0d7389vboxsync/**
19edb133387698f301b529248daa3719fe0d7389vboxsync * Object class used to hold Host USB Device properties.
19edb133387698f301b529248daa3719fe0d7389vboxsync */
19edb133387698f301b529248daa3719fe0d7389vboxsyncclass ATL_NO_VTABLE HostUSBDevice :
19edb133387698f301b529248daa3719fe0d7389vboxsync public VirtualBoxBaseNEXT,
19edb133387698f301b529248daa3719fe0d7389vboxsync public VirtualBoxSupportErrorInfoImpl <HostUSBDevice, IHostUSBDevice>,
7203f6c17d0f467b2735c4cf235948225e73c2cevboxsync public VirtualBoxSupportTranslation <HostUSBDevice>,
7203f6c17d0f467b2735c4cf235948225e73c2cevboxsync public IHostUSBDevice
7203f6c17d0f467b2735c4cf235948225e73c2cevboxsync{
7203f6c17d0f467b2735c4cf235948225e73c2cevboxsyncpublic:
12cd783de945853c8fc377095e8d0bbd4c97d8a1vboxsync
7203f6c17d0f467b2735c4cf235948225e73c2cevboxsync VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostUSBDevice)
039cd2c4871a00e51af909222a34695d9cec3000vboxsync
039cd2c4871a00e51af909222a34695d9cec3000vboxsync DECLARE_NOT_AGGREGATABLE(HostUSBDevice)
1a8be88b5b9a6353e5efdb82fddd5093dd78b3e3vboxsync
1a8be88b5b9a6353e5efdb82fddd5093dd78b3e3vboxsync DECLARE_PROTECT_FINAL_CONSTRUCT()
1a8be88b5b9a6353e5efdb82fddd5093dd78b3e3vboxsync
1a8be88b5b9a6353e5efdb82fddd5093dd78b3e3vboxsync BEGIN_COM_MAP(HostUSBDevice)
1a8be88b5b9a6353e5efdb82fddd5093dd78b3e3vboxsync COM_INTERFACE_ENTRY(ISupportErrorInfo)
19edb133387698f301b529248daa3719fe0d7389vboxsync COM_INTERFACE_ENTRY(IHostUSBDevice)
19edb133387698f301b529248daa3719fe0d7389vboxsync COM_INTERFACE_ENTRY(IUSBDevice)
19edb133387698f301b529248daa3719fe0d7389vboxsync END_COM_MAP()
27537ffef7291d0bb3a24e459a6b94c65586defevboxsync
039cd2c4871a00e51af909222a34695d9cec3000vboxsync NS_DECL_ISUPPORTS
bc710aaa6d8096ed8b2ad33ef5be2914f118494cvboxsync
19edb133387698f301b529248daa3719fe0d7389vboxsync DECLARE_EMPTY_CTOR_DTOR (HostUSBDevice)
b51cedf2af5c5e6fb04d36789233a9d6ffa54eacvboxsync
19edb133387698f301b529248daa3719fe0d7389vboxsync HRESULT FinalConstruct();
19edb133387698f301b529248daa3719fe0d7389vboxsync void FinalRelease();
// public initializer/uninitializer for internal purposes only
HRESULT init(PUSBDEVICE aUsb, USBProxyService *aUSBProxyService);
void uninit();
// IUSBDevice properties
STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
STDMETHOD(COMGETTER(VendorId))(USHORT *aVendorId);
STDMETHOD(COMGETTER(ProductId))(USHORT *aProductId);
STDMETHOD(COMGETTER(Revision))(USHORT *aRevision);
STDMETHOD(COMGETTER(Manufacturer))(BSTR *aManufacturer);
STDMETHOD(COMGETTER(Product))(BSTR *aProduct);
STDMETHOD(COMGETTER(SerialNumber))(BSTR *aSerialNumber);
STDMETHOD(COMGETTER(Address))(BSTR *aAddress);
STDMETHOD(COMGETTER(Port))(USHORT *aPort);
STDMETHOD(COMGETTER(Remote))(BOOL *aRemote);
// IHostUSBDevice properties
STDMETHOD(COMGETTER(State))(USBDeviceState_T *aState);
// public methods only for internal purposes
/* @note Must be called from under the object read lock. */
const Guid &id() const { return mId; }
/* @note Must be called from under the object read lock. */
USBDeviceState_T state() const { return mState; }
/* @note Must be called from under the object read lock. */
USBDeviceState_T pendingState() const { return mPendingState; }
/* @note Must be called from under the object read lock. */
ComObjPtr <SessionMachine> &machine() { return mMachine; }
/* @note Must be called from under the object read lock. */
bool isStatePending() const { return mIsStatePending; }
/* @note Must be called from under the object read lock. */
PCUSBDEVICE usbData() const { return mUsb; }
Utf8Str name();
bool requestCapture (SessionMachine *aMachine);
void requestRelease();
void requestHold();
void setHeld();
void reset();
void handlePendingStateChange();
void cancelPendingState();
bool isMatch (const USBDeviceFilter::Data &aData);
int compare (PCUSBDEVICE aDev2);
static int compare (PCUSBDEVICE aDev1, PCUSBDEVICE aDev2,
bool aIsStrict = true);
bool updateState (PCUSBDEVICE aDev);
// for VirtualBoxSupportErrorInfoImpl
static const wchar_t *getComponentName() { return L"HostUSBDevice"; }
private:
const Guid mId;
USBDeviceState_T mState;
USBDeviceState_T mPendingState;
ComObjPtr <SessionMachine> mMachine;
bool mIsStatePending : 1;
/** Pointer to the USB Proxy Service instance. */
USBProxyService *mUSBProxyService;
/** Pointer to the USB Device structure owned by this device.
* Only used for host devices. */
PUSBDEVICE mUsb;
};
COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostUSBDevice)
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