//! Post progress message //! //! @param progress - How many bytes of progress since last call //! @param message - Message to post, May be NULL to indicate no change. //! USBDM_ErrorCode ProgressTimer::progress(int progress, const char *_message) { USBDM_ErrorCode rc = PROGRAMMING_RC_OK; if (_message != NULL) { message = _message; } bytesDone += progress; int percent = 0; if (maximumBytes > 0) { percent = ((100UL*bytesDone)/maximumBytes); } double kBytesPerSec = 0; double elapsed = elapsedTime(); if ((elapsed > 0) && (bytesDone > 0)) { kBytesPerSec = bytesDone/(1024*elapsed); } if (message == NULL) { message = ""; } char messageBuffer[200]; snprintf(messageBuffer, sizeof(messageBuffer), "%s (%2.2f kBytes/sec)", message, kBytesPerSec); if ((progressCallBack != NULL) && (progress != 0)) { if (bytesDone>0) { rc = progressCallBack(PROGRAMMING_RC_OK, percent, messageBuffer); } else { rc = progressCallBack(PROGRAMMING_RC_OK, percent, message); } } // print("ProgressTimer::Timer::progress() - \'%s\', Time = %3.2f, Progress done = %d(+%d) (%d%%)\n", // messageBuffer, elapsed, bytesDone, progress, percent); return rc; }
//! Restart timer from 0 //! //! @param message - Message to post, May be NULL to indicate no change. //! USBDM_ErrorCode ProgressTimer::restart(const char *_message) { USBDM_ErrorCode rc = PROGRAMMING_RC_OK; lastBytesDone = 0; bytesDone = 0; if (gettimeofday(&timeStart, NULL) < 0) { print("ProgressTimer::Timer::restart() - gettimeofday() failed!\n"); return PROGRAMMING_RC_ERROR_INTERNAL_CHECK_FAILED; } if (_message != NULL) { message = _message; } if (progressCallBack != NULL) { rc = progressCallBack(PROGRAMMING_RC_OK, 0, message); } // print("ProgressTimer::Timer::restart() - \'%s\'\n", message); return rc; }
// -------------------------------------------------------------------------- // CDevEncStarterMemoryEntity::DoStartPollingL() // Starts a timer to periodically update the memory state in the UI // -------------------------------------------------------------------------- void CDevEncStarterMemoryEntity::DoStartPollingL( TTimeIntervalMicroSeconds32 aInterval ) { DFLOG( "CDevEncStarterMemoryEntity::DoStartPollingL" ); TCallBack pollCallBack( PollTick, static_cast<TAny*>( this ) ); TCallBack progressCallBack( ProgressTick, static_cast<TAny*>( this ) ); if ( !iPeriodic ) { iPeriodic = CPeriodic::NewL( EPriorityNormal ); } iPeriodic->Cancel(); if ( aInterval == KProgressInterval ) { iPeriodic->Start( 0, aInterval, progressCallBack ); } else { iPeriodic->Start( 0, aInterval, pollCallBack ); } }