Changeset 2845 in vbox for trunk/src/VBox
- Timestamp:
- May 24, 2007 4:16:41 PM (18 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/USBControllerImpl.cpp
r2805 r2845 43 43 ///////////////////////////////////////////////////////////////////////////// 44 44 45 DEFINE_EMPTY_CTOR_DTOR (USBController) 46 45 47 HRESULT USBController::FinalConstruct() 46 48 { … … 50 52 void USBController::FinalRelease() 51 53 { 52 if (isReady()) 53 uninit(); 54 uninit(); 54 55 } 55 56 … … 61 62 * 62 63 * @returns COM result indicator. 63 * @param a_pParent Pointer to our parent object. 64 */ 65 HRESULT USBController::init(Machine *a_pParent) 66 { 67 LogFlowMember(("USBController::init (%p)\n", a_pParent)); 68 69 ComAssertRet (a_pParent, E_INVALIDARG); 70 71 AutoLock alock(this); 72 ComAssertRet (!isReady(), E_UNEXPECTED); 73 74 m_Parent = a_pParent; 75 // m_Peer is left null 76 77 m_Data.allocate(); 78 m_DeviceFilters.allocate(); 79 80 setReady(true); 64 * @param aParent Pointer to our parent object. 65 */ 66 HRESULT USBController::init (Machine *aParent) 67 { 68 LogFlowThisFunc (("aParent=%p\n", aParent)); 69 70 ComAssertRet (aParent, E_INVALIDARG); 71 72 /* Enclose the state transition NotReady->InInit->Ready */ 73 AutoInitSpan autoInitSpan (this); 74 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 75 76 unconst (mParent) = aParent; 77 /* mPeer is left null */ 78 79 mData.allocate(); 80 mDeviceFilters.allocate(); 81 82 /* Confirm a successful initialization */ 83 autoInitSpan.setSucceeded(); 84 81 85 return S_OK; 82 86 } … … 89 93 * 90 94 * @returns COM result indicator. 91 * @param a _pParentPointer to our parent object.92 * @param a _pPeerThe object to share.93 * 94 * @ remarkThis object must be destroyed before the original object95 * @param aParent Pointer to our parent object. 96 * @param aPeer The object to share. 97 * 98 * @note This object must be destroyed before the original object 95 99 * it shares data with is destroyed. 96 100 */ 97 HRESULT USBController::init(Machine *a_pParent, USBController *a_pPeer) 98 { 99 LogFlowMember(("USBController::init (%p, %p)\n", a_pParent, a_pPeer)); 100 101 ComAssertRet (a_pParent && a_pPeer, E_INVALIDARG); 102 103 AutoLock alock(this); 104 ComAssertRet (!isReady(), E_UNEXPECTED); 105 106 m_Parent = a_pParent; 107 m_Peer = a_pPeer; 108 109 AutoLock thatlock(a_pPeer); 110 m_Data.share(a_pPeer->m_Data); 111 112 // create copies of all filters 113 m_DeviceFilters.allocate(); 114 DeviceFilterList::const_iterator it = a_pPeer->m_DeviceFilters->begin(); 115 while (it != a_pPeer->m_DeviceFilters->end()) 101 HRESULT USBController::init (Machine *aParent, USBController *aPeer) 102 { 103 LogFlowThisFunc (("aParent=%p, aPeer=%p\n", aParent, aPeer)); 104 105 ComAssertRet (aParent && aPeer, E_INVALIDARG); 106 107 /* Enclose the state transition NotReady->InInit->Ready */ 108 AutoInitSpan autoInitSpan (this); 109 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 110 111 unconst (mParent) = aParent; 112 unconst (mPeer) = aPeer; 113 114 AutoLock thatlock (aPeer); 115 mData.share (aPeer->mData); 116 117 /* create copies of all filters */ 118 mDeviceFilters.allocate(); 119 DeviceFilterList::const_iterator it = aPeer->mDeviceFilters->begin(); 120 while (it != aPeer->mDeviceFilters->end()) 116 121 { 117 122 ComObjPtr <USBDeviceFilter> filter; 118 123 filter.createObject(); 119 124 filter->init (this, *it); 120 m _DeviceFilters->push_back (filter);125 mDeviceFilters->push_back (filter); 121 126 ++ it; 122 127 } 123 128 124 setReady(true); 129 /* Confirm a successful initialization */ 130 autoInitSpan.setSucceeded(); 131 125 132 return S_OK; 126 133 } … … 132 139 * of the original object passed as an argument. 133 140 */ 134 HRESULT USBController::initCopy (Machine *a_pParent, USBController *a_pPeer) 135 { 136 LogFlowMember(("USBController::initCopy (%p, %p)\n", a_pParent, a_pPeer)); 137 138 ComAssertRet (a_pParent && a_pPeer, E_INVALIDARG); 139 140 AutoLock alock(this); 141 ComAssertRet (!isReady(), E_UNEXPECTED); 142 143 m_Parent = a_pParent; 144 // m_Peer is left null 145 146 AutoLock thatlock(a_pPeer); 147 m_Data.attachCopy (a_pPeer->m_Data); 148 149 // create private copies of all filters 150 m_DeviceFilters.allocate(); 151 DeviceFilterList::const_iterator it = a_pPeer->m_DeviceFilters->begin(); 152 while (it != a_pPeer->m_DeviceFilters->end()) 141 HRESULT USBController::initCopy (Machine *aParent, USBController *aPeer) 142 { 143 LogFlowThisFunc (("aParent=%p, aPeer=%p\n", aParent, aPeer)); 144 145 ComAssertRet (aParent && aPeer, E_INVALIDARG); 146 147 /* Enclose the state transition NotReady->InInit->Ready */ 148 AutoInitSpan autoInitSpan (this); 149 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 150 151 unconst (mParent) = aParent; 152 /* mPeer is left null */ 153 154 AutoLock thatlock (aPeer); 155 mData.attachCopy (aPeer->mData); 156 157 /* create private copies of all filters */ 158 mDeviceFilters.allocate(); 159 DeviceFilterList::const_iterator it = aPeer->mDeviceFilters->begin(); 160 while (it != aPeer->mDeviceFilters->end()) 153 161 { 154 162 ComObjPtr <USBDeviceFilter> filter; 155 163 filter.createObject(); 156 164 filter->initCopy (this, *it); 157 m _DeviceFilters->push_back (filter);165 mDeviceFilters->push_back (filter); 158 166 ++ it; 159 167 } 160 168 161 setReady(true); 169 /* Confirm a successful initialization */ 170 autoInitSpan.setSucceeded(); 171 162 172 return S_OK; 163 173 } … … 170 180 void USBController::uninit() 171 181 { 172 LogFlowMember(("USBController::uninit()\n")); 173 174 AutoLock alock(this); 175 AssertReturn (isReady(), (void) 0); 176 177 // uninit all filters (including those still referenced by clients) 182 LogFlowThisFunc (("\n")); 183 184 /* Enclose the state transition Ready->InUninit->NotReady */ 185 AutoUninitSpan autoUninitSpan (this); 186 if (autoUninitSpan.uninitDone()) 187 return; 188 189 /* uninit all filters (including those still referenced by clients) */ 178 190 uninitDependentChildren(); 179 191 180 m_DeviceFilters.free(); 181 m_Data.free(); 182 183 m_Peer.setNull(); 184 m_Parent.setNull(); 185 186 setReady(false); 187 } 188 192 mDeviceFilters.free(); 193 mData.free(); 194 195 unconst (mPeer).setNull(); 196 unconst (mParent).setNull(); 197 } 189 198 190 199 … … 192 201 ///////////////////////////////////////////////////////////////////////////// 193 202 194 STDMETHODIMP USBController::COMGETTER(Enabled) (BOOL *a_pfEnabled)195 { 196 if (!a _pfEnabled)203 STDMETHODIMP USBController::COMGETTER(Enabled) (BOOL *aEnabled) 204 { 205 if (!aEnabled) 197 206 return E_POINTER; 198 207 199 AutoLock alock(this); 200 CHECK_READY(); 201 202 *a_pfEnabled = m_Data->m_fEnabled; 203 LogFlowMember(("USBController::GetEnabled: returns %p\n", *a_pfEnabled)); 204 return S_OK; 205 } 206 207 208 STDMETHODIMP USBController::COMSETTER(Enabled)(BOOL a_fEnabled) 209 { 210 LogFlowMember(("USBController::SetEnabled: %s\n", a_fEnabled ? "enable" : "disable")); 211 212 AutoLock alock(this); 213 CHECK_READY(); 214 215 CHECK_MACHINE_MUTABILITY (m_Parent); 216 217 if (m_Data->m_fEnabled != a_fEnabled) 218 { 219 m_Data.backup(); 220 m_Data->m_fEnabled = a_fEnabled; 221 222 alock.unlock(); 223 m_Parent->onUSBControllerChange(); 224 } 225 226 return S_OK; 227 } 228 229 /** 230 * Get the USB standard version. 231 * 232 * @param a_pusUSBStandard Where to store the BCD version word. 233 */ 234 STDMETHODIMP USBController::COMGETTER(USBStandard)(USHORT *a_pusUSBStandard) 235 { 236 if (!a_pusUSBStandard) 208 AutoCaller autoCaller (this); 209 CheckComRCReturnRC (autoCaller.rc()); 210 211 AutoReaderLock alock (this); 212 213 *aEnabled = mData->mEnabled; 214 215 LogFlowThisFunc (("returns %RTbool\n", *aEnabled)); 216 217 return S_OK; 218 } 219 220 221 STDMETHODIMP USBController::COMSETTER(Enabled) (BOOL aEnabled) 222 { 223 LogFlowThisFunc (("aEnabled=%RTbool\n", aEnabled)); 224 225 AutoCaller autoCaller (this); 226 CheckComRCReturnRC (autoCaller.rc()); 227 228 AutoLock alock (this); 229 230 CHECK_MACHINE_MUTABILITY (mParent); 231 232 if (mData->mEnabled != aEnabled) 233 { 234 mData.backup(); 235 mData->mEnabled = aEnabled; 236 237 /* leave the lock for safety */ 238 alock.leave(); 239 240 mParent->onUSBControllerChange(); 241 } 242 243 return S_OK; 244 } 245 246 STDMETHODIMP USBController::COMGETTER(USBStandard) (USHORT *aUSBStandard) 247 { 248 if (!aUSBStandard) 237 249 return E_POINTER; 238 250 239 AutoLock alock(this); 240 CHECK_READY(); 241 242 *a_pusUSBStandard = 0x0101; 243 LogFlowMember(("USBController::GetUSBStandard: returns 0x0101\n")); 251 AutoCaller autoCaller (this); 252 CheckComRCReturnRC (autoCaller.rc()); 253 254 /* not accessing data -- no need to lock */ 255 256 *aUSBStandard = 0x0101; 257 258 LogFlowThisFunc (("returns %04hX\n", *aUSBStandard)); 259 244 260 return S_OK; 245 261 } … … 250 266 return E_POINTER; 251 267 252 AutoLock lock(this); 253 CHECK_READY(); 268 AutoCaller autoCaller (this); 269 CheckComRCReturnRC (autoCaller.rc()); 270 271 AutoReaderLock alock (this); 254 272 255 273 ComObjPtr <USBDeviceFilterCollection> collection; 256 274 collection.createObject(); 257 collection->init (*m _DeviceFilters.data());275 collection->init (*mDeviceFilters.data()); 258 276 collection.queryInterfaceTo (aDevicesFilters); 277 259 278 return S_OK; 260 279 } … … 272 291 return E_INVALIDARG; 273 292 274 AutoLock lock (this); 275 CHECK_READY(); 276 277 CHECK_MACHINE_MUTABILITY (m_Parent); 293 AutoCaller autoCaller (this); 294 CheckComRCReturnRC (autoCaller.rc()); 295 296 AutoLock alock (this); 297 298 CHECK_MACHINE_MUTABILITY (mParent); 278 299 279 300 ComObjPtr <USBDeviceFilter> filter; 280 301 filter.createObject(); 281 302 HRESULT rc = filter->init (this, aName); 282 ComAssertComRCRet (rc,rc);303 ComAssertComRCRetRC (rc); 283 304 rc = filter.queryInterfaceTo (aFilter); 284 AssertComRCReturn (rc, rc); 305 AssertComRCReturnRC (rc); 306 285 307 return S_OK; 286 308 } … … 292 314 return E_INVALIDARG; 293 315 294 Auto Lock lock(this);295 C HECK_READY();316 AutoCaller autoCaller (this); 317 CheckComRCReturnRC (autoCaller.rc()); 296 318 297 319 /* the machine needs to be mutable */ 298 Machine::AutoStateDependency <Machine::MutableStateDep> adep (m _Parent);320 Machine::AutoStateDependency <Machine::MutableStateDep> adep (mParent); 299 321 CheckComRCReturnRC (adep.rc()); 322 323 AutoLock alock (this); 300 324 301 325 ComObjPtr <USBDeviceFilter> filter = getDependentChild (aFilter); … … 310 334 311 335 /* backup the list before modification */ 312 m _DeviceFilters.backup();336 mDeviceFilters.backup(); 313 337 314 338 /* iterate to the position... */ 315 339 DeviceFilterList::iterator it; 316 if (aPosition < m _DeviceFilters->size())317 { 318 it = m _DeviceFilters->begin();340 if (aPosition < mDeviceFilters->size()) 341 { 342 it = mDeviceFilters->begin(); 319 343 std::advance (it, aPosition); 320 344 } 321 345 else 322 it = m _DeviceFilters->end();346 it = mDeviceFilters->end(); 323 347 /* ...and insert */ 324 m _DeviceFilters->insert (it, filter);348 mDeviceFilters->insert (it, filter); 325 349 filter->mInList = true; 326 350 … … 335 359 #endif 336 360 { 337 USBProxyService *service = m _Parent->virtualBox()->host()->usbProxyService();361 USBProxyService *service = mParent->virtualBox()->host()->usbProxyService(); 338 362 ComAssertRet (service, E_FAIL); 339 363 … … 351 375 return E_POINTER; 352 376 353 Auto Lock lock(this);354 C HECK_READY();377 AutoCaller autoCaller (this); 378 CheckComRCReturnRC (autoCaller.rc()); 355 379 356 380 /* the machine needs to be mutable */ 357 Machine::AutoStateDependency <Machine::MutableStateDep> adep (m _Parent);381 Machine::AutoStateDependency <Machine::MutableStateDep> adep (mParent); 358 382 CheckComRCReturnRC (adep.rc()); 359 383 360 if (!m_DeviceFilters->size()) 384 AutoLock alock (this); 385 386 if (!mDeviceFilters->size()) 361 387 return setError (E_INVALIDARG, 362 388 tr ("The USB device filter list is empty")); 363 389 364 if (aPosition >= m _DeviceFilters->size())390 if (aPosition >= mDeviceFilters->size()) 365 391 return setError (E_INVALIDARG, 366 392 tr ("Invalid position: %lu (must be in range [0, %lu])"), 367 aPosition, m _DeviceFilters->size() - 1);393 aPosition, mDeviceFilters->size() - 1); 368 394 369 395 /* backup the list before modification */ 370 m _DeviceFilters.backup();396 mDeviceFilters.backup(); 371 397 372 398 ComObjPtr <USBDeviceFilter> filter; 373 399 { 374 400 /* iterate to the position... */ 375 DeviceFilterList::iterator it = m _DeviceFilters->begin();401 DeviceFilterList::iterator it = mDeviceFilters->begin(); 376 402 std::advance (it, aPosition); 377 403 /* ...get an element from there... */ … … 379 405 /* ...and remove */ 380 406 filter->mInList = false; 381 m _DeviceFilters->erase (it);407 mDeviceFilters->erase (it); 382 408 } 383 409 … … 397 423 #endif 398 424 { 399 USBProxyService *service = m _Parent->virtualBox()->host()->usbProxyService();425 USBProxyService *service = mParent->virtualBox()->host()->usbProxyService(); 400 426 ComAssertRet (service, E_FAIL); 401 427 … … 411 437 ///////////////////////////////////////////////////////////////////////////// 412 438 413 /** Loads settings from the configuration node */ 439 /** 440 * Loads settings from the configuration node. 441 * 442 * @note Locks objects for reading! 443 */ 414 444 HRESULT USBController::loadSettings (CFGNODE aMachine) 415 445 { 416 AutoLock lock (this);417 CHECK_READY();418 419 446 ComAssertRet (aMachine, E_FAIL); 447 448 AutoCaller autoCaller (this); 449 CheckComRCReturnRC (autoCaller.rc()); 450 451 AutoLock alock (this); 420 452 421 453 CFGNODE controller = NULL; … … 423 455 Assert (controller); 424 456 425 / / enabled457 /* enabled */ 426 458 bool enabled; 427 459 CFGLDRQueryBool (controller, "enabled", &enabled); 428 m _Data->m_fEnabled = enabled;460 mData->mEnabled = enabled; 429 461 430 462 HRESULT rc = S_OK; … … 466 498 manufacturer, product, serialNumber, 467 499 port, remote); 468 / / error info is set by init() when appropriate500 /* error info is set by init() when appropriate */ 469 501 if (SUCCEEDED (rc)) 470 502 { 471 m _DeviceFilters->push_back (filterObj);503 mDeviceFilters->push_back (filterObj); 472 504 filterObj->mInList = true; 473 505 } … … 481 513 } 482 514 483 /** Saves settings to the configuration node */ 515 /** 516 * Saves settings to the configuration node. 517 * 518 * @note Locks objects for reading! 519 */ 484 520 HRESULT USBController::saveSettings (CFGNODE aMachine) 485 521 { 486 AutoLock lock (this);487 CHECK_READY();488 489 522 ComAssertRet (aMachine, E_FAIL); 490 523 491 // first, delete the entry 524 AutoCaller autoCaller (this); 525 CheckComRCReturnRC (autoCaller.rc()); 526 527 AutoReaderLock alock (this); 528 529 /* first, delete the entry */ 492 530 CFGNODE controller = NULL; 493 531 int vrc = CFGLDRGetChildNode (aMachine, "USBController", 0, &controller); … … 497 535 ComAssertRCRet (vrc, E_FAIL); 498 536 } 499 / / then, recreate it537 /* then, recreate it */ 500 538 vrc = CFGLDRCreateChildNode (aMachine, "USBController", &controller); 501 539 ComAssertRCRet (vrc, E_FAIL); 502 540 503 / / enabled504 CFGLDRSetBool (controller, "enabled", !!m _Data->m_fEnabled);505 506 DeviceFilterList::const_iterator it = m _DeviceFilters->begin();507 while (it != m _DeviceFilters->end())541 /* enabled */ 542 CFGLDRSetBool (controller, "enabled", !!mData->mEnabled); 543 544 DeviceFilterList::const_iterator it = mDeviceFilters->begin(); 545 while (it != mDeviceFilters->end()) 508 546 { 509 547 AutoLock filterLock (*it); … … 516 554 CFGLDRSetBool (filter, "active", !!data.mActive); 517 555 518 / / all are optional556 /* all are optional */ 519 557 if (data.mVendorId.string()) 520 558 CFGLDRSetBSTR (filter, "vendorid", data.mVendorId.string()); … … 544 582 } 545 583 584 /** @note Locks objects for reading! */ 546 585 bool USBController::isModified() 547 586 { 548 AutoLock alock(this); 549 550 if (m_Data.isBackedUp() || m_DeviceFilters.isBackedUp()) 587 AutoCaller autoCaller (this); 588 AssertComRCReturn (autoCaller.rc(), false); 589 590 AutoReaderLock alock (this); 591 592 if (mData.isBackedUp() || mDeviceFilters.isBackedUp()) 551 593 return true; 552 594 553 595 /* see whether any of filters has changed its data */ 554 596 for (DeviceFilterList::const_iterator 555 it = m _DeviceFilters->begin();556 it != m _DeviceFilters->end();597 it = mDeviceFilters->begin(); 598 it != mDeviceFilters->end(); 557 599 ++ it) 558 600 { … … 564 606 } 565 607 608 /** @note Locks objects for reading! */ 566 609 bool USBController::isReallyModified() 567 610 { 568 AutoLock alock(this); 569 570 if (m_Data.hasActualChanges()) 611 AutoCaller autoCaller (this); 612 AssertComRCReturn (autoCaller.rc(), false); 613 614 AutoReaderLock alock (this); 615 616 if (mData.hasActualChanges()) 571 617 return true; 572 618 573 if (!m _DeviceFilters.isBackedUp())619 if (!mDeviceFilters.isBackedUp()) 574 620 { 575 621 /* see whether any of filters has changed its data */ 576 622 for (DeviceFilterList::const_iterator 577 it = m _DeviceFilters->begin();578 it != m _DeviceFilters->end();623 it = mDeviceFilters->begin(); 624 it != mDeviceFilters->end(); 579 625 ++ it) 580 626 { … … 586 632 } 587 633 588 if (m _DeviceFilters->size() != m_DeviceFilters.backedUpData()->size())634 if (mDeviceFilters->size() != mDeviceFilters.backedUpData()->size()) 589 635 return true; 590 636 591 if (m _DeviceFilters->size() == 0)637 if (mDeviceFilters->size() == 0) 592 638 return false; 593 639 594 640 /* Make copies to speed up comparison */ 595 DeviceFilterList devices = *m _DeviceFilters.data();596 DeviceFilterList backDevices = *m _DeviceFilters.backedUpData();641 DeviceFilterList devices = *mDeviceFilters.data(); 642 DeviceFilterList backDevices = *mDeviceFilters.backedUpData(); 597 643 598 644 DeviceFilterList::iterator it = devices.begin(); … … 623 669 } 624 670 671 /** @note Locks objects for writing! */ 625 672 bool USBController::rollback() 626 673 { 674 AutoCaller autoCaller (this); 675 AssertComRCReturn (autoCaller.rc(), false); 676 677 /* we need the machine state */ 678 Machine::AutoStateDependency <Machine::MutableStateDep> adep (mParent); 679 AssertComRCReturn (adep.rc(), false); 680 627 681 AutoLock alock (this); 628 682 629 /* we need the machine state */630 Machine::AutoStateDependency <Machine::MutableStateDep> adep (m_Parent);631 AssertComRCReturn (adep.rc(), false);632 633 683 bool dataChanged = false; 634 684 635 if (m _Data.isBackedUp())685 if (mData.isBackedUp()) 636 686 { 637 687 /* we need to check all data to see whether anything will be changed 638 688 * after rollback */ 639 dataChanged = m _Data.hasActualChanges();640 m _Data.rollback();641 } 642 643 if (m _DeviceFilters.isBackedUp())644 { 645 USBProxyService *service = m _Parent->virtualBox()->host()->usbProxyService();689 dataChanged = mData.hasActualChanges(); 690 mData.rollback(); 691 } 692 693 if (mDeviceFilters.isBackedUp()) 694 { 695 USBProxyService *service = mParent->virtualBox()->host()->usbProxyService(); 646 696 ComAssertRet (service, false); 647 697 648 698 /* uninitialize all new filters (absent in the backed up list) */ 649 DeviceFilterList::const_iterator it = m _DeviceFilters->begin();650 DeviceFilterList *backedList = m _DeviceFilters.backedUpData();651 while (it != m _DeviceFilters->end())699 DeviceFilterList::const_iterator it = mDeviceFilters->begin(); 700 DeviceFilterList *backedList = mDeviceFilters.backedUpData(); 701 while (it != mDeviceFilters->end()) 652 702 { 653 703 if (std::find (backedList->begin(), backedList->end(), *it) == … … 688 738 while (it != backedList->end()) 689 739 { 690 if (std::find (m _DeviceFilters->begin(), m_DeviceFilters->end(), *it) ==691 m _DeviceFilters->end())740 if (std::find (mDeviceFilters->begin(), mDeviceFilters->end(), *it) == 741 mDeviceFilters->end()) 692 742 { 693 743 /* notify the proxy (only when necessary) */ … … 705 755 706 756 /* restore the list */ 707 m _DeviceFilters.rollback();757 mDeviceFilters.rollback(); 708 758 } 709 759 … … 712 762 713 763 /* rollback any changes to filters after restoring the list */ 714 DeviceFilterList::const_iterator it = m _DeviceFilters->begin();715 while (it != m _DeviceFilters->end())764 DeviceFilterList::const_iterator it = mDeviceFilters->begin(); 765 while (it != mDeviceFilters->end()) 716 766 { 717 767 if ((*it)->isModified()) … … 727 777 } 728 778 779 /** @note Locks objects for writing! */ 729 780 void USBController::commit() 730 781 { 782 AutoCaller autoCaller (this); 783 AssertComRCReturnVoid (autoCaller.rc()); 784 731 785 AutoLock alock (this); 732 786 733 if (m _Data.isBackedUp())734 { 735 m _Data.commit();736 if (m _Peer)787 if (mData.isBackedUp()) 788 { 789 mData.commit(); 790 if (mPeer) 737 791 { 738 792 // attach new data to the peer and reshare it 739 AutoLock peerlock (m _Peer);740 m _Peer->m_Data.attach (m_Data);793 AutoLock peerlock (mPeer); 794 mPeer->mData.attach (mData); 741 795 } 742 796 } … … 744 798 bool commitFilters = false; 745 799 746 if (m _DeviceFilters.isBackedUp())747 { 748 m _DeviceFilters.commit();800 if (mDeviceFilters.isBackedUp()) 801 { 802 mDeviceFilters.commit(); 749 803 750 804 // apply changes to peer 751 if (m _Peer)752 { 753 AutoLock peerlock (m _Peer);805 if (mPeer) 806 { 807 AutoLock peerlock (mPeer); 754 808 // commit all changes to new filters (this will reshare data with 755 809 // peers for those who have peers) 756 810 DeviceFilterList *newList = new DeviceFilterList(); 757 DeviceFilterList::const_iterator it = m _DeviceFilters->begin();758 while (it != m _DeviceFilters->end())811 DeviceFilterList::const_iterator it = mDeviceFilters->begin(); 812 while (it != mDeviceFilters->end()) 759 813 { 760 814 (*it)->commit(); … … 767 821 // create a peer owning data this filter share it with 768 822 peer.createObject(); 769 peer->init (m _Peer, *it, true /* aReshare */);823 peer->init (mPeer, *it, true /* aReshare */); 770 824 } 771 825 else 772 826 { 773 827 // remove peer from the old list 774 m _Peer->m_DeviceFilters->remove (peer);828 mPeer->mDeviceFilters->remove (peer); 775 829 } 776 830 // and add it to the new list … … 781 835 782 836 // uninit old peer's filters that are left 783 it = m _Peer->m_DeviceFilters->begin();784 while (it != m _Peer->m_DeviceFilters->end())837 it = mPeer->mDeviceFilters->begin(); 838 while (it != mPeer->mDeviceFilters->end()) 785 839 { 786 840 (*it)->uninit(); … … 789 843 790 844 // attach new list of filters to our peer 791 m _Peer->m_DeviceFilters.attach (newList);845 mPeer->mDeviceFilters.attach (newList); 792 846 } 793 847 else … … 807 861 if (commitFilters) 808 862 { 809 DeviceFilterList::const_iterator it = m _DeviceFilters->begin();810 while (it != m _DeviceFilters->end())863 DeviceFilterList::const_iterator it = mDeviceFilters->begin(); 864 while (it != mDeviceFilters->end()) 811 865 { 812 866 (*it)->commit(); … … 816 870 } 817 871 872 /** @note Locks object for writing and that object for reading! */ 818 873 void USBController::copyFrom (USBController *aThat) 819 874 { 820 AutoLock alock (this); 821 AutoLock thatLock (aThat); 822 823 if (m_Parent->isRegistered()) 824 { 825 // reuse onMachineRegistered to tell USB proxy to remove all current filters 875 AutoCaller autoCaller (this); 876 AssertComRCReturnVoid (autoCaller.rc()); 877 878 AutoMultiLock <2> alock (this->wlock(), aThat->rlock()); 879 880 if (mParent->isRegistered()) 881 { 882 /* reuse onMachineRegistered to tell USB proxy to remove all current 883 filters */ 826 884 HRESULT rc = onMachineRegistered (FALSE); 827 885 AssertComRCReturn (rc, (void) 0); 828 886 } 829 887 830 / / this will back up current data831 m _Data.assignCopy (aThat->m_Data);832 833 / / create private copies of all filters834 m _DeviceFilters.backup();835 m _DeviceFilters->clear();836 for (DeviceFilterList::const_iterator it = aThat->m _DeviceFilters->begin();837 it != aThat->m _DeviceFilters->end();888 /* this will back up current data */ 889 mData.assignCopy (aThat->mData); 890 891 /* create private copies of all filters */ 892 mDeviceFilters.backup(); 893 mDeviceFilters->clear(); 894 for (DeviceFilterList::const_iterator it = aThat->mDeviceFilters->begin(); 895 it != aThat->mDeviceFilters->end(); 838 896 ++ it) 839 897 { … … 841 899 filter.createObject(); 842 900 filter->initCopy (this, *it); 843 m_DeviceFilters->push_back (filter); 844 } 845 846 if (m_Parent->isRegistered()) 847 { 848 // reuse onMachineRegistered to tell USB proxy to insert all current filters 901 mDeviceFilters->push_back (filter); 902 } 903 904 if (mParent->isRegistered()) 905 { 906 /* reuse onMachineRegistered to tell USB proxy to insert all current 907 filters */ 849 908 HRESULT rc = onMachineRegistered (TRUE); 850 909 AssertComRCReturn (rc, (void) 0); … … 857 916 * 858 917 * @param aRegistered new registered state of the machine 918 * 919 * @note Locks nothing. 859 920 */ 860 921 HRESULT USBController::onMachineRegistered (BOOL aRegistered) 861 922 { 862 Auto Lock alock(this);863 CHECK_READY();923 AutoCaller autoCaller (this); 924 AssertComRCReturnRC (autoCaller.rc()); 864 925 865 926 /// @todo After rewriting Win32 USB support, no more necessary; … … 874 935 /** 875 936 * Called by setter methods of all USB device filters. 937 * 938 * @note Locks nothing. 876 939 */ 877 940 HRESULT USBController::onDeviceFilterChange (USBDeviceFilter *aFilter, 878 941 BOOL aActiveChanged /* = FALSE */) 879 942 { 880 Auto Lock alock(this);881 CHECK_READY();943 AutoCaller autoCaller (this); 944 AssertComRCReturnRC (autoCaller.rc()); 882 945 883 946 /// @todo After rewriting Win32 USB support, no more necessary; … … 886 949 #else 887 950 /* we need the machine state */ 888 Machine::AutoStateDependency <Machine::MutableStateDep> adep (m _Parent);951 Machine::AutoStateDependency <Machine::MutableStateDep> adep (mParent); 889 952 AssertComRCReturnRC (adep.rc()); 890 953 … … 894 957 #endif 895 958 896 if (aFilter->mInList && m_Parent->isRegistered()) 897 { 898 USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService(); 959 /* we don't modify our data fields -- no need to lock */ 960 961 if (aFilter->mInList && mParent->isRegistered()) 962 { 963 USBProxyService *service = mParent->virtualBox()->host()->usbProxyService(); 899 964 ComAssertRet (service, E_FAIL); 900 965 … … 936 1001 * 937 1002 * A HostUSBDevice specific version. 1003 * 1004 * @note Locks this object for reading. 938 1005 */ 939 1006 bool USBController::hasMatchingFilter (ComObjPtr <HostUSBDevice> &aDevice) 940 1007 { 941 AutoLock alock (this); 942 if (!isReady()) 943 return false; 1008 AutoCaller autoCaller (this); 1009 AssertComRCReturn (autoCaller.rc(), false); 1010 1011 AutoReaderLock alock (this); 944 1012 945 1013 bool match = false; 946 1014 947 / / apply self filters948 for (DeviceFilterList::const_iterator it = m _DeviceFilters->begin();949 !match && it != m _DeviceFilters->end();1015 /* apply self filters */ 1016 for (DeviceFilterList::const_iterator it = mDeviceFilters->begin(); 1017 !match && it != mDeviceFilters->end(); 950 1018 ++ it) 951 1019 { … … 966 1034 * This method MUST correlate with HostUSBDevice::isMatch() 967 1035 * in the sense of the device matching logic. 1036 * 1037 * @note Locks this object for reading. 968 1038 */ 969 1039 bool USBController::hasMatchingFilter (IUSBDevice *aUSBDevice) 970 1040 { 971 LogFlowThisFunc (("\n")); 972 973 AutoLock alock (this); 974 if (!isReady()) 975 return false; 1041 LogFlowThisFuncEnter(); 1042 1043 AutoCaller autoCaller (this); 1044 AssertComRCReturn (autoCaller.rc(), false); 1045 1046 AutoReaderLock alock (this); 976 1047 977 1048 HRESULT rc = S_OK; 978 1049 979 / / query fields1050 /* query fields */ 980 1051 981 1052 USHORT vendorId = 0; … … 1020 1091 bool match = false; 1021 1092 1022 / / apply self filters1023 for (DeviceFilterList::const_iterator it = m _DeviceFilters->begin();1024 it != m _DeviceFilters->end();1093 /* apply self filters */ 1094 for (DeviceFilterList::const_iterator it = mDeviceFilters->begin(); 1095 it != mDeviceFilters->end(); 1025 1096 ++ it) 1026 1097 { … … 1038 1109 1039 1110 #if !defined (__WIN__) 1040 / / these filters are temporarily ignored on Win321111 /* these filters are temporarily ignored on Win32 */ 1041 1112 if (!aData.mManufacturer.isMatch (manufacturer)) 1042 1113 continue; … … 1056 1127 } 1057 1128 1058 LogFlowMember (("USBController::hasMatchingFilter() returns: %d\n", match)); 1129 LogFlowThisFunc (("returns: %d\n", match)); 1130 LogFlowThisFuncLeave(); 1131 1059 1132 return match; 1060 1133 } 1061 1134 1135 /** 1136 * Notifies the proxy service about all filters as requested by the 1137 * @a aInsertFilters argument. 1138 * 1139 * @param aInsertFilters @c true to insert filters, @c false to remove. 1140 * 1141 * @note Locks this object for reading. 1142 */ 1062 1143 HRESULT USBController::notifyProxy (bool aInsertFilters) 1063 1144 { 1064 1145 LogFlowThisFunc (("aInsertFilters=%RTbool\n", aInsertFilters)); 1065 1146 1066 AutoLock alock (this); 1067 if (!isReady()) 1068 return false; 1069 1070 USBProxyService *service = m_Parent->virtualBox()->host()->usbProxyService(); 1147 AutoCaller autoCaller (this); 1148 AssertComRCReturn (autoCaller.rc(), false); 1149 1150 AutoReaderLock alock (this); 1151 1152 USBProxyService *service = mParent->virtualBox()->host()->usbProxyService(); 1071 1153 AssertReturn (service, E_FAIL); 1072 1154 1073 DeviceFilterList::const_iterator it = m _DeviceFilters->begin();1074 while (it != m _DeviceFilters->end())1155 DeviceFilterList::const_iterator it = mDeviceFilters->begin(); 1156 while (it != mDeviceFilters->end()) 1075 1157 { 1076 1158 USBDeviceFilter *flt = *it; /* resolve ambiguity (for ComPtr below) */ -
trunk/src/VBox/Main/include/USBControllerImpl.h
r2805 r2845 33 33 class HostUSBDevice; 34 34 35 /** 36 * @note we cannot use VirtualBoxBaseWithTypedChildren <USBDeviceFilter> as a 37 * base class, because we want a quick (map-based) way of validating 38 * IUSBDeviceFilter pointers passed from outside as method parameters that 39 * VirtualBoxBaseWithChildren::getDependentChild() gives us. 40 */ 41 35 42 class ATL_NO_VTABLE USBController : 36 public VirtualBoxBaseWithChildren ,37 public VirtualBoxSupportErrorInfoImpl <USBController, IUSBController>,38 public VirtualBoxSupportTranslation <USBController>,43 public VirtualBoxBaseWithChildrenNEXT, 44 public VirtualBoxSupportErrorInfoImpl <USBController, IUSBController>, 45 public VirtualBoxSupportTranslation <USBController>, 39 46 public IUSBController 40 47 { … … 44 51 { 45 52 /* Constructor. */ 46 Data() : m _fEnabled(FALSE) { }53 Data() : mEnabled (FALSE) { } 47 54 48 55 bool operator== (const Data &that) const 49 56 { 50 return this == &that || m _fEnabled == that.m_fEnabled;57 return this == &that || mEnabled == that.mEnabled; 51 58 } 52 59 53 60 /** Enabled indicator. */ 54 BOOL m_fEnabled;61 BOOL mEnabled; 55 62 }; 56 63 57 64 public: 58 65 59 DECLARE_NOT_AGGREGATABLE(USBController) 66 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (USBController) 67 68 DECLARE_NOT_AGGREGATABLE (USBController) 60 69 61 70 DECLARE_PROTECT_FINAL_CONSTRUCT() 62 71 63 72 BEGIN_COM_MAP(USBController) 64 COM_INTERFACE_ENTRY (ISupportErrorInfo)65 COM_INTERFACE_ENTRY (IUSBController)73 COM_INTERFACE_ENTRY (ISupportErrorInfo) 74 COM_INTERFACE_ENTRY (IUSBController) 66 75 END_COM_MAP() 67 76 68 77 NS_DECL_ISUPPORTS 78 79 DECLARE_EMPTY_CTOR_DTOR (USBController) 69 80 70 81 HRESULT FinalConstruct(); … … 72 83 73 84 // public initializer/uninitializer for internal purposes only 74 HRESULT init (Machine * parent);75 HRESULT init (Machine * parent, USBController *that);76 HRESULT initCopy (Machine * parent, USBController *that);85 HRESULT init (Machine *aParent); 86 HRESULT init (Machine *aParent, USBController *aThat); 87 HRESULT initCopy (Machine *aParent, USBController *aThat); 77 88 void uninit(); 78 89 79 90 // IUSBController properties 80 STDMETHOD(COMGETTER(Enabled)) (BOOL *a_pfEnabled);81 STDMETHOD(COMSETTER(Enabled)) (BOOL a_fEnabled);82 STDMETHOD(COMGETTER(USBStandard)) (USHORT *a_pusUSBStandard);83 STDMETHOD(COMGETTER(DeviceFilters)) (IUSBDeviceFilterCollection **aDevicesFilters);91 STDMETHOD(COMGETTER(Enabled)) (BOOL *aEnabled); 92 STDMETHOD(COMSETTER(Enabled)) (BOOL aEnabled); 93 STDMETHOD(COMGETTER(USBStandard)) (USHORT *aUSBStandard); 94 STDMETHOD(COMGETTER(DeviceFilters)) (IUSBDeviceFilterCollection **aDevicesFilters); 84 95 85 96 // IUSBController methods … … 90 101 // public methods only for internal purposes 91 102 92 ComObjPtr <Machine, ComWeakRef> &parent() { return m_Parent; };103 const ComObjPtr <Machine, ComWeakRef> &parent() { return mParent; }; 93 104 94 105 HRESULT loadSettings (CFGNODE aMachine); … … 101 112 void copyFrom (USBController *aThat); 102 113 103 const Backupable<Data> &data() { return m _Data; }114 const Backupable<Data> &data() { return mData; } 104 115 105 116 HRESULT onMachineRegistered (BOOL aRegistered); … … 130 141 131 142 /** Parent object. */ 132 ComObjPtr<Machine, ComWeakRef> m_Parent;143 const ComObjPtr<Machine, ComWeakRef> mParent; 133 144 /** Peer object. */ 134 ComObjPtr<USBController> m_Peer;145 const ComObjPtr <USBController> mPeer; 135 146 /** Data. */ 136 Backupable <Data> m_Data;147 Backupable <Data> mData; 137 148 138 149 // the following fields need special backup/rollback/commit handling, … … 140 151 141 152 typedef std::list <ComObjPtr <USBDeviceFilter> > DeviceFilterList; 142 Backupable <DeviceFilterList> m _DeviceFilters;153 Backupable <DeviceFilterList> mDeviceFilters; 143 154 }; 144 155
Note:
See TracChangeset
for help on using the changeset viewer.