EmulatedUSBImpl.cpp revision dcc837f3a6f10996beb8aa7965f67f7f6c273fb4
/* $Id$ */
/** @file
*
* Emulated USB manager implementation.
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* 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.
*/
#include "EmulatedUSBImpl.h"
#include "ConsoleImpl.h"
#include "Logging.h"
/*
* Emulated USB webcam device instance.
*/
typedef enum EUSBDEVICESTATUS
{
class EUSBWEBCAM /* : public EUSBDEVICE */
{
private:
char mszUuid[RTUUID_STR_LENGTH];
void *mpvObject;
HRESULT settingsParse(void);
~EUSBWEBCAM()
{
}
public:
:
mcRefs(1),
{
}
{
return ASMAtomicIncS32(&mcRefs);
}
void Release(void)
{
if (c == 0)
{
delete this;
}
}
void *pvObject);
const char *pszDriver);
};
{
int rc = VINF_SUCCESS;
{
/* Convert some well known settings for backward compatibility. */
{
if (rc == VINF_SUCCESS)
{
}
else
{
{
}
}
}
else
{
}
if (RT_FAILURE(rc))
{
break;
}
}
return rc;
}
/* static */ DECLCALLBACK(int) EUSBWEBCAM::emulatedWebcamAttach(PUVM pUVM, EUSBWEBCAM *pThis, const char *pszDriver)
{
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
/* pInstance will be used by PDM and deallocated on error. */
return rc;
}
{
}
void *pvObject)
{
if (RT_SUCCESS(vrc))
{
{
}
{
hrc = settingsParse();
{
}
}
}
{
"Init emulated USB webcam (%Rrc)", vrc);
}
return hrc;
}
{
/* Parse mSettings string:
* "[dev:|drv:]Name1=Value1;[dev:|drv:]Name2=Value2"
*/
if (pszSrc)
{
while (*pszSrc)
{
/* Does the setting belong to device of driver. Default is both. */
bool fDev = true;
bool fDrv = true;
{
fDev = false;
}
{
fDrv = false;
}
if (!pszEq)
{
hr = E_INVALIDARG;
break;
}
if (!pszEnd)
{
}
*pszEq = 0;
*pszEnd = 0;
/* Empty strings not allowed. */
{
if (fDev)
{
}
if (fDrv)
{
}
}
*pszEq = '=';
if (*pszSrc == ';')
{
pszSrc++;
}
}
{
}
}
return hr;
}
const char *pszDriver)
{
{
"Attach emulated USB webcam (%Rrc)", vrc);
}
return hrc;
}
{
pUVM, this);
{
"Detach emulated USB webcam (%Rrc)", vrc);
}
return hrc;
}
/*
* EmulatedUSB implementation.
*/
{
return BaseFinalConstruct();
}
void EmulatedUSB::FinalRelease()
{
uninit();
}
/*
* Initializes the instance.
*
* @param pConsole The owner.
*/
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization */
return S_OK;
}
/*
* Uninitializes the instance.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void EmulatedUSB::uninit()
{
LogFlowThisFunc(("\n"));
{
p->Release();
}
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
}
{
try
{
}
{
hrc = E_OUTOFMEMORY;
}
catch (...)
{
}
{
size_t i;
}
return hrc;
}
{
}
const char *pszDriver,
void *pvObject)
{
{
EUSBWEBCAM *p = new EUSBWEBCAM();
if (p)
{
{
{
p->AddRef();
try
{
}
{
hrc = E_OUTOFMEMORY;
}
catch (...)
{
}
}
else
{
}
}
{
}
{
p->enmStatus = EUSBDEVICE_ATTACHED;
}
else
{
if (p->enmStatus != EUSBDEVICE_CREATED)
{
}
}
p->Release();
}
else
{
hrc = E_OUTOFMEMORY;
}
}
else
{
}
return hrc;
}
{
return i_webcamDetachInternal(aPath);
}
{
{
EUSBWEBCAM *p = NULL;
{
{
}
}
if (p)
{
p->Release();
}
else
{
hrc = E_INVALIDARG;
}
}
else
{
}
return hrc;
}
/* static */ DECLCALLBACK(int) EmulatedUSB::eusbCallbackEMT(EmulatedUSB *pThis, char *pszId, uint32_t iEvent,
{
int rc = VINF_SUCCESS;
if (iEvent == 0)
{
{
{
}
}
else
{
rc = VERR_NOT_FOUND;
}
}
else
{
}
return rc;
}
/* static */ DECLCALLBACK(int) EmulatedUSB::i_eusbCallback(void *pv, const char *pszId, uint32_t iEvent,
{
/* Make a copy of parameters, forward to EMT and leave the callback to not hold any lock in the device. */
int rc = VINF_SUCCESS;
void *pvDataCopy = NULL;
if (cbData > 0)
{
if (!pvDataCopy)
{
rc = VERR_NO_MEMORY;
}
}
if (RT_SUCCESS(rc))
{
if (!pvIdCopy)
{
rc = VERR_NO_MEMORY;
}
}
if (RT_SUCCESS(rc))
{
{
/* No wait. */
}
else
{
}
}
if (RT_FAILURE(rc))
{
}
return rc;
}
{
{
{
{
break;
}
}
{
}
}
else
{
}
return hr;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */