1/*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions, and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions, and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * 3. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32// Connection.cpp
33// e.moon 25jun99
34
35#include "Connection.h"
36#include "NodeManager.h"
37#include "NodeRef.h"
38
39#if CORTEX_XML
40	#include "ExportContext.h"
41	#include "MediaFormatIO.h"
42	#include "xml_export_utils.h"
43#endif /*CORTEX_XML*/
44
45#include <Debug.h>
46
47// -------------------------------------------------------- //
48
49__USE_CORTEX_NAMESPACE
50
51// -------------------------------------------------------- //
52// ctor/dtor
53// -------------------------------------------------------- //
54
55Connection::~Connection() {
56
57//	PRINT(("~Connection(): '%s'->'%s'\n",
58//		outputName(), inputName()));
59//
60	// deallocate hints
61	if(m_outputHint) delete m_outputHint;
62	if(m_inputHint) delete m_inputHint;
63}
64
65Connection::Connection() :
66	m_disconnected(true),
67	m_id(0),
68	m_outputHint(0),
69	m_inputHint(0) {}
70
71Connection::Connection(
72	uint32										id,
73	media_node								srcNode,
74	const media_source&				src,
75	const char*								outputName,
76	media_node								destNode,
77	const media_destination&	dest,
78	const char*								inputName,
79	const media_format&				format,
80	uint32										flags) :
81
82	m_disconnected(false),
83	m_id(id),
84	m_sourceNode(srcNode),
85	m_source(src),
86	m_outputName(outputName),
87	m_outputHint(0),
88	m_destinationNode(destNode),
89	m_destination(dest),
90	m_inputName(inputName),
91	m_inputHint(0),
92	m_format(format),
93	m_flags(flags) {
94
95	ASSERT(id);
96	m_requestedFormat.type = B_MEDIA_NO_TYPE;
97}
98
99Connection::Connection(
100	const Connection&					clone) {
101	operator=(clone);
102}
103
104Connection& Connection::operator=(
105	const Connection&					clone) {
106
107	m_disconnected = clone.m_disconnected;
108	m_id = clone.m_id;
109	m_sourceNode = clone.m_sourceNode;
110	m_source = clone.m_source;
111	m_outputName = clone.m_outputName;
112	m_outputHint = (clone.m_outputHint ?
113		new endpoint_hint(
114			clone.m_outputHint->name.String(),
115			clone.m_outputHint->format) :
116		0);
117	m_destinationNode = clone.m_destinationNode;
118	m_destination = clone.m_destination;
119	m_inputName = clone.m_inputName;
120	m_inputHint = (clone.m_inputHint ?
121		new endpoint_hint(
122			clone.m_inputHint->name.String(),
123			clone.m_inputHint->format) :
124		0);
125	m_format = clone.m_format;
126	m_flags = clone.m_flags;
127	m_requestedFormat = clone.m_requestedFormat;
128
129	return *this;
130}
131
132// input/output access [e.moon 14oct99]
133
134status_t Connection::getInput(
135	media_input*							outInput) const {
136
137	if(!isValid())
138		return B_ERROR;
139
140	outInput->node = m_destinationNode;
141	strcpy(outInput->name, m_inputName.String());
142	outInput->format = format();
143	outInput->source = m_source;
144	outInput->destination = m_destination;
145	return B_OK;
146}
147
148
149status_t Connection::getOutput(
150	media_output*							outOutput) const {
151
152	if(!isValid())
153		return B_ERROR;
154
155	outOutput->node = m_sourceNode;
156	strcpy(outOutput->name, m_outputName.String());
157	outOutput->format = format();
158	outOutput->source = m_source;
159	outOutput->destination = m_destination;
160	return B_OK;
161}
162
163// hint access
164
165status_t Connection::getOutputHint(
166	const char**							outName,
167	media_format*							outFormat) const {
168
169	if(!m_outputHint)
170		return B_NOT_ALLOWED;
171	*outName = m_outputHint->name.String();
172	*outFormat = m_outputHint->format;
173	return B_OK;
174}
175
176status_t Connection::getInputHint(
177	const char**							outName,
178	media_format*							outFormat) const {
179
180	if(!m_inputHint)
181		return B_NOT_ALLOWED;
182	*outName = m_inputHint->name.String();
183	*outFormat = m_inputHint->format;
184	return B_OK;
185}
186
187
188void Connection::setOutputHint(
189	const char*									origName,
190	const media_format&				origFormat) {
191
192	if(m_outputHint) delete m_outputHint;
193	m_outputHint = new endpoint_hint(origName, origFormat);
194}
195
196void Connection::setInputHint(
197	const char*									origName,
198	const media_format&				origFormat) {
199
200	if(m_inputHint) delete m_inputHint;
201	m_inputHint = new endpoint_hint(origName, origFormat);
202}
203
204// [e.moon 8dec99]
205void Connection::setRequestedFormat(
206	const media_format&				reqFormat) {
207	m_requestedFormat = reqFormat;
208}
209
210// END -- Connection.cpp --
211