AVSystem / Anjay

C implementation of the client-side OMA LwM2M protocol
Other
188 stars 68 forks source link

Adding recurrent task in anjay's main loop #49

Closed christopheronco closed 3 years ago

christopheronco commented 3 years ago

Hello, I want to execute a recurrent task each 30s. In this task, I might have to notify that some resources changed. My goal is to do that without creating a thread and integrated in anjay's framework.

I saw the tutorial BC6 about notify and it calls a time_object method each time it schedules anjay. That's not really what I want even if it is doable like that if we don't want to have a precision greater than 1 second on when the job is done

I tried to do that using AVS_SCHED macros and anjay scheduler. With a code like that:

AVS_SCHED_DELAYED(anjay->sched, &(obj->job_handle), duration, cellular_configuration_job, obj, sizeof(obj));

But I have no access to anjay_t internals in my code. I assume this is done on purpose and that's not the right way to do it. Did I miss an api that will allow me to add a task to anjay's scheduler?

I also tried to create my own scheduler inside my object (using avs_sched_new). And in my main_loop, I will have to compute minimal time between the two scheds (using avs_sched_time_of_next) and then call both avs_sched_run with my object scheduler and anjay_sched_run. I failed to do that (I have errors at runtime), maybe my code is bad. But maybe that's not the right way to do it, it is quite more complicated that the first solution and I don't see why I can't use anjay's scheduler.

So how should we add our own scheduled tasks to the tasks executed in the anjay's main loop? Best Regards,

panekk commented 3 years ago

Hello,

Actually there's anjay_get_scheduler() function introduced in Anjay 2.3a, so you can use it to access the Anjay's scheduler and schedule your own jobs.

Best regards, Kamil

christopheronco commented 3 years ago

Sorry, I haven't seen this one. I was able to add my recurrent example task (and a notify inside). Thanks for you quick answer, Christophe