- Timestamp:
- Jul 4, 2007 11:25:35 AM (17 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
-
USBDeviceFilterImpl.cpp (modified) (87 diffs)
-
include/USBControllerImpl.h (modified) (3 diffs)
-
include/USBDeviceFilterImpl.h (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/USBDeviceFilterImpl.cpp
r2981 r3412 27 27 #include "Logging.h" 28 28 29 #include <iprt/cpputils.h> 30 29 31 //////////////////////////////////////////////////////////////////////////////// 30 32 // USBDeviceFilter … … 34 36 //////////////////////////////////////////////////////////////////////////////// 35 37 38 DEFINE_EMPTY_CTOR_DTOR (USBDeviceFilter) 39 36 40 HRESULT USBDeviceFilter::FinalConstruct() 37 41 { … … 48 52 49 53 /** 50 * Initializes the USB device filter object. 54 * Initializes the USB device filter object. 55 * 56 * @param aParent Handle of the parent object. 51 57 */ 52 58 HRESULT USBDeviceFilter::init (USBController *aParent, … … 58 64 INPTR BSTR aPort, INPTR BSTR aRemote) 59 65 { 60 LogFlow Member (("USBDeviceFilter::init (%p)\n", aParent));66 LogFlowThisFunc (("aParent=%p\n", aParent)); 61 67 62 68 ComAssertRet (aParent && aName && *aName, E_INVALIDARG); 63 69 64 AutoLock alock (this); 65 ComAssertRet (!isReady(), E_UNEXPECTED); 66 67 mParent = aParent; 70 /* Enclose the state transition NotReady->InInit->Ready */ 71 AutoInitSpan autoInitSpan (this); 72 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 73 74 unconst (mParent) = aParent; 75 /* mPeer is left null */ 76 77 /* register with parent early, since uninit() will unconditionally 78 * unregister on failure */ 79 mParent->addDependentChild (this); 68 80 69 81 mData.allocate(); … … 71 83 mData->mActive = aActive; 72 84 73 / / initialize all filters to any match using null string85 /* initialize all filters to any match using null string */ 74 86 mData->mVendorId = NULL; 75 87 mData->mProductId = NULL; … … 83 95 mInList = false; 84 96 85 // use setters for the attributes below to reuse parsing errors handling 86 setReady (true); 97 /* use setters for the attributes below to reuse parsing errors 98 * handling */ 99 87 100 HRESULT rc = S_OK; 88 101 do 89 102 { 90 103 rc = COMSETTER(VendorId) (aVendorId); 91 if (FAILED (rc)) 92 break; 104 CheckComRCBreakRC (rc); 93 105 rc = COMSETTER(ProductId) (aProductId); 94 if (FAILED (rc)) 95 break; 106 CheckComRCBreakRC (rc); 96 107 rc = COMSETTER(Revision) (aRevision); 97 if (FAILED (rc)) 98 break; 108 CheckComRCBreakRC (rc); 99 109 rc = COMSETTER(Manufacturer) (aManufacturer); 100 if (FAILED (rc)) 101 break; 110 CheckComRCBreakRC (rc); 102 111 rc = COMSETTER(Product) (aProduct); 103 if (FAILED (rc)) 104 break; 112 CheckComRCBreakRC (rc); 105 113 rc = COMSETTER(SerialNumber) (aSerialNumber); 106 if (FAILED (rc)) 107 break; 114 CheckComRCBreakRC (rc); 108 115 rc = COMSETTER(Port) (aPort); 109 if (FAILED (rc)) 110 break; 116 CheckComRCBreakRC (rc); 111 117 rc = COMSETTER(Remote) (aRemote); 112 if (FAILED (rc)) 113 break; 118 CheckComRCBreakRC (rc); 114 119 } 115 120 while (0); 116 121 122 /* Confirm successful initialization when it's the case */ 117 123 if (SUCCEEDED (rc)) 118 mParent->addDependentChild (this); 119 else 120 setReady (false); 124 autoInitSpan.setSucceeded(); 121 125 122 126 return rc; … … 124 128 125 129 /** 126 * Initializes the USB device filter object (short version). 130 * Initializes the USB device filter object (short version). 131 * 132 * @param aParent Handle of the parent object. 127 133 */ 128 134 HRESULT USBDeviceFilter::init (USBController *aParent, INPTR BSTR aName) 129 135 { 130 LogFlow Member (("USBDeviceFilter::init (%p) [short]\n", aParent));136 LogFlowThisFunc (("aParent=%p\n", aParent)); 131 137 132 138 ComAssertRet (aParent && aName && *aName, E_INVALIDARG); 133 139 134 AutoLock alock (this); 135 ComAssertRet (!isReady(), E_UNEXPECTED); 136 137 mParent = aParent; 138 // mPeer is left null 140 /* Enclose the state transition NotReady->InInit->Ready */ 141 AutoInitSpan autoInitSpan (this); 142 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 143 144 unconst (mParent) = aParent; 145 /* mPeer is left null */ 146 147 /* register with parent early, since uninit() will unconditionally 148 * unregister on failure */ 149 mParent->addDependentChild (this); 139 150 140 151 mData.allocate(); … … 143 154 mData->mActive = FALSE; 144 155 145 / / initialize all filters to any match using null string156 /* initialize all filters to any match using null string */ 146 157 mData->mVendorId = NULL; 147 158 mData->mProductId = NULL; … … 155 166 mInList = false; 156 167 157 mParent->addDependentChild (this);158 159 setReady (true); 168 /* Confirm successful initialization */ 169 autoInitSpan.setSucceeded(); 170 160 171 return S_OK; 161 172 } … … 173 184 * @note This object must be destroyed before the original object 174 185 * it shares data with is destroyed. 186 * 187 * @note Locks @a aThat object for writing if @a aReshare is @c true, or for 188 * reading if @a aReshare is false. 175 189 */ 176 190 HRESULT USBDeviceFilter::init (USBController *aParent, USBDeviceFilter *aThat, 177 191 bool aReshare /* = false */) 178 192 { 179 LogFlow Member (("USBDeviceFilter::init (%p, %p): aReshare=%d\n",180 aParent, aThat, aReshare));193 LogFlowThisFunc (("aParent=%p, aThat=%p, aReshare=%RTbool\n", 194 aParent, aThat, aReshare)); 181 195 182 196 ComAssertRet (aParent && aThat, E_INVALIDARG); 183 197 184 AutoLock alock (this); 185 ComAssertRet (!isReady(), E_UNEXPECTED); 186 187 mParent = aParent; 188 189 AutoLock thatlock (aThat); 198 /* Enclose the state transition NotReady->InInit->Ready */ 199 AutoInitSpan autoInitSpan (this); 200 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 201 202 unconst (mParent) = aParent; 203 204 /* register with parent early, since uninit() will unconditionally 205 * unregister on failure */ 206 mParent->addDependentChild (this); 207 208 /* sanity */ 209 AutoCaller thatCaller (aThat); 210 AssertComRCReturnRC (thatCaller.rc()); 211 190 212 if (aReshare) 191 213 { 192 aThat->mPeer = this; 214 AutoLock thatLock (aThat); 215 216 unconst (aThat->mPeer) = this; 193 217 mData.attach (aThat->mData); 194 218 } 195 219 else 196 220 { 197 mPeer = aThat; 221 unconst (mPeer) = aThat; 222 223 AutoReaderLock thatLock (aThat); 198 224 mData.share (aThat->mData); 199 225 } 200 226 201 / /the arbitrary ID field is not reset because202 // the copy is a shadow of the original227 /* the arbitrary ID field is not reset because 228 * the copy is a shadow of the original */ 203 229 204 230 mInList = aThat->mInList; 205 231 206 mParent->addDependentChild (this);207 208 setReady (true); 232 /* Confirm successful initialization */ 233 autoInitSpan.setSucceeded(); 234 209 235 return S_OK; 210 236 } … … 214 240 * (a kind of copy constructor). This object makes a private copy of data 215 241 * of the original object passed as an argument. 242 * 243 * @note Locks @a aThat object for reading. 216 244 */ 217 245 HRESULT USBDeviceFilter::initCopy (USBController *aParent, USBDeviceFilter *aThat) 218 246 { 219 LogFlow Member (("USBDeviceFilter::initCopy (%p, %p)\n", aParent, aThat));247 LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat)); 220 248 221 249 ComAssertRet (aParent && aThat, E_INVALIDARG); 222 250 223 AutoLock alock (this); 224 ComAssertRet (!isReady(), E_UNEXPECTED); 225 226 mParent = aParent; 227 // mPeer is left null 228 229 AutoLock thatlock (aThat); 251 /* Enclose the state transition NotReady->InInit->Ready */ 252 AutoInitSpan autoInitSpan (this); 253 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 254 255 unconst (mParent) = aParent; 256 /* mPeer is left null */ 257 258 /* register with parent early, since uninit() will unconditionally 259 * unregister on failure */ 260 mParent->addDependentChild (this); 261 262 /* sanity */ 263 AutoCaller thatCaller (aThat); 264 AssertComRCReturnRC (thatCaller.rc()); 265 266 AutoReaderLock thatLock (aThat); 230 267 mData.attachCopy (aThat->mData); 231 268 232 / /reset the arbitrary ID field233 //(this field is something unique that two distinct objects, even if they234 // are deep copies of each other, should not share)269 /* reset the arbitrary ID field 270 * (this field is something unique that two distinct objects, even if they 271 * are deep copies of each other, should not share) */ 235 272 mData->mId = NULL; 236 273 237 274 mInList = aThat->mInList; 238 275 239 mParent->addDependentChild (this);240 241 setReady (true); 276 /* Confirm successful initialization */ 277 autoInitSpan.setSucceeded(); 278 242 279 return S_OK; 243 280 } … … 249 286 void USBDeviceFilter::uninit() 250 287 { 251 LogFlowMember (("USBDeviceFilter::uninit()\n")); 252 253 AutoLock alock (this); 254 255 LogFlowMember (("USBDeviceFilter::uninit(): isReady=%d\n", isReady())); 256 257 if (!isReady()) 288 LogFlowThisFunc (("\n")); 289 290 /* Enclose the state transition Ready->InUninit->NotReady */ 291 AutoUninitSpan autoUninitSpan (this); 292 if (autoUninitSpan.uninitDone()) 258 293 return; 259 294 … … 262 297 mData.free(); 263 298 264 setReady (false);265 266 alock.leave();267 299 mParent->removeDependentChild (this); 268 alock.enter(); 269 270 mPeer.setNull(); 271 mParent.setNull(); 300 301 unconst (mPeer).setNull(); 302 unconst (mParent).setNull(); 272 303 } 273 304 … … 280 311 return E_POINTER; 281 312 282 AutoLock alock (this); 283 CHECK_READY(); 313 AutoCaller autoCaller (this); 314 CheckComRCReturnRC (autoCaller.rc()); 315 316 AutoReaderLock alock (this); 284 317 285 318 mData->mName.cloneTo (aName); 319 286 320 return S_OK; 287 321 } … … 292 326 return E_INVALIDARG; 293 327 294 AutoLock alock (this); 295 CHECK_READY(); 296 CHECK_MACHINE_MUTABILITY (mParent->parent()); 328 AutoCaller autoCaller (this); 329 CheckComRCReturnRC (autoCaller.rc()); 330 331 /* the machine needs to be mutable */ 332 Machine::AutoMutableStateDependency adep (mParent->parent()); 333 CheckComRCReturnRC (adep.rc()); 334 335 AutoLock alock (this); 297 336 298 337 if (mData->mName != aName) … … 301 340 mData->mName = aName; 302 341 303 // notify parent 304 alock.unlock(); 342 /* leave the lock before informing callbacks */ 343 alock.unlock(); 344 305 345 return mParent->onDeviceFilterChange (this); 306 346 } … … 314 354 return E_POINTER; 315 355 316 AutoLock alock (this); 317 CHECK_READY(); 356 AutoCaller autoCaller (this); 357 CheckComRCReturnRC (autoCaller.rc()); 358 359 AutoReaderLock alock (this); 318 360 319 361 *aActive = mData->mActive; 362 320 363 return S_OK; 321 364 } … … 323 366 STDMETHODIMP USBDeviceFilter::COMSETTER(Active) (BOOL aActive) 324 367 { 325 AutoLock alock (this); 326 CHECK_READY(); 327 CHECK_MACHINE_MUTABILITY (mParent->parent()); 368 AutoCaller autoCaller (this); 369 CheckComRCReturnRC (autoCaller.rc()); 370 371 /* the machine needs to be mutable */ 372 Machine::AutoMutableStateDependency adep (mParent->parent()); 373 CheckComRCReturnRC (adep.rc()); 374 375 AutoLock alock (this); 328 376 329 377 if (mData->mActive != aActive) … … 332 380 mData->mActive = aActive; 333 381 334 // notify parent 335 alock.unlock(); 382 /* leave the lock before informing callbacks */ 383 alock.unlock(); 384 336 385 return mParent->onDeviceFilterChange (this, TRUE /* aActiveChanged */); 337 386 } … … 345 394 return E_POINTER; 346 395 347 AutoLock alock (this); 348 CHECK_READY(); 396 AutoCaller autoCaller (this); 397 CheckComRCReturnRC (autoCaller.rc()); 398 399 AutoReaderLock alock (this); 349 400 350 401 mData->mVendorId.string().cloneTo (aVendorId); 402 351 403 return S_OK; 352 404 } … … 354 406 STDMETHODIMP USBDeviceFilter::COMSETTER(VendorId) (INPTR BSTR aVendorId) 355 407 { 356 AutoLock alock (this); 357 CHECK_READY(); 358 CHECK_MACHINE_MUTABILITY (mParent->parent()); 408 AutoCaller autoCaller (this); 409 CheckComRCReturnRC (autoCaller.rc()); 410 411 /* the machine needs to be mutable */ 412 Machine::AutoMutableStateDependency adep (mParent->parent()); 413 CheckComRCReturnRC (adep.rc()); 414 415 AutoLock alock (this); 359 416 360 417 if (mData->mVendorId.string() != aVendorId) … … 377 434 mData->mVendorId = flt; 378 435 379 // notify parent 380 alock.unlock(); 436 /* leave the lock before informing callbacks */ 437 alock.unlock(); 438 381 439 return mParent->onDeviceFilterChange (this); 382 440 } … … 390 448 return E_POINTER; 391 449 392 AutoLock alock (this); 393 CHECK_READY(); 450 AutoCaller autoCaller (this); 451 CheckComRCReturnRC (autoCaller.rc()); 452 453 AutoReaderLock alock (this); 394 454 395 455 mData->mProductId.string().cloneTo (aProductId); 456 396 457 return S_OK; 397 458 } … … 399 460 STDMETHODIMP USBDeviceFilter::COMSETTER(ProductId) (INPTR BSTR aProductId) 400 461 { 401 AutoLock alock (this); 402 CHECK_READY(); 403 CHECK_MACHINE_MUTABILITY (mParent->parent()); 462 AutoCaller autoCaller (this); 463 CheckComRCReturnRC (autoCaller.rc()); 464 465 /* the machine needs to be mutable */ 466 Machine::AutoMutableStateDependency adep (mParent->parent()); 467 CheckComRCReturnRC (adep.rc()); 468 469 AutoLock alock (this); 404 470 405 471 if (mData->mProductId.string() != aProductId) … … 422 488 mData->mProductId = flt; 423 489 424 // notify parent 425 alock.unlock(); 490 /* leave the lock before informing callbacks */ 491 alock.unlock(); 492 426 493 return mParent->onDeviceFilterChange (this); 427 494 } … … 435 502 return E_POINTER; 436 503 437 AutoLock alock (this); 438 CHECK_READY(); 504 AutoCaller autoCaller (this); 505 CheckComRCReturnRC (autoCaller.rc()); 506 507 AutoReaderLock alock (this); 439 508 440 509 mData->mRevision.string().cloneTo (aRevision); 510 441 511 return S_OK; 442 512 } … … 444 514 STDMETHODIMP USBDeviceFilter::COMSETTER(Revision) (INPTR BSTR aRevision) 445 515 { 446 AutoLock alock (this); 447 CHECK_READY(); 448 CHECK_MACHINE_MUTABILITY (mParent->parent()); 516 AutoCaller autoCaller (this); 517 CheckComRCReturnRC (autoCaller.rc()); 518 519 /* the machine needs to be mutable */ 520 Machine::AutoMutableStateDependency adep (mParent->parent()); 521 CheckComRCReturnRC (adep.rc()); 522 523 AutoLock alock (this); 449 524 450 525 if (mData->mRevision.string() != aRevision) … … 467 542 mData->mRevision = flt; 468 543 469 // notify parent 470 alock.unlock(); 544 /* leave the lock before informing callbacks */ 545 alock.unlock(); 546 471 547 return mParent->onDeviceFilterChange (this); 472 548 } … … 480 556 return E_POINTER; 481 557 482 AutoLock alock (this); 483 CHECK_READY(); 558 AutoCaller autoCaller (this); 559 CheckComRCReturnRC (autoCaller.rc()); 560 561 AutoReaderLock alock (this); 484 562 485 563 mData->mManufacturer.string().cloneTo (aManufacturer); … … 489 567 STDMETHODIMP USBDeviceFilter::COMSETTER(Manufacturer) (INPTR BSTR aManufacturer) 490 568 { 491 AutoLock alock (this); 492 CHECK_READY(); 493 CHECK_MACHINE_MUTABILITY (mParent->parent()); 569 AutoCaller autoCaller (this); 570 CheckComRCReturnRC (autoCaller.rc()); 571 572 /* the machine needs to be mutable */ 573 Machine::AutoMutableStateDependency adep (mParent->parent()); 574 CheckComRCReturnRC (adep.rc()); 575 576 AutoLock alock (this); 494 577 495 578 if (mData->mManufacturer.string() != aManufacturer) … … 505 588 mData->mManufacturer = flt; 506 589 507 // notify parent 508 alock.unlock(); 590 /* leave the lock before informing callbacks */ 591 alock.unlock(); 592 509 593 return mParent->onDeviceFilterChange (this); 510 594 } … … 518 602 return E_POINTER; 519 603 520 AutoLock alock (this); 521 CHECK_READY(); 604 AutoCaller autoCaller (this); 605 CheckComRCReturnRC (autoCaller.rc()); 606 607 AutoReaderLock alock (this); 522 608 523 609 mData->mProduct.string().cloneTo (aProduct); 610 524 611 return S_OK; 525 612 } … … 527 614 STDMETHODIMP USBDeviceFilter::COMSETTER(Product) (INPTR BSTR aProduct) 528 615 { 529 AutoLock alock (this); 530 CHECK_READY(); 531 CHECK_MACHINE_MUTABILITY (mParent->parent()); 616 AutoCaller autoCaller (this); 617 CheckComRCReturnRC (autoCaller.rc()); 618 619 /* the machine needs to be mutable */ 620 Machine::AutoMutableStateDependency adep (mParent->parent()); 621 CheckComRCReturnRC (adep.rc()); 622 623 AutoLock alock (this); 532 624 533 625 if (mData->mProduct.string() != aProduct) … … 543 635 mData->mProduct = flt; 544 636 545 // notify parent 546 alock.unlock(); 637 /* leave the lock before informing callbacks */ 638 alock.unlock(); 639 547 640 return mParent->onDeviceFilterChange (this); 548 641 } … … 556 649 return E_POINTER; 557 650 558 AutoLock alock (this); 559 CHECK_READY(); 651 AutoCaller autoCaller (this); 652 CheckComRCReturnRC (autoCaller.rc()); 653 654 AutoReaderLock alock (this); 560 655 561 656 mData->mSerialNumber.string().cloneTo (aSerialNumber); 657 562 658 return S_OK; 563 659 } … … 565 661 STDMETHODIMP USBDeviceFilter::COMSETTER(SerialNumber) (INPTR BSTR aSerialNumber) 566 662 { 567 AutoLock alock (this); 568 CHECK_READY(); 569 CHECK_MACHINE_MUTABILITY (mParent->parent()); 663 AutoCaller autoCaller (this); 664 CheckComRCReturnRC (autoCaller.rc()); 665 666 /* the machine needs to be mutable */ 667 Machine::AutoMutableStateDependency adep (mParent->parent()); 668 CheckComRCReturnRC (adep.rc()); 669 670 AutoLock alock (this); 570 671 571 672 if (mData->mSerialNumber.string() != aSerialNumber) … … 581 682 mData->mSerialNumber = flt; 582 683 583 // notify parent 584 alock.unlock(); 684 /* leave the lock before informing callbacks */ 685 alock.unlock(); 686 585 687 return mParent->onDeviceFilterChange (this); 586 688 } … … 594 696 return E_POINTER; 595 697 596 AutoLock alock (this); 597 CHECK_READY(); 698 AutoCaller autoCaller (this); 699 CheckComRCReturnRC (autoCaller.rc()); 700 701 AutoReaderLock alock (this); 598 702 599 703 mData->mPort.string().cloneTo (aPort); 704 600 705 return S_OK; 601 706 } … … 603 708 STDMETHODIMP USBDeviceFilter::COMSETTER(Port) (INPTR BSTR aPort) 604 709 { 605 AutoLock alock (this); 606 CHECK_READY(); 607 CHECK_MACHINE_MUTABILITY (mParent->parent()); 710 AutoCaller autoCaller (this); 711 CheckComRCReturnRC (autoCaller.rc()); 712 713 /* the machine needs to be mutable */ 714 Machine::AutoMutableStateDependency adep (mParent->parent()); 715 CheckComRCReturnRC (adep.rc()); 716 717 AutoLock alock (this); 608 718 609 719 if (mData->mPort.string() != aPort) … … 626 736 mData->mPort = flt; 627 737 628 // notify parent 629 alock.unlock(); 738 /* leave the lock before informing callbacks */ 739 alock.unlock(); 740 630 741 return mParent->onDeviceFilterChange (this); 631 742 } … … 639 750 return E_POINTER; 640 751 641 AutoLock alock (this); 642 CHECK_READY(); 752 AutoCaller autoCaller (this); 753 CheckComRCReturnRC (autoCaller.rc()); 754 755 AutoReaderLock alock (this); 643 756 644 757 mData->mRemote.string().cloneTo (aRemote); 758 645 759 return S_OK; 646 760 } … … 648 762 STDMETHODIMP USBDeviceFilter::COMSETTER(Remote) (INPTR BSTR aRemote) 649 763 { 650 AutoLock alock (this); 651 CHECK_READY(); 652 CHECK_MACHINE_MUTABILITY (mParent->parent()); 764 AutoCaller autoCaller (this); 765 CheckComRCReturnRC (autoCaller.rc()); 766 767 /* the machine needs to be mutable */ 768 Machine::AutoMutableStateDependency adep (mParent->parent()); 769 CheckComRCReturnRC (adep.rc()); 770 771 AutoLock alock (this); 653 772 654 773 if (mData->mRemote.string() != aRemote) … … 664 783 mData->mRemote = flt; 665 784 666 // notify parent 667 alock.unlock(); 785 /* leave the lock before informing callbacks */ 786 alock.unlock(); 787 668 788 return mParent->onDeviceFilterChange (this); 669 789 } … … 675 795 //////////////////////////////////////////////////////////////////////////////// 676 796 797 /** 798 * @note Locks this object for writing. 799 */ 800 bool USBDeviceFilter::rollback() 801 { 802 /* sanity */ 803 AutoCaller autoCaller (this); 804 AssertComRCReturn (autoCaller.rc(), false); 805 806 AutoLock alock (this); 807 808 bool changed = false; 809 810 if (mData.isBackedUp()) 811 { 812 /* we need to check all data to see whether anything will be changed 813 * after rollback */ 814 changed = mData.hasActualChanges(); 815 mData.rollback(); 816 } 817 818 return changed; 819 } 820 821 /** 822 * @note Locks this object for writing, together with the peer object (also 823 * for writing) if there is one. 824 */ 677 825 void USBDeviceFilter::commit() 678 826 { 679 AutoLock alock (this); 827 /* sanity */ 828 AutoCaller autoCaller (this); 829 AssertComRCReturnVoid (autoCaller.rc()); 830 831 /* sanity too */ 832 AutoCaller thatCaller (mPeer); 833 AssertComRCReturnVoid (thatCaller.rc()); 834 835 /* lock both for writing since we modify both */ 836 AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeWlock (mPeer)); 837 680 838 if (mData.isBackedUp()) 681 839 { … … 683 841 if (mPeer) 684 842 { 685 // attach new data to the peer and reshare it 686 AutoLock peerlock (mPeer); 843 /* attach new data to the peer and reshare it */ 687 844 mPeer->mData.attach (mData); 688 845 } … … 693 850 * Cancels sharing (if any) by making an independent copy of data. 694 851 * This operation also resets this object's peer to NULL. 852 * 853 * @note Locks this object for writing, together with the peer object 854 * represented by @a aThat (locked for reading). 695 855 */ 696 856 void USBDeviceFilter::unshare() 697 857 { 698 AutoLock alock (this); 858 /* sanity */ 859 AutoCaller autoCaller (this); 860 AssertComRCReturnVoid (autoCaller.rc()); 861 862 /* sanity too */ 863 AutoCaller thatCaller (mPeer); 864 AssertComRCReturnVoid (thatCaller.rc()); 865 866 /* peer is not modified, lock it for reading */ 867 AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeRlock (mPeer)); 868 699 869 if (mData.isShared()) 700 870 { 871 701 872 if (!mData.isBackedUp()) 702 873 mData.backup(); 874 703 875 mData.commit(); 704 876 } 705 mPeer.setNull(); 877 878 unconst (mPeer).setNull(); 706 879 } 707 880 … … 713 886 //////////////////////////////////////////////////////////////////////////////// 714 887 888 DEFINE_EMPTY_CTOR_DTOR (HostUSBDeviceFilter) 889 715 890 HRESULT HostUSBDeviceFilter::FinalConstruct() 716 891 { … … 727 902 728 903 /** 729 * Initializes the USB device filter object. 904 * Initializes the USB device filter object. 905 * 906 * @param aParent Handle of the parent object. 730 907 */ 731 908 HRESULT HostUSBDeviceFilter::init (Host *aParent, … … 738 915 USBDeviceFilterAction_T aAction) 739 916 { 740 LogFlow Member (("HostUSBDeviceFilter::init(): isReady=%d\n", isReady()));917 LogFlowThisFunc (("aParent=%p\n", aParent)); 741 918 742 919 ComAssertRet (aParent && aName && *aName, E_INVALIDARG); 743 920 744 AutoLock alock (this); 745 ComAssertRet (!isReady(), E_UNEXPECTED); 746 747 mParent = aParent; 921 /* Enclose the state transition NotReady->InInit->Ready */ 922 AutoInitSpan autoInitSpan (this); 923 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 924 925 unconst (mParent) = aParent; 926 927 /* register with parent early, since uninit() will unconditionally 928 * unregister on failure */ 929 mParent->addDependentChild (this); 748 930 749 931 mData.allocate(); … … 752 934 mData->mAction = aAction; 753 935 754 / / initialize all filters to any match using null string936 /* initialize all filters to any match using null string */ 755 937 mData->mVendorId = NULL; 756 938 mData->mProductId = NULL; … … 764 946 mInList = false; 765 947 766 // use setters for the attributes below to reuse parsing errors handling 767 setReady (true); 768 HRESULT rc; 948 /* use setters for the attributes below to reuse parsing errors 949 * handling */ 950 951 HRESULT rc = S_OK; 769 952 do 770 953 { 771 954 rc = COMSETTER(VendorId) (aVendorId); 772 if (FAILED (rc)) 773 break; 955 CheckComRCBreakRC (rc); 774 956 rc = COMSETTER(ProductId) (aProductId); 775 if (FAILED (rc)) 776 break; 957 CheckComRCBreakRC (rc); 777 958 rc = COMSETTER(Revision) (aRevision); 778 if (FAILED (rc)) 779 break; 959 CheckComRCBreakRC (rc); 780 960 rc = COMSETTER(Manufacturer) (aManufacturer); 781 if (FAILED (rc)) 782 break; 961 CheckComRCBreakRC (rc); 783 962 rc = COMSETTER(Product) (aProduct); 784 if (FAILED (rc)) 785 break; 963 CheckComRCBreakRC (rc); 786 964 rc = COMSETTER(SerialNumber) (aSerialNumber); 787 if (FAILED (rc)) 788 break; 965 CheckComRCBreakRC (rc); 789 966 rc = COMSETTER(Port) (aPort); 790 if (FAILED (rc)) 791 break; 967 CheckComRCBreakRC (rc); 792 968 } 793 969 while (0); 794 970 971 /* Confirm successful initialization when it's the case */ 795 972 if (SUCCEEDED (rc)) 796 mParent->addDependentChild (this); 797 else 798 setReady (false); 973 autoInitSpan.setSucceeded(); 799 974 800 975 return rc; … … 802 977 803 978 /** 804 * Initializes the USB device filter object (short version). 979 * Initializes the USB device filter object (short version). 980 * 981 * @param aParent Handle of the parent object. 805 982 */ 806 983 HRESULT HostUSBDeviceFilter::init (Host *aParent, INPTR BSTR aName) 807 984 { 808 LogFlow Member (("HostUSBDeviceFilter::init(): isReady=%d\n", isReady()));985 LogFlowThisFunc (("aParent=%p\n", aParent)); 809 986 810 987 ComAssertRet (aParent && aName && *aName, E_INVALIDARG); 811 988 812 AutoLock alock (this); 813 ComAssertRet (!isReady(), E_UNEXPECTED); 814 815 mParent = aParent; 989 /* Enclose the state transition NotReady->InInit->Ready */ 990 AutoInitSpan autoInitSpan (this); 991 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 992 993 unconst (mParent) = aParent; 994 995 /* register with parent early, since uninit() will unconditionally 996 * unregister on failure */ 997 mParent->addDependentChild (this); 816 998 817 999 mData.allocate(); 1000 818 1001 mData->mName = aName; 819 1002 mData->mActive = FALSE; … … 822 1005 mInList = false; 823 1006 824 / / initialize all filters using null string (any match)1007 /* initialize all filters to any match using null string */ 825 1008 mData->mVendorId = NULL; 826 1009 mData->mProductId = NULL; … … 832 1015 mData->mRemote = NULL; 833 1016 834 mParent->addDependentChild (this);835 836 setReady (true); 1017 /* Confirm successful initialization */ 1018 autoInitSpan.setSucceeded(); 1019 837 1020 return S_OK; 838 1021 } … … 844 1027 void HostUSBDeviceFilter::uninit() 845 1028 { 846 LogFlowMember (("HostUSBDeviceFilter::uninit()\n")); 847 848 AutoLock alock (this); 849 850 LogFlowMember (("HostUSBDeviceFilter::uninit(): isReady=%d\n", isReady())); 851 852 if (!isReady()) 1029 LogFlowThisFunc (("\n")); 1030 1031 /* Enclose the state transition Ready->InUninit->NotReady */ 1032 AutoUninitSpan autoUninitSpan (this); 1033 if (autoUninitSpan.uninitDone()) 853 1034 return; 854 1035 … … 857 1038 mData.free(); 858 1039 859 setReady (false);860 861 alock.leave();862 1040 mParent->removeDependentChild (this); 863 alock.enter(); 864 865 mParent.setNull(); 1041 1042 unconst (mParent).setNull(); 866 1043 } 867 1044 … … 874 1051 return E_POINTER; 875 1052 876 AutoLock alock (this); 877 CHECK_READY(); 1053 AutoCaller autoCaller (this); 1054 CheckComRCReturnRC (autoCaller.rc()); 1055 1056 AutoReaderLock alock (this); 878 1057 879 1058 mData->mName.cloneTo (aName); 1059 880 1060 return S_OK; 881 1061 } … … 886 1066 return E_INVALIDARG; 887 1067 888 AutoLock alock (this); 889 CHECK_READY(); 1068 AutoCaller autoCaller (this); 1069 CheckComRCReturnRC (autoCaller.rc()); 1070 1071 AutoLock alock (this); 890 1072 891 1073 if (mData->mName != aName) … … 893 1075 mData->mName = aName; 894 1076 895 // notify parent 896 alock.unlock(); 1077 /* leave the lock before informing callbacks */ 1078 alock.unlock(); 1079 897 1080 return mParent->onUSBDeviceFilterChange (this); 898 1081 } … … 906 1089 return E_POINTER; 907 1090 908 AutoLock alock (this); 909 CHECK_READY(); 1091 AutoCaller autoCaller (this); 1092 CheckComRCReturnRC (autoCaller.rc()); 1093 1094 AutoReaderLock alock (this); 910 1095 911 1096 *aActive = mData->mActive; 1097 912 1098 return S_OK; 913 1099 } … … 915 1101 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Active) (BOOL aActive) 916 1102 { 917 AutoLock alock (this); 918 CHECK_READY(); 1103 AutoCaller autoCaller (this); 1104 CheckComRCReturnRC (autoCaller.rc()); 1105 1106 AutoLock alock (this); 919 1107 920 1108 if (mData->mActive != aActive) … … 922 1110 mData->mActive = aActive; 923 1111 924 // notify parent 925 alock.unlock(); 1112 /* leave the lock before informing callbacks */ 1113 alock.unlock(); 1114 926 1115 return mParent->onUSBDeviceFilterChange (this, TRUE /* aActiveChanged */); 927 1116 } … … 935 1124 return E_POINTER; 936 1125 937 AutoLock alock (this); 938 CHECK_READY(); 1126 AutoCaller autoCaller (this); 1127 CheckComRCReturnRC (autoCaller.rc()); 1128 1129 AutoReaderLock alock (this); 939 1130 940 1131 mData->mVendorId.string().cloneTo (aVendorId); 1132 941 1133 return S_OK; 942 1134 } … … 944 1136 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(VendorId) (INPTR BSTR aVendorId) 945 1137 { 946 AutoLock alock (this); 947 CHECK_READY(); 1138 AutoCaller autoCaller (this); 1139 CheckComRCReturnRC (autoCaller.rc()); 1140 1141 AutoLock alock (this); 948 1142 949 1143 if (mData->mVendorId.string() != aVendorId) … … 965 1159 mData->mVendorId = flt; 966 1160 967 // notify parent 968 alock.unlock(); 1161 /* leave the lock before informing callbacks */ 1162 alock.unlock(); 1163 969 1164 return mParent->onUSBDeviceFilterChange (this); 970 1165 } … … 978 1173 return E_POINTER; 979 1174 980 AutoLock alock (this); 981 CHECK_READY(); 1175 AutoCaller autoCaller (this); 1176 CheckComRCReturnRC (autoCaller.rc()); 1177 1178 AutoReaderLock alock (this); 982 1179 983 1180 mData->mProductId.string().cloneTo (aProductId); 1181 984 1182 return S_OK; 985 1183 } … … 987 1185 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(ProductId) (INPTR BSTR aProductId) 988 1186 { 989 AutoLock alock (this); 990 CHECK_READY(); 1187 AutoCaller autoCaller (this); 1188 CheckComRCReturnRC (autoCaller.rc()); 1189 1190 AutoLock alock (this); 991 1191 992 1192 if (mData->mProductId.string() != aProductId) … … 1008 1208 mData->mProductId = flt; 1009 1209 1010 // notify parent 1011 alock.unlock(); 1210 /* leave the lock before informing callbacks */ 1211 alock.unlock(); 1212 1012 1213 return mParent->onUSBDeviceFilterChange (this); 1013 1214 } … … 1021 1222 return E_POINTER; 1022 1223 1023 AutoLock alock (this); 1024 CHECK_READY(); 1224 AutoCaller autoCaller (this); 1225 CheckComRCReturnRC (autoCaller.rc()); 1226 1227 AutoReaderLock alock (this); 1025 1228 1026 1229 mData->mRevision.string().cloneTo (aRevision); 1230 1027 1231 return S_OK; 1028 1232 } … … 1030 1234 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Revision) (INPTR BSTR aRevision) 1031 1235 { 1032 AutoLock alock (this); 1033 CHECK_READY(); 1236 AutoCaller autoCaller (this); 1237 CheckComRCReturnRC (autoCaller.rc()); 1238 1239 AutoLock alock (this); 1034 1240 1035 1241 if (mData->mRevision.string() != aRevision) … … 1051 1257 mData->mRevision = flt; 1052 1258 1053 // notify parent 1054 alock.unlock(); 1259 /* leave the lock before informing callbacks */ 1260 alock.unlock(); 1261 1055 1262 return mParent->onUSBDeviceFilterChange (this); 1056 1263 } … … 1064 1271 return E_POINTER; 1065 1272 1066 AutoLock alock (this); 1067 CHECK_READY(); 1273 AutoCaller autoCaller (this); 1274 CheckComRCReturnRC (autoCaller.rc()); 1275 1276 AutoReaderLock alock (this); 1068 1277 1069 1278 mData->mManufacturer.string().cloneTo (aManufacturer); 1279 1070 1280 return S_OK; 1071 1281 } … … 1073 1283 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Manufacturer) (INPTR BSTR aManufacturer) 1074 1284 { 1075 AutoLock alock (this); 1076 CHECK_READY(); 1285 AutoCaller autoCaller (this); 1286 CheckComRCReturnRC (autoCaller.rc()); 1287 1288 AutoLock alock (this); 1077 1289 1078 1290 if (mData->mManufacturer.string() != aManufacturer) … … 1087 1299 mData->mManufacturer = flt; 1088 1300 1089 // notify parent 1090 alock.unlock(); 1301 /* leave the lock before informing callbacks */ 1302 alock.unlock(); 1303 1091 1304 return mParent->onUSBDeviceFilterChange (this); 1092 1305 } … … 1100 1313 return E_POINTER; 1101 1314 1102 AutoLock alock (this); 1103 CHECK_READY(); 1315 AutoCaller autoCaller (this); 1316 CheckComRCReturnRC (autoCaller.rc()); 1317 1318 AutoReaderLock alock (this); 1104 1319 1105 1320 mData->mProduct.string().cloneTo (aProduct); 1321 1106 1322 return S_OK; 1107 1323 } … … 1109 1325 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Product) (INPTR BSTR aProduct) 1110 1326 { 1111 AutoLock alock (this); 1112 CHECK_READY(); 1327 AutoCaller autoCaller (this); 1328 CheckComRCReturnRC (autoCaller.rc()); 1329 1330 AutoLock alock (this); 1113 1331 1114 1332 if (mData->mProduct.string() != aProduct) … … 1123 1341 mData->mProduct = flt; 1124 1342 1125 // notify parent 1126 alock.unlock(); 1343 /* leave the lock before informing callbacks */ 1344 alock.unlock(); 1345 1127 1346 return mParent->onUSBDeviceFilterChange (this); 1128 1347 } … … 1136 1355 return E_POINTER; 1137 1356 1138 AutoLock alock (this); 1139 CHECK_READY(); 1357 AutoCaller autoCaller (this); 1358 CheckComRCReturnRC (autoCaller.rc()); 1359 1360 AutoReaderLock alock (this); 1140 1361 1141 1362 mData->mSerialNumber.string().cloneTo (aSerialNumber); 1363 1142 1364 return S_OK; 1143 1365 } … … 1145 1367 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(SerialNumber) (INPTR BSTR aSerialNumber) 1146 1368 { 1147 AutoLock alock (this); 1148 CHECK_READY(); 1369 AutoCaller autoCaller (this); 1370 CheckComRCReturnRC (autoCaller.rc()); 1371 1372 AutoLock alock (this); 1149 1373 1150 1374 if (mData->mSerialNumber.string() != aSerialNumber) … … 1159 1383 mData->mSerialNumber = flt; 1160 1384 1161 // notify parent 1162 alock.unlock(); 1385 /* leave the lock before informing callbacks */ 1386 alock.unlock(); 1387 1163 1388 return mParent->onUSBDeviceFilterChange (this); 1164 1389 } … … 1172 1397 return E_POINTER; 1173 1398 1174 AutoLock alock (this); 1175 CHECK_READY(); 1399 AutoCaller autoCaller (this); 1400 CheckComRCReturnRC (autoCaller.rc()); 1401 1402 AutoReaderLock alock (this); 1176 1403 1177 1404 mData->mPort.string().cloneTo (aPort); 1405 1178 1406 return S_OK; 1179 1407 } … … 1181 1409 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Port) (INPTR BSTR aPort) 1182 1410 { 1183 AutoLock alock (this); 1184 CHECK_READY(); 1411 AutoCaller autoCaller (this); 1412 CheckComRCReturnRC (autoCaller.rc()); 1413 1414 AutoLock alock (this); 1185 1415 1186 1416 if (mData->mPort.string() != aPort) … … 1202 1432 mData->mPort = flt; 1203 1433 1204 // notify parent 1205 alock.unlock(); 1434 /* leave the lock before informing callbacks */ 1435 alock.unlock(); 1436 1206 1437 return mParent->onUSBDeviceFilterChange (this); 1207 1438 } … … 1215 1446 return E_POINTER; 1216 1447 1217 AutoLock alock (this); 1218 CHECK_READY(); 1448 AutoCaller autoCaller (this); 1449 CheckComRCReturnRC (autoCaller.rc()); 1450 1451 AutoReaderLock alock (this); 1219 1452 1220 1453 mData->mRemote.string().cloneTo (aRemote); 1454 1221 1455 return S_OK; 1222 1456 } … … 1237 1471 return E_POINTER; 1238 1472 1239 AutoLock alock (this); 1240 CHECK_READY(); 1473 AutoCaller autoCaller (this); 1474 CheckComRCReturnRC (autoCaller.rc()); 1475 1476 AutoReaderLock alock (this); 1241 1477 1242 1478 *aAction = mData->mAction; 1479 1243 1480 return S_OK; 1244 1481 } … … 1246 1483 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Action) (USBDeviceFilterAction_T aAction) 1247 1484 { 1248 AutoLock alock (this); 1249 CHECK_READY(); 1485 AutoCaller autoCaller (this); 1486 CheckComRCReturnRC (autoCaller.rc()); 1487 1488 AutoLock alock (this); 1250 1489 1251 1490 if (mData->mAction != aAction) … … 1253 1492 mData->mAction = aAction; 1254 1493 1255 // notify parent 1256 alock.unlock(); 1494 /* leave the lock before informing callbacks */ 1495 alock.unlock(); 1496 1257 1497 return mParent->onUSBDeviceFilterChange (this); 1258 1498 } -
trunk/src/VBox/Main/include/USBControllerImpl.h
r2981 r3412 101 101 // public methods only for internal purposes 102 102 103 const ComObjPtr <Machine, ComWeakRef> &parent() { return mParent; };104 105 103 HRESULT loadSettings (CFGNODE aMachine); 106 104 HRESULT saveSettings (CFGNODE aMachine); … … 111 109 void commit(); 112 110 void copyFrom (USBController *aThat); 113 114 const Backupable<Data> &data() { return mData; }115 111 116 112 HRESULT onMachineRegistered (BOOL aRegistered); … … 123 119 124 120 HRESULT notifyProxy (bool aInsertFilters); 121 122 // public methods for internal purposes only 123 // (ensure there is a caller and a read lock before calling them!) 124 125 /** @note this doesn't require a read lock since mParent is constant. */ 126 const ComObjPtr <Machine, ComWeakRef> &parent() { return mParent; }; 127 128 const Backupable<Data> &data() { return mData; } 125 129 126 130 // for VirtualBoxSupportErrorInfoImpl -
trunk/src/VBox/Main/include/USBDeviceFilterImpl.h
r2981 r3412 36 36 37 37 class ATL_NO_VTABLE USBDeviceFilter : 38 public VirtualBoxBaseNEXT, 38 39 public VirtualBoxSupportErrorInfoImpl <USBDeviceFilter, IUSBDeviceFilter>, 39 40 public VirtualBoxSupportTranslation <USBDeviceFilter>, 40 public VirtualBoxBase,41 41 public IUSBDeviceFilter 42 42 { … … 101 101 }; 102 102 103 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (USBDeviceFilter) 104 103 105 DECLARE_NOT_AGGREGATABLE(USBDeviceFilter) 104 106 … … 111 113 112 114 NS_DECL_ISUPPORTS 115 116 DECLARE_EMPTY_CTOR_DTOR (USBDeviceFilter) 113 117 114 118 HRESULT FinalConstruct(); … … 153 157 // public methods only for internal purposes 154 158 159 bool isModified() { AutoLock alock (this); return mData.isBackedUp(); } 160 bool isReallyModified() { AutoLock alock (this); return mData.hasActualChanges(); } 161 bool rollback(); 162 void commit(); 163 164 void unshare(); 165 166 // public methods for internal purposes only 167 // (ensure there is a caller and a read lock before calling them!) 168 155 169 void *& id() { return mData.data()->mId; } 156 170 … … 158 172 ComObjPtr <USBDeviceFilter> peer() { return mPeer; } 159 173 160 bool isModified() { AutoLock alock (this); return mData.isBackedUp(); }161 bool isReallyModified() { AutoLock alock (this); return mData.hasActualChanges(); }162 void rollback() { AutoLock alock (this); mData.rollback(); }163 void commit();164 165 void unshare();166 167 174 // for VirtualBoxSupportErrorInfoImpl 168 175 static const wchar_t *getComponentName() { return L"USBDeviceFilter"; } … … 170 177 private: 171 178 172 ComObjPtr <USBController, ComWeakRef> mParent; 173 ComObjPtr <USBDeviceFilter> mPeer; 179 const ComObjPtr <USBController, ComWeakRef> mParent; 180 const ComObjPtr <USBDeviceFilter> mPeer; 181 174 182 Backupable <Data> mData; 175 183 … … 185 193 186 194 class ATL_NO_VTABLE HostUSBDeviceFilter : 195 public VirtualBoxBaseNEXT, 187 196 public VirtualBoxSupportErrorInfoImpl <HostUSBDeviceFilter, IHostUSBDeviceFilter>, 188 197 public VirtualBoxSupportTranslation <HostUSBDeviceFilter>, 189 public VirtualBoxBase,190 198 public IHostUSBDeviceFilter 191 199 { … … 198 206 USBDeviceFilterAction_T mAction; 199 207 }; 208 209 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostUSBDeviceFilter) 200 210 201 211 DECLARE_NOT_AGGREGATABLE(HostUSBDeviceFilter) … … 210 220 211 221 NS_DECL_ISUPPORTS 222 223 DECLARE_EMPTY_CTOR_DTOR (HostUSBDeviceFilter) 212 224 213 225 HRESULT FinalConstruct(); … … 254 266 // public methods only for internal purposes 255 267 268 // public methods for internal purposes only 269 // (ensure there is a caller and a read lock before calling them!) 270 256 271 void *& id() { return mData.data()->mId; } 257 272 … … 263 278 private: 264 279 265 ComObjPtr <Host, ComWeakRef> mParent; 280 const ComObjPtr <Host, ComWeakRef> mParent; 281 266 282 Backupable <Data> mData; 267 283 … … 285 301 STDMETHOD(FindById) (INPTR GUIDPARAM aId, IUSBDevice **aDevice) 286 302 { 287 / / internal collection, no need to implement303 /* internal collection, no need to implement */ 288 304 return E_NOTIMPL; 289 305 } … … 291 307 STDMETHOD(FindByAddress) (INPTR BSTR aAddress, IUSBDevice **aDevice) 292 308 { 293 / / internal collection, no need to implement309 /* internal collection, no need to implement */ 294 310 return E_NOTIMPL; 295 311 }
Note:
See TracChangeset
for help on using the changeset viewer.

