xref: /haiku/src/apps/cortex/RouteApp/ConnectionIO.cpp (revision 19ae20e67e91fc09cc9fc5c0e60e21e24e7a53eb)
1*c284bb0fSMatt Madia /*
2*c284bb0fSMatt Madia  * Copyright (c) 1999-2000, Eric Moon.
3*c284bb0fSMatt Madia  * All rights reserved.
4*c284bb0fSMatt Madia  *
5*c284bb0fSMatt Madia  * Redistribution and use in source and binary forms, with or without
6*c284bb0fSMatt Madia  * modification, are permitted provided that the following conditions
7*c284bb0fSMatt Madia  * are met:
8*c284bb0fSMatt Madia  *
9*c284bb0fSMatt Madia  * 1. Redistributions of source code must retain the above copyright
10*c284bb0fSMatt Madia  *    notice, this list of conditions, and the following disclaimer.
11*c284bb0fSMatt Madia  *
12*c284bb0fSMatt Madia  * 2. Redistributions in binary form must reproduce the above copyright
13*c284bb0fSMatt Madia  *    notice, this list of conditions, and the following disclaimer in the
14*c284bb0fSMatt Madia  *    documentation and/or other materials provided with the distribution.
15*c284bb0fSMatt Madia  *
16*c284bb0fSMatt Madia  * 3. The name of the author may not be used to endorse or promote products
17*c284bb0fSMatt Madia  *    derived from this software without specific prior written permission.
18*c284bb0fSMatt Madia  *
19*c284bb0fSMatt Madia  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20*c284bb0fSMatt Madia  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21*c284bb0fSMatt Madia  * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*c284bb0fSMatt Madia  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23*c284bb0fSMatt Madia  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24*c284bb0fSMatt Madia  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25*c284bb0fSMatt Madia  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26*c284bb0fSMatt Madia  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27*c284bb0fSMatt Madia  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28*c284bb0fSMatt Madia  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*c284bb0fSMatt Madia  */
30*c284bb0fSMatt Madia 
31*c284bb0fSMatt Madia 
32a0795c6fSMarcus Overhagen // ConnectionIO.cpp
33a0795c6fSMarcus Overhagen 
34a0795c6fSMarcus Overhagen #include "ConnectionIO.h"
35a0795c6fSMarcus Overhagen #include "LiveNodeIO.h"
36a0795c6fSMarcus Overhagen #include "NodeManager.h"
37a0795c6fSMarcus Overhagen #include "NodeSetIOContext.h"
38a0795c6fSMarcus Overhagen 
39a0795c6fSMarcus Overhagen #include "MediaFormatIO.h"
40a0795c6fSMarcus Overhagen #include "route_app_io.h"
41a0795c6fSMarcus Overhagen 
42a0795c6fSMarcus Overhagen #include <vector>
43a0795c6fSMarcus Overhagen #include <Debug.h>
44a0795c6fSMarcus Overhagen 
4523e67806SIthamar R. Adema using namespace std;
4623e67806SIthamar R. Adema 
47a0795c6fSMarcus Overhagen __USE_CORTEX_NAMESPACE
48a0795c6fSMarcus Overhagen 
49a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
50a0795c6fSMarcus Overhagen // *** ctor/dtor
51a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
52a0795c6fSMarcus Overhagen 
~ConnectionIO()53a0795c6fSMarcus Overhagen ConnectionIO::~ConnectionIO() {
54a0795c6fSMarcus Overhagen 	if(m_inputNodeIO) delete m_inputNodeIO;
55a0795c6fSMarcus Overhagen 	if(m_outputNodeIO) delete m_outputNodeIO;
56a0795c6fSMarcus Overhagen }
57a0795c6fSMarcus Overhagen 
58a0795c6fSMarcus Overhagen // initialize for import
ConnectionIO()59a0795c6fSMarcus Overhagen ConnectionIO::ConnectionIO() :
60a0795c6fSMarcus Overhagen 	m_inputNodeIO(0),
61a0795c6fSMarcus Overhagen 	m_outputNodeIO(0),
62a0795c6fSMarcus Overhagen 	m_flags(0),
63a0795c6fSMarcus Overhagen 	m_exportValid(false),
64a0795c6fSMarcus Overhagen 	m_importState(IMPORT_NONE) {
65a0795c6fSMarcus Overhagen 
66a0795c6fSMarcus Overhagen 	m_outputFormat.type = B_MEDIA_NO_TYPE;
67a0795c6fSMarcus Overhagen 	m_inputFormat.type = B_MEDIA_NO_TYPE;
68a0795c6fSMarcus Overhagen 	m_requestedFormat.type = B_MEDIA_NO_TYPE;
69a0795c6fSMarcus Overhagen }
70a0795c6fSMarcus Overhagen 
71a0795c6fSMarcus Overhagen // initialize for export
ConnectionIO(const Connection * con,const NodeManager * manager,const NodeSetIOContext * context)72a0795c6fSMarcus Overhagen ConnectionIO::ConnectionIO(
73a0795c6fSMarcus Overhagen 	const Connection*				con,
74a0795c6fSMarcus Overhagen 	const NodeManager*			manager,
75a0795c6fSMarcus Overhagen 	const NodeSetIOContext*	context) :
76a0795c6fSMarcus Overhagen 
77a0795c6fSMarcus Overhagen 	m_inputNodeIO(0),
78a0795c6fSMarcus Overhagen 	m_outputNodeIO(0),
79a0795c6fSMarcus Overhagen 	m_exportValid(false),
80a0795c6fSMarcus Overhagen 	m_importState(IMPORT_NONE) {
81a0795c6fSMarcus Overhagen 
82a0795c6fSMarcus Overhagen 	ASSERT(con);
83a0795c6fSMarcus Overhagen 	ASSERT(manager);
84a0795c6fSMarcus Overhagen 	ASSERT(context);
85a0795c6fSMarcus Overhagen 
86a0795c6fSMarcus Overhagen 	if(!con->isValid()) {
87a0795c6fSMarcus Overhagen 		PRINT((
88a0795c6fSMarcus Overhagen 			"!!! ConnectionIO(): invalid connection\n"));
89a0795c6fSMarcus Overhagen 		return;
90a0795c6fSMarcus Overhagen 	}
91a0795c6fSMarcus Overhagen 
92a0795c6fSMarcus Overhagen 	m_outputNodeIO = new LiveNodeIO(
93a0795c6fSMarcus Overhagen 		manager,
94a0795c6fSMarcus Overhagen 		context,
95a0795c6fSMarcus Overhagen 		con->sourceNode());
96a0795c6fSMarcus Overhagen 
97a0795c6fSMarcus Overhagen 	// fetch output (connection-point) description
98a0795c6fSMarcus Overhagen 	const char* name;
99a0795c6fSMarcus Overhagen 	if(con->getOutputHint(
100a0795c6fSMarcus Overhagen 		&name,
101a0795c6fSMarcus Overhagen 		&m_outputFormat) == B_OK)
102a0795c6fSMarcus Overhagen 		m_outputName = name;
103a0795c6fSMarcus Overhagen 	else {
104a0795c6fSMarcus Overhagen 		m_outputName = con->outputName();
105a0795c6fSMarcus Overhagen 	}
106a0795c6fSMarcus Overhagen 
107a0795c6fSMarcus Overhagen 	m_inputNodeIO = new LiveNodeIO(
108a0795c6fSMarcus Overhagen 		manager,
109a0795c6fSMarcus Overhagen 		context,
110a0795c6fSMarcus Overhagen 		con->destinationNode());
111a0795c6fSMarcus Overhagen 
112a0795c6fSMarcus Overhagen 	// fetch input (connection-point) description
113a0795c6fSMarcus Overhagen 	if(con->getInputHint(
114a0795c6fSMarcus Overhagen 		&name,
115a0795c6fSMarcus Overhagen 		&m_inputFormat) == B_OK)
116a0795c6fSMarcus Overhagen 		m_inputName = name;
117a0795c6fSMarcus Overhagen 
118a0795c6fSMarcus Overhagen 	else {
119a0795c6fSMarcus Overhagen 		m_inputName = con->inputName();
120a0795c6fSMarcus Overhagen 	}
121a0795c6fSMarcus Overhagen 
122a0795c6fSMarcus Overhagen 	m_requestedFormat = con->requestedFormat();
123a0795c6fSMarcus Overhagen 	m_flags = con->flags();
124a0795c6fSMarcus Overhagen 
125a0795c6fSMarcus Overhagen 	m_exportValid = true;
126a0795c6fSMarcus Overhagen }
127a0795c6fSMarcus Overhagen 
128a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
129a0795c6fSMarcus Overhagen // *** operations
130a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
131a0795c6fSMarcus Overhagen 
132a0795c6fSMarcus Overhagen // call when object imported to create the described
133a0795c6fSMarcus Overhagen // connection
134a0795c6fSMarcus Overhagen 
135a0795c6fSMarcus Overhagen // +++++ to do
136a0795c6fSMarcus Overhagen // smarter input/output matching -- if no name/format provided,
137a0795c6fSMarcus Overhagen // pick the first available endpoint.  otherwise, make two passes:
138a0795c6fSMarcus Overhagen // 1) match all nodes w/ given name (pass wildcards through to roster)
139a0795c6fSMarcus Overhagen // 2) filter by format
140a0795c6fSMarcus Overhagen 
instantiate(NodeManager * manager,const NodeSetIOContext * context,Connection * outCon)141a0795c6fSMarcus Overhagen status_t ConnectionIO::instantiate(
142a0795c6fSMarcus Overhagen 	NodeManager*						manager,
143a0795c6fSMarcus Overhagen 	const NodeSetIOContext*	context,
144a0795c6fSMarcus Overhagen 	Connection*							outCon) {
145a0795c6fSMarcus Overhagen 
146a0795c6fSMarcus Overhagen 	// sanity checks
147a0795c6fSMarcus Overhagen 	ASSERT(manager);
148a0795c6fSMarcus Overhagen 	if(!m_inputNodeIO || !m_outputNodeIO)
149a0795c6fSMarcus Overhagen 		return B_NOT_ALLOWED;
150a0795c6fSMarcus Overhagen 
151a0795c6fSMarcus Overhagen 	status_t err;
152a0795c6fSMarcus Overhagen 	media_node_id node;
153a0795c6fSMarcus Overhagen 
154a0795c6fSMarcus Overhagen 	// find output node
155a0795c6fSMarcus Overhagen 	NodeRef* outputRef;
156a0795c6fSMarcus Overhagen 	err = m_outputNodeIO->getNode(manager, context, &node);
157a0795c6fSMarcus Overhagen 	if(err < B_OK)
158a0795c6fSMarcus Overhagen 		return err;
159a0795c6fSMarcus Overhagen 	err = manager->getNodeRef(
160a0795c6fSMarcus Overhagen 		node,
161a0795c6fSMarcus Overhagen 		&outputRef);
162a0795c6fSMarcus Overhagen 	if(err < B_OK)
163a0795c6fSMarcus Overhagen 		return err;
164a0795c6fSMarcus Overhagen 
165a0795c6fSMarcus Overhagen 	// find output +++++ currently matches by name only
166a0795c6fSMarcus Overhagen 	const int32 outputBufferSize = 16;
167a0795c6fSMarcus Overhagen 	media_output outputs[outputBufferSize];
168a0795c6fSMarcus Overhagen 	int32 count = outputBufferSize;
169a0795c6fSMarcus Overhagen 
170a0795c6fSMarcus Overhagen 	//vector<media_output> outputs;
171a0795c6fSMarcus Overhagen //	err = outputRef->getFreeOutputs(
172a0795c6fSMarcus Overhagen //		outputs/*,
173a0795c6fSMarcus Overhagen //		m_outputFormat.type*/);
174a0795c6fSMarcus Overhagen 
175a0795c6fSMarcus Overhagen 	err = outputRef->getFreeOutputs(
176a0795c6fSMarcus Overhagen 		outputs,
177a0795c6fSMarcus Overhagen 		outputBufferSize,
178a0795c6fSMarcus Overhagen 		&count);
179a0795c6fSMarcus Overhagen 	if(err < B_OK)
180a0795c6fSMarcus Overhagen 		return err;
181a0795c6fSMarcus Overhagen 
182a0795c6fSMarcus Overhagen 	media_output output;
183a0795c6fSMarcus Overhagen 	bool found = false;
184a0795c6fSMarcus Overhagen 	for(int n = 0; n < count; ++n) {
185a0795c6fSMarcus Overhagen 		if(m_outputName == outputs[n].name) {
186a0795c6fSMarcus Overhagen 			output = outputs[n];
187a0795c6fSMarcus Overhagen 			found = true;
188a0795c6fSMarcus Overhagen 			break;
189a0795c6fSMarcus Overhagen 		}
190a0795c6fSMarcus Overhagen 	}
191a0795c6fSMarcus Overhagen 	if(!found) {
192a0795c6fSMarcus Overhagen 		PRINT(("!!! output '%s' of node '%s' not found\n",
193a0795c6fSMarcus Overhagen 			m_outputName.String(),
194a0795c6fSMarcus Overhagen 			outputRef->name()));
195a0795c6fSMarcus Overhagen 		return B_NAME_NOT_FOUND;
196a0795c6fSMarcus Overhagen 	}
197a0795c6fSMarcus Overhagen 
198a0795c6fSMarcus Overhagen 	// find input node
199a0795c6fSMarcus Overhagen 	NodeRef* inputRef;
200a0795c6fSMarcus Overhagen 	err = m_inputNodeIO->getNode(manager, context, &node);
201a0795c6fSMarcus Overhagen 	if(err < B_OK)
202a0795c6fSMarcus Overhagen 		return err;
203a0795c6fSMarcus Overhagen 	err = manager->getNodeRef(
204a0795c6fSMarcus Overhagen 		node,
205a0795c6fSMarcus Overhagen 		&inputRef);
206a0795c6fSMarcus Overhagen 	if(err < B_OK)
207a0795c6fSMarcus Overhagen 		return err;
208a0795c6fSMarcus Overhagen 
209a0795c6fSMarcus Overhagen 	// find input +++++ currently matches by name only
210a0795c6fSMarcus Overhagen 	vector<media_input> inputs;
211a0795c6fSMarcus Overhagen 	err = inputRef->getFreeInputs(
212a0795c6fSMarcus Overhagen 		inputs /*,
213a0795c6fSMarcus Overhagen 		m_inputFormat.type*/);
214a0795c6fSMarcus Overhagen 	if(err < B_OK)
215a0795c6fSMarcus Overhagen 		return err;
216a0795c6fSMarcus Overhagen 
217a0795c6fSMarcus Overhagen 	media_input input;
218a0795c6fSMarcus Overhagen 	found = false;
219a0795c6fSMarcus Overhagen 	for(unsigned int n = 0; n < inputs.size(); ++n) {
220a0795c6fSMarcus Overhagen 		if(m_inputName == inputs[n].name) {
221a0795c6fSMarcus Overhagen 			input = inputs[n];
222a0795c6fSMarcus Overhagen 			found = true;
223a0795c6fSMarcus Overhagen 			break;
224a0795c6fSMarcus Overhagen 		}
225a0795c6fSMarcus Overhagen 	}
226a0795c6fSMarcus Overhagen 	if(!found) {
227a0795c6fSMarcus Overhagen 		PRINT(("!!! input '%s' of node '%s' not found\n",
228a0795c6fSMarcus Overhagen 			m_inputName.String(),
229a0795c6fSMarcus Overhagen 			inputRef->name()));
230a0795c6fSMarcus Overhagen 		return B_NAME_NOT_FOUND;
231a0795c6fSMarcus Overhagen 	}
232a0795c6fSMarcus Overhagen 
233a0795c6fSMarcus Overhagen 	// connect
234a0795c6fSMarcus Overhagen 	Connection con;
235a0795c6fSMarcus Overhagen 	if(m_requestedFormat.type != B_MEDIA_NO_TYPE)
236a0795c6fSMarcus Overhagen 		err = manager->connect(
237a0795c6fSMarcus Overhagen 			output,
238a0795c6fSMarcus Overhagen 			input,
239a0795c6fSMarcus Overhagen 			m_requestedFormat,
240a0795c6fSMarcus Overhagen 			&con);
241a0795c6fSMarcus Overhagen 	else
242a0795c6fSMarcus Overhagen 		err = manager->connect(
243a0795c6fSMarcus Overhagen 			output,
244a0795c6fSMarcus Overhagen 			input,
245a0795c6fSMarcus Overhagen 			&con);
246a0795c6fSMarcus Overhagen 
247a0795c6fSMarcus Overhagen 	if(err < B_OK)
248a0795c6fSMarcus Overhagen 		return err;
249a0795c6fSMarcus Overhagen 
250a0795c6fSMarcus Overhagen 	if(outCon)
251a0795c6fSMarcus Overhagen 		*outCon = con;
252a0795c6fSMarcus Overhagen 	return B_OK;
253a0795c6fSMarcus Overhagen }
254a0795c6fSMarcus Overhagen 
255a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
256a0795c6fSMarcus Overhagen // *** document-type setup
257a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
258a0795c6fSMarcus Overhagen 
259a0795c6fSMarcus Overhagen /*static*/
AddTo(XML::DocumentType * docType)260a0795c6fSMarcus Overhagen void ConnectionIO::AddTo(
261a0795c6fSMarcus Overhagen 	XML::DocumentType*			docType) {
262a0795c6fSMarcus Overhagen 
263a0795c6fSMarcus Overhagen 	// map self
264a0795c6fSMarcus Overhagen 	docType->addMapping(new Mapping<ConnectionIO>(_CONNECTION_ELEMENT));
265a0795c6fSMarcus Overhagen 
266a0795c6fSMarcus Overhagen 	// map simple (content-only) elements
267a0795c6fSMarcus Overhagen 	// +++++ should these be added at a higher level, since they're
268a0795c6fSMarcus Overhagen 	//       shared?  no harm is done if one is added more than once,
269a0795c6fSMarcus Overhagen 	//       since they'll always map to StringContent -- but it's way
270a0795c6fSMarcus Overhagen 	//       messy!
271a0795c6fSMarcus Overhagen 	// +++++
272a0795c6fSMarcus Overhagen 	//docType->addMapping(new Mapping<StringContent>(_LIVE_NODE_ELEMENT));
273a0795c6fSMarcus Overhagen //	docType->addMapping(new Mapping<StringContent>(_NAME_ELEMENT));
274a0795c6fSMarcus Overhagen //	docType->addMapping(new Mapping<StringContent>(_KIND_ELEMENT));
275a0795c6fSMarcus Overhagen //	docType->addMapping(new Mapping<StringContent>(_FLAG_ELEMENT));
276a0795c6fSMarcus Overhagen }
277a0795c6fSMarcus Overhagen 
278a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
279a0795c6fSMarcus Overhagen // *** IPersistent
280a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
281a0795c6fSMarcus Overhagen 
282a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
283a0795c6fSMarcus Overhagen // EXPORT:
284a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
285a0795c6fSMarcus Overhagen 
286a0795c6fSMarcus Overhagen 
287a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
xmlExportBegin(ExportContext & context) const288a0795c6fSMarcus Overhagen void ConnectionIO::xmlExportBegin(
289a0795c6fSMarcus Overhagen 	ExportContext&						context) const {
290a0795c6fSMarcus Overhagen 
291a0795c6fSMarcus Overhagen 	if(!m_exportValid) {
292a0795c6fSMarcus Overhagen 		context.reportError(
293a0795c6fSMarcus Overhagen 			"ConnectionIO::xmlExportBegin():\n"
294a0795c6fSMarcus Overhagen 			"*** invalid ***\n");
295a0795c6fSMarcus Overhagen 		return;
296a0795c6fSMarcus Overhagen 	}
297a0795c6fSMarcus Overhagen 
298a0795c6fSMarcus Overhagen 	context.beginElement(_CONNECTION_ELEMENT);
299a0795c6fSMarcus Overhagen }
300a0795c6fSMarcus Overhagen 
xmlExportAttributes(ExportContext & context) const301a0795c6fSMarcus Overhagen void ConnectionIO::xmlExportAttributes(
302a0795c6fSMarcus Overhagen 	ExportContext&						context) const { TOUCH(context); }
303a0795c6fSMarcus Overhagen 
xmlExportContent(ExportContext & context) const304a0795c6fSMarcus Overhagen void ConnectionIO::xmlExportContent(
305a0795c6fSMarcus Overhagen 	ExportContext&						context) const {
306a0795c6fSMarcus Overhagen 
307a0795c6fSMarcus Overhagen 	context.beginContent();
308a0795c6fSMarcus Overhagen 
309a0795c6fSMarcus Overhagen 	// write output
310a0795c6fSMarcus Overhagen 	{
311a0795c6fSMarcus Overhagen 		context.beginElement(_OUTPUT_ELEMENT);
312a0795c6fSMarcus Overhagen 		context.beginContent();
313a0795c6fSMarcus Overhagen 
314a0795c6fSMarcus Overhagen 		// describe the node
315a0795c6fSMarcus Overhagen //		LiveNodeIO nodeIO(
316a0795c6fSMarcus Overhagen //			m_manager,
317a0795c6fSMarcus Overhagen //			dynamic_cast<NodeSetIOContext*>(&context),
318a0795c6fSMarcus Overhagen //			m_outputNode);
319a0795c6fSMarcus Overhagen 		context.writeObject(m_outputNodeIO);
320a0795c6fSMarcus Overhagen 
321a0795c6fSMarcus Overhagen //		context.beginElement(_LIVE_NODE_ELEMENT);
322a0795c6fSMarcus Overhagen //		if(m_outputNodeKey.Length()) {
323a0795c6fSMarcus Overhagen //			context.writeAttr("key", m_outputNodeKey);
324a0795c6fSMarcus Overhagen //		}
325a0795c6fSMarcus Overhagen //		else {
326a0795c6fSMarcus Overhagen //			_write_simple("name", m_outputNodeName.String(), context);
327a0795c6fSMarcus Overhagen //			_write_node_kinds(m_outputNodeKind, context);
328a0795c6fSMarcus Overhagen //		}
329a0795c6fSMarcus Overhagen //		context.endElement(); // _LIVE_NODE_ELEMENT
330a0795c6fSMarcus Overhagen 
331a0795c6fSMarcus Overhagen 		// describe the output
332a0795c6fSMarcus Overhagen 
333a0795c6fSMarcus Overhagen 		_write_simple("name", m_outputName.String(), context);
334a0795c6fSMarcus Overhagen 
335a0795c6fSMarcus Overhagen 		if(m_outputFormat.type > B_MEDIA_UNKNOWN_TYPE) {
336a0795c6fSMarcus Overhagen 			MediaFormatIO io(m_outputFormat);
337a0795c6fSMarcus Overhagen 			context.writeObject(&io);
338a0795c6fSMarcus Overhagen 		}
339a0795c6fSMarcus Overhagen 
340a0795c6fSMarcus Overhagen 		context.endElement(); // _OUTPUT_ELEMENT
341a0795c6fSMarcus Overhagen 	}
342a0795c6fSMarcus Overhagen 
343a0795c6fSMarcus Overhagen 	// write input
344a0795c6fSMarcus Overhagen 	{
345a0795c6fSMarcus Overhagen 		context.beginElement(_INPUT_ELEMENT);
346a0795c6fSMarcus Overhagen 		context.beginContent();
347a0795c6fSMarcus Overhagen 
348a0795c6fSMarcus Overhagen 		// describe the node
349a0795c6fSMarcus Overhagen //		LiveNodeIO nodeIO(
350a0795c6fSMarcus Overhagen //			m_manager,
351a0795c6fSMarcus Overhagen //			dynamic_cast<NodeSetIOContext*>(&context),
352a0795c6fSMarcus Overhagen //			m_inputNode);
353a0795c6fSMarcus Overhagen 		context.writeObject(m_inputNodeIO);
354a0795c6fSMarcus Overhagen 
355a0795c6fSMarcus Overhagen //		context.beginElement(_LIVE_NODE_ELEMENT);
356a0795c6fSMarcus Overhagen //		if(m_inputNodeKey.Length()) {
357a0795c6fSMarcus Overhagen //			context.writeAttr("key", m_inputNodeKey);
358a0795c6fSMarcus Overhagen //		}
359a0795c6fSMarcus Overhagen //		else {
360a0795c6fSMarcus Overhagen //			_write_simple("name", m_inputNodeName.String(), context);
361a0795c6fSMarcus Overhagen //			_write_node_kinds(m_inputNodeKind, context);
362a0795c6fSMarcus Overhagen //		}
363a0795c6fSMarcus Overhagen //		context.endElement(); // _LIVE_NODE_ELEMENT
364a0795c6fSMarcus Overhagen 
365a0795c6fSMarcus Overhagen 		// describe the input
366a0795c6fSMarcus Overhagen 
367a0795c6fSMarcus Overhagen 		_write_simple("name", m_inputName.String(), context);
368a0795c6fSMarcus Overhagen 
369a0795c6fSMarcus Overhagen 		if(m_inputFormat.type > B_MEDIA_UNKNOWN_TYPE) {
370a0795c6fSMarcus Overhagen 			MediaFormatIO io(m_inputFormat);
371a0795c6fSMarcus Overhagen 			context.writeObject(&io);
372a0795c6fSMarcus Overhagen 		}
373a0795c6fSMarcus Overhagen 
374a0795c6fSMarcus Overhagen 		context.endElement(); // _INPUT_ELEMENT
375a0795c6fSMarcus Overhagen 	}
376a0795c6fSMarcus Overhagen 
377a0795c6fSMarcus Overhagen 	// write requested format
378a0795c6fSMarcus Overhagen 	if(m_requestedFormat.type > B_MEDIA_UNKNOWN_TYPE) {
379a0795c6fSMarcus Overhagen 		MediaFormatIO io(m_requestedFormat);
380a0795c6fSMarcus Overhagen 		BString comment = "\n";
381a0795c6fSMarcus Overhagen 		comment << context.indentString();
382a0795c6fSMarcus Overhagen 		comment << "<!-- initial requested format -->";
383a0795c6fSMarcus Overhagen 		context.writeString(comment);
384a0795c6fSMarcus Overhagen 		context.writeObject(&io);
385a0795c6fSMarcus Overhagen 	}
386a0795c6fSMarcus Overhagen }
387a0795c6fSMarcus Overhagen 
xmlExportEnd(ExportContext & context) const388a0795c6fSMarcus Overhagen void ConnectionIO::xmlExportEnd(
389a0795c6fSMarcus Overhagen 	ExportContext&						context) const {
390a0795c6fSMarcus Overhagen 
391a0795c6fSMarcus Overhagen 	context.endElement(); // _CONNECTION_ELEMENT
392a0795c6fSMarcus Overhagen }
393a0795c6fSMarcus Overhagen 
394a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
395a0795c6fSMarcus Overhagen // IMPORT:
396a0795c6fSMarcus Overhagen // -------------------------------------------------------- //
397a0795c6fSMarcus Overhagen 
xmlImportBegin(ImportContext & context)398a0795c6fSMarcus Overhagen void ConnectionIO::xmlImportBegin(
399a0795c6fSMarcus Overhagen 	ImportContext&						context) { TOUCH(context); }
400a0795c6fSMarcus Overhagen 
xmlImportAttribute(const char * key,const char * value,ImportContext & context)401a0795c6fSMarcus Overhagen void ConnectionIO::xmlImportAttribute(
402a0795c6fSMarcus Overhagen 	const char*								key,
403a0795c6fSMarcus Overhagen 	const char*								value,
404a0795c6fSMarcus Overhagen 	ImportContext&						context) { TOUCH(key); TOUCH(value); TOUCH(context); }
405a0795c6fSMarcus Overhagen 
xmlImportContent(const char * data,uint32 length,ImportContext & context)406a0795c6fSMarcus Overhagen void ConnectionIO::xmlImportContent(
407a0795c6fSMarcus Overhagen 	const char*								data,
408a0795c6fSMarcus Overhagen 	uint32										length,
409a0795c6fSMarcus Overhagen 	ImportContext&						context) { TOUCH(data); TOUCH(length); TOUCH(context); }
410a0795c6fSMarcus Overhagen 
xmlImportChild(IPersistent * child,ImportContext & context)411a0795c6fSMarcus Overhagen void ConnectionIO::xmlImportChild(
412a0795c6fSMarcus Overhagen 	IPersistent*							child,
413a0795c6fSMarcus Overhagen 	ImportContext&						context) {
414a0795c6fSMarcus Overhagen 
415a0795c6fSMarcus Overhagen 	status_t err;
416a0795c6fSMarcus Overhagen 
417a0795c6fSMarcus Overhagen 	if(!strcmp(context.element(), _LIVE_NODE_ELEMENT)) {
418a0795c6fSMarcus Overhagen 		LiveNodeIO* nodeIO = dynamic_cast<LiveNodeIO*>(child);
419a0795c6fSMarcus Overhagen 		ASSERT(nodeIO);
420a0795c6fSMarcus Overhagen 
421a0795c6fSMarcus Overhagen 		// store the LiveNodeIO for now; it will be used in
422a0795c6fSMarcus Overhagen 		// instantiate()
423a0795c6fSMarcus Overhagen 
424a0795c6fSMarcus Overhagen 		switch(m_importState) {
425a0795c6fSMarcus Overhagen 			case IMPORT_OUTPUT:
426a0795c6fSMarcus Overhagen 				m_outputNodeIO = nodeIO;
427a0795c6fSMarcus Overhagen 				child = 0; // don't delete child object
428a0795c6fSMarcus Overhagen 				break;
429a0795c6fSMarcus Overhagen 
430a0795c6fSMarcus Overhagen 			case IMPORT_INPUT:
431a0795c6fSMarcus Overhagen 				m_inputNodeIO = nodeIO;
432a0795c6fSMarcus Overhagen 				child = 0; // don't delete child object
433a0795c6fSMarcus Overhagen 				break;
434a0795c6fSMarcus Overhagen 
435a0795c6fSMarcus Overhagen 			case IMPORT_NONE:
436a0795c6fSMarcus Overhagen 				context.reportError("Unexpected node description.\n");
437a0795c6fSMarcus Overhagen 				delete child;
438a0795c6fSMarcus Overhagen 				return;
439a0795c6fSMarcus Overhagen 		}
440a0795c6fSMarcus Overhagen 	}
441a0795c6fSMarcus Overhagen 	else if(!strcmp(context.element(), _NAME_ELEMENT)) {
442a0795c6fSMarcus Overhagen 		StringContent* c = dynamic_cast<StringContent*>(child);
443a0795c6fSMarcus Overhagen 		ASSERT(c);
444a0795c6fSMarcus Overhagen 
445a0795c6fSMarcus Overhagen 		switch(m_importState) {
446a0795c6fSMarcus Overhagen 			case IMPORT_OUTPUT:
447a0795c6fSMarcus Overhagen 				m_outputName = c->content;
448a0795c6fSMarcus Overhagen 				break;
449a0795c6fSMarcus Overhagen 
450a0795c6fSMarcus Overhagen 			case IMPORT_INPUT:
451a0795c6fSMarcus Overhagen 				m_inputName = c->content;
452a0795c6fSMarcus Overhagen 				break;
453a0795c6fSMarcus Overhagen 
454a0795c6fSMarcus Overhagen 			case IMPORT_NONE:
455a0795c6fSMarcus Overhagen 				context.reportError("Unexpected node name.\n");
456a0795c6fSMarcus Overhagen 				delete child;
457a0795c6fSMarcus Overhagen 				return;
458a0795c6fSMarcus Overhagen 		}
459a0795c6fSMarcus Overhagen 	}
460a0795c6fSMarcus Overhagen 	else {
461a0795c6fSMarcus Overhagen 		MediaFormatIO* io = dynamic_cast<MediaFormatIO*>(child);
462a0795c6fSMarcus Overhagen 		if(!io) {
463a0795c6fSMarcus Overhagen 			context.reportError("Unexpected element.\n");
464a0795c6fSMarcus Overhagen 			delete child;
465a0795c6fSMarcus Overhagen 			return;
466a0795c6fSMarcus Overhagen 		}
467a0795c6fSMarcus Overhagen 
468a0795c6fSMarcus Overhagen 		media_format f;
469a0795c6fSMarcus Overhagen 		err = io->getFormat(f);
470a0795c6fSMarcus Overhagen 		if(err < B_OK) {
471a0795c6fSMarcus Overhagen 			context.reportError("Malformed format.\n");
472a0795c6fSMarcus Overhagen 			delete child;
473a0795c6fSMarcus Overhagen 			return;
474a0795c6fSMarcus Overhagen 		}
475a0795c6fSMarcus Overhagen 
476a0795c6fSMarcus Overhagen 		switch(m_importState) {
477a0795c6fSMarcus Overhagen 			case IMPORT_OUTPUT:
478a0795c6fSMarcus Overhagen 				m_outputFormat = f;
479a0795c6fSMarcus Overhagen 				break;
480a0795c6fSMarcus Overhagen 
481a0795c6fSMarcus Overhagen 			case IMPORT_INPUT:
482a0795c6fSMarcus Overhagen 				m_inputFormat = f;
483a0795c6fSMarcus Overhagen 				break;
484a0795c6fSMarcus Overhagen 
485a0795c6fSMarcus Overhagen 			case IMPORT_NONE:
486a0795c6fSMarcus Overhagen 				m_requestedFormat = f;
487a0795c6fSMarcus Overhagen 				break;
488a0795c6fSMarcus Overhagen 		}
489a0795c6fSMarcus Overhagen 	}
490a0795c6fSMarcus Overhagen 
491a0795c6fSMarcus Overhagen 	if(child)
492a0795c6fSMarcus Overhagen 		delete child;
493a0795c6fSMarcus Overhagen }
494a0795c6fSMarcus Overhagen 
xmlImportComplete(ImportContext & context)495a0795c6fSMarcus Overhagen void ConnectionIO::xmlImportComplete(
496a0795c6fSMarcus Overhagen 	ImportContext&						context) {
497a0795c6fSMarcus Overhagen 
498a0795c6fSMarcus Overhagen 	// +++++
499a0795c6fSMarcus Overhagen }
500a0795c6fSMarcus Overhagen 
xmlImportChildBegin(const char * name,ImportContext & context)501a0795c6fSMarcus Overhagen void ConnectionIO::xmlImportChildBegin(
502a0795c6fSMarcus Overhagen 	const char*								name,
503a0795c6fSMarcus Overhagen 	ImportContext&						context) {
504a0795c6fSMarcus Overhagen 
505a0795c6fSMarcus Overhagen 	if(!strcmp(name, "input")) {
506a0795c6fSMarcus Overhagen 		if(m_importState != IMPORT_NONE) {
507a0795c6fSMarcus Overhagen 			context.reportError("ConnectionIO: unexpected nested child element\n");
508a0795c6fSMarcus Overhagen 			return;
509a0795c6fSMarcus Overhagen 		}
510a0795c6fSMarcus Overhagen 		m_importState = IMPORT_INPUT;
511a0795c6fSMarcus Overhagen 	}
512a0795c6fSMarcus Overhagen 	else if(!strcmp(name, "output")) {
513a0795c6fSMarcus Overhagen 		if(m_importState != IMPORT_NONE) {
514a0795c6fSMarcus Overhagen 			context.reportError("ConnectionIO: unexpected nested child element\n");
515a0795c6fSMarcus Overhagen 			return;
516a0795c6fSMarcus Overhagen 		}
517a0795c6fSMarcus Overhagen 		m_importState = IMPORT_OUTPUT;
518a0795c6fSMarcus Overhagen 	}
519a0795c6fSMarcus Overhagen 	else
520a0795c6fSMarcus Overhagen 		context.reportError("ConnectionIO: unexpected child element\n");
521a0795c6fSMarcus Overhagen }
522a0795c6fSMarcus Overhagen 
xmlImportChildComplete(const char * name,ImportContext & context)523a0795c6fSMarcus Overhagen void ConnectionIO::xmlImportChildComplete(
524a0795c6fSMarcus Overhagen 	const char*								name,
525a0795c6fSMarcus Overhagen 	ImportContext&						context) {
526a0795c6fSMarcus Overhagen 	TOUCH(name); TOUCH(context);
527a0795c6fSMarcus Overhagen 
528a0795c6fSMarcus Overhagen 	m_importState = IMPORT_NONE;
529a0795c6fSMarcus Overhagen }
530a0795c6fSMarcus Overhagen 
531a0795c6fSMarcus Overhagen // END -- ConnectionIO.cpp --
532