USBProxyService.cpp revision 03b802818ffd2f36e2b9210243cef54f4d4aa5ac
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VirtualBox USB Proxy Service (base) class.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Copyright (C) 2006 InnoTek Systemberatung GmbH
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * available from http://www.virtualbox.org. This file is free software;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * you can redistribute it and/or modify it under the terms of the GNU
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * General Public License as published by the Free Software Foundation,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * If you received this file as part of a commercial VirtualBox
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * distribution, then only the terms of your commercial VirtualBox
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * license agreement apply instead of the previous paragraph.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/** @todo add the required locking. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Initialize data members.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync : mHost (aHost), mThread (NIL_RTTHREAD), mTerminate (false), mDevices (), mLastError (VINF_SUCCESS)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlowMember (("USBProxyService::USBProxyService: aHost=%p\n", aHost));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Empty destructor.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlowMember (("USBProxyService::~USBProxyService: \n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Force update before starting the poller thread.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Create the poller thread which will look for changes.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = RTThreadCreate (&mThread, USBProxyService::serviceThread, this,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync 0, RTTHREADTYPE_INFREQUENT_POLLER, RTTHREADFLAGS_WAITABLE, "USBPROXY");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlow (("USBProxyService::start: started mThread=%RTthrd\n", mThread));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlow (("USBProxyService::start: already running, mThread=%RTthrd\n", mThread));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Mark the thread for termination and kick it.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Wait for the thread to finish and then update the state.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlowMember (("USBProxyService::stop: stopped mThread=%RTthrd\n", mThread));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlowMember (("USBProxyService::stop: not active\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Sort a list of USB devices.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @returns Pointer to the head of the sorted doubly linked list.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param aDevices Head pointer (can be both singly and doubly linked list).
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* unlink head */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* find location. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* insert (after pCur) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlowMember (("USBProxyService::processChanges: \n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Get the sorted list of USB devices.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Compare previous list with the previous list of devices
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * and merge in any changes while notifying Host.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HostUSBDeviceList::iterator It = this->mDevices.begin();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Device still there, update the state and move on.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pDevices = pDevices->pNext; /* treated as singly linked */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** @todo detect status changes! */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Head of pDevices was attached.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log (("USBProxyService::processChanges: attached %p/%p:{.idVendor=%#06x, .idProduct=%#06x, .pszProduct=\"%s\", .pszManufacturer=\"%s\"}\n",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync (HostUSBDevice *)NewObj, pNew, pNew->idVendor, pNew->idProduct, pNew->pszProduct, pNew->pszManufacturer));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * DevPtr was detached.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log (("USBProxyService::processChanges: detached %p\n", (HostUSBDevice *)DevPtr)); /** @todo add details .*/
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync } /* while */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* All devices were detached */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HostUSBDeviceList::iterator It = this->mDevices.begin();
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * DevPtr was detached.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync Log (("USBProxyService::processChanges: detached %p\n", (HostUSBDevice *)DevPtr)); /** @todo add details .*/
78df65edff21c11c537f38e736707ea434ab5623vboxsync LogFlowMember (("USBProxyService::processChanges: returns void\n"));
78df65edff21c11c537f38e736707ea434ab5623vboxsync/*static*/ DECLCALLBACK (int) USBProxyService::serviceThread (RTTHREAD Thread, void *pvUser)
78df65edff21c11c537f38e736707ea434ab5623vboxsync USBProxyService *pThis = (USBProxyService *)pvUser;
78df65edff21c11c537f38e736707ea434ab5623vboxsync LogFlow (("USBProxyService::serviceThread: pThis=%p\n", pThis));
78df65edff21c11c537f38e736707ea434ab5623vboxsync * Processing loop.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync LogFlow (("USBProxyService::serviceThread: returns VINF_SUCCESS\n"));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/*static*/ void USBProxyService::freeDevice (PUSBDEVICE pDevice)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync while (cCfgs-- > 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync while (cIfs-- > 0)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* static */ uint64_t USBProxyService::calcSerialHash (const char *aSerial)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync register const uint8_t *pu8 = (const uint8_t *)aSerial;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* Stubs which the host specific classes overrides: */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The default implementation returns non-NULL to emulate successful insertions
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * for those subclasses that don't reimplement this method.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvoid *USBProxyService::insertFilter (IUSBDeviceFilter * /* aFilter */)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync // return non-NULL to prevent failed assertions in Main
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return (void *) 1;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvoid USBProxyService::removeFilter (void * /* aID */)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncint USBProxyService::captureDevice (HostUSBDevice *pDevice)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncint USBProxyService::holdDevice (HostUSBDevice *pDevice)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncint USBProxyService::releaseDevice (HostUSBDevice *pDevice)