2 Copyright (C) 1998-2009 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 #ifndef __pbd_abstract_ui_h__
21 #define __pbd_abstract_ui_h__
27 #include <glibmm/threads.h>
29 #include "pbd/libpbd_visibility.h"
30 #include "pbd/receiver.h"
31 #include "pbd/ringbufferNPT.h"
32 #include "pbd/signals.h"
33 #include "pbd/base_ui.h"
35 /* We have a special case in libpbd of a template class that gets instantiated
36 * as the base class of several classes in other libraries. It is not possible
37 * to use LIBFOO_API to mark this visible, because the FOO in each case is
38 * different. So we define this generic visible/export/hidden/import pair
39 * of macros to try to deal with this special case. These should NEVER be
40 * used anywhere except AbstractUI<T> (or similar cases if they arise.
42 * Note the assumption here that other libs are being built as DLLs if this one is.
45 #ifdef ABSTRACT_UI_EXPORTS
46 #define ABSTRACT_UI_API LIBPBD_DLL_EXPORT
48 #define ABSTRACT_UI_API LIBPBD_DLL_IMPORT
54 template<typename RequestObject>
55 class ABSTRACT_UI_API AbstractUI : public BaseUI
58 AbstractUI (const std::string& name);
59 virtual ~AbstractUI() {}
61 void register_thread (std::string, pthread_t, std::string, uint32_t num_requests);
62 void call_slot (EventLoop::InvalidationRecord*, const boost::function<void()>&);
63 Glib::Threads::Mutex& slot_invalidation_mutex() { return request_buffer_map_lock; }
65 Glib::Threads::Mutex request_buffer_map_lock;
68 struct RequestBuffer : public PBD::RingBufferNPT<RequestObject> {
70 AbstractUI<RequestObject>& ui;
71 RequestBuffer (uint32_t size, AbstractUI<RequestObject>& uir)
72 : PBD::RingBufferNPT<RequestObject> (size)
76 typedef typename RequestBuffer::rw_vector RequestBufferVector;
78 typedef typename std::map<pthread_t,RequestBuffer*>::iterator RequestBufferMapIterator;
79 typedef std::map<pthread_t,RequestBuffer*> RequestBufferMap;
81 RequestBufferMap request_buffers;
82 static Glib::Threads::Private<RequestBuffer> per_thread_request_buffer;
84 Glib::Threads::Mutex request_list_lock;
85 std::list<RequestObject*> request_list;
87 RequestObject* get_request (RequestType);
88 void handle_ui_requests ();
89 void send_request (RequestObject *);
91 virtual void do_request (RequestObject *) = 0;
92 PBD::ScopedConnection new_thread_connection;
95 #endif /* __pbd_abstract_ui_h__ */