Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
22 
23 #include <map>
24 #include <string>
25 #include <pthread.h>
26 
27 #include <glibmm/threads.h>
28 
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"
34 
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.
41  *
42  * Note the assumption here that other libs are being built as DLLs if this one is.
43  */
44 
45 #ifdef ABSTRACT_UI_EXPORTS
46 #define ABSTRACT_UI_API LIBPBD_DLL_EXPORT
47 #else
48 #define ABSTRACT_UI_API LIBPBD_DLL_IMPORT
49 #endif
50 
51 
52 class Touchable;
53 
54 template<typename RequestObject>
56 {
57 public:
58  AbstractUI (const std::string& name);
59  virtual ~AbstractUI();
60 
61  void register_thread (pthread_t, std::string, uint32_t num_requests);
62  bool call_slot (EventLoop::InvalidationRecord*, const std::function<void()>&);
63  Glib::Threads::RWLock& slot_invalidation_rwlock() { return request_buffer_map_lock; }
64 
65  Glib::Threads::RWLock request_buffer_map_lock;
66 
67 protected:
68  struct RequestBuffer : public PBD::RingBufferNPT<RequestObject> {
69  bool dead;
70  RequestBuffer (uint32_t size)
71  : PBD::RingBufferNPT<RequestObject> (size)
72  , dead (false) {}
73  };
74  typedef typename RequestBuffer::rw_vector RequestBufferVector;
75 
76 #if defined(COMPILER_MINGW) && defined(PTW32_VERSION)
77  struct pthread_cmp
78  {
79  bool operator() (const ptw32_handle_t& thread1, const ptw32_handle_t& thread2)
80  {
81  return thread1.p < thread2.p;
82  }
83  };
84  typedef typename std::map<pthread_t,RequestBuffer*, pthread_cmp>::iterator RequestBufferMapIterator;
85  typedef std::map<pthread_t,RequestBuffer*, pthread_cmp> RequestBufferMap;
86 #else
87  typedef typename std::map<pthread_t,RequestBuffer*>::iterator RequestBufferMapIterator;
88  typedef std::map<pthread_t,RequestBuffer*> RequestBufferMap;
89 #endif
90 
92 
93  std::list<RequestObject*> request_list;
94 
95  RequestObject* get_request (RequestType);
97  void send_request (RequestObject*);
98 
99  virtual void do_request (RequestObject *) = 0;
101 
103 
104 };
105 
#define ABSTRACT_UI_API
Definition: abstract_ui.h:48
virtual void do_request(RequestObject *)=0
std::map< pthread_t, RequestBuffer * > RequestBufferMap
Definition: abstract_ui.h:88
std::list< RequestObject * > request_list
Definition: abstract_ui.h:93
RequestBuffer * get_per_thread_request_buffer()
void send_request(RequestObject *)
RequestBuffer::rw_vector RequestBufferVector
Definition: abstract_ui.h:74
RequestBufferMap request_buffers
Definition: abstract_ui.h:91
Glib::Threads::RWLock & slot_invalidation_rwlock()
Definition: abstract_ui.h:63
Glib::Threads::RWLock request_buffer_map_lock
Definition: abstract_ui.h:65
virtual ~AbstractUI()
bool call_slot(EventLoop::InvalidationRecord *, const std::function< void()> &)
std::map< pthread_t, RequestBuffer * >::iterator RequestBufferMapIterator
Definition: abstract_ui.h:87
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:100
RequestObject * get_request(RequestType)
void handle_ui_requests()
Definition: base_ui.h:47
GtkImageIconNameData name
Definition: gtkimage.h:6
Definition: axis_view.h:42
RequestBuffer(uint32_t size)
Definition: abstract_ui.h:70