UploadTimerCallback.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "UploadTimerCallback.h"
  2. #include "Util.h"
  3. #include "Poco/Util/IniFileConfiguration.h"
  4. #include "Poco/AutoPtr.h"
  5. using Poco::Util::IniFileConfiguration;
  6. using Poco::AutoPtr;
  7. CUploadTimerCallback::CUploadTimerCallback(pProgressAndSpeedCallback pCallback, string stringIniFilePath, unsigned long nAlreadyUploadSize, unsigned long nTotalSize, string stringLocalFilePath)
  8. :m_pCallback(pCallback), m_stringIniFilePath(stringIniFilePath), m_nCurrentUploadFileSize(nAlreadyUploadSize),
  9. m_nPreUploadFileSize(nAlreadyUploadSize), m_nTotalSize(nTotalSize), m_stringLocalFilePath(stringLocalFilePath), m_nSeconds(0)
  10. {
  11. }
  12. CUploadTimerCallback::~CUploadTimerCallback(void)
  13. {
  14. }
  15. void CUploadTimerCallback::onTimer(Timer& timer)
  16. {
  17. m_nSeconds++;
  18. AutoPtr<IniFileConfiguration> iniFile = new IniFileConfiguration(m_stringIniFilePath, "gbk");
  19. m_nCurrentUploadFileSize = CUtil::StringToULong(iniFile->getString("ALREADY_UPLOAD_SIZE", "0"));
  20. //¼ÆËã½ø¶È
  21. double dProgress = 0.0;
  22. if(m_nCurrentUploadFileSize <= m_nTotalSize)
  23. {
  24. dProgress = ((double)(m_nCurrentUploadFileSize))/m_nTotalSize*100;
  25. }
  26. else
  27. {
  28. dProgress = 100.0;
  29. }
  30. //¼ÆËãËÙ¶È
  31. static double dSpeed = 0.0;
  32. long nInterval = 1000;
  33. // if(timer.getPeriodicInterval() == 0)
  34. // {
  35. // nInterval = 1000;
  36. // }
  37. // else
  38. // {
  39. // nInterval = timer.getPeriodicInterval();
  40. // }
  41. unsigned long nTimeCount = m_nSeconds*nInterval/1000;
  42. if(m_nCurrentUploadFileSize>m_nPreUploadFileSize && nTimeCount!=0)
  43. {
  44. dSpeed = (m_nCurrentUploadFileSize-m_nPreUploadFileSize)/nTimeCount;
  45. m_nPreUploadFileSize = m_nCurrentUploadFileSize;
  46. m_nSeconds = 0;
  47. }
  48. if(m_pCallback != NULL)
  49. {
  50. m_pCallback(dProgress, dSpeed, "", m_stringLocalFilePath.c_str());
  51. }
  52. return;
  53. }