1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include "UploadTimerCallback.h"
- #include "Util.h"
- #include "Poco/Util/IniFileConfiguration.h"
- #include "Poco/AutoPtr.h"
- using Poco::Util::IniFileConfiguration;
- using Poco::AutoPtr;
- CUploadTimerCallback::CUploadTimerCallback(pProgressAndSpeedCallback pCallback, string stringIniFilePath, unsigned long nAlreadyUploadSize, unsigned long nTotalSize, string stringLocalFilePath)
- :m_pCallback(pCallback), m_stringIniFilePath(stringIniFilePath), m_nCurrentUploadFileSize(nAlreadyUploadSize),
- m_nPreUploadFileSize(nAlreadyUploadSize), m_nTotalSize(nTotalSize), m_stringLocalFilePath(stringLocalFilePath), m_nSeconds(0)
- {
- }
- CUploadTimerCallback::~CUploadTimerCallback(void)
- {
- }
- void CUploadTimerCallback::onTimer(Timer& timer)
- {
- m_nSeconds++;
- AutoPtr<IniFileConfiguration> iniFile = new IniFileConfiguration(m_stringIniFilePath, "gbk");
- m_nCurrentUploadFileSize = CUtil::StringToULong(iniFile->getString("ALREADY_UPLOAD_SIZE", "0"));
- //¼ÆËã½ø¶È
- double dProgress = 0.0;
- if(m_nCurrentUploadFileSize <= m_nTotalSize)
- {
- dProgress = ((double)(m_nCurrentUploadFileSize))/m_nTotalSize*100;
- }
- else
- {
- dProgress = 100.0;
- }
- //¼ÆËãËÙ¶È
- static double dSpeed = 0.0;
- long nInterval = 1000;
- // if(timer.getPeriodicInterval() == 0)
- // {
- // nInterval = 1000;
- // }
- // else
- // {
- // nInterval = timer.getPeriodicInterval();
- // }
- unsigned long nTimeCount = m_nSeconds*nInterval/1000;
- if(m_nCurrentUploadFileSize>m_nPreUploadFileSize && nTimeCount!=0)
- {
- dSpeed = (m_nCurrentUploadFileSize-m_nPreUploadFileSize)/nTimeCount;
- m_nPreUploadFileSize = m_nCurrentUploadFileSize;
- m_nSeconds = 0;
- }
- if(m_pCallback != NULL)
- {
- m_pCallback(dProgress, dSpeed, "", m_stringLocalFilePath.c_str());
- }
- return;
- }
|