net: lib: lwm2m: Deprecate string based send
Deprecate send API using the string references as paths. Replace it with one using path structs. Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
This commit is contained in:
parent
49cf96858f
commit
460dd6530f
5 changed files with 58 additions and 12 deletions
|
@ -2089,6 +2089,8 @@ char *lwm2m_path_log_buf(char *buf, struct lwm2m_obj_path *path);
|
||||||
/**
|
/**
|
||||||
* @brief LwM2M SEND operation to given path list
|
* @brief LwM2M SEND operation to given path list
|
||||||
*
|
*
|
||||||
|
* @deprecated Use lwm2m_send() instead.
|
||||||
|
*
|
||||||
* @param ctx LwM2M context
|
* @param ctx LwM2M context
|
||||||
* @param path_list LwM2M Path string list
|
* @param path_list LwM2M Path string list
|
||||||
* @param path_list_size Length of path list. Max size is CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE
|
* @param path_list_size Length of path list. Max size is CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE
|
||||||
|
@ -2100,6 +2102,20 @@ char *lwm2m_path_log_buf(char *buf, struct lwm2m_obj_path *path);
|
||||||
int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t path_list_size,
|
int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t path_list_size,
|
||||||
bool confirmation_request);
|
bool confirmation_request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LwM2M SEND operation to given path list
|
||||||
|
*
|
||||||
|
* @param ctx LwM2M context
|
||||||
|
* @param path_list LwM2M path struct list
|
||||||
|
* @param path_list_size Length of path list. Max size is CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE
|
||||||
|
* @param confirmation_request True request confirmation for operation.
|
||||||
|
*
|
||||||
|
* @return 0 for success or negative in case of error.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int lwm2m_send(struct lwm2m_ctx *ctx, const struct lwm2m_obj_path path_list[],
|
||||||
|
uint8_t path_list_size, bool confirmation_request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns LwM2M client context
|
* @brief Returns LwM2M client context
|
||||||
*
|
*
|
||||||
|
|
|
@ -2937,8 +2937,8 @@ static bool init_next_pending_timeseries_data(struct lwm2m_cache_read_info *cach
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t path_list_size,
|
int lwm2m_send(struct lwm2m_ctx *ctx, const struct lwm2m_obj_path path_list[],
|
||||||
bool confirmation_request)
|
uint8_t path_list_size, bool confirmation_request)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1)
|
#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1)
|
||||||
struct lwm2m_message *msg;
|
struct lwm2m_message *msg;
|
||||||
|
@ -2946,7 +2946,6 @@ int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t pa
|
||||||
uint16_t content_format;
|
uint16_t content_format;
|
||||||
|
|
||||||
/* Path list buffer */
|
/* Path list buffer */
|
||||||
struct lwm2m_obj_path temp;
|
|
||||||
struct lwm2m_obj_path_list lwm2m_path_list_buf[CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE];
|
struct lwm2m_obj_path_list lwm2m_path_list_buf[CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE];
|
||||||
sys_slist_t lwm2m_path_list;
|
sys_slist_t lwm2m_path_list;
|
||||||
sys_slist_t lwm2m_path_free_list;
|
sys_slist_t lwm2m_path_free_list;
|
||||||
|
@ -2986,12 +2985,9 @@ int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t pa
|
||||||
|
|
||||||
/* Parse Path to internal used object path format */
|
/* Parse Path to internal used object path format */
|
||||||
for (int i = 0; i < path_list_size; i++) {
|
for (int i = 0; i < path_list_size; i++) {
|
||||||
ret = lwm2m_string_to_path(path_list[i], &temp, '/');
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/* Add to linked list */
|
/* Add to linked list */
|
||||||
if (lwm2m_engine_add_path_to_list(&lwm2m_path_list, &lwm2m_path_free_list, &temp)) {
|
if (lwm2m_engine_add_path_to_list(&lwm2m_path_list, &lwm2m_path_free_list,
|
||||||
|
&path_list[i])) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3087,3 +3083,24 @@ cleanup:
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t path_list_size,
|
||||||
|
bool confirmation_request)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct lwm2m_obj_path lwm2m_path_list[CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE];
|
||||||
|
|
||||||
|
if (path_list_size > CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE) {
|
||||||
|
return -E2BIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < path_list_size; i++) {
|
||||||
|
/* translate path -> path_obj */
|
||||||
|
ret = lwm2m_string_to_path(path_list[i], &lwm2m_path_list[i], '/');
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lwm2m_send(ctx, lwm2m_path_list, path_list_size, confirmation_request);
|
||||||
|
}
|
||||||
|
|
|
@ -1501,7 +1501,7 @@ void lwm2m_engine_path_list_init(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2
|
||||||
}
|
}
|
||||||
|
|
||||||
int lwm2m_engine_add_path_to_list(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list,
|
int lwm2m_engine_add_path_to_list(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list,
|
||||||
struct lwm2m_obj_path *path)
|
const struct lwm2m_obj_path *path)
|
||||||
{
|
{
|
||||||
struct lwm2m_obj_path_list *prev = NULL;
|
struct lwm2m_obj_path_list *prev = NULL;
|
||||||
struct lwm2m_obj_path_list *entry;
|
struct lwm2m_obj_path_list *entry;
|
||||||
|
|
|
@ -70,7 +70,7 @@ void lwm2m_engine_path_list_init(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2
|
||||||
* @return 0 on success or a negative error code
|
* @return 0 on success or a negative error code
|
||||||
*/
|
*/
|
||||||
int lwm2m_engine_add_path_to_list(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list,
|
int lwm2m_engine_add_path_to_list(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list,
|
||||||
struct lwm2m_obj_path *path);
|
const struct lwm2m_obj_path *path);
|
||||||
|
|
||||||
int lwm2m_get_path_reference_ptr(struct lwm2m_engine_obj *obj, const struct lwm2m_obj_path *path,
|
int lwm2m_get_path_reference_ptr(struct lwm2m_engine_obj *obj, const struct lwm2m_obj_path *path,
|
||||||
void **ref);
|
void **ref);
|
||||||
|
|
|
@ -62,6 +62,7 @@ static int cmd_send(const struct shell *sh, size_t argc, char **argv)
|
||||||
int path_cnt = argc - 1;
|
int path_cnt = argc - 1;
|
||||||
bool confirmable = true;
|
bool confirmable = true;
|
||||||
int ignore_cnt = 1; /* Subcmd + arguments preceding the path list */
|
int ignore_cnt = 1; /* Subcmd + arguments preceding the path list */
|
||||||
|
struct lwm2m_obj_path lwm2m_path_list[CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE];
|
||||||
|
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
shell_error(sh, "no lwm2m context yet\n");
|
shell_error(sh, "no lwm2m context yet\n");
|
||||||
|
@ -86,8 +87,20 @@ static int cmd_send(const struct shell *sh, size_t argc, char **argv)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = lwm2m_engine_send(ctx, (const char **)&(argv[ignore_cnt]),
|
if (path_cnt > CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE) {
|
||||||
path_cnt, confirmable);
|
return -E2BIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = ignore_cnt; i < path_cnt; i++) {
|
||||||
|
/* translate path -> path_obj */
|
||||||
|
ret = lwm2m_string_to_path(argv[i], &lwm2m_path_list[i], '/');
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = lwm2m_send(ctx, lwm2m_path_list, path_cnt, confirmable);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
shell_error(sh, "can't do send operation, request failed\n");
|
shell_error(sh, "can't do send operation, request failed\n");
|
||||||
return -ENOEXEC;
|
return -ENOEXEC;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue