USBDeviceFilterImpl.cpp revision 0010ccca43c2554000fdd0572c7b9cf5ad17ac91
/** @file
*
* Implementation of VirtualBox COM components:
* USBDeviceFilter and HostUSBDeviceFilter
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#include "USBDeviceFilterImpl.h"
#include "USBControllerImpl.h"
#include "MachineImpl.h"
#include "HostImpl.h"
#include "Logging.h"
#include <iprt/cpputils.h>
////////////////////////////////////////////////////////////////////////////////
// USBDeviceFilter
////////////////////////////////////////////////////////////////////////////////
// constructor / destructor
////////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void USBDeviceFilter::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
////////////////////////////////////////////////////////////////////////////////
/**
* Initializes the USB device filter object.
*
* @param aParent Handle of the parent object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
mParent->addDependentChild (this);
/* initialize all filters to any match using null string */
mInList = false;
/* use setters for the attributes below to reuse parsing errors
* handling */
do
{
}
while (0);
/* Confirm successful initialization when it's the case */
return rc;
}
/**
* Initializes the USB device filter object (short version).
*
* @param aParent Handle of the parent object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
mParent->addDependentChild (this);
/* initialize all filters to any match using null string */
mInList = false;
/* Confirm successful initialization */
return S_OK;
}
/**
* Initializes the object given another object
* (a kind of copy constructor). This object shares data with
* the object passed as an argument.
*
* @param aReshare
* When false, the original object will remain a data owner.
* Otherwise, data ownership will be transferred from the original
* object to this one.
*
* @note This object must be destroyed before the original object
* it shares data with is destroyed.
*
* @note Locks @a aThat object for writing if @a aReshare is @c true, or for
* reading if @a aReshare is false.
*/
bool aReshare /* = false */)
{
LogFlowThisFunc (("aParent=%p, aThat=%p, aReshare=%RTbool\n",
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
mParent->addDependentChild (this);
/* sanity */
if (aReshare)
{
}
else
{
}
/* the arbitrary ID field is not reset because
* the copy is a shadow of the original */
/* Confirm successful initialization */
return S_OK;
}
/**
* Initializes the guest object given another guest object
* (a kind of copy constructor). This object makes a private copy of data
* of the original object passed as an argument.
*
* @note Locks @a aThat object for reading.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
mParent->addDependentChild (this);
/* sanity */
/* reset the arbitrary ID field
* (this field is something unique that two distinct objects, even if they
* are deep copies of each other, should not share) */
/* Confirm successful initialization */
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void USBDeviceFilter::uninit()
{
LogFlowThisFunc (("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan (this);
if (autoUninitSpan.uninitDone())
return;
mInList = false;
mParent->removeDependentChild (this);
}
// IUSBDeviceFilter properties
////////////////////////////////////////////////////////////////////////////////
{
if (!aName)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
return E_INVALIDARG;
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aActive)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
/* leave the lock before informing callbacks */
}
return S_OK;
}
{
if (!aVendorId)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
return setError (E_INVALIDARG,
tr ("Vendor ID filter string '%ls' is not valid (error at position %d)"),
#if defined (RT_OS_WINDOWS)
// intervalic filters are temporarily disabled
return setError (E_INVALIDARG,
tr ("'%ls': Intervalic filters are not currently available on this platform"),
#endif
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aProductId)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
return setError (E_INVALIDARG,
tr ("Product ID filter string '%ls' is not valid (error at position %d)"),
#if defined (RT_OS_WINDOWS)
// intervalic filters are temporarily disabled
return setError (E_INVALIDARG,
tr ("'%ls': Intervalic filters are not currently available on this platform"),
#endif
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aRevision)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
return setError (E_INVALIDARG,
tr ("Revision filter string '%ls' is not valid (error at position %d)"),
#if defined (RT_OS_WINDOWS)
// intervalic filters are temporarily disabled
return setError (E_INVALIDARG,
tr ("'%ls': Intervalic filters are not currently available on this platform"),
#endif
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aManufacturer)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
return setError (E_INVALIDARG,
tr ("Manufacturer filter string '%ls' is not valid (error at position %d)"),
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aProduct)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
return setError (E_INVALIDARG,
tr ("Product filter string '%ls' is not valid (error at position %d)"),
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aSerialNumber)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
return setError (E_INVALIDARG,
tr ("Serial number filter string '%ls' is not valid (error at position %d)"),
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aPort)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
return setError (E_INVALIDARG,
tr ("Port number filter string '%ls' is not valid (error at position %d)"),
#if defined (RT_OS_WINDOWS)
// intervalic filters are temporarily disabled
return setError (E_INVALIDARG,
tr ("'%ls': Intervalic filters are not currently available on this platform"),
aPort);
#endif
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aRemote)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
return setError (E_INVALIDARG,
tr ("Remote state filter string '%ls' is not valid (error at position %d)"),
/* leave the lock before informing callbacks */
return mParent->onDeviceFilterChange (this);
}
return S_OK;
}
// public methods only for internal purposes
////////////////////////////////////////////////////////////////////////////////
/**
* @note Locks this object for writing.
*/
bool USBDeviceFilter::rollback()
{
/* sanity */
AutoCaller autoCaller (this);
bool changed = false;
if (mData.isBackedUp())
{
/* we need to check all data to see whether anything will be changed
* after rollback */
}
return changed;
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void USBDeviceFilter::commit()
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* lock both for writing since we modify both */
if (mData.isBackedUp())
{
if (mPeer)
{
/* attach new data to the peer and reshare it */
}
}
}
/**
* Cancels sharing (if any) by making an independent copy of data.
* This operation also resets this object's peer to NULL.
*
* @note Locks this object for writing, together with the peer object
* represented by @a aThat (locked for reading).
*/
void USBDeviceFilter::unshare()
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* peer is not modified, lock it for reading */
{
if (!mData.isBackedUp())
}
}
////////////////////////////////////////////////////////////////////////////////
// HostUSBDeviceFilter
////////////////////////////////////////////////////////////////////////////////
// constructor / destructor
////////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void HostUSBDeviceFilter::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
////////////////////////////////////////////////////////////////////////////////
/**
* Initializes the USB device filter object.
*
* @param aParent Handle of the parent object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
mParent->addDependentChild (this);
/* initialize all filters to any match using null string */
mInList = false;
/* use setters for the attributes below to reuse parsing errors
* handling */
do
{
}
while (0);
/* Confirm successful initialization when it's the case */
return rc;
}
/**
* Initializes the USB device filter object (short version).
*
* @param aParent Handle of the parent object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* register with parent early, since uninit() will unconditionally
* unregister on failure */
mParent->addDependentChild (this);
mInList = false;
/* initialize all filters to any match using null string */
/* Confirm successful initialization */
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void HostUSBDeviceFilter::uninit()
{
LogFlowThisFunc (("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan (this);
if (autoUninitSpan.uninitDone())
return;
mInList = false;
mParent->removeDependentChild (this);
}
// IUSBDeviceFilter properties
////////////////////////////////////////////////////////////////////////////////
{
if (!aName)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
return E_INVALIDARG;
AutoCaller autoCaller (this);
{
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aActive)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
/* leave the lock before informing callbacks */
}
return S_OK;
}
{
if (!aVendorId)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
return setError (E_INVALIDARG,
tr ("Vendor ID filter string '%ls' is not valid (error at position %d)"),
#if defined (RT_OS_WINDOWS)
// intervalic filters are temporarily disabled
return setError (E_INVALIDARG,
tr ("'%ls': Intervalic filters are not currently available on this platform"),
#endif
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aProductId)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
return setError (E_INVALIDARG,
tr ("Product ID filter string '%ls' is not valid (error at position %d)"),
#if defined (RT_OS_WINDOWS)
// intervalic filters are temporarily disabled
return setError (E_INVALIDARG,
tr ("'%ls': Intervalic filters are not currently available on this platform"),
#endif
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aRevision)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
return setError (E_INVALIDARG,
tr ("Revision filter string '%ls' is not valid (error at position %d)"),
#if defined (RT_OS_WINDOWS)
// intervalic filters are temporarily disabled
return setError (E_INVALIDARG,
tr ("'%ls': Intervalic filters are not currently available on this platform"),
#endif
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aManufacturer)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
return setError (E_INVALIDARG,
tr ("Manufacturer filter string '%ls' is not valid (error at position %d)"),
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aProduct)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
return setError (E_INVALIDARG,
tr ("Product filter string '%ls' is not valid (error at position %d)"),
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aSerialNumber)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
return setError (E_INVALIDARG,
tr ("Serial number filter string '%ls' is not valid (error at position %d)"),
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aPort)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
return setError (E_INVALIDARG,
tr ("Port number filter string '%ls' is not valid (error at position %d)"),
#if defined (RT_OS_WINDOWS)
// intervalic filters are temporarily disabled
return setError (E_INVALIDARG,
tr ("'%ls': Intervalic filters are not currently available on this platform"),
aPort);
#endif
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}
{
if (!aRemote)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
tr ("The remote state filter is not supported by "
"IHostUSBDeviceFilter objects"));
}
// IHostUSBDeviceFilter properties
////////////////////////////////////////////////////////////////////////////////
{
if (!aAction)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
{
/* leave the lock before informing callbacks */
return mParent->onUSBDeviceFilterChange (this);
}
return S_OK;
}