AceTime  1.7.1
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock 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 "../common/common.h"
11 #include "../LocalTime.h"
12 
13 namespace ace_time {
14 namespace clock {
15 
20 class Clock {
21  public:
26  static const acetime_t kInvalidSeconds = LocalTime::kInvalidSeconds;
27 
29  Clock() = default;
30 
36  ~Clock() = default;
37 
46  virtual acetime_t getNow() const = 0;
47 
49  virtual void sendRequest() const {}
50 
52  virtual bool isResponseReady() const { return true; }
53 
59  virtual acetime_t readResponse() const { return getNow(); }
60 
67  virtual void setNow(acetime_t /*epochSeconds*/) {}
68 
69  private:
70  // disable copy constructor and assignment operator
71  Clock(const Clock&) = delete;
72  Clock& operator=(const Clock&) = delete;
73 };
74 
75 }
76 }
77 
78 #endif
ace_time::clock::Clock::Clock
Clock()=default
Default constructor.
ace_time::clock::Clock::getNow
virtual acetime_t getNow() const =0
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
ace_time::clock::Clock::sendRequest
virtual void sendRequest() const
Send a time request asynchronously.
Definition: Clock.h:49
ace_time::LocalTime::kInvalidSeconds
static const acetime_t kInvalidSeconds
An invalid seconds marker that indicates isError() true.
Definition: LocalTime.h:29
ace_time::clock::Clock::setNow
virtual void setNow(acetime_t)
Set the time to the indicated seconds.
Definition: Clock.h:67
ace_time::clock::Clock::~Clock
~Clock()=default
We deliberately avoid using a virtual destructor.
ace_time::clock::Clock
Abstract base class for objects that provide and store time.
Definition: Clock.h:20
ace_time::clock::Clock::kInvalidSeconds
static const acetime_t kInvalidSeconds
Error value returned by getNow() and other methods when this object is not yet initialized.
Definition: Clock.h:26
ace_time::clock::Clock::isResponseReady
virtual bool isResponseReady() const
Return true if a response is ready.
Definition: Clock.h:52
ace_time::clock::Clock::readResponse
virtual acetime_t readResponse() const
Returns number of seconds since AceTime epoch (2000-01-01).
Definition: Clock.h:59