Skip to content

Commit 26acec1

Browse files
[sg temphack] lwm2m: allow triggering instance observer notification
Backported from f7fe1cd. Signed-off-by: Marc Lasch <[email protected]> (cherry picked from commit 3541f15)
1 parent 60af898 commit 26acec1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

subsys/net/lib/lwm2m/lwm2m_observation.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,48 @@ int lwm2m_notify_observer_path(struct lwm2m_obj_path *path)
381381
return ret;
382382
}
383383

384+
int lwm2m_force_notify_observer_path(struct lwm2m_obj_path *path)
385+
{
386+
struct observe_node *obs;
387+
struct notification_attrs nattrs = { 0 };
388+
int ret = 0;
389+
int rc;
390+
int i;
391+
struct lwm2m_ctx **sock_ctx = lwm2m_sock_ctx();
392+
393+
LOG_INF("Force-notifying observer path %d/%d/%d[:%d] (%d)",
394+
(int) path->obj_id,
395+
(int) path->obj_inst_id,
396+
(int) path->res_id,
397+
(int) path->level,
398+
(int) lwm2m_sock_nfds());
399+
400+
/* look for observers which match our resource */
401+
for (i = 0; i < lwm2m_sock_nfds(); ++i) {
402+
SYS_SLIST_FOR_EACH_CONTAINER(&sock_ctx[i]->observer, obs, node) {
403+
if (lwm2m_notify_observer_list(&obs->path_list, path)) {
404+
/* update the event time for this observer */
405+
rc = engine_observe_attribute_list_get(&obs->path_list, &nattrs,
406+
sock_ctx[i]->srv_obj_inst);
407+
if (rc < 0) {
408+
LOG_INF("Not exists: %d", (int)ret);
409+
return rc;
410+
}
411+
412+
/* Trigger immediately */
413+
obs->resource_update = path->level >= LWM2M_PATH_LEVEL_RESOURCE;
414+
obs->event_timestamp = k_uptime_get();
415+
416+
LOG_WRN("FORCE NOTIFY EVENT %u/%u/%u[:%d]", path->obj_id, path->obj_inst_id,
417+
path->res_id, (int) path->level);
418+
ret++;
419+
}
420+
}
421+
}
422+
423+
return ret;
424+
}
425+
384426
static struct observe_node *engine_allocate_observer(sys_slist_t *path_list, bool composite)
385427
{
386428
int i;

subsys/net/lib/lwm2m/lwm2m_observation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
int lwm2m_notify_observer(uint16_t obj_id, uint16_t obj_inst_id, uint16_t res_id);
1111
int lwm2m_notify_observer_path(struct lwm2m_obj_path *path);
12+
int lwm2m_force_notify_observer_path(struct lwm2m_obj_path *path);
1213

1314
#define MAX_TOKEN_LEN 8
1415

0 commit comments

Comments
 (0)