USBProxyService.cpp revision 60e0f5a98bb6781dfe5c134512c314f525501e48
/** @file
* VirtualBox USB Proxy Service (base) class.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung 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 "USBProxyService.h"
#include "Logging.h"
#include <iprt/semaphore.h>
/** @todo add the required locking. */
/**
* Initialize data members.
*/
{
}
/**
* Empty destructor.
*/
{
LogFlowMember (("USBProxyService::~USBProxyService: \n"));
mTerminate = true;
}
bool USBProxyService::isActive (void)
{
return mThread != NIL_RTTHREAD;
}
int USBProxyService::getLastError (void)
{
return mLastError;
}
int USBProxyService::start (void)
{
int rc = VINF_SUCCESS;
if (mThread == NIL_RTTHREAD)
{
/*
* Force update before starting the poller thread.
*/
wait (0);
processChanges ();
/*
* Create the poller thread which will look for changes.
*/
mTerminate = false;
if (VBOX_SUCCESS (rc))
else
{
mLastError = rc;
}
}
else
return rc;
}
int USBProxyService::stop (void)
{
int rc = VINF_SUCCESS;
if (mThread != NIL_RTTHREAD)
{
/*
* Mark the thread for termination and kick it.
*/
ASMAtomicXchgSize (&mTerminate, true);
rc = interruptWait();
/*
* Wait for the thread to finish and then update the state.
*/
if (rc == VERR_INVALID_HANDLE)
rc = VINF_SUCCESS;
if (VBOX_SUCCESS (rc))
{
mTerminate = false;
}
else
{
mLastError = rc;
}
}
else
LogFlowMember (("USBProxyService::stop: not active\n"));
return rc;
}
/**
* Sort a list of USB devices.
*
* @returns Pointer to the head of the sorted doubly linked list.
* @param aDevices Head pointer (can be both singly and doubly linked list).
*/
{
while (pDevices)
{
/* unlink head */
if (pDevices)
/* find location. */
while ( pCur
/* insert (after pCur) */
if (pCur)
{
else
}
else
{
if (pHead)
else
}
}
return pHead;
}
void USBProxyService::processChanges (void)
{
LogFlowMember (("USBProxyService::processChanges: \n"));
/*
* Get the sorted list of USB devices.
*/
if (pDevices)
{
/*
* Compare previous list with the previous list of devices
* and merge in any changes while notifying Host.
*/
|| pDevices)
{
/*
* Compare.
*/
int iDiff;
iDiff = 1;
else
{
if (!pDevices)
iDiff = -1;
else
}
if (!iDiff)
{
/*
* Device still there, update the state and move on.
*/
It++;
freeDevice (pFree);
}
else
{
if (iDiff > 0)
{
/*
* Head of pDevices was attached.
*/
Log (("USBProxyService::processChanges: attached %p/%p:{.idVendor=%#06x, .idProduct=%#06x, .pszProduct=\"%s\", .pszManufacturer=\"%s\"}\n",
(HostUSBDevice *)NewObj, pNew, pNew->idVendor, pNew->idProduct, pNew->pszProduct, pNew->pszManufacturer));
}
else
{
/*
* DevPtr was detached, unless there is a pending async request.
*/
/** @todo add a timeout here. */
if (!DevPtr->isStatePendingUnlocked())
{
Log (("USBProxyService::processChanges: detached %p\n", (HostUSBDevice *)DevPtr)); /** @todo add details .*/
}
/* else: operation pending */
}
}
} /* while */
}
else
{
/* All devices were detached */
{
/*
* DevPtr was detached.
*/
Log (("USBProxyService::processChanges: detached %p\n", (HostUSBDevice *)DevPtr)); /** @todo add details .*/
}
}
LogFlowMember (("USBProxyService::processChanges: returns void\n"));
}
{
/*
* Processing loop.
*/
for (;;)
{
if (pThis->mTerminate)
break;
pThis->processChanges();
}
LogFlow (("USBProxyService::serviceThread: returns VINF_SUCCESS\n"));
return VINF_SUCCESS;
}
{
while (cCfgs-- > 0)
{
while (cIfs-- > 0)
{
/* next */
pIf++;
}
/* next */
pCfg++;
}
}
{
if (!aSerial)
aSerial = "";
for (;;)
{
if (!u8)
break;
pu8++;
}
return u64;
}
{
if (aDevice->isStatePendingUnlocked())
{
switch (aDevice->pendingStateUnlocked())
{
case USBDeviceState_USBDeviceUnavailable: aUSBDevice->enmState = USBDEVICESTATE_USED_BY_HOST; break;
case USBDeviceState_USBDeviceBusy: aUSBDevice->enmState = USBDEVICESTATE_USED_BY_HOST_CAPTURABLE; break;
default:
break;
}
}
}
/* Stubs which the host specific classes overrides: */
{
return RTThreadSleep (250);
}
int USBProxyService::interruptWait (void)
{
return VERR_NOT_IMPLEMENTED;
}
{
return NULL;
}
void USBProxyService::serviceThreadInit (void)
{
}
void USBProxyService::serviceThreadTerm (void)
{
}
/**
* The default implementation returns non-NULL to emulate successful insertions
* for those subclasses that don't reimplement this method.
*/
{
// return non-NULL to prevent failed assertions in Main
return (void *) 1;
}
{
}
{
return VERR_NOT_IMPLEMENTED;
}
{
return VERR_NOT_IMPLEMENTED;
}
{
return VERR_NOT_IMPLEMENTED;
}
{
return VERR_NOT_IMPLEMENTED;
}
{
}