Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvdailyevent.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * A period event stream.
00006  */
00007 
00008 #ifndef __WVDAILYEVENT_H
00009 #define __WVDAILYEVENT_H
00010 
00011 #include "wvstream.h"
00012 
00013 /**
00014  * A simple class that can trigger an event on a timed basis.
00015  * 
00016  * The period may be specified the following ways:
00017  * 
00018  *  - Given an hour, triggers once per day, on that hour.
00019  *  - Given a number of times per day, triggers that many times
00020  *     per day, evenly, starting at the specified hour.
00021  *  - WvDailyEvents can happen up to 1440 times a day, that is once per
00022  *     minute, no more.
00023  * 
00024  * 
00025  * Presently has a one-hour granularity in the first case, but that
00026  * can be fixed someday when someone cares.
00027  * 
00028  */
00029 class WvDailyEvent : public WvStream
00030 /**********************************/
00031 {
00032 public:
00033     /**
00034      * Constructs WvDailyEvent.
00035      * \param _first_hour the first hour of the day in which the event should 
00036      * occur.
00037      * \param _num_per_day the number of times in a day that the event should
00038      * occur.
00039      * If _num_per_day is not specified, it defaults to 0 (which is equivalent
00040      * to running the event once a day). 
00041      */
00042     WvDailyEvent( int _first_hour, int _num_per_day=0 );
00043 
00044     /** Returns true if the time is right for the event to occur.
00045      *  "The time is right" means that it is the first hour in some arbitrary 
00046      *  day that the event should occur or it is the first hour + 
00047      *  (number-of-minutes-in-a-day mod number of occurrences in a day) minutes
00048      *  in some arbitrary day that the event should occur.
00049      */
00050     virtual bool pre_select( SelectInfo& si );
00051     virtual bool post_select( SelectInfo& si );
00052 
00053     // execute() and any overridden versions of it must call reset().
00054     virtual void execute();
00055     
00056     /** 
00057      * Resets the object so that its execute() function will only be called if
00058      * it's time for the event to occur.
00059      */
00060     void reset();
00061 
00062     /// Always returns true.
00063     virtual bool isok() const;
00064 
00065     /**
00066      * Modifies the first hour in which the event should occur and the number of
00067      * times the event should occur in a day.
00068      * \param _first_hour the first hour of the day in which the event should 
00069      * occur.
00070      * \param _num_per_day the number of times in a day that the event should
00071      * occur.
00072      * If _num_per_day is not specified, it defaults to 0 (which is equivalent
00073      * to running the event once a day). 
00074      */
00075     void configure( int _first_hour, int _num_per_day=0 );
00076 
00077     /// Set number of times per day the event should occur - ONLY FOR TESTING!
00078     void set_num_per_day(int _num_per_day);
00079     
00080     /** 
00081      * Modifies the first hour in which the event should occur and leaves the 
00082      * number of times per day unmodified.
00083      */
00084     void set_hour( int h )
00085         { configure( h, num_per_day ); }
00086 
00087     /// return the time when the next event will occur
00088     time_t next_event() const;
00089 
00090 private:
00091     int     first_hour;
00092     int     num_per_day;
00093     bool    need_reset;
00094     time_t  prev;
00095     
00096     time_t  not_until;
00097 };
00098 
00099 #endif

Generated on Sat Feb 21 21:05:26 2004 for WvStreams by doxygen 1.3.5