Changeset 32780 in vbox for trunk/src/VBox/Main/ProgressImpl.cpp
- Timestamp:
- Sep 27, 2010 7:00:22 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ProgressImpl.cpp
r31625 r32780 6 6 7 7 /* 8 * Copyright (C) 2006-20 09Oracle Corporation8 * Copyright (C) 2006-2010 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 19 19 #include <iprt/types.h> 20 20 21 #if defined 21 #if defined(VBOX_WITH_XPCOM) 22 22 #include <nsIServiceManager.h> 23 23 #include <nsIExceptionService.h> 24 24 #include <nsCOMPtr.h> 25 #endif /* defined 25 #endif /* defined(VBOX_WITH_XPCOM) */ 26 26 27 27 #include "ProgressCombinedImpl.h" … … 46 46 47 47 ProgressBase::ProgressBase() 48 #if !defined 48 #if !defined(VBOX_COM_INPROC) 49 49 : mParent(NULL) 50 50 #endif … … 105 105 */ 106 106 HRESULT ProgressBase::protectedInit(AutoInitSpan &aAutoInitSpan, 107 #if !defined 107 #if !defined(VBOX_COM_INPROC) 108 108 VirtualBox *aParent, 109 109 #endif … … 113 113 { 114 114 /* Guarantees subclasses call this method at the proper time */ 115 NOREF 115 NOREF(aAutoInitSpan); 116 116 117 117 AutoCaller autoCaller(this); 118 118 AssertReturn(autoCaller.state() == InInit, E_FAIL); 119 119 120 #if !defined 120 #if !defined(VBOX_COM_INPROC) 121 121 AssertReturn(aParent, E_INVALIDARG); 122 122 #else … … 126 126 AssertReturn(aDescription, E_INVALIDARG); 127 127 128 #if !defined 128 #if !defined(VBOX_COM_INPROC) 129 129 /* share parent weakly */ 130 130 unconst(mParent) = aParent; 131 131 #endif 132 132 133 #if !defined 133 #if !defined(VBOX_COM_INPROC) 134 134 /* assign (and therefore addref) initiator only if it is not VirtualBox 135 135 * (to avoid cycling); otherwise mInitiator will remain null which means … … 149 149 mId.cloneTo(aId); 150 150 151 #if !defined 151 #if !defined(VBOX_COM_INPROC) 152 152 /* add to the global collection of progress operations (note: after 153 153 * creating mId) */ … … 173 173 * @param aAutoInitSpan AutoInitSpan object instantiated by a subclass. 174 174 */ 175 HRESULT ProgressBase::protectedInit 175 HRESULT ProgressBase::protectedInit(AutoInitSpan &aAutoInitSpan) 176 176 { 177 177 /* Guarantees subclasses call this method at the proper time */ 178 NOREF 178 NOREF(aAutoInitSpan); 179 179 180 180 return S_OK; … … 190 190 * @note Using the mParent member after this method returns is forbidden. 191 191 */ 192 void ProgressBase::protectedUninit 192 void ProgressBase::protectedUninit(AutoUninitSpan &aAutoUninitSpan) 193 193 { 194 194 /* release initiator (effective only if mInitiator has been assigned in … … 196 196 unconst(mInitiator).setNull(); 197 197 198 #if !defined 198 #if !defined(VBOX_COM_INPROC) 199 199 if (mParent) 200 200 { 201 201 /* remove the added progress on failure to complete the initialization */ 202 202 if (aAutoUninitSpan.initFailed() && !mId.isEmpty()) 203 mParent->removeProgress (mId);203 mParent->removeProgress(mId.ref()); 204 204 205 205 unconst(mParent) = NULL; … … 211 211 ///////////////////////////////////////////////////////////////////////////// 212 212 213 STDMETHODIMP ProgressBase::COMGETTER(Id) 213 STDMETHODIMP ProgressBase::COMGETTER(Id)(BSTR *aId) 214 214 { 215 215 CheckComArgOutPointerValid(aId); … … 224 224 } 225 225 226 STDMETHODIMP ProgressBase::COMGETTER(Description) 226 STDMETHODIMP ProgressBase::COMGETTER(Description)(BSTR *aDescription) 227 227 { 228 228 CheckComArgOutPointerValid(aDescription); … … 237 237 } 238 238 239 STDMETHODIMP ProgressBase::COMGETTER(Initiator) 239 STDMETHODIMP ProgressBase::COMGETTER(Initiator)(IUnknown **aInitiator) 240 240 { 241 241 CheckComArgOutPointerValid(aInitiator); … … 246 246 /* mInitiator/mParent are constant during life time, no need to lock */ 247 247 248 #if !defined 248 #if !defined(VBOX_COM_INPROC) 249 249 if (mInitiator) 250 250 mInitiator.queryInterfaceTo(aInitiator); … … 261 261 } 262 262 263 STDMETHODIMP ProgressBase::COMGETTER(Cancelable) 263 STDMETHODIMP ProgressBase::COMGETTER(Cancelable)(BOOL *aCancelable) 264 264 { 265 265 CheckComArgOutPointerValid(aCancelable); … … 379 379 } 380 380 381 STDMETHODIMP ProgressBase::COMGETTER(Completed) 381 STDMETHODIMP ProgressBase::COMGETTER(Completed)(BOOL *aCompleted) 382 382 { 383 383 CheckComArgOutPointerValid(aCompleted); … … 393 393 } 394 394 395 STDMETHODIMP ProgressBase::COMGETTER(Canceled) 395 STDMETHODIMP ProgressBase::COMGETTER(Canceled)(BOOL *aCanceled) 396 396 { 397 397 CheckComArgOutPointerValid(aCanceled); … … 407 407 } 408 408 409 STDMETHODIMP ProgressBase::COMGETTER(ResultCode) 409 STDMETHODIMP ProgressBase::COMGETTER(ResultCode)(LONG *aResultCode) 410 410 { 411 411 CheckComArgOutPointerValid(aResultCode); … … 425 425 } 426 426 427 STDMETHODIMP ProgressBase::COMGETTER(ErrorInfo) 427 STDMETHODIMP ProgressBase::COMGETTER(ErrorInfo)(IVirtualBoxErrorInfo **aErrorInfo) 428 428 { 429 429 CheckComArgOutPointerValid(aErrorInfo); … … 443 443 } 444 444 445 STDMETHODIMP ProgressBase::COMGETTER(OperationCount) 445 STDMETHODIMP ProgressBase::COMGETTER(OperationCount)(ULONG *aOperationCount) 446 446 { 447 447 CheckComArgOutPointerValid(aOperationCount); … … 457 457 } 458 458 459 STDMETHODIMP ProgressBase::COMGETTER(Operation) 459 STDMETHODIMP ProgressBase::COMGETTER(Operation)(ULONG *aOperation) 460 460 { 461 461 CheckComArgOutPointerValid(aOperation); … … 471 471 } 472 472 473 STDMETHODIMP ProgressBase::COMGETTER(OperationDescription) 473 STDMETHODIMP ProgressBase::COMGETTER(OperationDescription)(BSTR *aOperationDescription) 474 474 { 475 475 CheckComArgOutPointerValid(aOperationDescription); … … 647 647 * @param aId See ProgressBase::init(). 648 648 */ 649 HRESULT Progress::init 650 #if !defined 651 649 HRESULT Progress::init( 650 #if !defined(VBOX_COM_INPROC) 651 VirtualBox *aParent, 652 652 #endif 653 654 655 656 657 658 659 660 653 IUnknown *aInitiator, 654 CBSTR aDescription, 655 BOOL aCancelable, 656 ULONG cOperations, 657 ULONG ulTotalOperationsWeight, 658 CBSTR bstrFirstOperationDescription, 659 ULONG ulFirstOperationWeight, 660 OUT_GUID aId /* = NULL */) 661 661 { 662 662 LogFlowThisFunc(("aDescription=\"%ls\", cOperations=%d, ulTotalOperationsWeight=%d, bstrFirstOperationDescription=\"%ls\", ulFirstOperationWeight=%d\n", … … 676 676 HRESULT rc = S_OK; 677 677 678 rc = ProgressBase::protectedInit 679 #if !defined 680 678 rc = ProgressBase::protectedInit(autoInitSpan, 679 #if !defined(VBOX_COM_INPROC) 680 aParent, 681 681 #endif 682 682 aInitiator, aDescription, aId); 683 683 if (FAILED(rc)) return rc; 684 684 … … 693 693 m_ulOperationPercent = 0; 694 694 695 int vrc = RTSemEventMultiCreate 696 ComAssertRCRet 697 698 RTSemEventMultiReset 695 int vrc = RTSemEventMultiCreate(&mCompletedSem); 696 ComAssertRCRet(vrc, E_FAIL); 697 698 RTSemEventMultiReset(mCompletedSem); 699 699 700 700 /* Confirm a successful initialization when it's the case */ … … 732 732 HRESULT rc = S_OK; 733 733 734 rc = ProgressBase::protectedInit 734 rc = ProgressBase::protectedInit(autoInitSpan); 735 735 if (FAILED(rc)) return rc; 736 736 … … 747 747 m_ulOperationPercent = 0; 748 748 749 int vrc = RTSemEventMultiCreate 750 ComAssertRCRet 751 752 RTSemEventMultiReset 749 int vrc = RTSemEventMultiCreate(&mCompletedSem); 750 ComAssertRCRet(vrc, E_FAIL); 751 752 RTSemEventMultiReset(mCompletedSem); 753 753 754 754 /* Confirm a successful initialization when it's the case */ … … 776 776 if (mWaitersCount > 0) 777 777 { 778 LogFlow 779 780 RTSemEventMultiSignal 781 } 782 783 RTSemEventMultiDestroy 784 785 ProgressBase::protectedUninit 778 LogFlow(("WARNING: There are still %d threads waiting for '%ls' completion!\n", 779 mWaitersCount, mDescription.raw())); 780 RTSemEventMultiSignal(mCompletedSem); 781 } 782 783 RTSemEventMultiDestroy(mCompletedSem); 784 785 ProgressBase::protectedUninit(autoUninitSpan); 786 786 } 787 787 … … 798 798 * calling this method will definitely freeze event processing. 799 799 */ 800 STDMETHODIMP Progress::WaitForCompletion 800 STDMETHODIMP Progress::WaitForCompletion(LONG aTimeout) 801 801 { 802 802 LogFlowThisFuncEnter(); … … 1033 1033 /* try to import error info from the current thread */ 1034 1034 1035 #if !defined 1035 #if !defined(VBOX_WITH_XPCOM) 1036 1036 1037 1037 ComPtr<IErrorInfo> err; … … 1044 1044 } 1045 1045 1046 #else /* !defined 1046 #else /* !defined(VBOX_WITH_XPCOM) */ 1047 1047 1048 1048 nsCOMPtr<nsIExceptionService> es; … … 1064 1064 } 1065 1065 } 1066 #endif /* !defined 1067 1068 AssertMsg (rc == S_OK, ("Couldn't get error info (rc=%08X) while trying "1069 "to set a failed result (%08X)!\n",rc, aResultCode));1066 #endif /* !defined(VBOX_WITH_XPCOM) */ 1067 1068 AssertMsg(rc == S_OK, ("Couldn't get error info (rc=%08X) while trying to set a failed result (%08X)!\n", 1069 rc, aResultCode)); 1070 1070 } 1071 1071 … … 1116 1116 /* remove from the global collection of pending progress operations */ 1117 1117 if (mParent) 1118 mParent->removeProgress (mId);1118 mParent->removeProgress(mId.ref()); 1119 1119 #endif 1120 1120 … … 1180 1180 ComObjPtr<VirtualBoxErrorInfo> errorInfo; 1181 1181 HRESULT rc = errorInfo.createObject(); 1182 AssertComRC 1182 AssertComRC(rc); 1183 1183 if (SUCCEEDED(rc)) 1184 1184 { … … 1190 1190 /* remove from the global collection of pending progress operations */ 1191 1191 if (mParent) 1192 mParent->removeProgress (mId);1192 mParent->removeProgress(mId.ref()); 1193 1193 #endif 1194 1194 … … 1265 1265 * @param aId See ProgressBase::init(). 1266 1266 */ 1267 HRESULT CombinedProgress::protectedInit 1268 #if !defined 1269 1267 HRESULT CombinedProgress::protectedInit(AutoInitSpan &aAutoInitSpan, 1268 #if !defined(VBOX_COM_INPROC) 1269 VirtualBox *aParent, 1270 1270 #endif 1271 1272 1271 IUnknown *aInitiator, 1272 CBSTR aDescription, OUT_GUID aId) 1273 1273 { 1274 1274 LogFlowThisFunc(("aDescription={%ls} mProgresses.size()=%d\n", … … 1277 1277 HRESULT rc = S_OK; 1278 1278 1279 rc = ProgressBase::protectedInit 1280 #if !defined 1281 1279 rc = ProgressBase::protectedInit(aAutoInitSpan, 1280 #if !defined(VBOX_COM_INPROC) 1281 aParent, 1282 1282 #endif 1283 1283 aInitiator, aDescription, aId); 1284 1284 if (FAILED(rc)) return rc; 1285 1285 … … 1336 1336 */ 1337 1337 HRESULT CombinedProgress::init( 1338 #if !defined 1338 #if !defined(VBOX_COM_INPROC) 1339 1339 VirtualBox *aParent, 1340 1340 #endif … … 1354 1354 1355 1355 HRESULT rc = protectedInit(autoInitSpan, 1356 #if !defined 1356 #if !defined(VBOX_COM_INPROC) 1357 1357 aParent, 1358 1358 #endif … … 1385 1385 mProgresses.clear(); 1386 1386 1387 ProgressBase::protectedUninit 1387 ProgressBase::protectedUninit(autoUninitSpan); 1388 1388 } 1389 1389 … … 1417 1417 } 1418 1418 1419 STDMETHODIMP CombinedProgress::COMGETTER(Completed) 1419 STDMETHODIMP CombinedProgress::COMGETTER(Completed)(BOOL *aCompleted) 1420 1420 { 1421 1421 CheckComArgOutPointerValid(aCompleted); … … 1430 1430 if (FAILED(rc)) return rc; 1431 1431 1432 return ProgressBase::COMGETTER(Completed) 1433 } 1434 1435 STDMETHODIMP CombinedProgress::COMGETTER(Canceled) 1432 return ProgressBase::COMGETTER(Completed)(aCompleted); 1433 } 1434 1435 STDMETHODIMP CombinedProgress::COMGETTER(Canceled)(BOOL *aCanceled) 1436 1436 { 1437 1437 CheckComArgOutPointerValid(aCanceled); … … 1446 1446 if (FAILED(rc)) return rc; 1447 1447 1448 return ProgressBase::COMGETTER(Canceled) 1449 } 1450 1451 STDMETHODIMP CombinedProgress::COMGETTER(ResultCode) 1448 return ProgressBase::COMGETTER(Canceled)(aCanceled); 1449 } 1450 1451 STDMETHODIMP CombinedProgress::COMGETTER(ResultCode)(LONG *aResultCode) 1452 1452 { 1453 1453 CheckComArgOutPointerValid(aResultCode); … … 1462 1462 if (FAILED(rc)) return rc; 1463 1463 1464 return ProgressBase::COMGETTER(ResultCode) 1465 } 1466 1467 STDMETHODIMP CombinedProgress::COMGETTER(ErrorInfo) 1464 return ProgressBase::COMGETTER(ResultCode)(aResultCode); 1465 } 1466 1467 STDMETHODIMP CombinedProgress::COMGETTER(ErrorInfo)(IVirtualBoxErrorInfo **aErrorInfo) 1468 1468 { 1469 1469 CheckComArgOutPointerValid(aErrorInfo); … … 1478 1478 if (FAILED(rc)) return rc; 1479 1479 1480 return ProgressBase::COMGETTER(ErrorInfo) 1481 } 1482 1483 STDMETHODIMP CombinedProgress::COMGETTER(Operation) 1480 return ProgressBase::COMGETTER(ErrorInfo)(aErrorInfo); 1481 } 1482 1483 STDMETHODIMP CombinedProgress::COMGETTER(Operation)(ULONG *aOperation) 1484 1484 { 1485 1485 CheckComArgOutPointerValid(aOperation); … … 1494 1494 if (FAILED(rc)) return rc; 1495 1495 1496 return ProgressBase::COMGETTER(Operation) 1497 } 1498 1499 STDMETHODIMP CombinedProgress::COMGETTER(OperationDescription) 1496 return ProgressBase::COMGETTER(Operation)(aOperation); 1497 } 1498 1499 STDMETHODIMP CombinedProgress::COMGETTER(OperationDescription)(BSTR *aOperationDescription) 1500 1500 { 1501 1501 CheckComArgOutPointerValid(aOperationDescription); … … 1510 1510 if (FAILED(rc)) return rc; 1511 1511 1512 return ProgressBase::COMGETTER(OperationDescription) 1512 return ProgressBase::COMGETTER(OperationDescription)(aOperationDescription); 1513 1513 } 1514 1514 … … 1526 1526 if (FAILED(rc)) return rc; 1527 1527 1528 return ProgressBase::COMGETTER(OperationPercent) 1528 return ProgressBase::COMGETTER(OperationPercent)(aOperationPercent); 1529 1529 } 1530 1530 … … 1553 1553 * calling this method will definitely freeze event processing. 1554 1554 */ 1555 STDMETHODIMP CombinedProgress::WaitForCompletion 1555 STDMETHODIMP CombinedProgress::WaitForCompletion(LONG aTimeout) 1556 1556 { 1557 1557 LogFlowThisFuncEnter(); … … 1604 1604 * calling this method will definitely freeze event processing. 1605 1605 */ 1606 STDMETHODIMP CombinedProgress::WaitForOperationCompletion 1606 STDMETHODIMP CombinedProgress::WaitForOperationCompletion(ULONG aOperation, LONG aTimeout) 1607 1607 { 1608 1608 LogFlowThisFuncEnter(); … … 1756 1756 if (FAILED(mResultCode)) 1757 1757 { 1758 rc = progress->COMGETTER(ErrorInfo) 1758 rc = progress->COMGETTER(ErrorInfo)(mErrorInfo.asOutParam()); 1759 1759 if (FAILED(rc)) 1760 1760 return rc; … … 1768 1768 { 1769 1769 ULONG opCount = 0; 1770 rc = progress->COMGETTER(OperationCount) 1770 rc = progress->COMGETTER(OperationCount)(&opCount); 1771 1771 if (FAILED(rc)) 1772 1772 return rc; … … 1784 1784 while (fCompleted && !mCompleted); 1785 1785 1786 rc = progress->COMGETTER(OperationPercent) 1786 rc = progress->COMGETTER(OperationPercent)(&m_ulOperationPercent); 1787 1787 if (SUCCEEDED(rc)) 1788 1788 { 1789 1789 ULONG operation = 0; 1790 rc = progress->COMGETTER(Operation) 1790 rc = progress->COMGETTER(Operation)(&operation); 1791 1791 if (SUCCEEDED(rc) && mCompletedOperations + operation > m_ulCurrentOperation) 1792 1792 { 1793 1793 m_ulCurrentOperation = mCompletedOperations + operation; 1794 rc = progress->COMGETTER(OperationDescription) ( 1795 m_bstrOperationDescription.asOutParam()); 1794 rc = progress->COMGETTER(OperationDescription)(m_bstrOperationDescription.asOutParam()); 1796 1795 } 1797 1796 }
Note:
See TracChangeset
for help on using the changeset viewer.