ntp.h 508 B

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. #include <time.h>
  3. #include <string>
  4. #include <system/Thread.h>
  5. class ntp {
  6. public:
  7. ntp();
  8. virtual ~ntp();
  9. bool get(struct tm* t);
  10. static bool get_from(const std::string& ip, struct tm* t);
  11. };
  12. class NtpThread : public Thread {
  13. private:
  14. //同步时间失败时,重试次数
  15. int reTry;
  16. public:
  17. static NtpThread* getInstance(void);
  18. bool readyToRun();
  19. virtual bool threadLoop();
  20. private:
  21. NtpThread(){
  22. reTry = 5;
  23. }
  24. ~NtpThread(){}
  25. };
  26. #define NTPTHREAD NtpThread::getInstance()