net: lwm2m: allow formatters to perform processing prior to read_op

Data formatters are becoming too complex for a simple do_read_op()
function to handle all in one place.  Also, more data formatters are
going to be added for LwM2M v1.1 support in the future.

In order for data formatters to perform internal setup or deny
invalid requests (specific to the formatter's logic), let's
establish do_read_op_* functions in each formatter.

Once the internal processing is done, they can call back into the
more generic lwm2m_perform_read_op function.

Signed-off-by: Michael Scott <mike@foundries.io>
This commit is contained in:
Michael Scott 2018-08-29 13:35:50 -07:00 committed by Anas Nashif
commit 34a135b608
8 changed files with 69 additions and 0 deletions

View file

@ -2704,6 +2704,34 @@ static int lwm2m_delete_handler(struct lwm2m_engine_obj *obj,
static int do_read_op(struct lwm2m_engine_obj *obj,
struct lwm2m_engine_context *context,
u16_t content_format)
{
switch (content_format) {
case LWM2M_FORMAT_APP_OCTET_STREAM:
case LWM2M_FORMAT_PLAIN_TEXT:
case LWM2M_FORMAT_OMA_PLAIN_TEXT:
return do_read_op_plain_text(obj, context, content_format);
case LWM2M_FORMAT_OMA_TLV:
case LWM2M_FORMAT_OMA_OLD_TLV:
return do_read_op_tlv(obj, context, content_format);
#if defined(CONFIG_LWM2M_RW_JSON_SUPPORT)
case LWM2M_FORMAT_OMA_JSON:
case LWM2M_FORMAT_OMA_OLD_JSON:
return do_read_op_json(obj, context, content_format);
#endif
default:
SYS_LOG_ERR("Unsupported content-format: %u", content_format);
return -ENOMSG;
}
}
int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
struct lwm2m_engine_context *context,
u16_t content_format)
{
struct lwm2m_output_context *out = context->out;
struct lwm2m_obj_path *path = context->path;