xref: /haiku/src/apps/cortex/NodeManager/Connection.h (revision c90684742e7361651849be4116d0e5de3a817194)
1 // Connection.h (Cortex)
2 // * PURPOSE
3 //   Represents a general connection between two media nodes.
4 //
5 // * NOTES 13aug99
6 //   Connection is undergoing massive resimplification(TM).
7 //   1) It's now intended to be stored and passed by value; synchronization
8 //      and reference issues are no more.
9 //   2) It now refers to the participatory nodes by ID, not pointer.  This
10 //      makes the nodes slightly more cumbersome to look up, but makes
11 //      Connection completely 'safe': an outdated instance doesn't contain
12 //      any dangerous information.
13 //
14 // * NOTES 29jul99
15 //   1) For completeness, a release() or disconnect() method would be nice.  Problems?
16 //   2) How will connections between 'external' nodes be denoted?  For example,
17 //      the audioMixer->audioOutput connection must not be broken EVER.  Other external
18 //      connections might be manually broken, but should be left alone when the
19 //      NodeManager quits (whereas all internal connections need to be removed by
20 //      the dtor.)  This implies two flags: 'internal' and 'locked'...
21 //
22 // * HISTORY
23 //   e.moon		25jun99		Begun
24 
25 #ifndef __Connection_H__
26 #define __Connection_H__
27 
28 #include <Debug.h>
29 #include <MediaNode.h>
30 #include <String.h>
31 
32 #include "cortex_defs.h"
33 
34 __BEGIN_CORTEX_NAMESPACE
35 
36 class NodeManager;
37 class NodeGroup;
38 class NodeRef;
39 
40 class Connection {
41 
42 	// rather incestuous set of classes we've got here...
43 	friend class NodeRef;
44 	friend class NodeManager;
45 
46 public:					// *** types & constants
47 	enum flag_t {
48 		// connection should be removed automatically when the NodeManager
49 		//   is destroyed
50 		INTERNAL					= 1<<1,
51 		// connection must never be removed
52 		LOCKED						= 1<<2
53 	};
54 
55 public:					// *** dtor/user-level ctors
56 	virtual ~Connection();
57 
58 	Connection();
59 	Connection(
60 		const Connection&					clone); //nyi
61 	Connection& operator=(
62 		const Connection&					clone); //nyi
63 
64 public:					// *** accessors
65 
66 	uint32 id() const																{ return m_id; }
67 
68 	bool isValid() const														{ return
69 																										m_sourceNode != media_node::null &&
70 																										m_destinationNode != media_node::null &&
71 																										!m_disconnected; }
72 
73 	// changed 13aug99
74 	media_node_id sourceNode() const 								{ return m_sourceNode.node; }
75 	const media_source& source() const 							{ return m_source; }
76 	const char* outputName() const 									{ return m_outputName.String(); }
77 
78 	// changed 13aug99
79 	media_node_id destinationNode() const 					{ return m_destinationNode.node; }
80 	const media_destination& destination() const 		{ return m_destination; }
81 	const char* inputName() const 									{ return m_inputName.String(); }
82 
83 	const media_format& format() const 							{ return m_format; }
84 
85 	uint32 flags() const														{ return m_flags; }
86 
87 	// input/output access [e.moon 14oct99]
88 	status_t getInput(
89 		media_input*							outInput) const;
90 
91 	status_t getOutput(
92 		media_output*							outOutput) const;
93 
94 	// hint access
95 
96 	status_t getOutputHint(
97 		const char**							outName,
98 		media_format*							outFormat) const;
99 
100 	status_t getInputHint(
101 		const char**							outName,
102 		media_format*							outFormat) const;
103 
104 	const media_format& requestedFormat() const { return m_requestedFormat; }
105 
106 
107 protected:				// *** general ctor accessible to subclasses &
108 									//     cortex::NodeManager
109 
110 	// id must be non-0
111 	Connection(
112 		uint32										id,
113 		media_node								srcNode,
114 		const media_source&				src,
115 		const char*								outputName,
116 		media_node								destNode,
117 		const media_destination&	dest,
118 		const char*								inputName,
119 		const media_format&				format,
120 		uint32										flags);
121 
122 	// if any information about the pre-connection (free) output format
123 	// is known, call this method.  this info may be useful in
124 	// finding the output to re-establish the connection later on.
125 
126 	void setOutputHint(
127 		const char*								origName,
128 		const media_format&				origFormat);
129 
130 	// if any information about the pre-connection (free) input format
131 	// is known, call this method.  this info may be useful in
132 	// finding the output to re-establish the connection later on.
133 
134 	void setInputHint(
135 		const char*								origName,
136 		const media_format&				origFormat);
137 
138 	// [e.moon 8dec99]
139 	void setRequestedFormat(
140 		const media_format&				reqFormat);
141 
142 private:					// *** members
143 
144 	// info that may be useful for reconstituting a particular
145 	// connection later on.
146 	struct endpoint_hint {
147 		endpoint_hint(const char* _name, const media_format& _format) :
148 			name(_name), format(_format) {}
149 
150 		BString					name;
151 		media_format		format;
152 	};
153 
154 	// waiting to die?
155 	bool												m_disconnected;
156 
157 	// unique connection ID
158 	uint32											m_id;
159 
160 	// [e.moon 14oct99] now stores media_nodes
161 
162 	// source/output info
163 	media_node									m_sourceNode;
164 	media_source								m_source;
165 	BString											m_outputName;
166 
167 	endpoint_hint*							m_outputHint;
168 
169 	// dest/input info
170 	media_node									m_destinationNode;
171 	media_destination						m_destination;
172 	BString											m_inputName;
173 
174 	endpoint_hint*							m_inputHint;
175 
176 	// connection format
177 	media_format								m_format;
178 
179 	// behaviour modification
180 	uint32											m_flags;
181 
182 	// [e.moon 8dec99] initial requested format
183 	media_format								m_requestedFormat;
184 };
185 
186 __END_CORTEX_NAMESPACE
187 
188 #endif /*__Connection_H__*/
189