Program Listing for File ntp.h
↰ Return to documentation for file (include_public/anj/ntp.h)
/*
* Copyright 2023-2026 AVSystem <avsystem@avsystem.com>
* AVSystem Anjay Lite LwM2M SDK
* All rights reserved.
*
* Licensed under AVSystem Anjay Lite LwM2M Client SDK - Non-Commercial License.
* See the attached LICENSE file for details.
*/
#include <anj/init.h>
#ifndef ANJ_NTP_H
# define ANJ_NTP_H
# include <anj/compat/net/anj_net_api.h>
# include <anj/defs.h>
# ifdef ANJ_WITH_PERSISTENCE
# include <anj/persistence.h>
# endif // ANJ_WITH_PERSISTENCE
# define ANJ_INTERNAL_INCLUDE_EXCHANGE
# include <anj_internal/exchange.h>
# undef ANJ_INTERNAL_INCLUDE_EXCHANGE
# ifdef __cplusplus
extern "C" {
# endif
# ifdef ANJ_WITH_NTP
# define ANJ_NTP_ERR_IN_PROGRESS -1
# define ANJ_NTP_ERR_CONFIGURATION -2
# define ANJ_NTP_ERR_OBJECT_CREATION_FAILED -3
typedef enum {
ANJ_NTP_STATUS_INITIAL,
ANJ_NTP_STATUS_PERIOD_EXCEEDED,
ANJ_NTP_STATUS_IN_PROGRESS,
ANJ_NTP_STATUS_FINISHED_SUCCESSFULLY,
ANJ_NTP_STATUS_FINISHED_WITH_ERROR,
# ifdef ANJ_WITH_PERSISTENCE
ANJ_NTP_STATUS_OBJECT_UPDATED,
# endif // ANJ_WITH_PERSISTENCE
} anj_ntp_status_t;
typedef void anj_ntp_event_callback_t(void *arg,
anj_ntp_t *ntp,
anj_ntp_status_t status,
anj_time_real_t synchronized_time);
typedef struct anj_ntp_configuration_struct {
anj_ntp_event_callback_t *event_cb;
void *event_cb_arg;
const char *ntp_server_address;
const char *backup_ntp_server_address;
uint32_t ntp_period_hours;
uint16_t attempts;
anj_time_duration_t response_timeout;
const anj_net_socket_configuration_t *net_socket_cfg;
} anj_ntp_configuration_t;
int anj_ntp_init(anj_t *anj,
anj_ntp_t *ntp,
const anj_ntp_configuration_t *config);
void anj_ntp_step(anj_ntp_t *ntp);
int anj_ntp_start(anj_ntp_t *ntp);
void anj_ntp_terminate(anj_ntp_t *ntp);
# ifdef ANJ_WITH_PERSISTENCE
int anj_ntp_obj_store(anj_ntp_t *ntp, const anj_persistence_context_t *ctx);
int anj_ntp_obj_restore(anj_ntp_t *ntp, const anj_persistence_context_t *ctx);
# endif // ANJ_WITH_PERSISTENCE
# define ANJ_INTERNAL_INCLUDE_NTP
# include <anj_internal/ntp.h>
# undef ANJ_INTERNAL_INCLUDE_NTP
# endif // ANJ_WITH_NTP
# ifdef __cplusplus
}
# endif
#endif // ANJ_NTP_H