jack_audiobackend.cc finally compiles
[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     int  reestablish_ports ();
63     int  reconnect_ports ();
64
65     /* other Port management */
66     
67     bool port_is_physical (const std::string&) const;
68     void get_physical_outputs (DataType type, std::vector<std::string>&);
69     void get_physical_inputs (DataType type, std::vector<std::string>&);
70     boost::shared_ptr<Port> get_port_by_name (const std::string &);
71     void port_renamed (const std::string&, const std::string&);
72     ChanCount n_physical_outputs () const;
73     ChanCount n_physical_inputs () const;
74     const char ** get_ports (const std::string& port_name_pattern, const std::string& type_name_pattern, uint32_t flags);
75     
76     void remove_all_ports ();
77     
78     /* per-Port monitoring */
79     
80     bool can_request_input_monitoring () const;
81     void request_input_monitoring (const std::string&, bool) const;
82     void ensure_input_monitoring (const std::string&, bool) const;
83     
84     class PortRegistrationFailure : public std::exception {
85       public:
86         PortRegistrationFailure (std::string const & why = "")
87                 : reason (why) {}
88         
89         ~PortRegistrationFailure () throw () {}
90         
91         const char *what() const throw () { return reason.c_str(); }
92         
93       private:
94         std::string reason;
95     };
96
97
98   protected:
99     PortEngine* _impl;
100     SerializedRCUManager<Ports> ports;
101
102     boost::shared_ptr<Port> register_port (DataType type, const std::string& portname, bool input);
103     void port_registration_failure (const std::string& portname);
104 };
105         
106 }
107
108 #endif /* __libardour_port_manager_h__ */