net: lib: lwm2m: add lwm2m_engine_is_observed function

add helper function to check wether a specific lwm2m
path is observed

Signed-off-by: Henning Fleddermann <henning.fleddermann@grandcentrix.net>
This commit is contained in:
Henning Fleddermann 2022-02-08 01:48:32 +01:00 committed by Anas Nashif
commit 7eb25df526
2 changed files with 42 additions and 0 deletions

View file

@ -1062,6 +1062,19 @@ int lwm2m_engine_update_service_period(k_work_handler_t service, uint32_t period
*/ */
int lwm2m_update_device_service_period(uint32_t period_ms); int lwm2m_update_device_service_period(uint32_t period_ms);
/**
* @brief Check whether a path is observed
*
* @param[in] pathstr LwM2M path string to check, e.g. "3/0/1"
*
* @return true when there exists an observation of the same level
* or lower as the given path, false if it doesn't or path is not a
* valid LwM2M-path.
* E.g. true if path refers to a resource and the parent object has an
* observation, false for the inverse.
*/
bool lwm2m_engine_path_is_observed(const char *pathstr);
/** /**
* @brief Start the LwM2M engine * @brief Start the LwM2M engine
* *

View file

@ -2105,6 +2105,35 @@ int lwm2m_engine_delete_res_inst(const char *pathstr)
return 0; return 0;
} }
bool lwm2m_engine_path_is_observed(const char *pathstr)
{
struct observe_node *obs;
struct lwm2m_obj_path path;
int ret;
int i;
ret = string_to_path(pathstr, &path, '/');
if (ret < 0) {
return false;
}
for (i = 0; i < sock_nfds; ++i) {
SYS_SLIST_FOR_EACH_CONTAINER(&sock_ctx[i]->observer, obs, node) {
if (obs->path.level <= path.level &&
(obs->path.obj_id == path.obj_id &&
(obs->path.level < LWM2M_PATH_LEVEL_OBJECT_INST ||
(obs->path.obj_inst_id == path.obj_inst_id &&
(obs->path.level < LWM2M_PATH_LEVEL_RESOURCE ||
(obs->path.res_id == path.res_id &&
(obs->path.level < LWM2M_PATH_LEVEL_RESOURCE_INST ||
obs->path.res_inst_id == path.res_inst_id))))))) {
return true;
}
}
}
return false;
}
int lwm2m_engine_register_read_callback(const char *pathstr, int lwm2m_engine_register_read_callback(const char *pathstr,
lwm2m_engine_get_data_cb_t cb) lwm2m_engine_get_data_cb_t cb)
{ {