D-Bus server: ensure progress percentage is 0-100

For example in the new TestLocalCache.testItemDelete100, the
percentage value in the ProgressChanged signal become larger
than 100 and then revert to 100 at the end of the sync.

Seems the underlying calculation is faulty or simply inaccurate.
This patch does not fix that. Instead it just clips the final
result to the valid range. It also cleans up ownership of the
actual int32_t progress value.
This commit is contained in:
Patrick Ohly 2012-08-24 10:43:44 +02:00
parent f0c7a3e2da
commit 5214e0052a
4 changed files with 21 additions and 13 deletions

View File

@ -29,8 +29,8 @@ const float ProgressData::ONEITEM_SEND_RATIO = 0.05;
const float ProgressData::ONEITEM_RECEIVE_RATIO = 0.05;
const float ProgressData::CONN_SETUP_RATIO = 0.5;
ProgressData::ProgressData(int32_t &progress)
: m_progress(progress),
ProgressData::ProgressData()
: m_progress(0),
m_step(PRO_SYNC_INVALID),
m_sendCounts(0),
m_internalMode(INTERNAL_NONE)
@ -57,11 +57,18 @@ ProgressData::ProgressData(int32_t &progress)
m_syncProp[PRO_SYNC_TOTAL - 1] = 1.0;
}
void ProgressData::setProgress(int progress)
{
m_progress = progress > 100 ? 100 :
progress < 0 ? 0 :
progress;
}
void ProgressData::setStep(ProgressStep step)
{
if(m_step != step) {
/** if state is changed, progress is set as the end of current step*/
m_progress = 100.0 * m_syncProp[(int)m_step];
setProgress(100.0 * m_syncProp[(int)m_step]);
m_step = step; ///< change to new state
m_sendCounts = 0; ///< clear send/receive counts
m_source = ""; ///< clear source
@ -157,7 +164,7 @@ void ProgressData::itemReceive(const std::string &source, int count, int total)
void ProgressData::updateProg(float ratio)
{
m_progress += m_propOfUnit * 100 * ratio;
setProgress(m_progress + m_propOfUnit * 100 * ratio);
m_syncUnits[(int)m_step] -= ratio;
}

View File

@ -103,7 +103,12 @@ public:
/** default times of message send/receive in each step */
static const int MSG_SEND_RECEIVE_TIMES = 1;
ProgressData(int32_t &progress);
ProgressData();
int32_t getProgress() const { return m_progress; }
/** set percentage, including clipping to the 0-100 range */
void setProgress(int32_t progress);
/**
* change the big step
@ -155,8 +160,8 @@ private:
static float getDefaultUnits(ProgressStep step);
private:
/** a reference of progress percentage */
int32_t &m_progress;
/** progress percentage */
int32_t m_progress;
/** current big step */
ProgressStep m_step;
/** count of message send/receive in current step. Cleared in the start of a new step */

View File

@ -484,7 +484,7 @@ void Session::getProgress(int32_t &progress,
SourceProgresses_t &sources)
{
Session::LoggingGuard guard(this);
progress = m_progress;
progress = m_progData.getProgress();
sources = m_sourceProgress;
}
@ -557,8 +557,6 @@ Session::Session(Server &server,
m_syncStatus(SYNC_QUEUEING),
m_stepIsWaiting(false),
m_priority(PRI_DEFAULT),
m_progress(0),
m_progData(m_progress),
m_error(0),
m_statusTimer(100),
m_progressTimer(50),
@ -1141,7 +1139,7 @@ void Session::sourceProgress(sysync::TProgressEventEnum type,
m_restoreSrcEnd++;
SourceStatus &status = m_sourceStatus[sourceName];
status.set(PrettyPrintSyncMode(sourceSyncMode), "done", 0);
m_progress = 100 * m_restoreSrcEnd / m_restoreSrcTotal;
m_progData.setProgress(100 * m_restoreSrcEnd / m_restoreSrcTotal);
fireStatus(true);
fireProgress(true);
}

View File

@ -197,8 +197,6 @@ class Session : public GDBusCXX::DBusObjectHelper,
*/
int m_priority;
int32_t m_progress;
/** progress data, holding progress calculation related info */
ProgressData m_progData;