1 /*
2  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2007 Tim Mayberry <mojofunk@gmail.com>
4  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
5  * Copyright (C) 2009 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2015-2016 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef ardour_control_protocol_manager_h
24 #define ardour_control_protocol_manager_h
25 
26 #include <string>
27 #include <list>
28 
29 
30 #include <glibmm/threads.h>
31 
32 #include "pbd/stateful.h"
33 
34 #include "control_protocol/types.h"
35 
36 #include "ardour/session_handle.h"
37 
38 namespace ARDOUR {
39 
40 class ControlProtocol;
41 class ControlProtocolDescriptor;
42 class Session;
43 
44 class LIBARDOUR_API ControlProtocolInfo {
45 	public:
46 		ControlProtocolDescriptor* descriptor;
47 		ControlProtocol* protocol;
48 		std::string name;
49 		std::string path;
50 		bool requested;
51 		bool mandatory;
52 		bool supports_feedback;
53 		XMLNode* state;
54 
ControlProtocolInfo()55 		ControlProtocolInfo() : descriptor (0), protocol (0), requested(false),
56 		mandatory(false), supports_feedback(false), state (0)
57 	{}
58 		~ControlProtocolInfo();
59 
60 };
61 
62 class LIBARDOUR_API ControlProtocolManager : public PBD::Stateful, public ARDOUR::SessionHandlePtr
63 {
64   public:
65 	~ControlProtocolManager ();
66 
67 	static ControlProtocolManager& instance();
68 
69 	void set_session (Session*);
70 	void discover_control_protocols ();
71 	void foreach_known_protocol (boost::function<void(const ControlProtocolInfo*)>);
72 	void load_mandatory_protocols ();
73 	void midi_connectivity_established ();
74 	void drop_protocols ();
75 	void register_request_buffer_factories ();
76 
77 	int activate (ControlProtocolInfo&);
78         int deactivate (ControlProtocolInfo&);
79 
80 	std::list<ControlProtocolInfo*> control_protocol_info;
81 
82 	static const std::string state_node_name;
83 
84 	int set_state (const XMLNode&, int version);
85 	XMLNode& get_state (void);
86 
87         PBD::Signal1<void,ControlProtocolInfo*> ProtocolStatusChange;
88 
89         void stripable_selection_changed (ARDOUR::StripableNotificationListPtr);
90         static PBD::Signal1<void,ARDOUR::StripableNotificationListPtr> StripableSelectionChanged;
91 
92   private:
93 	ControlProtocolManager ();
94 	static ControlProtocolManager* _instance;
95 
96 	Glib::Threads::RWLock protocols_lock;
97 	std::list<ControlProtocol*>    control_protocols;
98 
99 	void session_going_away ();
100 
101 	int control_protocol_discover (std::string path);
102 	ControlProtocolDescriptor* get_descriptor (std::string path);
103 	ControlProtocolInfo* cpi_by_name (std::string);
104 	ControlProtocol* instantiate (ControlProtocolInfo&);
105 	int teardown (ControlProtocolInfo&, bool lock_required);
106 };
107 
108 } // namespace
109 
110 #endif // ardour_control_protocol_manager_h
111