Changeset 3412
- Timestamp:
- 07/04/07 13:25:35 (2 years ago)
- Files:
-
- trunk/src/VBox/Main/USBDeviceFilterImpl.cpp (modified) (87 diffs)
- trunk/src/VBox/Main/include/USBControllerImpl.h (modified) (3 diffs)
- trunk/src/VBox/Main/include/USBDeviceFilterImpl.h (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
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

