|
Anjay Lite
|
Data model definitions: resources, instances, objects, and handlers. More...
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 |
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 } |
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 struct anj_dm_handlers_struct anj_dm_handlers_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.
| anj | Anjay object. |
| obj | Object definition pointer. |
| iid | New object Instance ID. |
| 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.
| anj | Anjay object. |
| obj | Pointer to the object definition. |
| iid | Object Instance ID to be deleted. |
| 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.
| anj | Anjay object. |
| obj | Pointer to the object definition. |
| iid | Object Instance ID to reset. |
| typedef struct anj_dm_obj_inst_struct anj_dm_obj_inst_t |
Struct defining an Object Instance.
| typedef struct anj_dm_obj_struct anj_dm_obj_t |
Struct defining an Object.
| 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.
| anj | Anjay object. |
| obj | Object definition pointer. |
| iid | Object Instance ID. |
| rid | Resource ID. |
| execute_arg | Payload provided in Execute request, NULL if not present. |
| execute_arg_len | Execute payload length. |
| 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.
| anj | Anjay object. |
| obj | Pointer to the object definition. |
| iid | Object Instance ID. |
| rid | Resource ID. |
| riid | Resource Instance ID of newly created Resource Instance. |
| 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.
| anj | Anjay object. |
| obj | Pointer to the object definition. |
| iid | Object Instance ID. |
| rid | Resource ID. |
| riid | Resource Instance ID to be deleted. |
| 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.
| anj | Anjay object. | |
| obj | Object definition pointer. | |
| iid | Object Instance ID. | |
| rid | Resource ID. | |
| riid | Resource Instance ID, or ANJ_ID_INVALID in case of a Single-Instance Resource. | |
| [out] | out_value | Resource value. |
| typedef struct anj_dm_res_struct anj_dm_res_t |
Struct defining a Resource.
| 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.
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.| anj | Anjay object. |
| obj | Object definition pointer. |
| iid | Object Instance ID. |
| rid | Resource ID. |
| riid | Resource Instance ID, or ANJ_ID_INVALID in case of a Single-Instance Resource. |
| value | Resource value. |
| 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.
| anj | Anjay object. |
| obj | Object definition pointer. |
| 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.
| anj | Anjay object. |
| obj | Object definition pointer. |
| result | Result of the operation. |
| 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.
| anj | Anjay object. |
| obj | Object definition pointer. |
| enum anj_dm_res_kind_t |
Resource kinds: single/multiple instance, readable/writable/executable.
| Enumerator | |
|---|---|
| ANJ_DM_RES_R | Read-only Single-Instance Resource.
|
| ANJ_DM_RES_RM | Read-only Multiple-Instance Resource.
|
| 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. |