VBoxManageUSB.cpp revision 81379f9b8d22c1605054c0d14bfc27bffbe76987
/* $Id$ */
/** @file
* VBoxManage - VirtualBox's command-line interface.
*/
/*
* Copyright (C) 2006-2009 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "VBoxManage.h"
/* missing XPCOM <-> COM wrappers */
#ifndef STDMETHOD_
#endif
#ifndef NS_GET_IID
# define NS_GET_IID(I) IID_##I
#endif
#ifndef RT_OS_WINDOWS
#define IUnknown nsISupports
#endif
using namespace com;
/**
* Quick IUSBDevice implementation for detaching / attaching
* devices to the USB Controller.
*/
class MyUSBDevice : public IUSBDevice
{
public:
// public initializer/uninitializer for internal purposes only
MyUSBDevice(uint16_t a_u16VendorId, uint16_t a_u16ProductId, uint16_t a_bcdRevision, uint64_t a_u64SerialHash, const char *a_pszComment)
m_cRefs(0)
{
}
{
return ASMAtomicIncU32(&m_cRefs);
}
{
if (!cRefs)
delete this;
return cRefs;
}
{
#ifdef RT_OS_WINDOWS
#endif
*ppvObject = (IUSBDevice *)this;
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
STDMETHOD(COMGETTER(VendorId))(USHORT *a_pusVendorId) { *a_pusVendorId = m_usVendorId; return S_OK; }
STDMETHOD(COMGETTER(ProductId))(USHORT *a_pusProductId) { *a_pusProductId = m_usProductId; return S_OK; }
STDMETHOD(COMGETTER(Revision))(USHORT *a_pusRevision) { *a_pusRevision = m_bcdRevision; return S_OK; }
STDMETHOD(COMGETTER(SerialHash))(ULONG64 *a_pullSerialHash) { *a_pullSerialHash = m_u64SerialHash; return S_OK; }
private:
/** The vendor id of this USB device. */
/** The product id of this USB device. */
/** The product revision number of this USB device.
* (high byte = integer; low byte = decimal) */
/** The USB serial hash of the device. */
/** The user comment string. */
/** Reference counter. */
};
// types
///////////////////////////////////////////////////////////////////////////////
template <typename T>
class Nullable
{
public:
operator const T&() const { return mValue; }
{
mIsNull = false;
return *this;
}
private:
bool mIsNull;
T mValue;
};
/** helper structure to encapsulate USB filter manipulation commands */
struct USBFilterCmd
{
struct USBFilter
{
USBFilter ()
{}
};
/** flag whether the command target is a global filter */
bool mGlobal;
/** machine this command is targeted at (null for global filters) */
};
int handleUSBFilter (HandlerArg *a)
{
/* at least: 0: command, 1: index, 2: --target, 3: <target value> */
if (a->argc < 4)
/* which command? */
/* which index? */
{
case USBFilterCmd::Add:
case USBFilterCmd::Modify:
{
/* at least: 0: command, 1: index, 2: --target, 3: <target value>, 4: --name, 5: <name value> */
if (a->argc < 6)
{
}
// set Active to true by default
// (assuming that the user sets up all necessary attributes
// at once and wants the filter to be active immediately)
for (int i = 2; i < a->argc; i++)
{
{
i++;
else
{
/* assume it's a UUID of a machine */
{
/* must be a name */
}
}
}
{
i++;
}
{
if (a->argc <= i + 1)
i++;
else
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
if (RT_FAILURE(vrc))
return errorArgument("Failed to convert the --maskedinterfaces value '%s' to a number, vrc=%Rrc", a->argv[i], vrc);
}
{
if (a->argc <= i + 1)
i++;
else
}
else
"Unknown option '%s'", a->argv[i]);
}
{
||
)
)
{
}
}
break;
}
case USBFilterCmd::Remove:
{
/* at least: 0: command, 1: index, 2: --target, 3: <target value> */
if (a->argc < 4)
for (int i = 2; i < a->argc; i++)
{
{
i++;
else
{
/* assume it's a UUID of a machine */
{
/* must be a name */
}
}
}
}
// mandatory options
break;
}
default: break;
}
else
{
/* open a session for the VM */
/* get the mutable session machine */
/* and get the USB controller */
}
{
case USBFilterCmd::Add:
{
{
if (!f.mProductId.isNull())
if (!f.mManufacturer.isNull())
if (!f.mSerialNumber.isNull())
if (!f.mMaskedInterfaces.isNull())
if (f.mAction != USBDeviceFilterAction_Null)
}
else
{
if (!f.mProductId.isNull())
if (!f.mManufacturer.isNull())
if (!f.mSerialNumber.isNull())
if (!f.mMaskedInterfaces.isNull())
}
break;
}
case USBFilterCmd::Modify:
{
{
if (!f.mProductId.isNull())
if (!f.mManufacturer.isNull())
if (!f.mSerialNumber.isNull())
if (!f.mMaskedInterfaces.isNull())
if (f.mAction != USBDeviceFilterAction_Null)
}
else
{
if (!f.mProductId.isNull())
if (!f.mManufacturer.isNull())
if (!f.mSerialNumber.isNull())
if (!f.mMaskedInterfaces.isNull())
}
break;
}
case USBFilterCmd::Remove:
{
{
}
else
{
}
break;
}
default:
break;
}
{
{
/* commit the session */
}
/* close the session */
}
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */