part-way through getting the audioengine changes to compile
[ardour.git] / libs / ardour / ardour / port_manager.h
1 /*
2     Copyright (C) 2013 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 __libardour_port_manager_h__
21 #define __libardour_port_manager_h__
22
23 #include <vector>
24 #include <string>
25 #include <exception>
26 #include <map>
27
28 #include <stdint.h>
29
30 #include <boost/shared_ptr.hpp>
31
32 #include "pbd/rcu.h"
33
34 #include "ardour/chan_count.h"
35 #include "ardour/port.h"
36 #include "ardour/port_engine.h"
37
38 namespace ARDOUR {
39
40 class PortManager 
41 {
42   public:
43     typedef std::map<std::string,boost::shared_ptr<Port> > Ports;
44     
45     PortManager();
46     virtual ~PortManager() {}
47
48     PortEngine& port_engine() { return *_impl; }
49     
50     /* Port registration */
51     
52     boost::shared_ptr<Port> register_input_port (DataType, const std::string& portname);
53     boost::shared_ptr<Port> register_output_port (DataType, const std::string& portname);
54     int unregister_port (boost::shared_ptr<Port>);
55     
56     /* Port connectivity */
57     
58     int connect (const std::string& source, const std::string& destination);
59     int disconnect (const std::string& source, const std::string& destination);
60     int disconnect (boost::shared_ptr<Port>);
61     bool connected (const std::string&);
62
63     /* other Port management */
64     
65     bool port_is_physical (const std::string&) const;
66     void get_physical_outputs (DataType type, std::vector<std::string>&);
67     void get_physical_inputs (DataType type, std::vector<std::string>&);
68     boost::shared_ptr<Port> get_port_by_name (const std::string &);
69     void port_renamed (const std::string&, const std::string&);
70     ChanCount n_physical_outputs () const;
71     ChanCount n_physical_inputs () const;
72     const char ** get_ports (const std::string& port_name_pattern, const std::string& type_name_pattern, uint32_t flags);
73     
74     void remove_all_ports ();
75     
76     /* per-Port monitoring */
77     
78     bool can_request_input_monitoring () const;
79     void request_input_monitoring (const std::string&, bool) const;
80     void ensure_input_monitoring (const std::string&, bool) const;
81
82     std::string make_port_name_relative (const std::string&) const;
83     std::string make_port_name_non_relative (const std::string&) const;
84     bool port_is_mine (const std::string&) const;
85     
86     class PortRegistrationFailure : public std::exception {
87       public:
88         PortRegistrationFailure (std::string const & why = "")
89                 : reason (why) {}
90         
91         ~PortRegistrationFailure () throw () {}
92         
93         const char *what() const throw () { return reason.c_str(); }
94         
95       private:
96         std::string reason;
97     };
98
99
100   protected:
101     PortEngine* _impl;
102     SerializedRCUManager<Ports> ports;
103
104     boost::shared_ptr<Port> register_port (DataType type, const std::string& portname, bool input);
105     void port_registration_failure (const std::string& portname);
106 };
107         
108 }
109
110 #endif /* __libardour_port_manager_h__ */