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