]> git.sesse.net Git - vlc/blob - modules/gui/skins2/x11/x11_timer.hpp
ba4c44e2a17e1da5f18131d913694dbfc2be2ca7
[vlc] / modules / gui / skins2 / x11 / x11_timer.hpp
1 /*****************************************************************************
2  * x11_timer.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef X11_TIMER_HPP
26 #define X11_TIMER_HPP
27
28 #include "../src/os_timer.hpp"
29
30 #include <list>
31
32 // Forward declaration
33 class X11TimerLoop;
34 class CmdGeneric;
35
36
37 // X11 specific timer
38 class X11Timer: public OSTimer
39 {
40     public:
41         X11Timer( intf_thread_t *pIntf, CmdGeneric &rCmd );
42         virtual ~X11Timer();
43
44         /// (Re)start the timer with the given delay (in ms). If oneShot is
45         /// true, stop it after the first execution of the callback.
46         virtual void start( int delay, bool oneShot );
47
48         /// Stop the timer
49         virtual void stop();
50
51         mtime_t getNextDate() const;
52
53         /// Execute the callback.
54         /// Returns false if the timer must be removed after
55         bool execute();
56
57     private:
58         /// Command to execute
59         CmdGeneric &m_rCommand;
60         /// Timer loop
61         X11TimerLoop *m_pTimerLoop;
62         /// Delay between two execute
63         mtime_t m_interval;
64         /// Next date at which the timer must be executed
65         mtime_t m_nextDate;
66         /// Flag to tell if the timer must be stopped after the first execution
67         bool m_oneShot;
68 };
69
70
71 /// Class to manage a set of timers
72 class X11TimerLoop: public SkinObject
73 {
74     public:
75         /// Create the timer loop with the communication number of the X11
76         /// display
77         X11TimerLoop( intf_thread_t *pIntf, int connectionNumber );
78         virtual ~X11TimerLoop();
79
80         /// Add a timer in the manager
81         void addTimer( X11Timer &rTimer );
82
83         /// Remove a timer from the manager
84         void removeTimer( X11Timer &rTimer );
85
86         /// Wait for the next timer and execute it
87         void waitNextTimer();
88
89     private:
90         /// Connection number of the X11 display
91         int m_connectionNumber;
92         /// List of timers
93         list<X11Timer*> m_timers;
94
95         /// Sleep for delay milliseconds, unless an X11 event is received
96         /// Returns true if the sleep has been interupted.
97         bool sleep( int delay );
98 };
99
100
101 #endif