14#if DETWS_ENABLE_TIME_SOURCE
31 const char *active =
nullptr;
42 if (!s_ts.sources[i].used)
44 s_ts.sources[i].name = name;
45 s_ts.sources[i].fn = fn;
46 s_ts.sources[i].priority = priority;
47 s_ts.sources[i].used =
true;
56 s_ts.active =
nullptr;
68 if (!s_ts.sources[i].used || (queried & (1u << i)))
70 if (sel < 0 || s_ts.sources[i].priority < s_ts.sources[sel].priority)
76 queried |= (1u << sel);
77 uint32_t epoch = s_ts.sources[sel].fn();
80 s_ts.active = s_ts.sources[sel].name;
95 s_ts.sources[i] = Src{};
96 s_ts.active =
nullptr;
#define DETWS_TIME_SOURCE_MAX
Maximum registered time sources (DETWS_ENABLE_TIME_SOURCE).
Format a Unix epoch as an RFC 7231 IMF-fixdate (one shared copy).
size_t detws_http_date(time_t epoch, char *out, size_t out_cap)
Write epoch as an RFC 7231 IMF-fixdate into out (always GMT).
bool detws_time_source_add(const char *, uint8_t, TimeSourceFn)
Register a time source.
const char * detws_time_source_active(void)
Name of the source that satisfied the last detws_time_now(), or nullptr.
void detws_time_source_reset(void)
Clear all registered sources.
uint32_t detws_time_now(void)
Current best time.
size_t detws_time_http_date(char *out, size_t out_cap)
The current best time (detws_time_now, any registered NTP / GPS / RTC / ... source) formatted as an R...
Multi-source time fallback matrix (DETWS_ENABLE_TIME_SOURCE).
uint32_t(* TimeSourceFn)(void)
A time source: returns the current Unix epoch seconds for this source, or 0 if it currently has no va...