ardour
base_ui.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000-2009 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #ifndef __pbd_base_ui_h__
21 #define __pbd_base_ui_h__
22 
23 #include <string>
24 #include <stdint.h>
25 
26 #include <sigc++/slot.h>
27 #include <sigc++/trackable.h>
28 
29 #include <glibmm/threads.h>
30 #include <glibmm/main.h>
31 
32 #include "pbd/libpbd_visibility.h"
33 #include "pbd/crossthread.h"
34 #include "pbd/event_loop.h"
35 
45 class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop
46 {
47  public:
48  BaseUI (const std::string& name);
49  virtual ~BaseUI();
50 
51  BaseUI* base_instance() { return base_ui_instance; }
52 
53  Glib::RefPtr<Glib::MainLoop> main_loop() const { return _main_loop; }
54  Glib::Threads::Thread* event_loop_thread() const { return run_loop_thread; }
55  bool caller_is_self () const { return Glib::Threads::Thread::self() == run_loop_thread; }
56 
57  std::string name() const { return _name; }
58 
59  bool ok() const { return _ok; }
60 
61  static RequestType new_request_type();
63  static RequestType Quit;
64 
67  void run ();
68 
72  void quit ();
73 
74  protected:
75  bool _ok;
76 
77  Glib::RefPtr<Glib::MainLoop> _main_loop;
78  Glib::RefPtr<Glib::MainContext> m_context;
79  Glib::Threads::Thread* run_loop_thread;
80  Glib::Threads::Mutex _run_lock;
81  Glib::Threads::Cond _running;
82 
83  /* this signals _running from within the event loop,
84  from an idle callback
85  */
86 
87  bool signal_running ();
88 
94  virtual void thread_init () {};
95 
98  bool request_handler (Glib::IOCondition);
99 
100  void signal_new_request ();
101  void attach_request_source ();
102 
107  virtual void handle_ui_requests () = 0;
108 
109  private:
110  std::string _name;
112 
114 
115  static uint64_t rt_bit;
116 
117  int setup_request_pipe ();
118  void main_thread ();
119 };
120 
121 #endif /* __pbd_base_ui_h__ */
static RequestType CallSlot
Definition: base_ui.h:62
Glib::Threads::Cond _running
Definition: base_ui.h:81
bool _ok
Definition: base_ui.h:75
std::string name() const
Definition: base_ui.h:57
Glib::RefPtr< Glib::MainContext > m_context
Definition: base_ui.h:78
virtual void thread_init()
Definition: base_ui.h:94
#define LIBPBD_API
BaseUI * base_instance()
Definition: base_ui.h:51
static uint64_t rt_bit
Definition: base_ui.h:115
BaseUI * base_ui_instance
Definition: base_ui.h:111
CrossThreadChannel request_channel
Definition: base_ui.h:113
Glib::Threads::Mutex _run_lock
Definition: base_ui.h:80
Glib::Threads::Thread * event_loop_thread() const
Definition: base_ui.h:54
bool ok() const
Definition: base_ui.h:59
const char * name
bool caller_is_self() const
Definition: base_ui.h:55
std::string _name
Definition: base_ui.h:110
static RequestType Quit
Definition: base_ui.h:63
Glib::Threads::Thread * run_loop_thread
Definition: base_ui.h:79
Glib::RefPtr< Glib::MainLoop > main_loop() const
Definition: base_ui.h:53
Definition: base_ui.h:45
Glib::RefPtr< Glib::MainLoop > _main_loop
Definition: base_ui.h:77