autoheartbeat.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "autoheartbeat.h"
  2. #include "respheartbeat.h"
  3. #include "sncdatabase.h"
  4. AutoHeartBeat::AutoHeartBeat(QObject *parent) :
  5. QThread(parent)
  6. {
  7. m_numchk = new WSNumChk();
  8. m_refreshStamp = "";
  9. }
  10. AutoHeartBeat::~AutoHeartBeat()
  11. {
  12. m_numchk->abort();
  13. delete m_numchk;
  14. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  15. <<"FormNumchk.AutoHeartBeat Destroyed.";
  16. }
  17. void AutoHeartBeat::abort()
  18. {
  19. m_numchk->abort();
  20. }
  21. void AutoHeartBeat::setAccountInfo(QMap<QString, QString> accountInfo)
  22. {
  23. m_account = accountInfo;
  24. }
  25. void AutoHeartBeat::setHost(QString host, QString port)
  26. {
  27. m_host = host;
  28. m_port = port;
  29. m_numchk->setHost(m_host,m_port);
  30. }
  31. void AutoHeartBeat::run()
  32. {
  33. QString src = "SNC-" + SNCDataBase::getAppVersion();
  34. QString userHash = m_account.value("userhash");
  35. if(userHash.isEmpty())
  36. return ;
  37. QString json = m_numchk->heartBeat(userHash,src,m_refreshStamp);
  38. RespHeartBeat response(json);
  39. if(response.getRtnCode()==1)
  40. {
  41. m_refreshStamp = response.getRefreshStamp();
  42. QString refreshParam = response.getRefreshParam();
  43. if(refreshParam.left(1)=="1")
  44. {
  45. emit userStateChanged();
  46. }
  47. }
  48. }