2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
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.
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.
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.
34 #include "LiveNodeIO.h"
35 #include "ImportContext.h"
36 #include "ExportContext.h"
37 #include "NodeSetIOContext.h"
38 #include "StringContent.h"
40 #include "NodeManager.h"
43 #include <MediaAddOn.h>
44 #include <MediaDefs.h>
45 #include <MediaRoster.h>
48 #include "route_app_io.h"
50 __USE_CORTEX_NAMESPACE
52 // -------------------------------------------------------- //
54 // -------------------------------------------------------- //
56 LiveNodeIO::~LiveNodeIO() {}
58 LiveNodeIO::LiveNodeIO() :
60 m_exportValid(false) {}
62 LiveNodeIO::LiveNodeIO(
63 const NodeManager
* manager
,
64 const NodeSetIOContext
* context
,
66 m_exportValid(false) {
72 err
= _get_node_signature(
85 // -------------------------------------------------------- //
86 // *** import operations
87 // -------------------------------------------------------- //
89 // locate the referenced live node
90 status_t
LiveNodeIO::getNode(
91 const NodeManager
* manager
,
92 const NodeSetIOContext
* context
,
93 media_node_id
* outNode
) const {
100 // match key against previously imported nodes
101 err
= context
->getNodeFor(key(), outNode
);
104 // match key against system nodes
105 err
= _match_system_node_key(key(), manager
, outNode
);
109 "!!! No node found for key '%s'\n",
111 return B_NAME_NOT_FOUND
;
116 err
= _match_node_signature(
122 "!!! No node found named '%s' with kinds %" B_PRId64
"\n",
125 return B_NAME_NOT_FOUND
;
132 // -------------------------------------------------------- //
133 // *** document-type setup
134 // -------------------------------------------------------- //
137 void LiveNodeIO::AddTo(
138 XML::DocumentType
* docType
) {
141 docType
->addMapping(new Mapping
<LiveNodeIO
>(_LIVE_NODE_ELEMENT
));
144 // -------------------------------------------------------- //
146 // -------------------------------------------------------- //
148 // -------------------------------------------------------- //
150 // -------------------------------------------------------- //
152 void LiveNodeIO::xmlExportBegin(
153 ExportContext
& context
) const {
157 "LiveNodeIO::xmlExportBegin():\n"
158 "*** invalid ***\n");
162 context
.beginElement(_LIVE_NODE_ELEMENT
);
165 void LiveNodeIO::xmlExportAttributes(
166 ExportContext
& context
) const {
168 if(m_key
.Length() > 0)
169 context
.writeAttr("key", m_key
.String());
172 void LiveNodeIO::xmlExportContent(
173 ExportContext
& context
) const {
175 if(m_name
.Length() > 0) {
176 context
.beginContent();
178 _write_simple(_NAME_ELEMENT
, m_name
.String(), context
);
179 _write_node_kinds(m_kind
, context
);
183 void LiveNodeIO::xmlExportEnd(
184 ExportContext
& context
) const {
186 context
.endElement();
189 // -------------------------------------------------------- //
191 // -------------------------------------------------------- //
193 void LiveNodeIO::xmlImportBegin(
194 ImportContext
& context
) {}
196 void LiveNodeIO::xmlImportAttribute(
199 ImportContext
& context
) {
201 if(!strcmp(key
, "key")) {
206 err
<< "LiveNodeIO: unknown attribute '" << key
<< "'\n";
207 context
.reportError(err
.String());
211 void LiveNodeIO::xmlImportContent(
214 ImportContext
& context
) {}
216 void LiveNodeIO::xmlImportChild(
218 ImportContext
& context
) {
220 StringContent
* obj
= dynamic_cast<StringContent
*>(child
);
223 err
<< "LiveNodeIO: unexpected element '" <<
224 context
.element() << "'\n";
225 context
.reportError(err
.String());
229 if(!strcmp(context
.element(), _NAME_ELEMENT
))
230 m_name
= obj
->content
;
231 else if(!strcmp(context
.element(), _KIND_ELEMENT
))
232 _read_node_kind(m_kind
, obj
->content
.String(), context
);
235 err
<< "LiveNodeIO: unexpected element '" <<
236 context
.element() << "'\n";
237 context
.reportError(err
.String());
243 void LiveNodeIO::xmlImportComplete(
244 ImportContext
& context
) {}
246 // END -- LiveNodeIO.cpp --