Skip to content

net/gcoap: expose creation of resource list to API#7408

Merged
miri64 merged 2 commits intoRIOT-OS:masterfrom
haukepetersen:opt_gcoap_exportresourcelistcreation
Aug 8, 2017
Merged

net/gcoap: expose creation of resource list to API#7408
miri64 merged 2 commits intoRIOT-OS:masterfrom
haukepetersen:opt_gcoap_exportresourcelistcreation

Conversation

@haukepetersen
Copy link
Copy Markdown
Contributor

Creating the resource list is useful outside the /.well-known/core
handler, e.g. for the registration to resource directories.

@haukepetersen haukepetersen added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jul 25, 2017
@haukepetersen haukepetersen added this to the Release 2017.10 milestone Jul 25, 2017
@haukepetersen haukepetersen force-pushed the opt_gcoap_exportresourcelistcreation branch from a0a00f5 to fa303d3 Compare July 26, 2017 09:02
Copy link
Copy Markdown
Member

@kb2ma kb2ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me when buf not null.

for (unsigned i = 0; i < listener->resources_len; i++) {
size_t path_len = strlen(resource->path);
/* only add new resources if there is space in the buffer */
if ((pos + path_len + 3) > maxlen) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function spec says maxlen ignored if buf is NULL.

}
else {
out += (i) ? 3 : 2;
out += path_len;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want to increment pos here? ;-)

@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Aug 5, 2017

Also, what is the value of returning only the length of the resource list without also providing the content?

@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Aug 7, 2017

It also should be straightforward to write a unit test for this new function since no packet exchange is required.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

what is the value of returning only the length of the resource list without also providing the content?

The idea was to be able to find out the length of the resulting string so one can allocate/provide a sufficient buffer later (same principle as applied for the fmt module). But looking at this now, I think this makes only limited this context, so I tend to remove this 'feature' for simplification.

It also should be straightforward to write a unit test for this new function since no packet exchange is required.

Didn't seem that simple to me, though I have not really looked into it more than 30s... Will look some seconds more and see what I can do :-)

@haukepetersen
Copy link
Copy Markdown
Contributor Author

added unittests

@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Aug 8, 2017

Thanks for the unit test and the rationale on returning only the length of the contents. The more I think about this function, it seems valuable to ensure a client can retrieve the entire list. I wonder if it would be more useful to recast it like this:

int gcoap_print_resource(void *buf, size_t maxlen, unsigned index, uint8_t cf)

where index is into the list of resources. This way buf doesn't need to be so big, and the client is guaranteed to be able to increment through all of the resources. The function can return some flag value like GCOAP_END_OF_RESOURCES when done.

This approach would mesh well with CoAP block support for a /.well-known/core request.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

I have been thinking the same, but came to the conclusion that I wanted to keep the function straight forward in the first round and add this 'advanced' buffer handling later. I actually expect this function to change/advance anyway in the near future, as I am looking into ways to specify more context information about the resources (e.g. d, et, ct, ...). My current thought is to add one additional function for each resource, that returns the context information for that resource in some way. This will be especially useful when looking in the direction of wildcards for resource paths... This could lead to something like

void gcoap_init_reslist(gcoap_reslist_ctx_t *ctx, size_t blocksize, unsigned block_num, uint8_t cf);
int gcoap_read_reslist(gcoap_reslist_ctx-t *ctx, void *buf);

But anyway: I would like to put this on the (ever growing) 'lets-improve-later' list if that is alright with you.

@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Aug 8, 2017

Sounds good. ACK on this PR.

Creating the resource list is useful outside the /.well-known/core
handler, e.g. for the registration to resource directories.
@haukepetersen haukepetersen force-pushed the opt_gcoap_exportresourcelistcreation branch from 75cf78a to 813c92e Compare August 8, 2017 14:00
@haukepetersen
Copy link
Copy Markdown
Contributor Author

awesome.

Fixed typo in doxygen and squashed -> Murdock should be happy now.

Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy-ACK and go

@miri64 miri64 merged commit ea4a8e3 into RIOT-OS:master Aug 8, 2017
@haukepetersen haukepetersen deleted the opt_gcoap_exportresourcelistcreation branch August 8, 2017 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants