NetBurner 3.5.6
PDF Version
nbtime.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5#include <servlets.h>
6#include <config_obj.h>
7#include <nbstring.h>
8#include <nettimer.h>
9#include <nettypes.h>
10
77#include <time.h>
78
79#ifndef _NB_TIME_H
80#define _NB_TIME_H
81
82#ifdef __cplusplus
83extern "C"
84{
85#endif /* __cplusplus */
86
94time_t time(time_t *pt);
95
96#ifdef __cplusplus
97};
98#endif /* __cplusplus */
99
108time_t set_time(time_t time_to_set, uint32_t fraction=0);
109
121time_t timegm(struct tm *bts);
122
123#ifdef NB_NET_TYPES_H
124
134BOOL SetNTPTime(IPADDR ntpserver);
135
146BOOL SetTimeNTPFromPool(bool debug = FALSE);
147
158time_t GetNTPTime(IPADDR NTP_server_ip, uint32_t * pFraction=0);
159
160
161#define TWELVE_HOURS_SECS (12*3600)
162#define ONE_DAY_SECS (14*3600)
163
185class NtpClientServlet: public servlet, public config_obj, public TimeOutElement
186{
187 public:
188 config_string m_ServerAddress;
189 config_int m_interval;
190 ConfigEndMarker; // No new data members below this line
191 protected:
192 OS_FLAGS NTPFlag;
193 NBString m_server; //Name of server
194 time_t last_update; //time of last valid update in system Secs
195 time_t last_attempt; //time of last update in system Secs
196 uint32_t m_TickSent; //Transmit time
197 servlet_list * m_pWhoToReJoin;
198
199 int m_fd; //fd to hold DNS Requests and UDP send/rx
200 int cur_state; //State variable
201
202 //Servlet virtual functions
203 virtual int AddToSelectSet(fd_set &rd_set, fd_set &wr_set, fd_set &er_set);
204 virtual void ProcessSelectResult(fd_set &rd_set, fd_set &wr_set, fd_set &er_set);
205 //Timeout element virtual function
206 virtual void TimeElementEvent();
207
208 public:
215 NtpClientServlet(const char* NTP_Server="pool.ntp.org",uint32_t update_interval_sec=TWELVE_HOURS_SECS);
216
225 NtpClientServlet(servlet_list * List_To_Join, const char* NTP_Server="pool.ntp.org",uint32_t update_interval_sec=TWELVE_HOURS_SECS);
226
235 bool TimeIsValid();
236
244 bool TimeIsCurrent();
245
253 bool RefreshNow(uint32_t ticks_to_wait);
254
262 bool WaitForValid(uint32_t ticks_to_wait);
263
269 inline time_t GetSecsSinceUpdate() {return Secs-last_update; }
270
276 inline void SetServer(const char* pServer) {m_server = pServer; m_ServerAddress = pServer; cur_state = 0;}
277};
278
279#endif /* NB_NET_TYPES_H */
280
281
282/*
283 * Legacy function calls.
284 */
285// int IOBoardRTCSetSystemFromRTCTime(void);
286// int IOBoardRTCSetRTCfromSystemTime(void);
287
288/*
289 * Set the local time zone by using the TZ environment variable.
290 * Use one of the following for the U.S.:
291 *
292 * tzsetchar( "EST5EDT4,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Eastern
293 * tzsetchar( "CST6CDT5,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Central
294 * tzsetchar( "MST7MDT6,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Mountain
295 * tzsetchar( "MST7" ); Arizona
296 * tzsetchar( "PST8PDT7,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Pacific
297 * tzsetchar( "AKST9AKDT8,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Alaska
298 * tzsetchar( "HST10" ); Hawaii
299 *
300 * Effective 2007, the U.S. starts daylight savings time on the second Sunday of
301 * March at 2:00 AM and ends on the first Sunday of November at 2:00 AM. The
302 * starting and ending date/times for daylight savings time can be omitted from
303 * the string since these rules are used by default.
304 */
305
329void tzsetchar(const char *tzenv);
330
331#endif /* _NB_TIME_H */
332
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:700
Base class used to create configuration objects.
Definition config_obj.h:320
String Configuration Variable.
Definition config_obj.h:1127
void tzsetchar(const char *tzenv)
Set the system local time.
time_t timegm(struct tm *bts)
Converts a tm structure to time_t in GMT.
time_t time(time_t *pt)
Gets the current system GMT time.
time_t set_time(time_t time_to_set, uint32_t fraction=0)
Set the system time to the value passed in the time_t parameter.