Added path.cc and tokenizer.h from win32 branch.
[ardour.git] / libs / pbd3 / pbd / abstract_ui.h
1 /*
2     Copyright (C) 1998-99 Paul Barton-Davis 
3
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.
8
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.
13
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.
17
18     $Id$
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 <sigc++/sigc++.h>
29
30 #include <glibmm/thread.h>
31
32 #include <pbd/receiver.h>
33 #include <pbd/ringbufferNPT.h>
34 #include <pbd/base_ui.h>
35
36 class Touchable;
37
38 template <class RequestObject>
39 class AbstractUI : public BaseUI
40 {
41   public:
42         AbstractUI (std::string name, bool with_signal_pipe);
43         virtual ~AbstractUI() {}
44
45         virtual bool caller_is_ui_thread() = 0;
46
47         void call_slot (sigc::slot<void> el_slot) {
48                 RequestObject *req = get_request (BaseUI::CallSlot);
49                 
50                 if (req == 0) {
51                         return;
52                 }
53                 
54                 req->slot = el_slot;
55                 send_request (req);
56         }       
57
58         void register_thread (pthread_t, std::string);
59         void register_thread_with_request_count (pthread_t, std::string, uint32_t num_requests);
60
61   protected:
62         typedef RingBufferNPT<RequestObject> RequestBuffer;
63         typedef typename RequestBuffer::rw_vector RequestBufferVector;
64         typedef typename std::map<pthread_t,RequestBuffer*>::iterator RequestBufferMapIterator;
65
66     Glib::Mutex request_buffer_map_lock;
67         typedef std::map<pthread_t,RequestBuffer*> RequestBufferMap;
68         RequestBufferMap request_buffers;
69         pthread_key_t thread_request_buffer_key;
70         RequestObject* get_request (RequestType);
71         void handle_ui_requests ();
72         void send_request (RequestObject *);
73
74         virtual void do_request (RequestObject *) = 0;
75 };
76
77 #endif /* __pbd_abstract_ui_h__ */
78
79