Typedef anjay_dm_resource_read_t

Typedef Documentation

typedef int anjay_dm_resource_read_t(anjay_t *anjay, const anjay_dm_object_def_t *const *obj_ptr, anjay_iid_t iid, anjay_rid_t rid, anjay_riid_t riid, anjay_output_ctx_t *ctx)

A handler that reads the Resource or Resource Instance value, called only if the Resource is PRESENT and is one of the ANJAY_DM_RES_R, ANJAY_DM_RES_RW, ANJAY_DM_RES_RM or ANJAY_DM_RES_RWM kinds (as returned by anjay_dm_list_resources_t).

NOTE: One of the anjay_ret_* functions MUST be called in this handler before returning successfully. Failure to do so will result in 5.00 Internal Server Error being sent to the server.

NOTE: This handler will only be called with riid set to a valid value if the Resource Instance is PRESENT (has recently been returned via anjay_dm_list_resource_instances_t).

Param anjay:

Anjay object to operate on.

Param obj_ptr:

Object definition pointer, as passed to anjay_register_object .

Param iid:

Object Instance ID.

Param rid:

Resource ID.

Param riid:

Resource Instance ID, or ANJAY_ID_INVALID in case of a Single Resource.

Param ctx:

Output context to write the resource value to using the anjay_ret_* function family.

Return:

This handler should return:

  • 0 on success,

  • a negative value in case of error. If it returns one of ANJAY_ERR_ constants, it will be used as a hint for the CoAP response code to use. The library may decide to override the returned value in case of a more specific internal error (e.g. 4.06 Not Acceptable in response to an invalid Accept option).

    Note that the CoAP response sent by the library will always be valid. If the value returned is a negative number that is not any of the ANJAY_ERR_ constant, the normal fallback response is 5.00 Internal Server Error.