k_timer


Flavio Santes <flavio.santes@...>
 

Hello,

After playing a bit with k_timer and the expiry and stop callbacks, I realize that there is no way to manipulate application specific data inside the callbacks. These routines are implemented by the user so it makes sense that user-provided data can be manipulated inside expiry and stop routines. What do you think?

Regards,
Flavio


Johan Hedberg
 

Hi Flavio,

On Thu, Dec 08, 2016, Flavio Santes wrote:
After playing a bit with k_timer and the expiry and stop callbacks, I
realize that there is no way to manipulate application specific data
inside the callbacks. These routines are implemented by the user so it
makes sense that user-provided data can be manipulated inside expiry
and stop routines. What do you think?
At least I'm using CONTAINER_OF() to accomplish this. I think that's the
main idea of how these APIs are designed (same with k_work as well). So
you embed these objects in your "user data" struct and the get back your
own struct in the callback with the help of CONTAINER_OF.

Johan


Flavio Santes <flavio.santes@...>
 

Hello Johan,

I was thinking on adding an additional parameter to the callbacks as seen in some cb's that receive the "user_data" parameter. So, it seems the best way to solve this is with CONTAINER_OF. Thanks for the feedback!

Regards,
Flavio