Ardour  8.12
abstract_ui.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2015 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2013-2014 John Emmas <john@creativepost.co.uk>
4  * Copyright (C) 2014-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 #ifndef __pbd_abstract_ui_h__
22 #define __pbd_abstract_ui_h__
23 
24 #include <map>
25 #include <string>
26 #include <pthread.h>
27 
28 #include <glibmm/threads.h>
29 
30 #include "pbd/libpbd_visibility.h"
31 #include "pbd/receiver.h"
32 #include "pbd/ringbufferNPT.h"
33 #include "pbd/signals.h"
34 #include "pbd/base_ui.h"
35 
36 /* We have a special case in libpbd of a template class that gets instantiated
37  * as the base class of several classes in other libraries. It is not possible
38  * to use LIBFOO_API to mark this visible, because the FOO in each case is
39  * different. So we define this generic visible/export/hidden/import pair
40  * of macros to try to deal with this special case. These should NEVER be
41  * used anywhere except AbstractUI<T> (or similar cases if they arise.
42  *
43  * Note the assumption here that other libs are being built as DLLs if this one is.
44  */
45 
46 #ifdef ABSTRACT_UI_EXPORTS
47 #define ABSTRACT_UI_API LIBPBD_DLL_EXPORT
48 #else
49 #define ABSTRACT_UI_API LIBPBD_DLL_IMPORT
50 #endif
51 
52 
53 class Touchable;
54 
55 template<typename RequestObject>
57 {
58 public:
59  AbstractUI (const std::string& name);
60  virtual ~AbstractUI();
61 
62  void register_thread (pthread_t, std::string, uint32_t num_requests);
63  bool call_slot (EventLoop::InvalidationRecord*, const boost::function<void()>&);
64  Glib::Threads::RWLock& slot_invalidation_rwlock() { return request_buffer_map_lock; }
65 
66  Glib::Threads::RWLock request_buffer_map_lock;
67 
68 protected:
69  struct RequestBuffer : public PBD::RingBufferNPT<RequestObject> {
70  bool dead;
71  RequestBuffer (uint32_t size)
72  : PBD::RingBufferNPT<RequestObject> (size)
73  , dead (false) {}
74  };
75  typedef typename RequestBuffer::rw_vector RequestBufferVector;
76 
77 #if defined(COMPILER_MINGW) && defined(PTW32_VERSION)
78  struct pthread_cmp
79  {
80  bool operator() (const ptw32_handle_t& thread1, const ptw32_handle_t& thread2)
81  {
82  return thread1.p < thread2.p;
83  }
84  };
85  typedef typename std::map<pthread_t,RequestBuffer*, pthread_cmp>::iterator RequestBufferMapIterator;
86  typedef std::map<pthread_t,RequestBuffer*, pthread_cmp> RequestBufferMap;
87 #else
88  typedef typename std::map<pthread_t,RequestBuffer*>::iterator RequestBufferMapIterator;
89  typedef std::map<pthread_t,RequestBuffer*> RequestBufferMap;
90 #endif
91 
93 
94  std::list<RequestObject*> request_list;
95 
96  RequestObject* get_request (RequestType);
98  void send_request (RequestObject*);
99 
100  virtual void do_request (RequestObject *) = 0;
102 
104 
105 };
106 
107 #endif /* __pbd_abstract_ui_h__ */
#define ABSTRACT_UI_API
Definition: abstract_ui.h:49
virtual void do_request(RequestObject *)=0
std::map< pthread_t, RequestBuffer * > RequestBufferMap
Definition: abstract_ui.h:89
std::list< RequestObject * > request_list
Definition: abstract_ui.h:94
RequestBuffer * get_per_thread_request_buffer()
void send_request(RequestObject *)
RequestBuffer::rw_vector RequestBufferVector
Definition: abstract_ui.h:75
bool call_slot(EventLoop::InvalidationRecord *, const boost::function< void()> &)
RequestBufferMap request_buffers
Definition: abstract_ui.h:92
Glib::Threads::RWLock & slot_invalidation_rwlock()
Definition: abstract_ui.h:64
Glib::Threads::RWLock request_buffer_map_lock
Definition: abstract_ui.h:66
virtual ~AbstractUI()
std::map< pthread_t, RequestBuffer * >::iterator RequestBufferMapIterator
Definition: abstract_ui.h:88
AbstractUI(const std::string &name)
void register_thread(pthread_t, std::string, uint32_t num_requests)
PBD::ScopedConnection new_thread_connection
Definition: abstract_ui.h:101
RequestObject * get_request(RequestType)
void handle_ui_requests()
Definition: base_ui.h:48
GtkImageIconNameData name
Definition: gtkimage.h:6
Definition: axis_view.h:42
RequestBuffer(uint32_t size)
Definition: abstract_ui.h:71