net: lwm2m: obj inst processing per formatter

It depends from a content formatter is there need to put constructs
with a path level deeper than object instance. In other words with
resource- or resource-instance-level.

Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
This commit is contained in:
Veijo Pesonen 2022-03-02 15:58:36 +02:00 committed by Carles Cufí
commit 0032f0bcff
2 changed files with 15 additions and 12 deletions

View file

@ -3366,12 +3366,9 @@ static int lwm2m_perform_read_object_instance(struct lwm2m_message *msg,
/* update the obj_inst_id as we move through the instances */ /* update the obj_inst_id as we move through the instances */
msg->path.obj_inst_id = obj_inst->obj_inst_id; msg->path.obj_inst_id = obj_inst->obj_inst_id;
if (msg->path.level <= LWM2M_PATH_LEVEL_OBJECT) { ret = engine_put_begin_oi(&msg->out, &msg->path);
/* start instance formatting */ if (ret < 0) {
ret = engine_put_begin_oi(&msg->out, &msg->path); return ret;
if (ret < 0) {
return ret;
}
} }
for (int index = 0; index < obj_inst->resource_count; index++) { for (int index = 0; index < obj_inst->resource_count; index++) {
@ -3429,12 +3426,9 @@ static int lwm2m_perform_read_object_instance(struct lwm2m_message *msg,
} }
move_forward: move_forward:
if (msg->path.level <= LWM2M_PATH_LEVEL_OBJECT) { ret = engine_put_end_oi(&msg->out, &msg->path);
/* end instance formatting */ if (ret < 0) {
ret = engine_put_end_oi(&msg->out, &msg->path); return ret;
if (ret < 0) {
return ret;
}
} }
if (msg->path.level <= LWM2M_PATH_LEVEL_OBJECT) { if (msg->path.level <= LWM2M_PATH_LEVEL_OBJECT) {

View file

@ -336,6 +336,11 @@ static int put_begin_oi(struct lwm2m_output_context *out,
{ {
struct tlv_out_formatter_data *fd; struct tlv_out_formatter_data *fd;
/* No need for oi level TLV constructs */
if (path->level > LWM2M_PATH_LEVEL_OBJECT) {
return 0;
}
fd = engine_get_out_user_data(out); fd = engine_get_out_user_data(out);
if (!fd) { if (!fd) {
return -EINVAL; return -EINVAL;
@ -349,6 +354,10 @@ static int put_end_oi(struct lwm2m_output_context *out,
{ {
struct tlv_out_formatter_data *fd; struct tlv_out_formatter_data *fd;
if (path->level > LWM2M_PATH_LEVEL_OBJECT) {
return 0;
}
fd = engine_get_out_user_data(out); fd = engine_get_out_user_data(out);
if (!fd) { if (!fd) {
return -EINVAL; return -EINVAL;