pkg/wakaama: add get set functions and cleanup client connection#16203
Conversation
9f72f0c to
4cb77ee
Compare
|
I'm piggybacking the fixes to the issues spotted by the static test |
PeterKietzmann
left a comment
There was a problem hiding this comment.
This is not a full review, just some early comments
| @@ -0,0 +1,413 @@ | |||
| /* | |||
There was a problem hiding this comment.
This file is common to wakaama, right? Maybe prefix.
There was a problem hiding this comment.
What should I prefix? The file name? It is contained in the contrib folder, is it really necessary ?
pkg/wakaama/contrib/objects/common.c
Outdated
| case LWM2M_TYPE_OPAQUE: | ||
| if (data->value.asBuffer.length > out_len) { | ||
| DEBUG("[lwm2m:get_data] not enough space in buffer\n"); | ||
| result = -1; |
There was a problem hiding this comment.
| result = -1; | |
| result = -ENOMEM; |
pkg/wakaama/contrib/objects/common.c
Outdated
| lwm2m_object_t *object = lwm2m_get_object_by_id(client_data, uri->objectId); | ||
| if (!object || !object->readFunc) { | ||
| DEBUG("[lwm2m:get_data] could not find object with ID %d\n", uri->objectId); | ||
| result = -1; |
There was a problem hiding this comment.
| result = -1; | |
| result = -ENOENT; |
pkg/wakaama/contrib/objects/common.c
Outdated
| /* read the resource from the specified instance */ | ||
| uint8_t res = object->readFunc(uri->instanceId, &data_num, &data, object); | ||
| if (res != COAP_205_CONTENT || data->type != expected_type) { | ||
| result = -1; |
There was a problem hiding this comment.
| result = -1; | |
| result = -EINVAL; |
pkg/wakaama/contrib/objects/common.c
Outdated
| lwm2m_uri_t uri; | ||
| if (!lwm2m_stringToUri(path, path_len, &uri)) { | ||
| DEBUG("[lwm2m:get_resource] malformed path\n"); | ||
| return -1; |
There was a problem hiding this comment.
| return -1; | |
| return -EINVAL; |
pkg/wakaama/contrib/objects/common.c
Outdated
|
|
||
| default: | ||
| DEBUG("[lwm2m:get_data] not supported type\n"); | ||
| result = -1; |
There was a problem hiding this comment.
| result = -1; | |
| result = -ENOTSUP; |
pkg/wakaama/contrib/objects/common.c
Outdated
|
|
||
| default: | ||
| DEBUG("[lwm2m:get_data] not supported type\n"); | ||
| result = -1; |
There was a problem hiding this comment.
| result = -1; | |
| result = -ENOTSUP; |
pkg/wakaama/contrib/objects/common.c
Outdated
| /* write the resource of the specified instance */ | ||
| uint8_t res = object->writeFunc(uri->instanceId, 1, data, object); | ||
| if (res != COAP_204_CHANGED) { | ||
| result = -1; |
There was a problem hiding this comment.
| result = -1; | |
| result = -EINVAL; |
pkg/wakaama/contrib/objects/common.c
Outdated
| lwm2m_uri_t uri; | ||
| if (!lwm2m_stringToUri(path, path_len, &uri)) { | ||
| DEBUG("[lwm2m:set_resource] malformed path\n"); | ||
| return -1; |
There was a problem hiding this comment.
| return -1; | |
| return -EINVAL; |
| default: | ||
| DEBUG("[lwm2m:get_data] not supported type\n"); | ||
| result = -1; | ||
| break; |
There was a problem hiding this comment.
Just in case someone else adds code right after the switch-case
| break; | |
| goto free_out; | |
| break; |
There was a problem hiding this comment.
I simplified the return routine, now there is only on out point.
| if (data->value.asBuffer.length > out_len) { | ||
| DEBUG("[lwm2m:get_data] not enough space in buffer\n"); | ||
| result = -1; | ||
| } |
There was a problem hiding this comment.
| } | |
| goto free_out; | |
| } |
There was a problem hiding this comment.
Same for this one
df0d031 to
afda4ef
Compare
|
@jia200x I think I addressed your comments. I updated the documentation to reflect the new possible return values. Also added checks when allocating data structure. Finally, I rebased to resolve conflicts. |
|
please squash |
afda4ef to
327da03
Compare
|
Squashed! |
Use URI parser and common resource access functions.
|
Thanks for reviewing! |


Contribution description
This adds generic get/set functions to interact with resources of the LwM2M client. Also, the client connection code is refactored to use these functions and the URI parser module.
Testing procedure
The
examples/wakaamaapplication should work as usual.Issues/PRs references
None