Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

TimerEventTracker.h

00001 #ifndef _UNEVT_TimerEventTracker_H_  // -*-c++-*-
00002 
00003 /*
00004  * Copyright 2002 Eric M. Hopper <hopper@omnifarious.org>
00005  * 
00006  *     This program is free software; you can redistribute it and/or modify it
00007  *     under the terms of the GNU Lesser General Public License as published
00008  *     by the Free Software Foundation; either version 2 of the License, or
00009  *     (at your option) any later version.
00010  * 
00011  *     This program is distributed in the hope that it will be useful, but
00012  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *     Lesser General Public License for more details.
00015  * 
00016  *     You should have received a copy of the GNU Lesser General Public
00017  *     License along with this program; if not, write to the Free Software
00018  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifdef __GNUG__
00022 #  pragma interface
00023 #endif
00024 
00025 /* $Header: /home/hopper/src/cvs/C++/UniEvent/UniEvent/TimerEventTracker.h,v 1.6 2002/08/29 00:58:05 hopper Exp $ */
00026 
00027 // For a log, see ../ChangeLog
00028 
00029 #include <UniEvent/Timer.h>
00030 #include <LCore/Debugable.h>
00031 
00032 #define _UNEVT_TimerEventTracker_H_
00033 
00034 namespace strmod {
00035 namespace unievent {
00036 
00037 class Dispatcher;
00038 
00039 /** \class TimerEventTracker TimerEventTracker.h UniEvent/TimerEventTracker.h
00040  * \brief Tracks Timer events, can be used to implement Timer
00041  */
00042 class TimerEventTracker : virtual public Timer, virtual public lcore::Debugable
00043 {
00044  public:
00045    static const UNEVT_ClassIdent identifier;
00046 
00047    /** \brief Construct using the ANSI C time function to provide an initial
00048     * base.
00049     */
00050    TimerEventTracker();
00051    //! Construct using \c now as an initial base.
00052    explicit TimerEventTracker(const absolute_t &now);
00053    //! Nothing special or unexpected
00054    virtual ~TimerEventTracker();
00055 
00056    virtual int AreYouA(const lcore::ClassIdent &cid) const {
00057       return((identifier == cid) || Timer::AreYouA(cid)
00058              || Debugable::AreYouA(cid));
00059    }
00060 
00061    virtual void postAt(const absolute_t &t, const EventPtr &ev);
00062    // Leave the implementation of postIn as it is in Timer.
00063    virtual absolute_t currentTime() const = 0;
00064 
00065    /** Post all expired timer events.
00066     * @param now What you want the current time to be for the purposes of expiration
00067     * @param postto The Dispatcher to post the events to.
00068     * @return The number of events posted.
00069     *
00070     * Each call of this function must have a \c now parameter that is >= the \c
00071     * now parameter given in the previous call.  In other words, the \c now
00072     * parameter must monotonically increase in subsequent calls.
00073     *
00074     * Also, the first \c now must be >= the \c now you gave in the constructor,
00075     * or the value returned by the time() ANSI C call at construction time if
00076     * you didn't give a value in the constructor.
00077     */
00078    unsigned int postExpired(const absolute_t &now, Dispatcher *postto);
00079 
00080    /** Return the time of the next timer expiration, or maxtime.
00081     * @param now What time to calculate the next expiration from.
00082     * @param maxtime The maximum interval to return.
00083     * @return The internval from now until the next expiration.
00084     * If there is no timer scheduled to expire, or it's farther than maxtime
00085     * into the future, maxtime is returned.
00086     */
00087    interval_t nextExpirationIn(const absolute_t &now,
00088                                const interval_t &maxtime) const;
00089 
00090    virtual bool invariant() const                               { return true; }
00091    virtual void printState(::std::ostream &os) const;
00092 
00093  protected:
00094    virtual const lcore::ClassIdent *i_GetIdent() const  { return &identifier; }
00095 
00096  private:
00097    class Imp;
00098 
00099    time_t old_base_;
00100    time_t current_base_;
00101    interval_t base_diff_;
00102    Imp &impl_;
00103 };
00104 
00105 //-----------------------------inline functions--------------------------------
00106 
00107 } // namespace unievent
00108 } // namespace strmod
00109 
00110 #endif

Generated on Wed Jan 29 00:32:45 2003 for libNet by doxygen1.3-rc1