Anjay Lite
Loading...
Searching...
No Matches
core.h File Reference

Core data model API: object management, read/write helpers, bootstrap. More...

#include <anj/init.h>
#include <anj/defs.h>
#include <anj/dm/defs.h>

Go to the source code of this file.

Macros

#define ANJ_DM_ERR_BAD_REQUEST   (-(int) ANJ_COAP_CODE_BAD_REQUEST)
 
#define ANJ_DM_ERR_UNAUTHORIZED   (-(int) ANJ_COAP_CODE_UNAUTHORIZED)
 
#define ANJ_DM_ERR_NOT_FOUND   (-(int) ANJ_COAP_CODE_NOT_FOUND)
 
#define ANJ_DM_ERR_METHOD_NOT_ALLOWED    (-(int) ANJ_COAP_CODE_METHOD_NOT_ALLOWED)
 
#define ANJ_DM_ERR_INTERNAL   (-(int) ANJ_COAP_CODE_INTERNAL_SERVER_ERROR)
 
#define ANJ_DM_ERR_NOT_IMPLEMENTED   (-(int) ANJ_COAP_CODE_NOT_IMPLEMENTED)
 
#define ANJ_DM_ERR_SERVICE_UNAVAILABLE    (-(int) ANJ_COAP_CODE_SERVICE_UNAVAILABLE)
 

Functions

int anj_dm_add_obj (anj_t *anj, const anj_dm_obj_t *obj)
 
int anj_dm_remove_obj (anj_t *anj, anj_oid_t oid)
 
int anj_dm_res_read (anj_t *anj, const anj_uri_path_t *path, anj_res_value_t *out_value)
 
int anj_dm_write_bytes_chunked (const anj_res_value_t *value, uint8_t *buffer, size_t buffer_len, size_t *out_bytes_len, bool *out_is_last_chunk)
 
int anj_dm_write_string_chunked (const anj_res_value_t *value, char *buffer, size_t buffer_len, bool *out_is_last_chunk)
 

Detailed Description

Core data model API: object management, read/write helpers, bootstrap.

Provides error codes for data model handlers, functions to add/remove objects, read resources, handle chunked writes, and perform bootstrap cleanup.

Function Documentation

◆ anj_dm_add_obj()

int anj_dm_add_obj ( anj_t anj,
const anj_dm_obj_t obj 
)

Adds an Object to the data model and validates its structure.

obj parameter is not copied; the user must ensure that it remains valid for the entire lifetime of the anj object or until it is removed using anj_dm_remove_obj.

Note
Validation of the Object, its Instances, and Resources is performed only in debug builds (i.e., when the NDEBUG macro is not defined). In release builds, internal consistency checks are skipped.
Warning
Object Instances in the obj structure must be stored in ascending order by their oid.
Parameters
anjAnjay object.
objPointer to the Object definition struct.
Returns
0 on success, a non-zero value in case of an error.

◆ anj_dm_remove_obj()

int anj_dm_remove_obj ( anj_t anj,
anj_oid_t  oid 
)

Removes Object from the data model.

Parameters
anjAnjay object.
oidID number of the Object to be removed.
Returns
0 on success, a non-zero value in case of an error.

◆ anj_dm_res_read()

int anj_dm_res_read ( anj_t anj,
const anj_uri_path_t path,
anj_res_value_t out_value 
)

Reads the value of the Resource or Resource Instance.

Parameters
anjAnjay object.
pathResource or Resource Instance path.
[out]out_valueResource value.
Returns
0 on success, a non-zero value in case of an error.

◆ anj_dm_write_bytes_chunked()

int anj_dm_write_bytes_chunked ( const anj_res_value_t value,
uint8_t *  buffer,
size_t  buffer_len,
size_t *  out_bytes_len,
bool *  out_is_last_chunk 
)

Handles writing of a opaque data in the anj_dm_res_write_t handler.

This function assists in collecting binary data that may arrive in multiple chunks during the LwM2M Write operation. It copies a single chunk of data from the anj_res_value_t structure into the specified target buffer at the automatically tracked offset - for this reason, buffer is expected to be the same across multiple invocations of this function.

This function does not add a terminator — it is intended for binary (non-null-terminated) content.

Note
This function must be used only for Resources of type ANJ_DATA_TYPE_BYTES. For string values, use anj_dm_write_string_chunked instead.
Parameters
valueResource value to be written.
[out]bufferTarget buffer to write into.
buffer_lenSize of the target buffer.
[out]out_bytes_lenSet to total data length if the current chunk is the last one.
[out]out_is_last_chunkOptional parameter. Set to true if this is the last chunk of data.
Returns
0 on success, a non-zero value in case of an error.

◆ anj_dm_write_string_chunked()

int anj_dm_write_string_chunked ( const anj_res_value_t value,
char *  buffer,
size_t  buffer_len,
bool *  out_is_last_chunk 
)

Handles writing of a string value in the anj_dm_res_write_t handler.

This function assists in collecting strings that may arrive in multiple chunks during the LwM2M Write operation. It copies a single chunk of data from the anj_res_value_t structure into the specified target buffer at the automatically tracked offset - for this reason, buffer is expected to be the same across multiple invocations of this function.

When the final chunk is received, a null terminator ('\0') is additionally written into the buffer.

Note
This function must be used only for Resources of type ANJ_DATA_TYPE_STRING. For binary values, use anj_dm_write_bytes_chunked instead.
Parameters
valueResource value to be written.
[out]bufferTarget buffer to write the data into.
buffer_lenSize of the target buffer (must include space for the null terminator).
[out]out_is_last_chunkOptional parameter. Set to true if this is the last chunk of data.
Returns
0 on success, a non-zero value in case of an error.