-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callback Functions With User Supplied Data Pointers #14
Comments
I have worked with a lot of different Web API's and must say I like to keep the ResourceHandler as simple as possible and prefer to stick with a simple I know the following pattern from other languages. Maybe it can help you a bit with your issue:
You would probably need 100 different There might be use cases where a runtime lookup of I also don't like the idea of handling an additional void pointer in the context of every resource handler. It will increase the memory footprint of the lib and might only be used by a minority of applications (can't really judge this yet, but it's hard to take it back later on). Void pointers might also lead to nasty runtime bugs and are hard to track. What I like is the context concept of GOs that is also used in the HTTP package: https://golang.org/pkg/context/ |
Heh, I wrote this while a bit sleep deprived last night. I may have somehow forgotten that |
I'm still not quite with it it seems. ☕️ Would adding |
But where would you use the return value of What we could do is to atatch the € ahh I guess thats what you meant anyway. So I prefer adding it to the Request object instead of an extra parameter :) |
I propose that
CoAP_CreateResource(...)
(used to register resources) to have an additional opaquevoid* pUserData
parameter that will be included inCoAP_ResourceHandler_fPtr_t
andCoAP_ResourceNotifier_fPtr_t
. This would allow the application to register multiple resources and pass along identifying information inpUserData
to allow the apllication to quickly use without the need for a lookup table with the URI of the resource.I'll be happy to create a PR if this idea is good. Unless another solution is preferred?
Use Case
I have a for loop that generates 100 resources, that each has small data associated with it. would be nice to pass a pointer to the data to
CoAP_Res_t
(throughCoAP_CreateResource
) that is then passed to a single resource handler for all 100 resources. to quickly access the requried data without needing to parse the resource URI and fetch the associated data.The text was updated successfully, but these errors were encountered: