RTP Audio System  2.0.0
multitimerthread.h
Go to the documentation of this file.
00001 /*
00002  *  $Id: multitimerthread.h 1285 2011-12-18 13:25:14Z dreibh $
00003  *
00004  * SocketAPI implementation for the sctplib.
00005  * Copyright (C) 2005-2012 by Thomas Dreibholz
00006  *
00007  * Realized in co-operation between
00008  * - Siemens AG
00009  * - University of Essen, Institute of Computer Networking Technology
00010  * - University of Applied Sciences, Muenster
00011  *
00012  * Acknowledgement
00013  * This work was partially funded by the Bundesministerium fuer Bildung und
00014  * Forschung (BMBF) of the Federal Republic of Germany (Foerderkennzeichen 01AK045).
00015  * The authors alone are responsible for the contents.
00016  *
00017  * This program is free software: you can redistribute it and/or modify
00018  * it under the terms of the GNU General Public License as published by
00019  * the Free Software Foundation, either version 3 of the License, or
00020  * (at your option) any later version.
00021 
00022  * This program is distributed in the hope that it will be useful,
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025  * GNU General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00029  *
00030  * Contact: discussion@sctp.de
00031  *          dreibh@iem.uni-due.de
00032  *          tuexen@fh-muenster.de
00033  *
00034  * Purpose: Multi Timer Thread Implementation
00035  *
00036  */
00037 
00038 
00039 #ifndef MULTITIMERTHREAD_H
00040 #define MULTITIMERTHREAD_H
00041 
00042 
00043 #include "tdsystem.h"
00044 #include "tools.h"
00045 #include "thread.h"
00046 
00047 
00048 
00062 template<const cardinal Timers> class MultiTimerThread : public Thread
00063 {
00064    // ====== Constructor/Destructor =========================================
00065    public:
00087    MultiTimerThread(const char*    name  = "MultiTimerThread",
00088                     const cardinal flags = TF_CancelDeferred);
00089 
00093    ~MultiTimerThread();
00094 
00095 
00096    // ====== Interval functions =============================================
00103    inline card64 getInterval(const cardinal timer);
00104 
00117    inline void setInterval(const cardinal timer,
00118                            const card64   usec,
00119                            const card64   callLimit = 0);
00120 
00121 
00132    inline void setNextAction(const cardinal timer,
00133                              const card64   usec      = 0,
00134                              const card64   callLimit = 1);
00135 
00147    inline void setNextActionAbs(const cardinal timer,
00148                                 const card64   timeStamp = 0,
00149                                 const card64   callLimit = 1);
00150 
00159    inline cardinal getTimerCorrection(const cardinal timer);
00160 
00173    inline void setTimerCorrection(const cardinal timer,
00174                                   const cardinal maxCorrection = 0);
00175 
00183    inline void leaveCorrectionLoop(const cardinal timer);
00184 
00193    inline void setFastStart(const cardinal timer, const bool on);
00194 
00202    inline bool getFastStart(const cardinal timer) const;
00203 
00209    void cancel();
00210 
00216    void* stop();
00217 
00218 
00219    // ====== timerEvent() to be implemented by subclass =====================
00220    protected:
00227    virtual void timerEvent(const cardinal timer) = 0;
00228 
00229 
00230    // ====== Private data ===================================================
00231    private:
00232    void run();
00233    inline bool isShuttingDown();
00234 
00235    struct TimerParameters {
00236       card64   Interval;
00237       card64   CallLimit;
00238       cardinal TimerCorrection;
00239       bool     FastStart;
00240       bool     Running;
00241       bool     Updated;
00242       bool     LeaveCorrectionLoop;
00243    };
00244 
00245    TimerParameters     Parameters[Timers];
00246    bool                ParametersUpdated;
00247    bool                Shutdown;
00248    bool                LeaveCorrectionLoop[Timers];
00249 
00250    static const card64 UpdateResolution = 100000;
00251 };
00252 
00253 
00254 typedef MultiTimerThread<1> SingleTimerThread;
00255 
00256 
00257 #include "multitimerthread.icc"
00258 
00259 
00260 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines