Skip to content
Permalink
Browse files

net: lwm2m: remove lwm2m_engine_obj from most handlers/formatter OPs

Due to work combining data into the lwm2m_message structure, we no
longer need to pass the lwm2m_engine_obj parameter between
formatters and most of the operation handlers.

So, let's remove it.

Signed-off-by: Michael Scott <mike@foundries.io>
  • Loading branch information...
mike-scott authored and jukkar committed Jul 29, 2019
1 parent ca308ec commit 6a2f3623572986a3300d225da2040bc652bd376d
@@ -2596,14 +2596,13 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
return 0;
}

static int lwm2m_exec_handler(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg)
static int lwm2m_exec_handler(struct lwm2m_message *msg)
{
struct lwm2m_engine_obj_inst *obj_inst;
struct lwm2m_engine_res_inst *res = NULL;
int ret;

if (!obj || !msg) {
if (!msg) {
return -EINVAL;
}

@@ -2620,8 +2619,7 @@ static int lwm2m_exec_handler(struct lwm2m_engine_obj *obj,
return -ENOENT;
}

static int lwm2m_delete_handler(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg)
static int lwm2m_delete_handler(struct lwm2m_message *msg)
{
int ret;

@@ -2639,24 +2637,23 @@ static int lwm2m_delete_handler(struct lwm2m_engine_obj *obj,
return ret;
}

static int do_read_op(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg, u16_t content_format)
static int do_read_op(struct lwm2m_message *msg, 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, msg, content_format);
return do_read_op_plain_text(msg, content_format);

case LWM2M_FORMAT_OMA_TLV:
case LWM2M_FORMAT_OMA_OLD_TLV:
return do_read_op_tlv(obj, msg, content_format);
return do_read_op_tlv(msg, 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, msg, content_format);
return do_read_op_json(msg, content_format);
#endif

default:
@@ -2666,8 +2663,7 @@ static int do_read_op(struct lwm2m_engine_obj *obj,
}
}

int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg, u16_t content_format)
int lwm2m_perform_read_op(struct lwm2m_message *msg, u16_t content_format)
{
struct lwm2m_engine_obj_inst *obj_inst = NULL;
struct lwm2m_engine_res_inst *res = NULL;
@@ -3043,25 +3039,24 @@ int lwm2m_get_or_create_engine_obj(struct lwm2m_message *msg,
return ret;
}

static int do_write_op(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg,
static int do_write_op(struct lwm2m_message *msg,
u16_t format)
{
switch (format) {

case LWM2M_FORMAT_APP_OCTET_STREAM:
case LWM2M_FORMAT_PLAIN_TEXT:
case LWM2M_FORMAT_OMA_PLAIN_TEXT:
return do_write_op_plain_text(obj, msg);
return do_write_op_plain_text(msg);

case LWM2M_FORMAT_OMA_TLV:
case LWM2M_FORMAT_OMA_OLD_TLV:
return do_write_op_tlv(obj, msg);
return do_write_op_tlv(msg);

#ifdef CONFIG_LWM2M_RW_JSON_SUPPORT
case LWM2M_FORMAT_OMA_JSON:
case LWM2M_FORMAT_OMA_OLD_JSON:
return do_write_op_json(obj, msg);
return do_write_op_json(msg);
#endif

default:
@@ -3349,7 +3344,7 @@ static int handle_request(struct coap_packet *request,
}
}

r = do_read_op(obj, msg, accept);
r = do_read_op(msg, accept);
break;

case LWM2M_OP_DISCOVER:
@@ -3358,19 +3353,19 @@ static int handle_request(struct coap_packet *request,

case LWM2M_OP_WRITE:
case LWM2M_OP_CREATE:
r = do_write_op(obj, msg, format);
r = do_write_op(msg, format);
break;

case LWM2M_OP_WRITE_ATTR:
r = lwm2m_write_attr_handler(obj, msg);
break;

case LWM2M_OP_EXECUTE:
r = lwm2m_exec_handler(obj, msg);
r = lwm2m_exec_handler(msg);
break;

case LWM2M_OP_DELETE:
r = lwm2m_delete_handler(obj, msg);
r = lwm2m_delete_handler(msg);
break;

default:
@@ -3689,7 +3684,7 @@ static int generate_notify_message(struct observe_node *obs,
/* set the output writer */
select_writer(&msg->out, obs->format);

ret = do_read_op(obj_inst->obj, msg, obs->format);
ret = do_read_op(msg, obs->format);
if (ret < 0) {
LOG_ERR("error in multi-format read (err:%d)", ret);
goto cleanup;
@@ -81,8 +81,7 @@ int lwm2m_send_message(struct lwm2m_message *msg);

u16_t lwm2m_get_rd_data(u8_t *client_data, u16_t size);

int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg, u16_t content_format);
int lwm2m_perform_read_op(struct lwm2m_message *msg, u16_t content_format);

int lwm2m_write_handler(struct lwm2m_engine_obj_inst *obj_inst,
struct lwm2m_engine_res_inst *res,
@@ -702,8 +702,7 @@ const struct lwm2m_reader json_reader = {
.get_opaque = get_opaque,
};

int do_read_op_json(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg,
int content_format)
int do_read_op_json(struct lwm2m_message *msg, int content_format)
{
struct json_out_formatter_data fd;
int ret;
@@ -712,7 +711,7 @@ int do_read_op_json(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg,
engine_set_out_user_data(&msg->out, &fd);
/* save the level for output processing */
fd.path_level = msg->path.level;
ret = lwm2m_perform_read_op(obj, msg, content_format);
ret = lwm2m_perform_read_op(msg, content_format);
engine_clear_out_user_data(&msg->out);

return ret;
@@ -762,7 +761,7 @@ static int parse_path(const u8_t *buf, u16_t buflen,
return ret;
}

int do_write_op_json(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg)
int do_write_op_json(struct lwm2m_message *msg)
{
struct lwm2m_engine_obj_field *obj_field;
struct lwm2m_engine_obj_inst *obj_inst = NULL;
@@ -842,7 +841,8 @@ int do_write_op_json(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg)
}

obj_field = lwm2m_get_engine_obj_field(
obj, msg->path.res_id);
obj_inst->obj,
msg->path.res_id);
/*
* if obj_field is not found,
* treat as an optional resource
@@ -48,8 +48,7 @@
extern const struct lwm2m_writer json_writer;
extern const struct lwm2m_reader json_reader;

int do_read_op_json(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg,
int content_format);
int do_write_op_json(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg);
int do_read_op_json(struct lwm2m_message *msg, int content_format);
int do_write_op_json(struct lwm2m_message *msg);

#endif /* LWM2M_RW_JSON_H_ */
@@ -776,15 +776,14 @@ const struct lwm2m_reader oma_tlv_reader = {
.get_opaque = get_opaque,
};

int do_read_op_tlv(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg,
int content_format)
int do_read_op_tlv(struct lwm2m_message *msg, int content_format)
{
struct tlv_out_formatter_data fd;
int ret;

(void)memset(&fd, 0, sizeof(fd));
engine_set_out_user_data(&msg->out, &fd);
ret = lwm2m_perform_read_op(obj, msg, content_format);
ret = lwm2m_perform_read_op(msg, content_format);
engine_clear_out_user_data(&msg->out);
return ret;
}
@@ -869,7 +868,7 @@ static int do_write_op_tlv_item(struct lwm2m_message *msg)
return ret;
}

int do_write_op_tlv(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg)
int do_write_op_tlv(struct lwm2m_message *msg)
{
struct lwm2m_engine_obj_inst *obj_inst = NULL;
size_t len;
@@ -49,8 +49,7 @@
extern const struct lwm2m_writer oma_tlv_writer;
extern const struct lwm2m_reader oma_tlv_reader;

int do_read_op_tlv(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg,
int content_format);
int do_write_op_tlv(struct lwm2m_engine_obj *obj, struct lwm2m_message *msg);
int do_read_op_tlv(struct lwm2m_message *msg, int content_format);
int do_write_op_tlv(struct lwm2m_message *msg);

#endif /* LWM2M_RW_OMA_TLV_H_ */
@@ -316,19 +316,17 @@ const struct lwm2m_reader plain_text_reader = {
.get_opaque = get_opaque,
};

int do_read_op_plain_text(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg, int content_format)
int do_read_op_plain_text(struct lwm2m_message *msg, int content_format)
{
/* Plain text can only return single resource */
if (msg->path.level != 3U) {
return -EPERM; /* NOT_ALLOWED */
}

return lwm2m_perform_read_op(obj, msg, content_format);
return lwm2m_perform_read_op(msg, content_format);
}

int do_write_op_plain_text(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg)
int do_write_op_plain_text(struct lwm2m_message *msg)
{
struct lwm2m_engine_obj_inst *obj_inst = NULL;
struct lwm2m_engine_obj_field *obj_field;
@@ -341,7 +339,7 @@ int do_write_op_plain_text(struct lwm2m_engine_obj *obj,
return ret;
}

obj_field = lwm2m_get_engine_obj_field(obj, msg->path.res_id);
obj_field = lwm2m_get_engine_obj_field(obj_inst->obj, msg->path.res_id);
if (!obj_field) {
return -ENOENT;
}
@@ -52,9 +52,7 @@ extern const struct lwm2m_reader plain_text_reader;
size_t plain_text_put_format(struct lwm2m_output_context *out,
const char *format, ...);

int do_read_op_plain_text(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg, int content_format);
int do_write_op_plain_text(struct lwm2m_engine_obj *obj,
struct lwm2m_message *msg);
int do_read_op_plain_text(struct lwm2m_message *msg, int content_format);
int do_write_op_plain_text(struct lwm2m_message *msg);

#endif /* LWM2M_RW_PLAIN_TEXT_H_ */

0 comments on commit 6a2f362

Please sign in to comment.
You can’t perform that action at this time.