esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
systime.hpp
Go to the documentation of this file.
1#ifndef NDNPH_PORT_UNIXTIME_SYSTIME_HPP
2#define NDNPH_PORT_UNIXTIME_SYSTIME_HPP
3
4#include "../../core/common.hpp"
5
6#include <sys/time.h>
7
8namespace ndnph {
9namespace port_unixtime_systime {
10
12class UnixTime {
13public:
14 UnixTime() = delete;
15
20 static uint64_t now() {
21 ::timeval tv{};
22 ::gettimeofday(&tv, nullptr);
23 return static_cast<uint64_t>(tv.tv_sec) * 1000000 + static_cast<uint64_t>(tv.tv_usec);
24 }
25
27 static bool valid(uint64_t t) {
28 return t >= 540109800000000;
29 }
30
35 static void set(uint64_t t) {
36#ifdef NDNPH_PORT_UNIXTIME_SYSTIME_CANSET
37 ::timeval tv{
38 .tv_sec = static_cast<decltype(tv.tv_sec)>(t / 1000000),
39 .tv_usec = static_cast<decltype(tv.tv_usec)>(t % 1000000),
40 };
41 ::settimeofday(&tv, nullptr);
42#else
43 (void)t;
44#endif
45 }
46};
47
48} // namespace port_unixtime_systime
49
50#ifdef NDNPH_PORT_UNIXTIME_SYSTIME
51namespace port {
52using UnixTime = port_unixtime_systime::UnixTime;
53} // namespace port
54#endif
55
56} // namespace ndnph
57
58#endif // NDNPH_PORT_UNIXTIME_SYSTIME_HPP
Clock implemented with gettimeofday() .
Definition systime.hpp:12
static bool valid(uint64_t t)
Determine whether t is likely a valid current Unix timestamp.
Definition systime.hpp:27
static void set(uint64_t t)
Attempt to set current Unix timestamp, if allowed on current system.
Definition systime.hpp:35
static uint64_t now()
Retrieve current Unix timestamp in microseconds.
Definition systime.hpp:20
Definition fs.hpp:33