tweak transport bar spacing
[ardour.git] / libs / pbd / pbd / base_ui.h
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/thread.h>
30 #include <glibmm/main.h>
31
32 #include "pbd/crossthread.h"
33 #include "pbd/event_loop.h"
34
35 class BaseUI : virtual public sigc::trackable, public PBD::EventLoop
36 {
37   public:
38         BaseUI (const std::string& name);
39         virtual ~BaseUI();
40
41         BaseUI* base_instance() { return base_ui_instance; }
42
43         Glib::RefPtr<Glib::MainLoop> main_loop() const { return _main_loop; }
44         Glib::Thread* event_loop_thread() const { return run_loop_thread; }
45         bool caller_is_self () const { return Glib::Thread::self() == run_loop_thread; }
46
47         std::string name() const { return _name; }
48
49         bool ok() const { return _ok; }
50         
51         static RequestType new_request_type();
52         static RequestType CallSlot;
53         static RequestType Quit;
54
55         void run ();
56         void quit ();
57
58   protected:
59         CrossThreadChannel request_channel;
60         bool _ok; 
61
62         Glib::RefPtr<Glib::MainLoop> _main_loop;
63         Glib::Thread*                 run_loop_thread;
64
65         virtual void thread_init () {};
66         bool request_handler (Glib::IOCondition);
67
68         virtual void handle_ui_requests () = 0;
69
70   private:
71         std::string _name; 
72         BaseUI* base_ui_instance;
73         
74         static uint64_t rt_bit;
75
76         int setup_request_pipe ();
77         void main_thread ();
78 };
79
80 #endif /* __pbd_base_ui_h__ */