Changeset 44288 in vbox for trunk/src/VBox/Main/src-all
- Timestamp:
- Jan 14, 2013 6:22:18 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/ProgressImpl.cpp
r44124 r44288 40 40 #include "AutoCaller.h" 41 41 42 //////////////////////////////////////////////////////////////////////////////// 43 // ProgressBase class 44 //////////////////////////////////////////////////////////////////////////////// 45 46 // constructor / destructor 47 //////////////////////////////////////////////////////////////////////////////// 48 49 ProgressBase::ProgressBase() 42 43 Progress::Progress() 50 44 #if !defined(VBOX_COM_INPROC) 51 45 : mParent(NULL) … … 54 48 } 55 49 56 ProgressBase::~ProgressBase() 57 { 58 } 59 60 61 /** 62 * Subclasses must call this method from their FinalConstruct() implementations. 63 */ 64 HRESULT ProgressBase::FinalConstruct() 65 { 66 mCancelable = FALSE; 67 mCompleted = FALSE; 68 mCanceled = FALSE; 69 mResultCode = S_OK; 70 71 m_cOperations 72 = m_ulTotalOperationsWeight 73 = m_ulOperationsCompletedWeight 74 = m_ulCurrentOperation 75 = m_ulCurrentOperationWeight 76 = m_ulOperationPercent 77 = m_cMsTimeout 78 = 0; 79 80 // get creation timestamp 81 m_ullTimestamp = RTTimeMilliTS(); 82 83 m_pfnCancelCallback = NULL; 84 m_pvCancelUserArg = NULL; 85 86 return BaseFinalConstruct(); 87 } 88 89 // protected initializer/uninitializer for internal purposes only 90 //////////////////////////////////////////////////////////////////////////////// 91 92 /** 93 * Initializes the progress base object. 94 * 95 * Subclasses should call this or any other #protectedInit() method from their 96 * init() implementations. 97 * 98 * @param aAutoInitSpan AutoInitSpan object instantiated by a subclass. 99 * @param aParent Parent object (only for server-side Progress objects). 100 * @param aInitiator Initiator of the task (for server-side objects. Can be 101 * NULL which means initiator = parent, otherwise must not 102 * be NULL). 103 * @param aDescription ask description. 104 * @param aID Address of result GUID structure (optional). 105 * 106 * @return COM result indicator. 107 */ 108 HRESULT ProgressBase::protectedInit(AutoInitSpan &aAutoInitSpan, 109 #if !defined(VBOX_COM_INPROC) 110 VirtualBox *aParent, 111 #endif 112 IUnknown *aInitiator, 113 CBSTR aDescription, 114 OUT_GUID aId /* = NULL */) 115 { 116 /* Guarantees subclasses call this method at the proper time */ 117 NOREF(aAutoInitSpan); 118 119 AutoCaller autoCaller(this); 120 AssertReturn(autoCaller.state() == InInit, E_FAIL); 121 122 #if !defined(VBOX_COM_INPROC) 123 AssertReturn(aParent, E_INVALIDARG); 124 #else 125 AssertReturn(aInitiator, E_INVALIDARG); 126 #endif 127 128 AssertReturn(aDescription, E_INVALIDARG); 129 130 #if !defined(VBOX_COM_INPROC) 131 /* share parent weakly */ 132 unconst(mParent) = aParent; 133 #endif 134 135 #if !defined(VBOX_COM_INPROC) 136 /* assign (and therefore addref) initiator only if it is not VirtualBox 137 * (to avoid cycling); otherwise mInitiator will remain null which means 138 * that it is the same as the parent */ 139 if (aInitiator) 140 { 141 ComObjPtr<VirtualBox> pVirtualBox(mParent); 142 if (!(pVirtualBox == aInitiator)) 143 unconst(mInitiator) = aInitiator; 144 } 145 #else 146 unconst(mInitiator) = aInitiator; 147 #endif 148 149 unconst(mId).create(); 150 if (aId) 151 mId.cloneTo(aId); 152 153 #if !defined(VBOX_COM_INPROC) 154 /* add to the global collection of progress operations (note: after 155 * creating mId) */ 156 mParent->addProgress(this); 157 #endif 158 159 unconst(mDescription) = aDescription; 160 161 return S_OK; 162 } 163 164 /** 165 * Initializes the progress base object. 166 * 167 * This is a special initializer that doesn't initialize any field. Used by one 168 * of the Progress::init() forms to create sub-progress operations combined 169 * together using a CombinedProgress instance, so it doesn't require the parent, 170 * initiator, description and doesn't create an ID. 171 * 172 * Subclasses should call this or any other #protectedInit() method from their 173 * init() implementations. 174 * 175 * @param aAutoInitSpan AutoInitSpan object instantiated by a subclass. 176 */ 177 HRESULT ProgressBase::protectedInit(AutoInitSpan &aAutoInitSpan) 178 { 179 /* Guarantees subclasses call this method at the proper time */ 180 NOREF(aAutoInitSpan); 181 182 return S_OK; 183 } 184 185 /** 186 * Uninitializes the instance. 187 * 188 * Subclasses should call this from their uninit() implementations. 189 * 190 * @param aAutoUninitSpan AutoUninitSpan object instantiated by a subclass. 191 * 192 * @note Using the mParent member after this method returns is forbidden. 193 */ 194 void ProgressBase::protectedUninit(AutoUninitSpan &aAutoUninitSpan) 195 { 196 /* release initiator (effective only if mInitiator has been assigned in 197 * init()) */ 198 unconst(mInitiator).setNull(); 199 200 #if !defined(VBOX_COM_INPROC) 201 if (mParent) 202 { 203 /* remove the added progress on failure to complete the initialization */ 204 if (aAutoUninitSpan.initFailed() && mId.isValid() && !mId.isZero()) 205 mParent->removeProgress(mId.ref()); 206 207 unconst(mParent) = NULL; 208 } 209 #endif 210 } 50 Progress::~Progress() 51 { 52 } 53 211 54 212 55 // IProgress properties 213 56 ///////////////////////////////////////////////////////////////////////////// 214 57 215 STDMETHODIMP Progress Base::COMGETTER(Id)(BSTR *aId)58 STDMETHODIMP Progress::COMGETTER(Id)(BSTR *aId) 216 59 { 217 60 CheckComArgOutPointerValid(aId); … … 226 69 } 227 70 228 STDMETHODIMP Progress Base::COMGETTER(Description)(BSTR *aDescription)71 STDMETHODIMP Progress::COMGETTER(Description)(BSTR *aDescription) 229 72 { 230 73 CheckComArgOutPointerValid(aDescription); … … 239 82 } 240 83 241 STDMETHODIMP Progress Base::COMGETTER(Initiator)(IUnknown **aInitiator)84 STDMETHODIMP Progress::COMGETTER(Initiator)(IUnknown **aInitiator) 242 85 { 243 86 CheckComArgOutPointerValid(aInitiator); … … 263 106 } 264 107 265 STDMETHODIMP Progress Base::COMGETTER(Cancelable)(BOOL *aCancelable)108 STDMETHODIMP Progress::COMGETTER(Cancelable)(BOOL *aCancelable) 266 109 { 267 110 CheckComArgOutPointerValid(aCancelable); … … 286 129 * @return fractional percentage as a double value. 287 130 */ 288 double Progress Base::calcTotalPercent()131 double Progress::calcTotalPercent() 289 132 { 290 133 // avoid division by zero … … 304 147 * The caller should hold the object write lock. 305 148 */ 306 void Progress Base::checkForAutomaticTimeout(void)149 void Progress::checkForAutomaticTimeout(void) 307 150 { 308 151 if ( m_cMsTimeout … … 315 158 316 159 317 STDMETHODIMP Progress Base::COMGETTER(TimeRemaining)(LONG *aTimeRemaining)160 STDMETHODIMP Progress::COMGETTER(TimeRemaining)(LONG *aTimeRemaining) 318 161 { 319 162 CheckComArgOutPointerValid(aTimeRemaining); … … 338 181 uint64_t ullTimeRemaining = ullTimeTotal - ullTimeElapsed; 339 182 340 // Log(("Progress Base::GetTimeRemaining: dPercentDone %RI32, ullTimeNow = %RI64, ullTimeElapsed = %RI64, ullTimeTotal = %RI64, ullTimeRemaining = %RI64\n",183 // Log(("Progress::GetTimeRemaining: dPercentDone %RI32, ullTimeNow = %RI64, ullTimeElapsed = %RI64, ullTimeTotal = %RI64, ullTimeRemaining = %RI64\n", 341 184 // (uint32_t)dPercentDone, ullTimeNow, ullTimeElapsed, ullTimeTotal, ullTimeRemaining)); 342 185 … … 348 191 } 349 192 350 STDMETHODIMP Progress Base::COMGETTER(Percent)(ULONG *aPercent)193 STDMETHODIMP Progress::COMGETTER(Percent)(ULONG *aPercent) 351 194 { 352 195 CheckComArgOutPointerValid(aPercent); … … 381 224 } 382 225 383 STDMETHODIMP Progress Base::COMGETTER(Completed)(BOOL *aCompleted)226 STDMETHODIMP Progress::COMGETTER(Completed)(BOOL *aCompleted) 384 227 { 385 228 CheckComArgOutPointerValid(aCompleted); … … 395 238 } 396 239 397 STDMETHODIMP Progress Base::COMGETTER(Canceled)(BOOL *aCanceled)240 STDMETHODIMP Progress::COMGETTER(Canceled)(BOOL *aCanceled) 398 241 { 399 242 CheckComArgOutPointerValid(aCanceled); … … 409 252 } 410 253 411 STDMETHODIMP Progress Base::COMGETTER(ResultCode)(LONG *aResultCode)254 STDMETHODIMP Progress::COMGETTER(ResultCode)(LONG *aResultCode) 412 255 { 413 256 CheckComArgOutPointerValid(aResultCode); … … 427 270 } 428 271 429 STDMETHODIMP Progress Base::COMGETTER(ErrorInfo)(IVirtualBoxErrorInfo **aErrorInfo)272 STDMETHODIMP Progress::COMGETTER(ErrorInfo)(IVirtualBoxErrorInfo **aErrorInfo) 430 273 { 431 274 CheckComArgOutPointerValid(aErrorInfo); … … 445 288 } 446 289 447 STDMETHODIMP Progress Base::COMGETTER(OperationCount)(ULONG *aOperationCount)290 STDMETHODIMP Progress::COMGETTER(OperationCount)(ULONG *aOperationCount) 448 291 { 449 292 CheckComArgOutPointerValid(aOperationCount); … … 459 302 } 460 303 461 STDMETHODIMP Progress Base::COMGETTER(Operation)(ULONG *aOperation)304 STDMETHODIMP Progress::COMGETTER(Operation)(ULONG *aOperation) 462 305 { 463 306 CheckComArgOutPointerValid(aOperation); … … 473 316 } 474 317 475 STDMETHODIMP Progress Base::COMGETTER(OperationDescription)(BSTR *aOperationDescription)318 STDMETHODIMP Progress::COMGETTER(OperationDescription)(BSTR *aOperationDescription) 476 319 { 477 320 CheckComArgOutPointerValid(aOperationDescription); … … 487 330 } 488 331 489 STDMETHODIMP Progress Base::COMGETTER(OperationPercent)(ULONG *aOperationPercent)332 STDMETHODIMP Progress::COMGETTER(OperationPercent)(ULONG *aOperationPercent) 490 333 { 491 334 CheckComArgOutPointerValid(aOperationPercent); … … 504 347 } 505 348 506 STDMETHODIMP Progress Base::COMGETTER(OperationWeight)(ULONG *aOperationWeight)349 STDMETHODIMP Progress::COMGETTER(OperationWeight)(ULONG *aOperationWeight) 507 350 { 508 351 CheckComArgOutPointerValid(aOperationWeight); … … 518 361 } 519 362 520 STDMETHODIMP Progress Base::COMSETTER(Timeout)(ULONG aTimeout)363 STDMETHODIMP Progress::COMSETTER(Timeout)(ULONG aTimeout) 521 364 { 522 365 AutoCaller autoCaller(this); … … 534 377 } 535 378 536 STDMETHODIMP Progress Base::COMGETTER(Timeout)(ULONG *aTimeout)379 STDMETHODIMP Progress::COMGETTER(Timeout)(ULONG *aTimeout) 537 380 { 538 381 CheckComArgOutPointerValid(aTimeout); … … 561 404 * @param pvUser The callback argument. 562 405 */ 563 bool Progress Base::setCancelCallback(void (*pfnCallback)(void *), void *pvUser)406 bool Progress::setCancelCallback(void (*pfnCallback)(void *), void *pvUser) 564 407 { 565 408 AutoCaller autoCaller(this); … … 577 420 } 578 421 579 ////////////////////////////////////////////////////////////////////////////////580 // Progress class581 ////////////////////////////////////////////////////////////////////////////////582 583 422 HRESULT Progress::FinalConstruct() 584 423 { 585 HRESULT rc = ProgressBase::FinalConstruct(); 424 mCancelable = FALSE; 425 mCompleted = FALSE; 426 mCanceled = FALSE; 427 mResultCode = S_OK; 428 429 m_cOperations 430 = m_ulTotalOperationsWeight 431 = m_ulOperationsCompletedWeight 432 = m_ulCurrentOperation 433 = m_ulCurrentOperationWeight 434 = m_ulOperationPercent 435 = m_cMsTimeout 436 = 0; 437 438 // get creation timestamp 439 m_ullTimestamp = RTTimeMilliTS(); 440 441 m_pfnCancelCallback = NULL; 442 m_pvCancelUserArg = NULL; 443 444 HRESULT rc = Progress::BaseFinalConstruct(); 586 445 if (FAILED(rc)) return rc; 587 446 … … 639 498 * ulTotalOperationsWeight = ulFirstOperationWeight = 1. 640 499 * 641 * @param aParent See Progress Base::init().642 * @param aInitiator See Progress Base::init().643 * @param aDescription See Progress Base::init().500 * @param aParent See Progress::init(). 501 * @param aInitiator See Progress::init(). 502 * @param aDescription See Progress::init(). 644 503 * @param aCancelable Flag whether the task maybe canceled. 645 504 * @param cOperations Number of operations within this task (at least 1). … … 648 507 * @param bstrFirstOperationDescription Description of the first operation. 649 508 * @param ulFirstOperationWeight Weight of first sub-operation. 650 * @param aId See Progress Base::init().509 * @param aId See Progress::init(). 651 510 */ 652 511 HRESULT Progress::init( … … 679 538 HRESULT rc = S_OK; 680 539 681 rc = ProgressBase::protectedInit(autoInitSpan, 540 // rc = Progress::init( 541 //#if !defined(VBOX_COM_INPROC) 542 // aParent, 543 //#endif 544 // aInitiator, aDescription, FALSE, aId); 545 // NA 682 546 #if !defined(VBOX_COM_INPROC) 683 aParent, 547 AssertReturn(aParent, E_INVALIDARG); 548 #else 549 AssertReturn(aInitiator, E_INVALIDARG); 684 550 #endif 685 aInitiator, aDescription, aId); 551 552 AssertReturn(aDescription, E_INVALIDARG); 553 554 #if !defined(VBOX_COM_INPROC) 555 /* share parent weakly */ 556 unconst(mParent) = aParent; 557 #endif 558 559 #if !defined(VBOX_COM_INPROC) 560 /* assign (and therefore addref) initiator only if it is not VirtualBox 561 * * (to avoid cycling); otherwise mInitiator will remain null which means 562 * * that it is the same as the parent */ 563 if (aInitiator) 564 { 565 ComObjPtr<VirtualBox> pVirtualBox(mParent); 566 if (!(pVirtualBox == aInitiator)) 567 unconst(mInitiator) = aInitiator; 568 } 569 #else 570 unconst(mInitiator) = aInitiator; 571 #endif 572 573 unconst(mId).create(); 574 if (aId) 575 mId.cloneTo(aId); 576 577 #if !defined(VBOX_COM_INPROC) 578 /* add to the global collection of progress operations (note: after 579 * * creating mId) */ 580 mParent->addProgress(this); 581 #endif 582 583 unconst(mDescription) = aDescription; 584 585 586 // end of assertion 587 588 686 589 if (FAILED(rc)) return rc; 687 590 … … 713 616 * 714 617 * Objects initialized with this method are then combined together into the 715 * single task using a CombinedProgress instance, so it doesn't require the618 * single task using a Progress instance, so it doesn't require the 716 619 * parent, initiator, description and doesn't create an ID. Note that calling 717 620 * respective getter methods on an object initialized with this method is … … 734 637 735 638 HRESULT rc = S_OK; 736 737 rc = ProgressBase::protectedInit(autoInitSpan); 639 /* Guarantees subclasses call this method at the proper time */ 640 NOREF(autoInitSpan); 641 738 642 if (FAILED(rc)) return rc; 739 643 … … 762 666 } 763 667 668 764 669 /** 765 670 * Uninitializes the instance and sets the ready flag to FALSE. … … 786 691 RTSemEventMultiDestroy(mCompletedSem); 787 692 788 ProgressBase::protectedUninit(autoUninitSpan); 789 } 693 /* release initiator (effective only if mInitiator has been assigned in 694 * * init()) */ 695 unconst(mInitiator).setNull(); 696 697 #if !defined(VBOX_COM_INPROC) 698 if (mParent) 699 { 700 /* remove the added progress on failure to complete the initialization */ 701 if (autoUninitSpan.initFailed() && mId.isValid() && !mId.isZero()) 702 mParent->removeProgress(mId.ref()); 703 704 unconst(mParent) = NULL; 705 } 706 #endif 707 } 708 790 709 791 710 // IProgress properties
Note:
See TracChangeset
for help on using the changeset viewer.