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

Data model definitions: resources, instances, objects, and handlers. More...

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

Go to the source code of this file.

Data Structures

struct  anj_dm_res_struct
 
struct  anj_dm_obj_inst_struct
 
struct  anj_dm_obj_struct
 
struct  anj_dm_handlers_struct
 

Typedefs

typedef struct anj_dm_res_struct anj_dm_res_t
 
typedef struct anj_dm_obj_inst_struct anj_dm_obj_inst_t
 
typedef struct anj_dm_handlers_struct anj_dm_handlers_t
 
typedef struct anj_dm_obj_struct anj_dm_obj_t
 
typedef int anj_dm_res_read_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, anj_riid_t riid, anj_res_value_t *out_value)
 
typedef int anj_dm_res_write_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, anj_riid_t riid, const anj_res_value_t *value)
 
typedef int anj_dm_res_execute_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, const char *execute_arg, size_t execute_arg_len)
 
typedef int anj_dm_res_inst_create_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, anj_riid_t riid)
 
typedef int anj_dm_res_inst_delete_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, anj_riid_t riid)
 
typedef int anj_dm_inst_create_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid)
 
typedef int anj_dm_inst_delete_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid)
 
typedef int anj_dm_inst_reset_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid)
 
typedef int anj_dm_transaction_begin_t(anj_t *anj, const anj_dm_obj_t *obj)
 
typedef int anj_dm_transaction_validate_t(anj_t *anj, const anj_dm_obj_t *obj)
 
typedef void anj_dm_transaction_end_t(anj_t *anj, const anj_dm_obj_t *obj, anj_dm_transaction_result_t result)
 

Enumerations

enum  anj_dm_res_kind_t {
  ANJ_DM_RES_R , ANJ_DM_RES_RM , ANJ_DM_RES_W , ANJ_DM_RES_WM ,
  ANJ_DM_RES_RW , ANJ_DM_RES_RWM , ANJ_DM_RES_E
}
 
enum  anj_dm_transaction_result_t { ANJ_DM_TRANSACTION_SUCCESS = 0 , ANJ_DM_TRANSACTION_FAILURE = -1 }
 

Detailed Description

Data model definitions: resources, instances, objects, and handlers.

Provides enums and structures that describe LwM2M Objects, as well as handler prototypes for Read, Write, Execute, Create, Delete, and transaction management.

Typedef Documentation

◆ anj_dm_handlers_t

◆ anj_dm_inst_create_t

typedef int anj_dm_inst_create_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid)

A handler that creates a new Object Instance.

This function is called when a LwM2M Create operation is requested for the given Object. The handler is responsible for allocating and initializing a new Object Instance with the specified iid and inserting it into the anj_dm_obj_t::insts array. The array must remain sorted in ascending order of Object Instance IDs.

Warning
If the operation fails at a later stage (i.e., anj_dm_transaction_end_t is called with a failure result), the user is responsible for removing the newly added instance and restoring the array to its previous state.
Parameters
anjAnjay object.
objObject definition pointer.
iidNew object Instance ID.
Returns
This handler should return:

◆ anj_dm_inst_delete_t

typedef int anj_dm_inst_delete_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid)

A handler that deletes an Object Instance.

This function is called when a LwM2M Delete operation is requested for the given Object. The handler is responsible for removing the Object Instance with the specified iid from the anj_dm_obj_t::insts array. After the removal, the array must remain in ascending order, and all unused slots must be set to ANJ_ID_INVALID.

If the operation fails later (i.e., anj_dm_transaction_end_t is called with a failure result), the user is responsible for restoring the deleted instance and reinserting it into the Instances array at the correct position.

Parameters
anjAnjay object.
objPointer to the object definition.
iidObject Instance ID to be deleted.
Returns
This handler should return:

◆ anj_dm_inst_reset_t

typedef int anj_dm_inst_reset_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid)

A handler that resets an Object Instance to its default (post-creation) state.

This handler is used during the LwM2M Write Replace operation. It should remove all writable Resource Instances belonging to the specified Object Instance. After the reset, new Resource values will be provided by subsequent write calls.

Parameters
anjAnjay object.
objPointer to the object definition.
iidObject Instance ID to reset.
Returns
This handler should return:

◆ anj_dm_obj_inst_t

Struct defining an Object Instance.

◆ anj_dm_obj_t

Struct defining an Object.

◆ anj_dm_res_execute_t

typedef int anj_dm_res_execute_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, const char *execute_arg, size_t execute_arg_len)

A handler that performs the Execute operation on given Resource.

This function may be called only for Resources of ANJ_DM_RES_E kind.

Parameters
anjAnjay object.
objObject definition pointer.
iidObject Instance ID.
ridResource ID.
execute_argPayload provided in Execute request, NULL if not present.
execute_arg_lenExecute payload length.
Returns
This handler should return:

◆ anj_dm_res_inst_create_t

typedef int anj_dm_res_inst_create_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, anj_riid_t riid)

A handler called to create a new Resource Instance within a Multiple-Instance Resource.

This function is called when a LwM2M Write operation requires creating a new Resource Instance. The handler is responsible for initializing the new instance with the specified riid and inserting its ID into the anj_dm_res_t::insts array. The array must remain sorted in ascending order of Resource Instance IDs.

Warning
If the operation fails at a later stage (i.e., anj_dm_transaction_end_t is called with a failure result), the user is responsible for removing the newly added instance and restoring the array to its previous state.
Parameters
anjAnjay object.
objPointer to the object definition.
iidObject Instance ID.
ridResource ID.
riidResource Instance ID of newly created Resource Instance.
Returns
This handler should return:

◆ anj_dm_res_inst_delete_t

typedef int anj_dm_res_inst_delete_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, anj_riid_t riid)

A handler called to delete a Resource Instance of a Multiple-Instance Resource.

The handler is responsible for removing the Resource Instance with the specified riid from the anj_dm_res_t::insts array. After the removal, the array must remain in ascending order, and all unused slots must be set to ANJ_ID_INVALID.

Warning
If the operation fails at a later stage (i.e., anj_dm_transaction_end_t is called with a failure result), the user is responsible for removing the newly added instance and restoring the array to its previous state.
Parameters
anjAnjay object.
objPointer to the object definition.
iidObject Instance ID.
ridResource ID.
riidResource Instance ID to be deleted.
Returns
This handler should return:

◆ anj_dm_res_read_t

typedef int anj_dm_res_read_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, anj_riid_t riid, anj_res_value_t *out_value)

A handler that reads the value of a Resource or Resource Instance.

This callback may be called for Resources of the following kinds:

For values of type ANJ_DATA_TYPE_BYTES, you must set both the data pointer and anj_bytes_or_string_value_t::chunk_length in out_value.

For values of type ANJ_DATA_TYPE_STRING, do not modify any additional fields in out_value — only the data pointer should be provided.

For values of type ANJ_DATA_TYPE_EXTERNAL_BYTES and ANJ_DATA_TYPE_EXTERNAL_STRING, you must set anj_res_value_t::get_external_data callback. anj_res_value_t::open_external_data and anj_res_value_t::close_external_data callbacks are optional. If the external data source needs initialization, it should be performed in the anj_res_value_t::open_external_data callback. This handler should do nothing more than assign the relevant addresses to the pointers in the anj_res_value_t::external_data structure.

Parameters
anjAnjay object.
objObject definition pointer.
iidObject Instance ID.
ridResource ID.
riidResource Instance ID, or ANJ_ID_INVALID in case of a Single-Instance Resource.
[out]out_valueResource value.
Returns
This handler should return:

◆ anj_dm_res_t

Struct defining a Resource.

◆ anj_dm_res_write_t

typedef int anj_dm_res_write_t(anj_t *anj, const anj_dm_obj_t *obj, anj_iid_t iid, anj_rid_t rid, anj_riid_t riid, const anj_res_value_t *value)

A handler that writes the value of a Resource or Resource Instance.

This function may be called for Resources of the following kinds:

Additionally, this handler may called for Read-only Resources during the Bootstrap procedure, that is to Resources of following kinds:

For values of type ANJ_DATA_TYPE_BYTES and ANJ_DATA_TYPE_STRING, in case of a Block-Wise operation, the handler may be called several times, with consecutive chunks of value. See anj_dm_write_bytes_chunked and anj_dm_write_string_chunked functions that help with handling such case.

Warning
Values of type ANJ_DATA_TYPE_STRING are not null-terminated, hence instead of strlen(), use the anj_bytes_or_string_value_t::chunk_length field (of anj_res_value_t::bytes_or_string) to determine the length or just use anj_dm_write_string_chunked helper.
Parameters
anjAnjay object.
objObject definition pointer.
iidObject Instance ID.
ridResource ID.
riidResource Instance ID, or ANJ_ID_INVALID in case of a Single-Instance Resource.
valueResource value.
Returns
This handler should return:

◆ anj_dm_transaction_begin_t

typedef int anj_dm_transaction_begin_t(anj_t *anj, const anj_dm_obj_t *obj)

A handler called at the beginning of a transactional operation that may modify the Object.

This function is invoked when the LwM2M server sends a request involving this Object that may alter its state — specifically for Create, Write, or Delete operations.

User is expected to back up the current state of the Object in callback, so that in case of a failure later in the transaction (i.e., anj_dm_transaction_end_t is called with a failure result), they can restore the Object to its previous state.

Parameters
anjAnjay object.
objObject definition pointer.
Returns
This handler should return:

◆ anj_dm_transaction_end_t

typedef void anj_dm_transaction_end_t(anj_t *anj, const anj_dm_obj_t *obj, anj_dm_transaction_result_t result)

A handler called at the end of a transactional operation.

This function is invoked after handling a Create, Write, or Delete request from the LwM2M server. If result is ANJ_DM_TRANSACTION_FAILURE, the user is responsible for restoring the Object to its previous state.

Parameters
anjAnjay object.
objObject definition pointer.
resultResult of the operation.

◆ anj_dm_transaction_validate_t

typedef int anj_dm_transaction_validate_t(anj_t *anj, const anj_dm_obj_t *obj)

A handler called after a transaction is finished, but before it is finalized.

This function is used to validate whether the operation can be safely completed. It is invoked for transactional operations that may modify the Object (i.e., Create, Write, and Delete) after all handler calls have completed, but before anj_dm_transaction_end_t is called.

Warning
It is not guaranteed that this function will be called at some point after every call to anj_dm_transaction_begin_t. If an error occurs during the validation of other objects involed in the same operation (e.g. during Write-Composite), this function may never be called.
Parameters
anjAnjay object.
objObject definition pointer.
Returns
This handler should return:

Enumeration Type Documentation

◆ anj_dm_res_kind_t

Resource kinds: single/multiple instance, readable/writable/executable.

Enumerator
ANJ_DM_RES_R 

Read-only Single-Instance Resource.

Note
Bootstrap Server is allowed to write to such Resources during Bootstrap procedure, even though they are marked as read-only.
See also
anj_dm_res_write_t
ANJ_DM_RES_RM 

Read-only Multiple-Instance Resource.

Note
Bootstrap Server is allowed to write to such Resources during Bootstrap procedure, even though they are marked as read-only.
See also
anj_dm_res_write_t
ANJ_DM_RES_W 

Write-only Single-Instance Resource.

ANJ_DM_RES_WM 

Write-only Multiple-Instance Resource.

ANJ_DM_RES_RW 

Read/Write Single-Instance Resource.

ANJ_DM_RES_RWM 

Read/Write Multiple-Instance Resource.

ANJ_DM_RES_E 

Executable Resource.

◆ anj_dm_transaction_result_t

Result of a transactional operation.

Enumerator
ANJ_DM_TRANSACTION_SUCCESS 

The operation completed successfully.

ANJ_DM_TRANSACTION_FAILURE 

The operation failed. The object must be restored to its previous state.