1c284bb0fSMatt Madia/*
2c284bb0fSMatt Madia * Copyright (c) 1999-2000, Eric Moon.
3c284bb0fSMatt Madia * All rights reserved.
4c284bb0fSMatt Madia *
5c284bb0fSMatt Madia * Redistribution and use in source and binary forms, with or without
6c284bb0fSMatt Madia * modification, are permitted provided that the following conditions
7c284bb0fSMatt Madia * are met:
8c284bb0fSMatt Madia *
9c284bb0fSMatt Madia * 1. Redistributions of source code must retain the above copyright
10c284bb0fSMatt Madia *    notice, this list of conditions, and the following disclaimer.
11c284bb0fSMatt Madia *
12c284bb0fSMatt Madia * 2. Redistributions in binary form must reproduce the above copyright
13c284bb0fSMatt Madia *    notice, this list of conditions, and the following disclaimer in the
14c284bb0fSMatt Madia *    documentation and/or other materials provided with the distribution.
15c284bb0fSMatt Madia *
16c284bb0fSMatt Madia * 3. The name of the author may not be used to endorse or promote products
17c284bb0fSMatt Madia *    derived from this software without specific prior written permission.
18c284bb0fSMatt Madia *
19c284bb0fSMatt Madia * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20c284bb0fSMatt Madia * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21c284bb0fSMatt Madia * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22c284bb0fSMatt Madia * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23c284bb0fSMatt Madia * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24c284bb0fSMatt Madia * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25c284bb0fSMatt Madia * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26c284bb0fSMatt Madia * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27c284bb0fSMatt Madia * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28c284bb0fSMatt Madia * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c284bb0fSMatt Madia */
30c284bb0fSMatt Madia
31c284bb0fSMatt Madia
32a0795c6fSMarcus Overhagen// Connection.h (Cortex)
33a0795c6fSMarcus Overhagen// * PURPOSE
34a0795c6fSMarcus Overhagen//   Represents a general connection between two media nodes.
35a0795c6fSMarcus Overhagen//
36a0795c6fSMarcus Overhagen// * NOTES 13aug99
37a0795c6fSMarcus Overhagen//   Connection is undergoing massive resimplification(TM).
38a0795c6fSMarcus Overhagen//   1) It's now intended to be stored and passed by value; synchronization
39a0795c6fSMarcus Overhagen//      and reference issues are no more.
40a0795c6fSMarcus Overhagen//   2) It now refers to the participatory nodes by ID, not pointer.  This
41a0795c6fSMarcus Overhagen//      makes the nodes slightly more cumbersome to look up, but makes
42a0795c6fSMarcus Overhagen//      Connection completely 'safe': an outdated instance doesn't contain
43a0795c6fSMarcus Overhagen//      any dangerous information.
44a0795c6fSMarcus Overhagen//
45a0795c6fSMarcus Overhagen// * NOTES 29jul99
46a0795c6fSMarcus Overhagen//   1) For completeness, a release() or disconnect() method would be nice.  Problems?
47a0795c6fSMarcus Overhagen//   2) How will connections between 'external' nodes be denoted?  For example,
48a0795c6fSMarcus Overhagen//      the audioMixer->audioOutput connection must not be broken EVER.  Other external
49a0795c6fSMarcus Overhagen//      connections might be manually broken, but should be left alone when the
50a0795c6fSMarcus Overhagen//      NodeManager quits (whereas all internal connections need to be removed by
51a0795c6fSMarcus Overhagen//      the dtor.)  This implies two flags: 'internal' and 'locked'...
52a0795c6fSMarcus Overhagen//
53a0795c6fSMarcus Overhagen// * HISTORY
54a0795c6fSMarcus Overhagen//   e.moon		25jun99		Begun
55a0795c6fSMarcus Overhagen
56a0795c6fSMarcus Overhagen#ifndef __Connection_H__
57a0795c6fSMarcus Overhagen#define __Connection_H__
58a0795c6fSMarcus Overhagen
59a0795c6fSMarcus Overhagen#include <Debug.h>
60a0795c6fSMarcus Overhagen#include <MediaNode.h>
61a0795c6fSMarcus Overhagen#include <String.h>
62a0795c6fSMarcus Overhagen
63a0795c6fSMarcus Overhagen#include "cortex_defs.h"
64a0795c6fSMarcus Overhagen
65a0795c6fSMarcus Overhagen__BEGIN_CORTEX_NAMESPACE
66a0795c6fSMarcus Overhagen
67a0795c6fSMarcus Overhagenclass NodeManager;
68a0795c6fSMarcus Overhagenclass NodeGroup;
69a0795c6fSMarcus Overhagenclass NodeRef;
70a0795c6fSMarcus Overhagen
71a0795c6fSMarcus Overhagenclass Connection {
72a0795c6fSMarcus Overhagen
73a0795c6fSMarcus Overhagen	// rather incestuous set of classes we've got here...
7423e67806SIthamar R. Adema	friend class NodeRef;
7523e67806SIthamar R. Adema	friend class NodeManager;
76a0795c6fSMarcus Overhagen
77a0795c6fSMarcus Overhagenpublic:					// *** types & constants
78a0795c6fSMarcus Overhagen	enum flag_t {
79a0795c6fSMarcus Overhagen		// connection should be removed automatically when the NodeManager
80a0795c6fSMarcus Overhagen		//   is destroyed
81a0795c6fSMarcus Overhagen		INTERNAL					= 1<<1,
82a0795c6fSMarcus Overhagen		// connection must never be removed
83a0795c6fSMarcus Overhagen		LOCKED						= 1<<2
84a0795c6fSMarcus Overhagen	};
85a0795c6fSMarcus Overhagen
86a0795c6fSMarcus Overhagenpublic:					// *** dtor/user-level ctors
87a0795c6fSMarcus Overhagen	virtual ~Connection();
88a0795c6fSMarcus Overhagen
89a0795c6fSMarcus Overhagen	Connection();
90a0795c6fSMarcus Overhagen	Connection(
91a0795c6fSMarcus Overhagen		const Connection&					clone); //nyi
92a0795c6fSMarcus Overhagen	Connection& operator=(
93a0795c6fSMarcus Overhagen		const Connection&					clone); //nyi
94a0795c6fSMarcus Overhagen
95a0795c6fSMarcus Overhagenpublic:					// *** accessors
96a0795c6fSMarcus Overhagen
97a0795c6fSMarcus Overhagen	uint32 id() const																{ return m_id; }
98a0795c6fSMarcus Overhagen
99a0795c6fSMarcus Overhagen	bool isValid() const														{ return
100a0795c6fSMarcus Overhagen																										m_sourceNode != media_node::null &&
101a0795c6fSMarcus Overhagen																										m_destinationNode != media_node::null &&
102a0795c6fSMarcus Overhagen																										!m_disconnected; }
103a0795c6fSMarcus Overhagen
104a0795c6fSMarcus Overhagen	// changed 13aug99
105a0795c6fSMarcus Overhagen	media_node_id sourceNode() const 								{ return m_sourceNode.node; }
106a0795c6fSMarcus Overhagen	const media_source& source() const 							{ return m_source; }
107a0795c6fSMarcus Overhagen	const char* outputName() const 									{ return m_outputName.String(); }
108a0795c6fSMarcus Overhagen
109a0795c6fSMarcus Overhagen	// changed 13aug99
110a0795c6fSMarcus Overhagen	media_node_id destinationNode() const 					{ return m_destinationNode.node; }
111a0795c6fSMarcus Overhagen	const media_destination& destination() const 		{ return m_destination; }
112a0795c6fSMarcus Overhagen	const char* inputName() const 									{ return m_inputName.String(); }
113a0795c6fSMarcus Overhagen
114a0795c6fSMarcus Overhagen	const media_format& format() const 							{ return m_format; }
115a0795c6fSMarcus Overhagen
116a0795c6fSMarcus Overhagen	uint32 flags() const														{ return m_flags; }
117a0795c6fSMarcus Overhagen
118a0795c6fSMarcus Overhagen	// input/output access [e.moon 14oct99]
119a0795c6fSMarcus Overhagen	status_t getInput(
120a0795c6fSMarcus Overhagen		media_input*							outInput) const;
121a0795c6fSMarcus Overhagen
122a0795c6fSMarcus Overhagen	status_t getOutput(
123a0795c6fSMarcus Overhagen		media_output*							outOutput) const;
124a0795c6fSMarcus Overhagen
125a0795c6fSMarcus Overhagen	// hint access
126a0795c6fSMarcus Overhagen
127a0795c6fSMarcus Overhagen	status_t getOutputHint(
128a0795c6fSMarcus Overhagen		const char**							outName,
129a0795c6fSMarcus Overhagen		media_format*							outFormat) const;
130a0795c6fSMarcus Overhagen
131a0795c6fSMarcus Overhagen	status_t getInputHint(
132a0795c6fSMarcus Overhagen		const char**							outName,
133a0795c6fSMarcus Overhagen		media_format*							outFormat) const;
134a0795c6fSMarcus Overhagen
135a0795c6fSMarcus Overhagen	const media_format& requestedFormat() const { return m_requestedFormat; }
136a0795c6fSMarcus Overhagen
137a0795c6fSMarcus Overhagen
138a0795c6fSMarcus Overhagenprotected:				// *** general ctor accessible to subclasses &
139a0795c6fSMarcus Overhagen									//     cortex::NodeManager
140a0795c6fSMarcus Overhagen
141a0795c6fSMarcus Overhagen	// id must be non-0
142a0795c6fSMarcus Overhagen	Connection(
143a0795c6fSMarcus Overhagen		uint32										id,
144a0795c6fSMarcus Overhagen		media_node								srcNode,
145a0795c6fSMarcus Overhagen		const media_source&				src,
146a0795c6fSMarcus Overhagen		const char*								outputName,
147a0795c6fSMarcus Overhagen		media_node								destNode,
148a0795c6fSMarcus Overhagen		const media_destination&	dest,
149a0795c6fSMarcus Overhagen		const char*								inputName,
150a0795c6fSMarcus Overhagen		const media_format&				format,
151a0795c6fSMarcus Overhagen		uint32										flags);
152a0795c6fSMarcus Overhagen
153a0795c6fSMarcus Overhagen	// if any information about the pre-connection (free) output format
154a0795c6fSMarcus Overhagen	// is known, call this method.  this info may be useful in
155a0795c6fSMarcus Overhagen	// finding the output to re-establish the connection later on.
156a0795c6fSMarcus Overhagen
157a0795c6fSMarcus Overhagen	void setOutputHint(
158a0795c6fSMarcus Overhagen		const char*								origName,
159a0795c6fSMarcus Overhagen		const media_format&				origFormat);
160a0795c6fSMarcus Overhagen
161a0795c6fSMarcus Overhagen	// if any information about the pre-connection (free) input format
162a0795c6fSMarcus Overhagen	// is known, call this method.  this info may be useful in
163a0795c6fSMarcus Overhagen	// finding the output to re-establish the connection later on.
164a0795c6fSMarcus Overhagen
165a0795c6fSMarcus Overhagen	void setInputHint(
166a0795c6fSMarcus Overhagen		const char*								origName,
167a0795c6fSMarcus Overhagen		const media_format&				origFormat);
168a0795c6fSMarcus Overhagen
169a0795c6fSMarcus Overhagen	// [e.moon 8dec99]
170a0795c6fSMarcus Overhagen	void setRequestedFormat(
171a0795c6fSMarcus Overhagen		const media_format&				reqFormat);
172a0795c6fSMarcus Overhagen
173a0795c6fSMarcus Overhagenprivate:					// *** members
174a0795c6fSMarcus Overhagen
175a0795c6fSMarcus Overhagen	// info that may be useful for reconstituting a particular
176a0795c6fSMarcus Overhagen	// connection later on.
177a0795c6fSMarcus Overhagen	struct endpoint_hint {
178a0795c6fSMarcus Overhagen		endpoint_hint(const char* _name, const media_format& _format) :
179a0795c6fSMarcus Overhagen			name(_name), format(_format) {}
180a0795c6fSMarcus Overhagen
181a0795c6fSMarcus Overhagen		BString					name;
182a0795c6fSMarcus Overhagen		media_format		format;
183a0795c6fSMarcus Overhagen	};
184a0795c6fSMarcus Overhagen
185a0795c6fSMarcus Overhagen	// waiting to die?
186a0795c6fSMarcus Overhagen	bool												m_disconnected;
187a0795c6fSMarcus Overhagen
188a0795c6fSMarcus Overhagen	// unique connection ID
189a0795c6fSMarcus Overhagen	uint32											m_id;
190a0795c6fSMarcus Overhagen
191a0795c6fSMarcus Overhagen	// [e.moon 14oct99] now stores media_nodes
192a0795c6fSMarcus Overhagen
193a0795c6fSMarcus Overhagen	// source/output info
194a0795c6fSMarcus Overhagen	media_node									m_sourceNode;
195a0795c6fSMarcus Overhagen	media_source								m_source;
196a0795c6fSMarcus Overhagen	BString											m_outputName;
197a0795c6fSMarcus Overhagen
198a0795c6fSMarcus Overhagen	endpoint_hint*							m_outputHint;
199a0795c6fSMarcus Overhagen
200a0795c6fSMarcus Overhagen	// dest/input info
201a0795c6fSMarcus Overhagen	media_node									m_destinationNode;
202a0795c6fSMarcus Overhagen	media_destination						m_destination;
203a0795c6fSMarcus Overhagen	BString											m_inputName;
204a0795c6fSMarcus Overhagen
205a0795c6fSMarcus Overhagen	endpoint_hint*							m_inputHint;
206a0795c6fSMarcus Overhagen
207a0795c6fSMarcus Overhagen	// connection format
208a0795c6fSMarcus Overhagen	media_format								m_format;
209a0795c6fSMarcus Overhagen
210a0795c6fSMarcus Overhagen	// behaviour modification
211a0795c6fSMarcus Overhagen	uint32											m_flags;
212a0795c6fSMarcus Overhagen
213a0795c6fSMarcus Overhagen	// [e.moon 8dec99] initial requested format
214a0795c6fSMarcus Overhagen	media_format								m_requestedFormat;
215a0795c6fSMarcus Overhagen};
216a0795c6fSMarcus Overhagen
217a0795c6fSMarcus Overhagen__END_CORTEX_NAMESPACE
218a0795c6fSMarcus Overhagen
219a0795c6fSMarcus Overhagen#endif /*__Connection_H__*/
220