15 #include "wvdailyevent.h"
17 #include "wvtimeutils.h"
26 #define NUM_MINS_IN_DAY (24*60)
27 #define NUM_SECS_IN_DAY (60*NUM_MINS_IN_DAY)
33 prev = wvstime().tv_sec;
34 configure(_first_hour, _num_per_day, _skip_first);
45 time_t now = wvstime().tv_sec;
50 assert(prev > 100000);
51 assert(next > 100000);
55 si.msec_timeout = msecdiff(now, next);
71 bool timer_rang =
false;
85 num_per_day = _num_per_day;
89 if (num_per_day > NUM_SECS_IN_DAY)
90 num_per_day = NUM_SECS_IN_DAY;
92 time_t max = num_per_day ? NUM_SECS_IN_DAY/num_per_day : 6*60*60;
97 prev = wvstime().tv_sec;
98 not_until = prev + max;
104 first_hour = _first_hour;
105 skip_first = _skip_first;
109 if (_num_per_day > NUM_MINS_IN_DAY)
110 _num_per_day = NUM_MINS_IN_DAY;
124 time_t interval = NUM_SECS_IN_DAY/num_per_day;
125 time_t start = prev + interval;
128 struct tm *tm = localtime(&start);
129 if (tm->tm_hour < first_hour)
131 start = prev - NUM_SECS_IN_DAY + 1;
132 tm = localtime(&start);
134 tm->tm_hour = first_hour;
135 tm->tm_min = tm->tm_sec = 0;
140 time_t next = prev + interval;
141 if ((next - start)%interval != 0)
142 next = start + (next - start)/interval * interval;
145 assert(next > 100000);
147 while (skip_first && next < not_until)
void set_num_per_day(int _num_per_day)
Set number of times per day the event should occur - ONLY FOR TESTING!
virtual void pre_select(SelectInfo &si)
Munges SelectInfo such that the stream will select when the time is right for the event to occur.
void configure(int _first_hour, int _num_per_day=0, bool _skip_first=true)
Modifies the first hour in which the event should occur and the number of times the event should occu...
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
time_t next_event() const
return the time when the next event will occur
WvDailyEvent(int _first_hour, int _num_per_day=0, bool _skip_first=true)
Constructs WvDailyEvent.
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
Based on (and interchangeable with) struct timeval.
the data structure used by pre_select()/post_select() and internally by select().