2 Copyright (C) 2014 Tim Mayberry
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __libpbd_timer_h__
21 #define __libpbd_timer_h__
23 #include <sigc++/signal.h>
25 #include <glibmm/main.h>
27 #include "pbd/libpbd_visibility.h"
32 * The Timer class is a wrapper around Glib TimeoutSources
33 * The Timer will start automatically when the first connection
34 * is made and stop when the last callback is disconnected.
36 class LIBPBD_API Timer
40 Timer (unsigned int interval,
41 const Glib::RefPtr<Glib::MainContext>& main_context);
43 unsigned int get_interval () const;
45 void set_interval (unsigned int new_interval);
47 virtual unsigned int connection_count () const = 0;
57 virtual bool on_elapsed () = 0;
62 Timer& operator= (const Timer&);
66 static gboolean _timeout_handler (void *data);
68 bool timeout_handler ();
70 GSource* m_timeout_source;
72 unsigned int m_timeout_interval;
74 const Glib::RefPtr<Glib::MainContext> m_main_context;
78 class LIBPBD_API StandardTimer : public Timer
82 StandardTimer (unsigned int interval,
83 const Glib::RefPtr<Glib::MainContext>& main_context = Glib::MainContext::get_default());
85 sigc::connection connect (const sigc::slot<void>& slot);
87 virtual unsigned int connection_count () const
88 { return m_signal.size (); }
92 virtual bool on_elapsed ();
94 sigc::signal<void> m_signal;
98 class LIBPBD_API BlinkTimer : public Timer
102 BlinkTimer (unsigned int interval,
103 const Glib::RefPtr<Glib::MainContext>& main_context = Glib::MainContext::get_default());
106 sigc::connection connect (const sigc::slot<void, bool>& slot);
108 virtual unsigned int connection_count () const
109 { return m_blink_signal.size (); }
113 virtual bool on_elapsed ();
115 sigc::signal<void, bool> m_blink_signal;
121 #endif // __libpbd_timer_h__