add new control protocol related files
[ardour.git] / libs / ardour / ardour / control_protocol.h
1 #ifndef ardour_control_protocols_h
2 #define ardour_control_protocols_h
3
4 #include <string>
5 #include <list>
6 #include <sigc++/sigc++.h>
7
8 namespace ARDOUR {
9
10 class Route;
11 class Session;
12
13 class ControlProtocol : sigc::trackable {
14   public:
15         ControlProtocol (Session&, std::string name);
16         virtual ~ControlProtocol();
17
18         virtual int init () { return 0; }
19
20         sigc::signal<void> ActiveChanged;
21
22         enum SendWhat {
23                 SendRoute,
24                 SendGlobal
25         };
26
27         std::string name() const { return _name; }
28
29         void set_send (SendWhat);
30         void set_active (bool yn);
31         bool get_active() const { return active_thread > 0; }
32
33
34         bool send() const { return _send != 0; }
35         bool send_route_feedback () const { return _send & SendRoute; }
36         bool send_global_feedback () const { return _send & SendGlobal; }
37
38         virtual void send_route_feedback (std::list<Route*>&) {}
39         virtual void send_global_feedback () {}
40
41   protected:
42
43         ARDOUR::Session& session;
44         SendWhat _send;
45         std::string _name;
46         int active_thread;
47         int thread_request_pipe[2];
48         pthread_t _thread;
49
50         static void* _thread_work (void *);
51         void* thread_work ();
52
53         struct ThreadRequest {
54             enum Type {
55                     Start,
56                     Stop,
57                     Quit
58             };
59         };
60
61         int init_thread();
62         int start_thread ();
63         int stop_thread ();
64         void terminate_thread ();
65         int  poke_thread (ThreadRequest::Type);
66 };
67
68 extern "C" {
69         struct ControlProtocolDescriptor {
70             const char* name;
71             void*       ptr;
72             void*       module;
73             ControlProtocol* (*initialize)(ControlProtocolDescriptor*,Session*);
74             void             (*destroy)(ControlProtocolDescriptor*,ControlProtocol*);
75             
76         };
77 }
78
79 }
80
81 #endif // ardour_control_protocols_h