Skip to content

Commit 3541f15

Browse files
AlexeyNezhdanovGardenamlasch
authored andcommitted
[sg temphack] lwm2m: allow triggering instance observer notification
Backported from f7fe1cd. Signed-off-by: Marc Lasch <[email protected]>
1 parent 2525ca6 commit 3541f15

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
@@ -386,6 +386,48 @@ int lwm2m_notify_observer_path(struct lwm2m_obj_path *path)
386386
return ret;
387387
}
388388

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