nux-1.14.0
TimerProc.h
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef TIMERPROC_H
00024 #define TIMERPROC_H
00025 
00026 namespace nux
00027 {
00028 
00029   class TimerHandler;
00030   class WindowThread;
00031   
00032   class TimerFunctor : public sigc::trackable
00033   {
00034   public:
00035     sigc::signal<void, void *> OnTimerExpired;
00036   };
00037 
00038   class TimerObject;
00039 
00040   class TimerHandle
00041   {
00042   public:
00043     TimerHandle();
00044     TimerHandle (TimerObject *timer_object);
00045     ~TimerHandle();
00046     TimerHandle (const TimerHandle &);
00047 
00048     TimerHandle &operator = (const TimerHandle &);
00049     bool IsValid() const;
00050 
00052     float GetProgress() const;
00053     float GetProgressDelta() const;
00054 
00055     int GetScheduledIterationCount() const;
00056     int GetProgressIterationCount() const;
00057     int GetElapsedTimed() const;
00058 
00059   private:
00060     TimerObject *m_d;
00061 
00062     friend class TimerHandler;
00063   };
00064 
00065   class TimerHandler
00066   {
00067   public:
00068     enum
00069     {
00070       TIMERTYPE_UNKNONW   = 0L,
00071       TIMERTYPE_PERIODIC,
00072       TIMERTYPE_DURATION,
00073       TIMERTYPE_ITERATION,
00074     };
00075 
00076     TimerHandler();
00077     ~TimerHandler();
00078 
00080 
00090     TimerHandle AddTimerHandler (unsigned int Period, TimerFunctor *Callback, void *Data, WindowThread* window_thread = NULL);
00092 
00102     TimerHandle AddPeriodicTimerHandler (unsigned int Period, int Duration, TimerFunctor *Callback, void *Data);
00104 
00115     TimerHandle AddCountIterationTimerHandler (unsigned int Period, int NumberOfIteration, TimerFunctor *Callback, void *Data);
00116 
00118 
00124     bool FindTimerHandle (TimerHandle &handle);
00125 
00127 
00131     bool RemoveTimerHandler (TimerHandle &handle);
00132 
00134 
00137     int DelayUntilNextTimerExpires();
00138 
00139 #if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP))
00140     int ExecTimerHandler (t_u32 timer_id);
00141 #else
00142     int ExecTimerHandler();
00143 #endif
00144 
00146     void StartEarlyTimerObjects();
00147 
00148   private:
00149     bool m_IsProceesingTimers;
00150     TimerObject *AddHandle (TimerObject *handle);
00151     t_u32 GetNumPendingHandler();
00152 
00154     TimerObject *m_timer_object_queue;
00155     std::list<TimerObject*> _early_timer_objects;  
00156   };
00157 
00158 }
00159 
00160 #endif // TIMERPROC_H
00161 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends