00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "wvstream.h"
00012 #include "wvdailyevent.h"
00013
00014 #include <time.h>
00015 #include <sys/time.h>
00016 #include <unistd.h>
00017
00018 WvDailyEvent::WvDailyEvent( int _first_hour, int _num_per_day )
00019
00020 : first_hour( _first_hour ), num_per_day( _num_per_day )
00021 {
00022 need_reset = false;
00023 last_hour = -1;
00024 last_minute = -1;
00025 }
00026
00027 bool WvDailyEvent::pre_select( SelectInfo& si )
00028
00029
00030
00031
00032 {
00033 time_t now;
00034 struct tm * tnow;
00035
00036 now = time( NULL );
00037 tnow = localtime( &now );
00038
00039
00040 if( tnow->tm_hour == first_hour ) {
00041 if( (first_hour-1) % 24 == last_hour )
00042 need_reset = true;
00043 }
00044 last_hour = tnow->tm_hour;
00045
00046
00047
00048
00049 int this_minute = ( ( tnow->tm_hour - first_hour )%24 )*60 + tnow->tm_min;
00050 if( num_per_day ) {
00051 int min_between = 24*60 / num_per_day;
00052 if( this_minute % min_between == 0 ) {
00053 if( last_minute != this_minute )
00054 need_reset = true;
00055 }
00056 }
00057 last_minute = this_minute;
00058
00059 return( need_reset );
00060 }
00061
00062 bool WvDailyEvent::post_select( SelectInfo& si )
00063
00064 {
00065 return( need_reset );
00066 }
00067
00068 void WvDailyEvent::execute()
00069
00070 {
00071 WvStream::execute();
00072 reset();
00073 }
00074
00075 void WvDailyEvent::reset()
00076
00077 {
00078 need_reset = false;
00079 }
00080
00081 bool WvDailyEvent::isok() const
00082
00083 {
00084 return( true );
00085 }
00086
00087 void WvDailyEvent::configure( int _first_hour, int _num_per_day )
00088
00089 {
00090 first_hour = _first_hour;
00091 num_per_day = _num_per_day;
00092 }