allow zero-input (i.e. tone generator) processors to be added
[ardour2.git] / libs / pbd / base_ui.cc
blobce7018a005293014c95b937468ef853c118deeed
1 /*
2 Copyright (C) 2000-2007 Paul Davis
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 #include <cstring>
21 #include <stdint.h>
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <cerrno>
25 #include <cstring>
27 #include "pbd/base_ui.h"
28 #include "pbd/pthread_utils.h"
29 #include "pbd/error.h"
30 #include "pbd/compose.h"
31 #include "pbd/failed_constructor.h"
33 #include "i18n.h"
35 using namespace std;
36 using namespace PBD;
37 using namespace Glib;
39 uint64_t BaseUI::rt_bit = 1;
40 BaseUI::RequestType BaseUI::CallSlot = BaseUI::new_request_type();
41 BaseUI::RequestType BaseUI::Quit = BaseUI::new_request_type();
43 BaseUI::BaseUI (const string& str)
44 : run_loop_thread (0)
45 , _name (str)
47 base_ui_instance = this;
49 request_channel.ios()->connect (sigc::mem_fun (*this, &BaseUI::request_handler));
51 /* derived class must set _ok */
54 BaseUI::~BaseUI()
58 BaseUI::RequestType
59 BaseUI::new_request_type ()
61 RequestType rt;
63 /* XXX catch out-of-range */
65 rt = RequestType (rt_bit);
66 rt_bit <<= 1;
68 return rt;
71 void
72 BaseUI::main_thread ()
74 set_event_loop_for_thread (this);
75 thread_init ();
76 _main_loop->run ();
79 void
80 BaseUI::run ()
82 /* to be called by UI's that need/want their own distinct, self-created event loop thread.
85 _main_loop = MainLoop::create (MainContext::create());
86 request_channel.ios()->attach (_main_loop->get_context());
88 /* glibmm hack - drop the refptr to the IOSource now before it can hurt */
89 request_channel.drop_ios ();
91 run_loop_thread = Thread::create (mem_fun (*this, &BaseUI::main_thread), true);
94 void
95 BaseUI::quit ()
97 if (_main_loop->is_running()) {
98 _main_loop->quit ();
99 run_loop_thread->join ();
103 bool
104 BaseUI::request_handler (Glib::IOCondition ioc)
106 /* check the transport request pipe */
108 if (ioc & ~IO_IN) {
109 _main_loop->quit ();
112 if (ioc & IO_IN) {
113 request_channel.drain ();
115 /* there may been an error. we'd rather handle requests first,
116 and then get IO_HUP or IO_ERR on the next loop.
119 /* handle requests */
121 handle_ui_requests ();
124 return true;