moved 2.1-staging to trunk @ rev 1765
[ardour.git] / libs / ardour / ardour / control_protocol_manager.h
1 /*
2     Copyright (C) 2000-2007 Paul 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 */
19
20 #ifndef ardour_control_protocol_manager_h
21 #define ardour_control_protocol_manager_h
22
23 #include <string>
24 #include <list>
25
26 #include <sigc++/sigc++.h>
27
28 #include <glibmm/thread.h>
29
30 #include <pbd/stateful.h> 
31
32 namespace ARDOUR {
33
34 class ControlProtocol;
35 class ControlProtocolDescriptor;
36 class Session;
37
38 struct ControlProtocolInfo {
39     ControlProtocolDescriptor* descriptor;
40     ControlProtocol* protocol;
41     std::string name;
42     std::string path;
43     bool requested;
44     bool mandatory;
45     bool supports_feedback;
46     XMLNode* state;
47
48     ControlProtocolInfo() : descriptor (0), protocol (0), state (0) {}
49     ~ControlProtocolInfo() { if (state) { delete state; } }
50 };
51
52  class ControlProtocolManager : public sigc::trackable, public Stateful
53 {
54   public:
55         ControlProtocolManager ();
56         ~ControlProtocolManager ();
57
58         static ControlProtocolManager& instance() { return *_instance; }
59
60         void set_session (Session&);
61         void discover_control_protocols (std::string search_path);
62         void foreach_known_protocol (sigc::slot<void,const ControlProtocolInfo*>);
63         void load_mandatory_protocols ();
64
65         ControlProtocol* instantiate (ControlProtocolInfo&);
66         int              teardown (ControlProtocolInfo&);
67
68         std::list<ControlProtocolInfo*> control_protocol_info;
69
70         static const std::string state_node_name;
71
72         void set_protocol_states (const XMLNode&);
73
74         int set_state (const XMLNode&);
75         XMLNode& get_state (void);
76
77   private:
78         static ControlProtocolManager* _instance;
79
80         Session* _session;
81         Glib::Mutex protocols_lock;
82         std::list<ControlProtocol*>    control_protocols;
83
84         void drop_session ();
85
86         int control_protocol_discover (std::string path);
87         ControlProtocolDescriptor* get_descriptor (std::string path);
88         ControlProtocolInfo* cpi_by_name (std::string);
89 };
90
91 } // namespace
92
93 #endif // ardour_control_protocol_manager_h