AceTimeClock  1.3.0
Clock classes for Arduino that can synchronize from an NTP server or an RTC chip
Clock.h
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 #ifndef ACE_TIME_CLOCK_H
7 #define ACE_TIME_CLOCK_H
8 
9 #include <stdint.h>
10 #include <AceTime.h> // LocalTime, acetime_t
11 
12 namespace ace_time {
13 namespace clock {
14 
19 class Clock {
20  public:
25  static const acetime_t kInvalidSeconds = LocalTime::kInvalidSeconds;
26 
28  Clock() = default;
29 
35  ~Clock() = default;
36 
45  virtual acetime_t getNow() const = 0;
46 
48  virtual void sendRequest() const {}
49 
51  virtual bool isResponseReady() const { return true; }
52 
58  virtual acetime_t readResponse() const { return getNow(); }
59 
66  virtual void setNow(acetime_t /*epochSeconds*/) {}
67 
68  private:
69  // disable copy constructor and assignment operator
70  Clock(const Clock&) = delete;
71  Clock& operator=(const Clock&) = delete;
72 };
73 
74 }
75 }
76 
77 #endif
Abstract base class for objects that provide and store time.
Definition: Clock.h:19
virtual acetime_t getNow() const =0
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
virtual void sendRequest() const
Send a time request asynchronously.
Definition: Clock.h:48
Clock()=default
Default constructor.
virtual void setNow(acetime_t)
Set the time to the indicated seconds.
Definition: Clock.h:66
virtual acetime_t readResponse() const
Returns number of seconds since AceTime epoch (2000-01-01).
Definition: Clock.h:58
~Clock()=default
We deliberately avoid using a virtual destructor.
virtual bool isResponseReady() const
Return true if a response is ready.
Definition: Clock.h:51
static const acetime_t kInvalidSeconds
Error value returned by getNow() and other methods when this object is not yet initialized.
Definition: Clock.h:25