xref: /haiku/src/apps/cortex/NodeManager/Connection.cpp (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 // Connection.cpp
2 // e.moon 25jun99
3 
4 #include "Connection.h"
5 #include "NodeManager.h"
6 #include "NodeRef.h"
7 
8 #if CORTEX_XML
9 	#include "ExportContext.h"
10 	#include "MediaFormatIO.h"
11 	#include "xml_export_utils.h"
12 #endif /*CORTEX_XML*/
13 
14 #include <Debug.h>
15 
16 // -------------------------------------------------------- //
17 
18 __USE_CORTEX_NAMESPACE
19 
20 // -------------------------------------------------------- //
21 // ctor/dtor
22 // -------------------------------------------------------- //
23 
24 Connection::~Connection() {
25 
26 //	PRINT(("~Connection(): '%s'->'%s'\n",
27 //		outputName(), inputName()));
28 //
29 	// deallocate hints
30 	if(m_outputHint) delete m_outputHint;
31 	if(m_inputHint) delete m_inputHint;
32 }
33 
34 Connection::Connection() :
35 	m_disconnected(true),
36 	m_id(0),
37 	m_outputHint(0),
38 	m_inputHint(0) {}
39 
40 Connection::Connection(
41 	uint32										id,
42 	media_node								srcNode,
43 	const media_source&				src,
44 	const char*								outputName,
45 	media_node								destNode,
46 	const media_destination&	dest,
47 	const char*								inputName,
48 	const media_format&				format,
49 	uint32										flags) :
50 
51 	m_disconnected(false),
52 	m_id(id),
53 	m_sourceNode(srcNode),
54 	m_source(src),
55 	m_outputName(outputName),
56 	m_outputHint(0),
57 	m_destinationNode(destNode),
58 	m_destination(dest),
59 	m_inputName(inputName),
60 	m_inputHint(0),
61 	m_format(format),
62 	m_flags(flags) {
63 
64 	ASSERT(id);
65 	m_requestedFormat.type = B_MEDIA_NO_TYPE;
66 }
67 
68 Connection::Connection(
69 	const Connection&					clone) {
70 	operator=(clone);
71 }
72 
73 Connection& Connection::operator=(
74 	const Connection&					clone) {
75 
76 	m_disconnected = clone.m_disconnected;
77 	m_id = clone.m_id;
78 	m_sourceNode = clone.m_sourceNode;
79 	m_source = clone.m_source;
80 	m_outputName = clone.m_outputName;
81 	m_outputHint = (clone.m_outputHint ?
82 		new endpoint_hint(
83 			clone.m_outputHint->name.String(),
84 			clone.m_outputHint->format) :
85 		0);
86 	m_destinationNode = clone.m_destinationNode;
87 	m_destination = clone.m_destination;
88 	m_inputName = clone.m_inputName;
89 	m_inputHint = (clone.m_inputHint ?
90 		new endpoint_hint(
91 			clone.m_inputHint->name.String(),
92 			clone.m_inputHint->format) :
93 		0);
94 	m_format = clone.m_format;
95 	m_flags = clone.m_flags;
96 	m_requestedFormat = clone.m_requestedFormat;
97 
98 	return *this;
99 }
100 
101 // input/output access [e.moon 14oct99]
102 
103 status_t Connection::getInput(
104 	media_input*							outInput) const {
105 
106 	if(!isValid())
107 		return B_ERROR;
108 
109 	outInput->node = m_destinationNode;
110 	strcpy(outInput->name, m_inputName.String());
111 	outInput->format = format();
112 	outInput->source = m_source;
113 	outInput->destination = m_destination;
114 	return B_OK;
115 }
116 
117 
118 status_t Connection::getOutput(
119 	media_output*							outOutput) const {
120 
121 	if(!isValid())
122 		return B_ERROR;
123 
124 	outOutput->node = m_sourceNode;
125 	strcpy(outOutput->name, m_outputName.String());
126 	outOutput->format = format();
127 	outOutput->source = m_source;
128 	outOutput->destination = m_destination;
129 	return B_OK;
130 }
131 
132 // hint access
133 
134 status_t Connection::getOutputHint(
135 	const char**							outName,
136 	media_format*							outFormat) const {
137 
138 	if(!m_outputHint)
139 		return B_NOT_ALLOWED;
140 	*outName = m_outputHint->name.String();
141 	*outFormat = m_outputHint->format;
142 	return B_OK;
143 }
144 
145 status_t Connection::getInputHint(
146 	const char**							outName,
147 	media_format*							outFormat) const {
148 
149 	if(!m_inputHint)
150 		return B_NOT_ALLOWED;
151 	*outName = m_inputHint->name.String();
152 	*outFormat = m_inputHint->format;
153 	return B_OK;
154 }
155 
156 
157 void Connection::setOutputHint(
158 	const char*									origName,
159 	const media_format&				origFormat) {
160 
161 	if(m_outputHint) delete m_outputHint;
162 	m_outputHint = new endpoint_hint(origName, origFormat);
163 }
164 
165 void Connection::setInputHint(
166 	const char*									origName,
167 	const media_format&				origFormat) {
168 
169 	if(m_inputHint) delete m_inputHint;
170 	m_inputHint = new endpoint_hint(origName, origFormat);
171 }
172 
173 // [e.moon 8dec99]
174 void Connection::setRequestedFormat(
175 	const media_format&				reqFormat) {
176 	m_requestedFormat = reqFormat;
177 }
178 
179 // END -- Connection.cpp --
180