Anjay Lite
|
#include <anj/anj_config.h>
#include <anj/compat/net/anj_net_api.h>
#include <anj/defs.h>
#include <anj/dm/core.h>
#include <anj_internal/exchange.h>
#include <anj_internal/bootstrap.h>
#include <anj/lwm2m_send.h>
#include <anj_internal/core.h>
Go to the source code of this file.
Data Structures | |
struct | anjay_configuration_struct |
Macros | |
#define | ANJ_INTERNAL_INCLUDE_EXCHANGE |
#define | ANJ_INTERNAL_INCLUDE_BOOTSTRAP |
#define | ANJ_SUPPORTED_BINDING_MODES "UT" |
#define | ANJ_INTERNAL_INCLUDE_CORE |
Typedefs | |
typedef void | anj_connection_status_callback_t(void *arg, anj_t *anj, anj_conn_status_t conn_status) |
typedef struct anjay_configuration_struct | anj_configuration_t |
Functions | |
int | anj_core_init (anj_t *anj, const anj_configuration_t *config) |
void | anj_core_step (anj_t *anj) |
uint64_t | anj_core_next_step_time (anj_t *anj) |
bool | anj_core_ongoing_operation (anj_t *anj) |
void | anj_core_server_obj_disable_executed (anj_t *anj, uint32_t timeout) |
void | anj_core_server_obj_registration_update_trigger_executed (anj_t *anj) |
void | anj_core_server_obj_bootstrap_request_trigger_executed (anj_t *anj) |
void | anj_core_data_model_changed (anj_t *anj, const anj_uri_path_t *path, anj_core_change_type_t change_type) |
void | anj_core_disable_server (anj_t *anj, uint64_t timeout_ms) |
void | anj_core_request_bootstrap (anj_t *anj) |
void | anj_core_restart (anj_t *anj) |
void | anj_core_request_update (anj_t *anj) |
int | anj_core_shutdown (anj_t *anj) |
#define ANJ_INTERNAL_INCLUDE_BOOTSTRAP |
#define ANJ_INTERNAL_INCLUDE_CORE |
#define ANJ_INTERNAL_INCLUDE_EXCHANGE |
#define ANJ_SUPPORTED_BINDING_MODES "UT" |
typedef struct anjay_configuration_struct anj_configuration_t |
Anjay Lite configuration. Provided in anj_core_init() function.
typedef void anj_connection_status_callback_t(void *arg, anj_t *anj, anj_conn_status_t conn_status) |
Callback type for connection status change notifications.
This function is called whenever the connection state of the LwM2M client changes — e.g., transitioning from bootstrapping to registered, or entering queue mode.
Users may use this callback to monitor client connectivity and act accordingly (e.g., update UI, manage power states, or trigger other logic).
arg | Opaque argument passed to the callback. |
anj | Anjay object reporting the status change. |
conn_status | New connection status value; see anj_conn_status_t. |
enum anj_conn_status_t |
This enum represents the possible states of a server connection.
Enumerator | |
---|---|
ANJ_CONN_STATUS_INITIAL | Initial state of the client after startup. Anjay Lite will automatically attempt to transition to either ANJ_CONN_STATUS_BOOTSTRAPPING or ANJ_CONN_STATUS_REGISTERING, depending on the configuration. If the provided configuration is invalid or incomplete, the client will immediately transition to ANJ_CONN_STATUS_INVALID. |
ANJ_CONN_STATUS_INVALID | Provided configuration is invalid and a connection cannot be established. This state is transient — the client will immediately transition to ANJ_CONN_STATUS_FAILURE to indicate a permanent failure. |
ANJ_CONN_STATUS_FAILURE | Indicates that bootstrap or registration has permanently failed (i.e., all configured retry attempts have been exhausted). In this case, reinitialization of the Anjay Lite client is required to attempt a new connection cycle. This can be done by calling anj_core_restart. |
ANJ_CONN_STATUS_BOOTSTRAPPING | Bootstrap process is ongoing. |
ANJ_CONN_STATUS_BOOTSTRAPPED | Bootstrapping process has finished successfully. |
ANJ_CONN_STATUS_REGISTERING | Registering process is ongoing. |
ANJ_CONN_STATUS_REGISTERED | Registering/Updating process has finished successfully. |
ANJ_CONN_STATUS_SUSPENDED | Connection is suspended. If the suspension was initiated by the server the client will remain suspended until the Disable Timeout (resource 1/x/5) expires. If the suspension was initiated by the client application no action is taken until user decides to resume or timeout occurs. |
ANJ_CONN_STATUS_ENTERING_QUEUE_MODE | Client is entering queue mode. |
ANJ_CONN_STATUS_QUEUE_MODE | Client is in queue mode: new requests still can be sent to the server, but no new messages are received. |
Contains information about the type of changes of the data model. Used in anj_core_data_model_changed function.
void anj_core_data_model_changed | ( | anj_t * | anj, |
const anj_uri_path_t * | path, | ||
anj_core_change_type_t | change_type | ||
) |
Notifies the library that data model changed. Depending on the change_type
there are three possible scenarios:
For correct handling of notifications, and registration updates, this function must be called on any change in the data model.
IMPORTANT: This function is to be used only for changes in the data model that are caused by user actions. Changes caused by the LwM2M Server are handled internally.
anj | Anjay object to operate on.t. |
path | Pointer to the path of the Resource that changed, or the Instance that was added/removed. |
change_type | Type of change; anj_core_change_type_t. |
void anj_core_disable_server | ( | anj_t * | anj, |
uint64_t | timeout_ms | ||
) |
Disables the LwM2M Server connection for a specified timeout. If the server is already disabled, this call will only update the timeout value.
timeout_ms
to ANJ_TIME_UNDEFINED.anj | Anjay object to operate on. |
timeout_ms | Timeout for server disable, i.e. time for which a server should be disabled before it's automatically enabled again, in miliseconds. |
int anj_core_init | ( | anj_t * | anj, |
const anj_configuration_t * | config | ||
) |
Initializes the core of the Anjay Lite library. The anj
object must be created and allocated by the user before calling this function.
anj | Anjay object to operate on. |
config | Configuration structure. |
uint64_t anj_core_next_step_time | ( | anj_t * | anj | ) |
Returns the time (in milliseconds) until the next call to anj_core_step is required.
In most cases, the returned value will be 0, indicating that the main loop should call anj_core_step immediately.
However, in certain low-activity states, this function may return a positive value:
This function is useful for optimizing power consumption or sleeping, allowing the main loop to wait the appropriate amount of time before calling anj_core_step again.
This function allows the integration layer to optimize power consumption or sleep scheduling by delaying calls to anj_core_step until necessary.
anj | Anjay object to operate on. |
bool anj_core_ongoing_operation | ( | anj_t * | anj | ) |
Checks if there is an ongoing exchange between the client and the server. User must not process operations on the data model if this function returns true.
anj | Anjay object to operate on. |
void anj_core_request_bootstrap | ( | anj_t * | anj | ) |
Forces the start of a Bootstrap sequence.
This function immediately initiates a client-side Bootstrap procedure, regardless of the current connection status.
anj | Anjay object to operate on. |
void anj_core_request_update | ( | anj_t * | anj | ) |
Forces to start a Registration Update sequence.
anj | Anjay object to operate on. |
void anj_core_restart | ( | anj_t * | anj | ) |
Restarts the Anjay Lite client connection by resetting its internal state to the initial state (ANJ_CONN_STATUS_INITIAL).
This function can be used to fully reinitialize the LwM2M connection cycle, e.g., after a configuration change, error recovery, or user-triggered reset.
The following operations are performed:
In this case, the connection is suspended intentionally by the server, and the client must remain idle until the disable timeout expires.
anj | Anjay object to operate on. |
void anj_core_server_obj_bootstrap_request_trigger_executed | ( | anj_t * | anj | ) |
Should be called when Bootstrap-Request Trigger resource of Server object (/1/x/9) is executed.
anj | Anjay object to operate on. |
void anj_core_server_obj_disable_executed | ( | anj_t * | anj, |
uint32_t | timeout | ||
) |
Should be called when Disable resource of Server object (/1/x/4) is executed.
anj | Anjay object to operate on. |
timeout | Timeout for server disable, i.e. time for which a server should be disabled before it's automatically enabled again, in seconds. It's taken from /1/x/5 Resource and if it's not set, default value of 86400 seconds (24h) should be used. |
void anj_core_server_obj_registration_update_trigger_executed | ( | anj_t * | anj | ) |
Should be called when Registration Update Trigger resource of Server object (/1/x/8) is executed.
anj | Anjay object to operate on. |
int anj_core_shutdown | ( | anj_t * | anj | ) |
Shuts down the Anjay Lite client instance.
This function halts all active LwM2M operations and clears the client’s internal state. Once called, the anj
object becomes unusable unless it is reinitialized using anj_core_init.
The following cleanup steps are performed:
Internally, this function invokes a sequence of operations to tear down networking, including shutting down and closing sockets, and releasing network context state. If any of these steps return ANJ_NET_EAGAIN, indicating that the operation is not yet complete, this function will immediately return that value. In this case, the client is not yet fully shut down, and the function should be called again later to complete the process.
If any networking-related call returns an error other than ANJ_NET_EAGAIN, the client is still fully shut down internally, but some network resources (such as sockets or internal handles) may not have been properly released.
anj | Pointer to the Anjay client instance to shut down. |
void anj_core_step | ( | anj_t * | anj | ) |
Main step function of the Anjay Lite library.
This function should be called regularly in the main application loop. It drives the internal state machine and handles all scheduled operations related to LwM2M communication (e.g., bootstrap, registration, notifications, queue mode transitions, etc.).
This function is non-blocking, unless a custom network implementation introduces blocking behavior.
anj | Anjay object to operate on. |