Ardour  9.0-pre0-582-g084a23a80d
base_ui.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2015 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
4  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
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 #include "pbd/pthread_utils.h"
36 
46 class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop
47 {
48  public:
49  BaseUI (const std::string& name);
50  virtual ~BaseUI();
51 
52  BaseUI* base_instance() { return base_ui_instance; }
53 
54  Glib::RefPtr<Glib::MainLoop> main_loop() const { return _main_loop; }
55  bool caller_is_self () const { return _run_loop_thread ? _run_loop_thread->caller_is_self () : true; }
56 
57  bool ok() const { return _ok; }
58 
61  static RequestType Quit;
62 
63  static void set_thread_priority (int p) {
64  _thread_priority = p;
65  }
66 
69  void run ();
70 
74  void quit ();
75 
76  protected:
77  bool _ok;
78 
79  Glib::RefPtr<Glib::MainLoop> _main_loop;
80  Glib::RefPtr<Glib::MainContext> m_context;
82  Glib::Threads::Mutex _run_lock;
83  Glib::Threads::Cond _running;
84 
85  /* this signals _running from within the event loop,
86  from an idle callback
87  */
88 
89  bool signal_running ();
90 
96  virtual void thread_init () {};
97 
98  int set_thread_priority () const;
99 
102  bool request_handler (Glib::IOCondition);
103 
106 
107  virtual void maybe_install_precall_handler (Glib::RefPtr<Glib::MainContext>) {}
108 
113  virtual void handle_ui_requests () = 0;
114 
115  private:
117 
119 
120  static uint64_t rt_bit;
121  static int _thread_priority;
122 
124  void main_thread ();
125 };
126 
Definition: base_ui.h:47
virtual void handle_ui_requests()=0
void main_thread()
static RequestType CallSlot
Definition: base_ui.h:60
CrossThreadChannel request_channel
Definition: base_ui.h:118
bool request_handler(Glib::IOCondition)
static RequestType Quit
Definition: base_ui.h:61
bool ok() const
Definition: base_ui.h:57
bool _ok
Definition: base_ui.h:77
virtual ~BaseUI()
static RequestType new_request_type()
static uint64_t rt_bit
Definition: base_ui.h:120
void attach_request_source()
virtual void thread_init()
Definition: base_ui.h:96
Glib::RefPtr< Glib::MainLoop > _main_loop
Definition: base_ui.h:79
Glib::RefPtr< Glib::MainLoop > main_loop() const
Definition: base_ui.h:54
static void set_thread_priority(int p)
Definition: base_ui.h:63
BaseUI * base_instance()
Definition: base_ui.h:52
void signal_new_request()
bool signal_running()
int setup_request_pipe()
void quit()
void run()
PBD::Thread * _run_loop_thread
Definition: base_ui.h:81
bool caller_is_self() const
Definition: base_ui.h:55
int set_thread_priority() const
virtual void maybe_install_precall_handler(Glib::RefPtr< Glib::MainContext >)
Definition: base_ui.h:107
BaseUI(const std::string &name)
Glib::RefPtr< Glib::MainContext > m_context
Definition: base_ui.h:80
Glib::Threads::Cond _running
Definition: base_ui.h:83
static int _thread_priority
Definition: base_ui.h:121
BaseUI * base_ui_instance
Definition: base_ui.h:116
Glib::Threads::Mutex _run_lock
Definition: base_ui.h:82
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBPBD_API