Ardour  8.12
pbd/pbd/timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Tim Mayberry <mojofunk@gmail.com>
3  * Copyright (C) 2015 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __libpbd_timer_h__
21 #define __libpbd_timer_h__
22 
23 #include <sigc++/signal.h>
24 
25 #include <glibmm/main.h>
26 
27 #include "pbd/libpbd_visibility.h"
28 
29 namespace PBD {
30 
37 {
38 public:
39 
40  Timer (unsigned int interval,
41  const Glib::RefPtr<Glib::MainContext>& main_context);
42 
43  unsigned int get_interval () const;
44 
45  void set_interval (unsigned int new_interval);
46 
47  virtual unsigned int connection_count () const = 0;
48 
49  void suspend () { m_suspended = true; }
50  void resume () { m_suspended = false; }
51 
52 protected:
53 
54  virtual ~Timer() { }
55 
56  void start ();
57 
58  void stop ();
59 
60  virtual bool on_elapsed () = 0;
61 
62  bool suspended () const { return m_suspended; }
63 
64 private:
65 
66  Timer(const Timer&);
67  Timer& operator= (const Timer&);
68 
69 private:
70 
71  static gboolean _timeout_handler (void *data);
72 
73  bool timeout_handler ();
74 
75  GSource* m_timeout_source;
76 
77  unsigned int m_timeout_interval;
78 
79  const Glib::RefPtr<Glib::MainContext> m_main_context;
80 
82 
83 };
84 
86 {
87 public:
88 
89  StandardTimer (unsigned int interval,
90  const Glib::RefPtr<Glib::MainContext>& main_context = Glib::MainContext::get_default());
91 
92  sigc::connection connect (const sigc::slot<void>& slot);
93 
94  virtual unsigned int connection_count () const
95  { return m_signal.size (); }
96 
97 protected:
98 
99  virtual bool on_elapsed ();
100 
101  sigc::signal<void> m_signal;
102 
103 };
104 
106 {
107 public:
108 
109  BlinkTimer (unsigned int interval,
110  const Glib::RefPtr<Glib::MainContext>& main_context = Glib::MainContext::get_default());
111 
112 
113  sigc::connection connect (const sigc::slot<void, bool>& slot);
114 
115  virtual unsigned int connection_count () const
116  { return m_blink_signal.size (); }
117 
118 protected:
119 
120  virtual bool on_elapsed ();
121 
122  sigc::signal<void, bool> m_blink_signal;
123 
124 };
125 
126 } // namespace PBD
127 
128 #endif // __libpbd_timer_h__
sigc::connection connect(const sigc::slot< void, bool > &slot)
BlinkTimer(unsigned int interval, const Glib::RefPtr< Glib::MainContext > &main_context=Glib::MainContext::get_default())
virtual bool on_elapsed()
virtual unsigned int connection_count() const
sigc::signal< void, bool > m_blink_signal
sigc::connection connect(const sigc::slot< void > &slot)
virtual bool on_elapsed()
StandardTimer(unsigned int interval, const Glib::RefPtr< Glib::MainContext > &main_context=Glib::MainContext::get_default())
sigc::signal< void > m_signal
virtual unsigned int connection_count() const
Definition: pbd/pbd/timer.h:94
const Glib::RefPtr< Glib::MainContext > m_main_context
Definition: pbd/pbd/timer.h:79
bool suspended() const
Definition: pbd/pbd/timer.h:62
virtual ~Timer()
Definition: pbd/pbd/timer.h:54
GSource * m_timeout_source
Definition: pbd/pbd/timer.h:75
void suspend()
Definition: pbd/pbd/timer.h:49
unsigned int m_timeout_interval
Definition: pbd/pbd/timer.h:77
virtual unsigned int connection_count() const =0
static gboolean _timeout_handler(void *data)
bool m_suspended
Definition: pbd/pbd/timer.h:81
unsigned int get_interval() const
void resume()
Definition: pbd/pbd/timer.h:50
void set_interval(unsigned int new_interval)
void stop()
bool timeout_handler()
Timer(const Timer &)
void start()
virtual bool on_elapsed()=0
Timer(unsigned int interval, const Glib::RefPtr< Glib::MainContext > &main_context)
#define LIBPBD_API
Definition: axis_view.h:42