1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/private/timer.h
3 // Purpose: wxTimer for wxBase (unix)
4 // Author: Lukasz Michalski
6 // Copyright: (c) Lukasz Michalski
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_UNIX_PRIVATE_TIMER_H_
11 #define _WX_UNIX_PRIVATE_TIMER_H_
15 #include "wx/private/timer.h"
17 // the type used for milliseconds is large enough for microseconds too but
18 // introduce a synonym for it to avoid confusion
19 typedef wxMilliClock_t wxUsecClock_t
;
21 // ----------------------------------------------------------------------------
22 // wxTimer implementation class for Unix platforms
23 // ----------------------------------------------------------------------------
25 // NB: we have to export at least this symbol from the shared library, because
26 // it's used by wxDFB's wxCore
27 class WXDLLIMPEXP_BASE wxUnixTimerImpl
: public wxTimerImpl
30 wxUnixTimerImpl(wxTimer
*timer
);
31 virtual ~wxUnixTimerImpl();
33 virtual bool IsRunning() const;
34 virtual bool Start(int milliseconds
= -1, bool oneShot
= false);
37 // for wxTimerScheduler only: resets the internal flag indicating that the
41 wxASSERT_MSG( m_isRunning
, wxT("stopping non-running timer?") );
50 // ----------------------------------------------------------------------------
51 // wxTimerSchedule: information about a single timer, used by wxTimerScheduler
52 // ----------------------------------------------------------------------------
54 struct wxTimerSchedule
56 wxTimerSchedule(wxUnixTimerImpl
*timer
, wxUsecClock_t expiration
)
58 m_expiration(expiration
)
62 // the timer itself (we don't own this pointer)
63 wxUnixTimerImpl
*m_timer
;
65 // the time of its next expiration, in usec
66 wxUsecClock_t m_expiration
;
69 // the linked list of all active timers, we keep it sorted by expiration time
70 WX_DECLARE_LIST(wxTimerSchedule
, wxTimerList
);
72 // ----------------------------------------------------------------------------
73 // wxTimerScheduler: class responsible for updating all timers
74 // ----------------------------------------------------------------------------
76 class wxTimerScheduler
79 // get the unique timer scheduler instance
80 static wxTimerScheduler
& Get()
83 ms_instance
= new wxTimerScheduler
;
88 // must be called on shutdown to delete the global timer scheduler
89 static void Shutdown()
98 // adds timer which should expire at the given absolute time to the list
99 void AddTimer(wxUnixTimerImpl
*timer
, wxUsecClock_t expiration
);
101 // remove timer from the list, called automatically from timer dtor
102 void RemoveTimer(wxUnixTimerImpl
*timer
);
105 // the functions below are used by the event loop implementation to monitor
106 // and notify timers:
108 // if this function returns true, the time remaining until the next time
109 // expiration is returned in the provided parameter (always positive or 0)
111 // it returns false if there are no timers
112 bool GetNext(wxUsecClock_t
*remaining
) const;
114 // trigger the timer event for all timers which have expired, return true
116 bool NotifyExpired();
119 // ctor and dtor are private, this is a singleton class only created by
120 // Get() and destroyed by Shutdown()
121 wxTimerScheduler() { }
124 // add the given timer schedule to the list in the right place
126 // we take ownership of the pointer "s" which must be heap-allocated
127 void DoAddTimer(wxTimerSchedule
*s
);
130 // the list of all currently active timers sorted by expiration
131 wxTimerList m_timers
;
133 static wxTimerScheduler
*ms_instance
;
136 #endif // wxUSE_TIMER
138 #endif // _WX_UNIX_PRIVATE_TIMER_H_