VirtualBox

Changeset 23279 in vbox for trunk/src/VBox/Main/HostImpl.cpp


Ignore:
Timestamp:
Sep 24, 2009 10:46:57 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
52765
Message:

Main: remove VirtualBoxBaseWithChildren, convert IHost away from using it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/HostImpl.cpp

    r23273 r23279  
    159159
    160160#ifdef VBOX_WITH_USB
    161     USBDeviceFilterList     llUSBDeviceFilters;
     161    WriteLockHandle         treeLock;                   // protects the below two lists
     162
     163    USBDeviceFilterList     llChildren;                 // all USB device filters
     164    USBDeviceFilterList     llUSBDeviceFilters;         // USB device filters in use by the USB proxy service
    162165
    163166    /** Pointer to the USBProxyService object. */
     
    337340    delete m->pHostPowerService;
    338341
     342#ifdef VBOX_WITH_USB
    339343    /* uninit all USB device filters still referenced by clients */
    340     uninitDependentChildren();
    341 
    342 #ifdef VBOX_WITH_USB
     344    for (USBDeviceFilterList::iterator it = m->llChildren.begin();
     345         it != m->llChildren.end();
     346         ++it)
     347    {
     348        ComObjPtr<HostUSBDeviceFilter> &pChild = *it;
     349        pChild->uninit();
     350    }
     351
     352    m->llChildren.clear();
     353
    343354    m->llUSBDeviceFilters.clear();
    344355#endif
     
    902913    CheckComRCReturnRC(rc);
    903914
    904     return m->pUSBProxyService->getDeviceCollection (ComSafeArrayOutArg(aUSBDevices));
     915    return m->pUSBProxyService->getDeviceCollection(ComSafeArrayOutArg(aUSBDevices));
    905916
    906917#else
     
    924935    CheckComRCReturnRC(autoCaller.rc());
    925936
    926     AutoWriteLock alock(this);
     937    AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock);
    927938
    928939    MultiResult rc = checkUSBProxyService();
    929940    CheckComRCReturnRC(rc);
    930941
    931     SafeIfaceArray<IHostUSBDeviceFilter> collection (m->llUSBDeviceFilters);
     942    SafeIfaceArray<IHostUSBDeviceFilter> collection(m->llUSBDeviceFilters);
    932943    collection.detachTo(ComSafeArrayOutArg(aUSBDeviceFilters));
    933944
     
    12581269    CheckComRCReturnRC(autoCaller.rc());
    12591270
    1260     AutoWriteLock alock(this);
     1271    AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock);
    12611272
    12621273    MultiResult rc = checkUSBProxyService();
    12631274    CheckComRCReturnRC(rc);
    12641275
    1265     ComObjPtr<HostUSBDeviceFilter> filter = getDependentChild (aFilter);
    1266     if (!filter)
    1267         return setError (VBOX_E_INVALID_OBJECT_STATE,
    1268             tr ("The given USB device filter is not created within "
    1269                 "this VirtualBox instance"));
    1270 
    1271     if (filter->mInList)
     1276    ComObjPtr<HostUSBDeviceFilter> pFilter;
     1277    for (USBDeviceFilterList::iterator it = m->llChildren.begin();
     1278         it != m->llChildren.end();
     1279         ++it)
     1280    {
     1281        if (*it == aFilter)
     1282        {
     1283            pFilter = *it;
     1284            break;
     1285        }
     1286    }
     1287    if (pFilter.isNull())
     1288        return setError(VBOX_E_INVALID_OBJECT_STATE,
     1289                        tr("The given USB device filter is not created within this VirtualBox instance"));
     1290
     1291    if (pFilter->mInList)
    12721292        return setError (E_INVALIDARG,
    12731293            tr ("The given USB device filter is already in the list"));
     
    12771297    std::advance (it, aPosition);
    12781298    /* ...and insert */
    1279     m->llUSBDeviceFilters.insert (it, filter);
    1280     filter->mInList = true;
     1299    m->llUSBDeviceFilters.insert(it, pFilter);
     1300    pFilter->mInList = true;
    12811301
    12821302    /* notify the proxy (only when the filter is active) */
    1283     if (m->pUSBProxyService->isActive() && filter->data().mActive)
    1284     {
    1285         ComAssertRet (filter->id() == NULL, E_FAIL);
    1286         filter->id() = m->pUSBProxyService->insertFilter (&filter->data().mUSBFilter);
     1303    if (    m->pUSBProxyService->isActive()
     1304         && pFilter->data().mActive)
     1305    {
     1306        ComAssertRet(pFilter->id() == NULL, E_FAIL);
     1307        pFilter->id() = m->pUSBProxyService->insertFilter(&pFilter->data().mUSBFilter);
    12871308    }
    12881309
     
    13081329    CheckComRCReturnRC(autoCaller.rc());
    13091330
    1310     AutoWriteLock alock(this);
     1331    AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock);
    13111332
    13121333    MultiResult rc = checkUSBProxyService();
     
    13311352        /* ...and remove */
    13321353        filter->mInList = false;
    1333         m->llUSBDeviceFilters.erase (it);
     1354        m->llUSBDeviceFilters.erase(it);
    13341355    }
    13351356
     
    15911612    CheckComRCReturnRC(autoCaller.rc());
    15921613
    1593     AutoWriteLock alock(this);
     1614    AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock);
    15941615
    15951616    HRESULT rc = S_OK;
     
    16281649    CheckComRCReturnRC(autoCaller.rc());
    16291650
    1630     AutoWriteLock alock(this);
     1651    AutoReadLock alock(&m->treeLock);
    16311652
    16321653#ifdef VBOX_WITH_USB
     
    16531674{
    16541675    return m->pUSBProxyService;
     1676}
     1677
     1678HRESULT Host::addChild(HostUSBDeviceFilter *pChild)
     1679{
     1680    AutoCaller autoCaller(this);
     1681    CheckComRCReturnRC(autoCaller.rc());
     1682
     1683    AutoWriteLock alock(&m->treeLock);
     1684
     1685    m->llChildren.push_back(pChild);
     1686
     1687    return S_OK;
     1688}
     1689
     1690HRESULT Host::removeChild(HostUSBDeviceFilter *pChild)
     1691{
     1692    AutoCaller autoCaller(this);
     1693    CheckComRCReturnRC(autoCaller.rc());
     1694
     1695    AutoWriteLock alock(&m->treeLock);
     1696
     1697    for (USBDeviceFilterList::iterator it = m->llChildren.begin();
     1698         it != m->llChildren.end();
     1699         ++it)
     1700    {
     1701        if (*it == pChild)
     1702        {
     1703            m->llChildren.erase(it);
     1704            break;
     1705        }
     1706    }
     1707
     1708    return S_OK;
    16551709}
    16561710
     
    17171771void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters)
    17181772{
    1719     AutoWriteLock alock(this);
     1773    AutoReadLock alock(&m->treeLock);
    17201774
    17211775    *aGlobalFilters = m->llUSBDeviceFilters;
     
    22292283
    22302284#ifdef VBOX_WITH_USB
    2231 ComObjPtr<HostUSBDeviceFilter> Host::getDependentChild (IHostUSBDeviceFilter *aFilter)
    2232 {
    2233     VirtualBoxBase *child = VirtualBoxBaseWithChildren::getDependentChild(ComPtr<IUnknown>(aFilter));
    2234     return child
    2235             ? dynamic_cast<HostUSBDeviceFilter*>(child)
    2236             : NULL;
    2237 }
    2238 
    2239 
    22402285/**
    22412286 *  Checks for the presense and status of the USB Proxy Service.
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette