ev_periodic like functionality for time intervals

Marc Lehmann schmorp at schmorp.de
Wed May 20 18:25:28 CEST 2015


> states depending on wall clock time:
> 
> - 22:00 to 10:00: off
> - 10:00 to 22:00 on
> 
> I guess in the latter case, I will need to detect a time jump backwards by, 
> for instance, comparing the return value of ev_now() with the return value of 
> ev_now() from a previous event loop iteration in an ev_check watcher.

The most compatible/conceptually simple solution would be to simply have
a one-minute timer or so and check for the interval yourself, which might
also simplify the interval check when it is in local time. One minute is
roughly the accuracy with which time jumps are detected.

A more advanced technique would be to run a periodic watcher in manual
reschedule mode. In that mode, a callback will be invoked whenever a time
jump is detected (teh callback is very limited in what it can do, check
the docs).

That callback could then compare the passed now value against your interval,
and compare the current outside/inside state against the state you are
currently in:

  current state    state indicated by "now"  return value
  off              off                       next 10:00
  off              on                        now
  on               off                       now
  on               on                        next 22:00

that should invoke your callback whenever a time jump causes a different
state than you were in before, or when normal time passes a switch point.

The callback should then check again whether it is in on or off mode.

Some experimenting might be required, as the reschedule callback will likely
get invoked before your callback is called (its not really documented when it
is invoked), so you might have to cope with multiple invocations (or too
few), but in general, you should be able to cope with manual reschedule mode.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the libev mailing list