ForestHub SDK 0.1.0
C++14 LLM SDK for PC and embedded platforms
Loading...
Searching...
No Matches
time.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (c) 2026 ForestHub. All rights reserved.
3// For commercial licensing, visit https://github.com/ForestHubAI/fh-sdk
4
5#ifndef FORESTHUB_PLATFORM_TIME_HPP
6#define FORESTHUB_PLATFORM_TIME_HPP
7
10
11#include <ctime>
12#include <string>
13
14namespace foresthub {
15namespace platform {
16
21struct TimeConfig {
22 const char* time_server = "pool.ntp.org";
23 long std_offset_sec = 0;
25 unsigned long timeout_ms = 5000;
26};
27
30public:
31 virtual ~TimeInterface() = default;
32
36 virtual std::string SyncTime(const TimeConfig& config = {}) = 0;
37
40 virtual unsigned long GetEpochTime() const = 0;
41
44 virtual unsigned long GetMillis() const = 0;
45
48 virtual void Delay(unsigned long ms) const = 0;
49
53 virtual bool IsSynced(unsigned long min_epoch = 1767225600) const = 0;
54
58 virtual void SetOffset(long std_offset_sec, int dst_offset_sec) = 0;
59
61 virtual long utc_offset_sec() const = 0;
62
67 unsigned long GetLocalEpoch() const {
68 return static_cast<unsigned long>(static_cast<long>(GetEpochTime()) + utc_offset_sec());
69 }
70
73 virtual void GetLocalTime(struct tm& result) const = 0;
74};
75
76} // namespace platform
77} // namespace foresthub
78
79#endif // FORESTHUB_PLATFORM_TIME_HPP
Abstract interface for time operations.
Definition time.hpp:29
virtual void GetLocalTime(struct tm &result) const =0
Get current local time as calendar fields (UTC + stored timezone offset).
virtual unsigned long GetEpochTime() const =0
Get current epoch time in seconds.
virtual void SetOffset(long std_offset_sec, int dst_offset_sec)=0
Set timezone offset locally (no network I/O).
virtual long utc_offset_sec() const =0
Get total UTC offset (standard + DST) in seconds.
virtual unsigned long GetMillis() const =0
Get milliseconds since startup (or arbitrary reference point).
virtual bool IsSynced(unsigned long min_epoch=1767225600) const =0
Check if time has been synchronized.
virtual void Delay(unsigned long ms) const =0
Delay execution for the specified number of milliseconds.
virtual std::string SyncTime(const TimeConfig &config={})=0
Synchronize system time with an external source.
unsigned long GetLocalEpoch() const
Get current local epoch time (UTC + timezone offset) in seconds.
Definition time.hpp:67
Client and provider configuration types.
Hardware abstraction layer: network, console, time, crypto, and GPIO interfaces.
Top-level namespace for the ForestHub SDK.
Call-time configuration for time synchronization.
Definition time.hpp:21
const char * time_server
Hostname of the time server.
Definition time.hpp:22
int dst_offset_sec
Additional daylight saving offset in seconds (e.g., 3600 when active).
Definition time.hpp:24
unsigned long timeout_ms
Maximum wait for synchronization in milliseconds.
Definition time.hpp:25
long std_offset_sec
Timezone standard offset from UTC in seconds (e.g., 3600 for CET).
Definition time.hpp:23