Search code examples
ceventscalendarscheduling

How to design and implement schedulable alarms/events which trigger parts of code in C


I have a piece of code which acts as a server and is switching different valves and other actuators. The commands for switching those actuators are being received via sockets from clients running on Android devices. Now Id like to add a module to my server which would allow me to schedule an calendar dependant switching of those actuators. I wonder how to do that. Right now I am thinking of time.h of course, as the very basic. Then I could imagine to have a stucture which holds the programmable events (time, date and what to trigger) and a task which would endlessly compare the time/date to the actual time.. However I am not really sure if that is the right approach. Please hint me in the right direction.

  1. What would the basic architecture look like?
  2. Are there libraries in C I could youse?

Solution

  • Options include:

    • setitimer() to set next signal time, and using a signal handler.
    • having a loop, sleeping, polling and checking system time against time for the schedule.