Skip to content

Commit 644e557

Browse files
author
Michael Scott
committed
net: lwm2m: save lwm2m_ctx instead of net_app_ctx in observer
This is the first part of a large refactoring of LwM2M library message functions and will simplify observer handling later. Signed-off-by: Michael Scott <[email protected]>
1 parent d44ed02 commit 644e557

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

subsys/net/lib/lwm2m/lwm2m_engine.c

+11-13
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
struct observe_node {
8383
sys_snode_t node;
84-
struct net_app_ctx *net_app_ctx;
84+
struct lwm2m_ctx *ctx;
8585
struct lwm2m_obj_path path;
8686
u8_t token[8];
8787
s64_t event_timestamp;
@@ -226,7 +226,7 @@ static int engine_add_observer(struct net_app_ctx *app_ctx,
226226

227227
/* make sure this observer doesn't exist already */
228228
SYS_SLIST_FOR_EACH_CONTAINER(&engine_observer_list, obs, node) {
229-
if (obs->net_app_ctx == app_ctx &&
229+
if (&obs->ctx->net_app_ctx == app_ctx &&
230230
memcmp(&obs->path, path, sizeof(*path)) == 0) {
231231
/* quietly update the token information */
232232
memcpy(obs->token, token, tkl);
@@ -255,7 +255,8 @@ static int engine_add_observer(struct net_app_ctx *app_ctx,
255255

256256
/* copy the values and add it to the list */
257257
observe_node_data[i].used = true;
258-
observe_node_data[i].net_app_ctx = app_ctx;
258+
observe_node_data[i].ctx = CONTAINER_OF(app_ctx,
259+
struct lwm2m_ctx, net_app_ctx);
259260
memcpy(&observe_node_data[i].path, path, sizeof(*path));
260261
memcpy(observe_node_data[i].token, token, tkl);
261262
observe_node_data[i].tkl = tkl;
@@ -2444,12 +2445,9 @@ static int generate_notify_message(struct observe_node *obs,
24442445
struct lwm2m_output_context out;
24452446
struct lwm2m_engine_context context;
24462447
struct lwm2m_obj_path path;
2447-
struct lwm2m_ctx *client_ctx;
24482448
int ret = 0;
24492449

2450-
client_ctx = CONTAINER_OF(obs->net_app_ctx,
2451-
struct lwm2m_ctx, net_app_ctx);
2452-
if (!client_ctx) {
2450+
if (!obs->ctx) {
24532451
SYS_LOG_ERR("observer has no valid LwM2M ctx!");
24542452
return -EINVAL;
24552453
}
@@ -2472,7 +2470,7 @@ static int generate_notify_message(struct observe_node *obs,
24722470
obs->path.level,
24732471
sprint_token(obs->token, obs->tkl),
24742472
lwm2m_sprint_ip_addr(
2475-
&obs->net_app_ctx->default_ctx->remote),
2473+
&obs->ctx->net_app_ctx.default_ctx->remote),
24762474
k_uptime_get());
24772475

24782476
obj_inst = get_engine_obj_inst(obs->path.obj_id,
@@ -2484,7 +2482,7 @@ static int generate_notify_message(struct observe_node *obs,
24842482
return -EINVAL;
24852483
}
24862484

2487-
ret = lwm2m_init_message(obs->net_app_ctx, out.out_zpkt, &pkt,
2485+
ret = lwm2m_init_message(&obs->ctx->net_app_ctx, out.out_zpkt, &pkt,
24882486
ZOAP_TYPE_CON, ZOAP_RESPONSE_CODE_CONTENT,
24892487
0, obs->token, obs->tkl);
24902488
if (ret) {
@@ -2523,13 +2521,13 @@ static int generate_notify_message(struct observe_node *obs,
25232521
goto cleanup;
25242522
}
25252523

2526-
pending = lwm2m_init_message_pending(client_ctx, out.out_zpkt);
2524+
pending = lwm2m_init_message_pending(obs->ctx, out.out_zpkt);
25272525
if (!pending) {
25282526
ret = -ENOMEM;
25292527
goto cleanup;
25302528
}
25312529

2532-
reply = zoap_reply_next_unused(client_ctx->replies,
2530+
reply = zoap_reply_next_unused(obs->ctx->replies,
25332531
CONFIG_LWM2M_ENGINE_MAX_REPLIES);
25342532
if (!reply) {
25352533
SYS_LOG_ERR("No resources for waiting for replies.");
@@ -2540,15 +2538,15 @@ static int generate_notify_message(struct observe_node *obs,
25402538
zoap_reply_init(reply, &request);
25412539
reply->reply = notify_message_reply_cb;
25422540

2543-
ret = lwm2m_udp_sendto(obs->net_app_ctx, pkt);
2541+
ret = lwm2m_udp_sendto(&obs->ctx->net_app_ctx, pkt);
25442542
if (ret < 0) {
25452543
SYS_LOG_ERR("Error sending LWM2M packet (err:%d).", ret);
25462544
goto cleanup;
25472545
}
25482546
SYS_LOG_DBG("NOTIFY MSG: SENT");
25492547

25502548
zoap_pending_cycle(pending);
2551-
k_delayed_work_submit(&client_ctx->retransmit_work, pending->timeout);
2549+
k_delayed_work_submit(&obs->ctx->retransmit_work, pending->timeout);
25522550
return ret;
25532551

25542552
cleanup:

0 commit comments

Comments
 (0)