00001 /***************************************************************************** 00002 * x11_timer.hpp 00003 ***************************************************************************** 00004 * Copyright (C) 2003 the VideoLAN team 00005 * $Id$ 00006 * 00007 * Authors: Cyril Deguet <asmax@via.ecp.fr> 00008 * Olivier Teulière <ipkiss@via.ecp.fr> 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 00023 *****************************************************************************/ 00024 00025 #ifndef X11_TIMER_HPP 00026 #define X11_TIMER_HPP 00027 00028 #include "../src/os_timer.hpp" 00029 00030 #include <list> 00031 00032 // Forward declaration 00033 class X11TimerLoop; 00034 class CmdGeneric; 00035 00036 00037 // X11 specific timer 00038 class X11Timer: public OSTimer 00039 { 00040 public: 00041 X11Timer( intf_thread_t *pIntf, CmdGeneric &rCmd ); 00042 virtual ~X11Timer(); 00043 00044 /// (Re)start the timer with the given delay (in ms). If oneShot is 00045 /// true, stop it after the first execution of the callback. 00046 virtual void start( int delay, bool oneShot ); 00047 00048 /// Stop the timer 00049 virtual void stop(); 00050 00051 mtime_t getNextDate() const; 00052 00053 /// Execute the callback. 00054 /// Returns false if the timer must be removed after 00055 bool execute(); 00056 00057 private: 00058 /// Command to execute 00059 CmdGeneric &m_rCommand; 00060 /// Timer loop 00061 X11TimerLoop *m_pTimerLoop; 00062 /// Delay between two execute 00063 mtime_t m_interval; 00064 /// Next date at which the timer must be executed 00065 mtime_t m_nextDate; 00066 /// Flag to tell if the timer must be stopped after the first execution 00067 bool m_oneShot; 00068 }; 00069 00070 00071 /// Class to manage a set of timers 00072 class X11TimerLoop: public SkinObject 00073 { 00074 public: 00075 /// Create the timer loop with the communication number of the X11 00076 /// display 00077 X11TimerLoop( intf_thread_t *pIntf, int connectionNumber ); 00078 virtual ~X11TimerLoop(); 00079 00080 /// Add a timer in the manager 00081 void addTimer( X11Timer &rTimer ); 00082 00083 /// Remove a timer from the manager 00084 void removeTimer( X11Timer &rTimer ); 00085 00086 /// Wait for the next timer and execute it 00087 void waitNextTimer(); 00088 00089 private: 00090 /// Connection number of the X11 display 00091 int m_connectionNumber; 00092 /// List of timers 00093 list<X11Timer*> m_timers; 00094 00095 /// Sleep for delay milliseconds, unless an X11 event is received 00096 /// Returns true if the sleep has been interupted. 00097 bool sleep( int delay ); 00098 }; 00099 00100 00101 #endif
1.5.1