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;
49 void suspend () { m_suspended = true; }
50 void resume () { m_suspended = false; }
60 virtual bool on_elapsed () = 0;
62 bool suspended () const { return m_suspended; }
67 Timer& operator= (const Timer&);
71 static gboolean _timeout_handler (void *data);
73 bool timeout_handler ();
75 GSource* m_timeout_source;
77 unsigned int m_timeout_interval;
79 const Glib::RefPtr<Glib::MainContext> m_main_context;
85 class LIBPBD_API StandardTimer : public Timer
89 StandardTimer (unsigned int interval,
90 const Glib::RefPtr<Glib::MainContext>& main_context = Glib::MainContext::get_default());
92 sigc::connection connect (const sigc::slot<void>& slot);
94 virtual unsigned int connection_count () const
95 { return m_signal.size (); }
99 virtual bool on_elapsed ();
101 sigc::signal<void> m_signal;
105 class LIBPBD_API BlinkTimer : public Timer
109 BlinkTimer (unsigned int interval,
110 const Glib::RefPtr<Glib::MainContext>& main_context = Glib::MainContext::get_default());
113 sigc::connection connect (const sigc::slot<void, bool>& slot);
115 virtual unsigned int connection_count () const
116 { return m_blink_signal.size (); }
120 virtual bool on_elapsed ();
122 sigc::signal<void, bool> m_blink_signal;
128 #endif // __libpbd_timer_h__