Back to index

nux  3.0.0
TimerProc.h
Go to the documentation of this file.
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 
00033   class TimeOutSignal : public sigc::trackable
00034   {
00035   public:
00036     sigc::signal<void, void *> time_expires;
00037   };
00038   typedef TimeOutSignal TimerFunctor;
00039 
00040   class TimerObject;
00041 
00042   class TimerHandle
00043   {
00044   public:
00045     TimerHandle();
00046     TimerHandle(TimerObject *timer_object);
00047     ~TimerHandle();
00048     TimerHandle(const TimerHandle &);
00049 
00050     TimerHandle &operator = (const TimerHandle &);
00051     bool IsValid() const; 
00052     bool Activated() const;
00053 
00055     float GetProgress() const;
00056     float GetProgressDelta() const;
00057 
00058     int GetScheduledIterationCount() const;
00059     int GetProgressIterationCount() const;
00060     int GetElapsedTimed() const;
00061 
00062   private:
00063     TimerObject *m_d;
00064 
00065     friend class TimerHandler;
00066   };
00067 
00069   class TimerHandler
00070   {
00071   public:
00072     enum
00073     {
00074       TIMERTYPE_UNKNONW   = 0L,
00075       TIMERTYPE_PERIODIC,
00076       TIMERTYPE_DURATION,
00077       TIMERTYPE_ITERATION,
00078     };
00079 
00080     TimerHandler(WindowThread *window_thread);
00081     ~TimerHandler();
00082 
00084 
00094     TimerHandle AddTimerHandler (unsigned int Period, TimeOutSignal *timeout_signal, void *Data, WindowThread* window_thread = NULL);
00096 
00106     TimerHandle AddPeriodicTimerHandler (unsigned int Period, int Duration, TimeOutSignal *timeout_signal, void *Data);
00108 
00119     TimerHandle AddCountIterationTimerHandler (unsigned int Period, int NumberOfIteration, TimeOutSignal *timeout_signal, void *Data);
00120 
00122 
00128     bool FindTimerHandle (TimerHandle &handle);
00129 
00131 
00135     bool RemoveTimerHandler (TimerHandle &handle);
00136 
00138 
00141     int DelayUntilNextTimerExpires();
00142 
00143 #if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP))
00144     int ExecTimerHandler (unsigned int timer_id);
00145 #else
00146     int ExecTimerHandler();
00147 #endif
00148 
00150     void StartEarlyTimerObjects();
00151 
00152   private:
00153     WindowThread *window_thread_; 
00154 
00155     bool m_IsProceesingTimers;
00156     TimerObject *AddHandle (TimerObject *handle);
00157     unsigned int GetNumPendingHandler();
00158 
00160     TimerObject *m_timer_object_queue;
00161     std::list<TimerObject*> _early_timer_objects;  
00162   };
00163 
00164 }
00165 
00166 #endif // TIMERPROC_H
00167