- Timestamp:
- Mar 27, 2009 3:31:21 PM (16 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r18396 r18406 127 127 ) 128 128 { 129 RTPrintf("(%ld/%ld) %ls %ld%% => %ld%%\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent); 129 LONG lSecsRem; 130 progress->COMGETTER(TimeRemaining)(&lSecsRem); 131 132 RTPrintf("(%ld/%ld) %ls %ld%% => %ld%% (%d s remaining)\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent, lSecsRem); 130 133 ulLastPercent = ulCurrentPercent; 131 134 ulLastOperationPercent = ulCurrentOperationPercent; -
trunk/src/VBox/Main/ProgressImpl.cpp
r18394 r18406 66 66 m_ulCurrentOperationWeight = 67 67 m_ulOperationPercent = 0; 68 69 // get creation timestamp 70 m_ullTimestamp = RTTimeMilliTS(); 68 71 69 72 return S_OK; … … 258 261 } 259 262 263 /** 264 * Internal helper to compute the total percent value based on the member values and 265 * returns it as a "double". This is used both by GetPercent (which returns it as a 266 * rounded ULONG) and GetTimeRemaining(). 267 * 268 * Requires locking by the caller! 269 * 270 * @return fractional percentage as a double value. 271 */ 272 double ProgressBase::calcTotalPercent() 273 { 274 // avoid division by zero 275 if (m_ulTotalOperationsWeight == 0) 276 return 0; 277 278 double dPercent = ( (double)m_ulOperationsCompletedWeight // weight of operations that have been completed 279 + ((double)m_ulOperationPercent * (double)m_ulCurrentOperationWeight / (double)100) // plus partial weight of the current operation 280 ) * (double)100 / (double)m_ulTotalOperationsWeight; 281 282 return dPercent; 283 } 284 285 STDMETHODIMP ProgressBase::COMGETTER(TimeRemaining)(LONG *aTimeRemaining) 286 { 287 CheckComArgOutPointerValid(aTimeRemaining); 288 289 AutoCaller autoCaller(this); 290 CheckComRCReturnRC(autoCaller.rc()); 291 292 AutoReadLock alock(this); 293 294 if (mCompleted) 295 *aTimeRemaining = 0; 296 else 297 { 298 double dPercentDone = calcTotalPercent(); 299 if (dPercentDone < 1) 300 *aTimeRemaining = -1; // unreliable, or avoid division by 0 below 301 else 302 { 303 uint64_t ullTimeNow = RTTimeMilliTS(); 304 uint64_t ullTimeElapsed = ullTimeNow - m_ullTimestamp; 305 uint64_t ullTimeTotal = (uint64_t)(ullTimeElapsed / dPercentDone * 100); 306 uint64_t ullTimeRemaining = ullTimeTotal - ullTimeElapsed; 307 308 // Log(("ProgressBase::GetTimeRemaining: dPercentDone %RI32, ullTimeNow = %RI64, ullTimeElapsed = %RI64, ullTimeTotal = %RI64, ullTimeRemaining = %RI64\n", 309 // (uint32_t)dPercentDone, ullTimeNow, ullTimeElapsed, ullTimeTotal, ullTimeRemaining)); 310 311 *aTimeRemaining = (LONG)(ullTimeRemaining / 1000); 312 } 313 } 314 315 return S_OK; 316 } 317 260 318 STDMETHODIMP ProgressBase::COMGETTER(Percent)(ULONG *aPercent) 261 319 { … … 271 329 else 272 330 { 273 ULONG ulPercent = (ULONG)( ( (double)m_ulOperationsCompletedWeight // weight of operations that have been completed 274 + ((double)m_ulOperationPercent * (double)m_ulCurrentOperationWeight / (double)100) // plus partial weight of the current operation 275 ) * (double)100 / (double)m_ulTotalOperationsWeight 276 ); 331 ULONG ulPercent = (ULONG)calcTotalPercent(); 277 332 // do not report 100% until we're really really done with everything as the Qt GUI dismisses progress dialogs in that case 278 333 if ( ulPercent == 100 -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r18388 r18406 7821 7821 <interface 7822 7822 name="IProgress" extends="$unknown" 7823 uuid=" ee1aa091-fda8-47a9-8f1c-4bba002a3229"7823 uuid="c4f94e6b-2273-446b-9539-4c05bb416fe7" 7824 7824 wsmap="managed" 7825 7825 > 7826 7826 <desc> 7827 The IProgress interface allows for monitoring the progress of7828 a n asynchronous tasks within VirtualBox.7827 The IProgress interface is used to track and control 7828 asynchronous tasks within VirtualBox. 7829 7829 7830 7830 An instance of this is returned every time VirtualBox starts … … 7844 7844 cancel the task by calling <link to="#cancel" />. 7845 7845 7846 A task represented by IProgress c an consist of one or more7847 s ub-operations that run sequentially, one by one (see7846 A task represented by IProgress consists of either one or 7847 several sub-operations that run sequentially, one by one (see 7848 7848 <link to="#operation" /> and <link to="#operationCount" />). 7849 7849 Every operation is identified by a number (starting from 0) … … 7854 7854 percentage of completion of the task as a whole 7855 7855 in <link to="#percent" />. 7856 7856 7857 Similarly, you can wait for the completion of a particular 7857 7858 operation via <link to="#waitForOperationCompletion" /> or … … 7882 7883 Returns 100 if <link to="#completed" /> is true. 7883 7884 </desc> 7885 </attribute> 7886 7887 <attribute name="timeRemaining" type="long" readonly="yes"> 7888 <desc> 7889 Estimated remaining time until the operation completes, in 7890 seconds. 7891 7892 Returns 0 if the task is complete. 7893 7894 Returns -1 if the time cannot be computed, in 7895 particular if the current progress is 0. 7896 7897 The estimate will be unreliable for low progress 7898 values. It will become more reliable as the task progresses; 7899 it is not recommended to display an ETA before 10% of 7900 a task have completed. 7901 </desc> 7884 7902 </attribute> 7885 7903 -
trunk/src/VBox/Main/include/ProgressImpl.h
r18269 r18406 73 73 STDMETHOD(COMGETTER(Cancelable)) (BOOL *aCancelable); 74 74 STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent); 75 STDMETHOD(COMGETTER(TimeRemaining)) (LONG *aTimeRemaining); 75 76 STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted); 76 77 STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled); … … 91 92 BOOL completed() const { return mCompleted; } 92 93 HRESULT resultCode() const { return mResultCode; } 94 double calcTotalPercent(); 93 95 94 96 protected: … … 103 105 const Guid mId; 104 106 const Bstr mDescription; 107 108 uint64_t m_ullTimestamp; // progress object creation timestamp, for ETA computation 105 109 106 110 /* The fields below are to be properly initalized by subclasses */
Note:
See TracChangeset
for help on using the changeset viewer.