|
Anjay Lite
|
Core LwM2M client API. More...
#include <anj/init.h>#include <anj/compat/net/anj_net_api.h>#include <anj/defs.h>#include <anj/dm/core.h>#include <anj/lwm2m_send.h>Go to the source code of this file.
Data Structures | |
| struct | anj_configuration_struct |
Macros | |
| #define | ANJ_SUPPORTED_BINDING_MODES "UT" |
Typedefs | |
| typedef void | anj_connection_status_callback_t(void *arg, anj_t *anj, anj_conn_status_t conn_status) |
| typedef struct anj_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) |
| anj_time_duration_t | anj_core_next_step_time (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, anj_time_duration_t timeout) |
| 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) |
Core LwM2M client API.
Declares configuration, connection state, and main loop functions that drive the Anjay Lite client.
| #define ANJ_SUPPORTED_BINDING_MODES "UT" |
| typedef struct anj_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 ANJ_CONN_STATUS_REGISTERING to ANJ_CONN_STATUS_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, as provided in anj_dm_device_object_init_t::reboot_cb_arg. |
| anj | Anjay object. |
| 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 | ||
| ) |
Informs the library that the application has modified the data model.
This function must be called whenever the application itself changes any Object, Instance, or Resource in the data model — i.e., when the change is not a direct result of an operation initiated by the LwM2M Server.
Typical examples where this function MUST be called:
| anj | Anjay object. |
| path | Pointer to the path of the changed Resource or affected Instance. |
| change_type | Type of change; see anj_core_change_type_t. |
| void anj_core_disable_server | ( | anj_t * | anj, |
| anj_time_duration_t | timeout | ||
| ) |
Temporarily disables the LwM2M Server connection.
If the server is currently active and registered, a De-Register message will be sent before the connection is closed. If the server is already disabled, calling this function updates the disable timeout.
The server will be automatically re-enabled after the specified duration. To disable the server indefinitely, set timeout to ANJ_TIME_DURATION_INVALID.
| anj | Anjay object. |
| timeout | Duration of the disable period, expressed as anj_time_duration_t. |
| 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. |
| anj_time_duration_t anj_core_next_step_time | ( | anj_t * | anj | ) |
Returns the time until the next call to anj_core_step is required.
In most cases, the returned value will be ANJ_TIME_DURATION_ZERO, 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. |
| 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. |
| void anj_core_request_update | ( | anj_t * | anj | ) |
Forces to start a Registration Update sequence.
| anj | Anjay object. |
| void anj_core_restart | ( | anj_t * | anj | ) |
Restarts the Anjay Lite client by resetting its internal state to ANJ_CONN_STATUS_INITIAL.
This fully reinitializes the LwM2M connection cycle and can be used after configuration changes, error recovery, or a user-triggered reset.
Actions performed:
| anj | Anjay object. |
| 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. |
| void anj_core_server_obj_disable_executed | ( | anj_t * | anj, |
| uint32_t | timeout | ||
| ) |
Should be called when the Disable Resource of the Server Object (/1/x/4) is executed.
| anj | Anjay object. |
| timeout | Timeout for which the server should remain disabled, in seconds. This value MUST be taken from the Disable Timeout Resource (/1/x/5) of the Server Object Instance corresponding to the LwM2M server that has executed the Resource. If that resource is not present, the default value of ANJ_DISABLE_TIMEOUT_DEFAULT_VALUE SHALL 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. |
| 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. |