Anjay Lite
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
defs.h File Reference
#include <anj/core.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, int result)
 

Enumerations

enum  anj_dm_res_operation_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
}
 

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 obj->insts array. The array must remain sorted in ascending order of instance IDs after insertion.

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 previous state of the Instances array by removing the newly added instance.

Parameters
anjAnjay object to operate on.
objObject definition pointer.
iidNew object Instance ID.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ 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 obj->insts array. The array must remain sorted in ascending order of instance IDs after the removal.

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 to operate on.
objPointer to the object definition.
iidObject Instance ID to be deleted.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ 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 to operate on.
objPointer to the object definition.
iidObject Instance ID to reset.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ anj_dm_obj_inst_t

A struct defining an Object Instance.

◆ anj_dm_obj_t

A 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 action on given Resource, called only if the Resource is ANJ_DM_RES_E kind.

Parameters
anjAnjay object to operate on.
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:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ 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 multi-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 res->insts array. The array must remain sorted in ascending order of Resource Instance IDs.

If the operation fails later (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 to operate on.
objPointer to the object definition.
iidObject Instance ID.
ridResource ID.
riidNew Resource Instance ID.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ 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 from a multi-instance Resource.

The handler is responsible for removing the Resource Instance with the specified riid from the res->insts array and marking its ID as ANJ_ID_INVALID. The array must remain sorted in ascending order of Resource Instance IDs after the removal.

If the deletion succeeds but the overall transaction is later marked as failed by anj_dm_transaction_end_t, the user is responsible for restoring the removed Resource Instance to its previous state.

Parameters
anjAnjay object to operate on.
objPointer to the object definition.
iidObject Instance ID.
ridResource ID.
riidResource Instance ID to be deleted.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ 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 function is called only for Resources of the following types: ANJ_DM_RES_R, ANJ_DM_RES_RW, ANJ_DM_RES_RM, or ANJ_DM_RES_RWM.

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 to operate on.
objObject definition pointer.
iidObject Instance ID.
ridResource ID.
riidResource Instance ID, or ANJ_ID_INVALID in case of a Single Resource.
[out]out_valueReturned Resource value.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ anj_dm_res_t

Main Resource struct.

◆ 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 Resource or Resource Instance value, called only if the Resource or Resource Instance is PRESENT and is one of the ANJ_DM_RES_W, ANJ_DM_RES_RW, ANJ_DM_RES_WM, ANJ_DM_RES_RWM.

For values of type ANJ_DATA_TYPE_BYTES and ANJ_DATA_TYPE_STRING, in case of the block operation, handler can be called several times, with consecutive chunks of value - offset value in anj_bytes_or_string_value_t will be changing.

IMPORTANT: For value of type ANJ_DATA_TYPE_STRING always use chunk_length to determine the length of the string, never use the strlen() function - pointer to string data points directly to CoAP message payload.

Parameters
anjAnjay object to operate on.
objObject definition pointer.
iidObject Instance ID.
ridResource ID.
riidResource Instance ID, or ANJ_ID_INVALID in case of a Single Resource.
valueResource value.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ 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. It marks the beginning of a transaction.

Parameters
anjAnjay object to operate on.
objObject definition pointer.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

◆ anj_dm_transaction_end_t

typedef void anj_dm_transaction_end_t(anj_t *anj, const anj_dm_obj_t *obj, int 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 non-zero value, the user is responsible for restoring the Object to its previous state.

Parameters
anjAnjay object to operate on.
objObject definition pointer.
resultResult of the operation. Non-zero value indicates failure. In case of failure, this value will either be:
  • One of the ANJ_DM_ERR_* constants,
  • Or a custom error code returned by the user from one of the callbacks (e.g. anj_dm_res_write_t).

◆ 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.

Parameters
anjAnjay object to operate on.
objObject definition pointer.
Returns
This handler should return:
  • 0 on success,
  • a negative value on error. If the error matches one of the ANJ_DM_ERR_* constants, an appropriate CoAP error code will be used in the response. Otherwise, the device will respond with ANJ_COAP_CODE_INTERNAL_SERVER_ERROR.

Enumeration Type Documentation

◆ anj_dm_res_operation_t

Resource operation types.

Enumerator
ANJ_DM_RES_R 

Read-only Single-Instance Resource. Bootstrap Server might attempt to write to it anyway.

ANJ_DM_RES_RM 

Read-only Multiple Instance Resource. Bootstrap Server might attempt to write to it anyway.

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.