BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / cortex / RouteApp / LiveNodeIO.cpp
blobe01757c05a1ec3a9bce980f6d16f3da50575efb6
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
32 // LiveNodeIO.cpp
34 #include "LiveNodeIO.h"
35 #include "ImportContext.h"
36 #include "ExportContext.h"
37 #include "NodeSetIOContext.h"
38 #include "StringContent.h"
40 #include "NodeManager.h"
42 #include <Debug.h>
43 #include <MediaAddOn.h>
44 #include <MediaDefs.h>
45 #include <MediaRoster.h>
46 #include <Path.h>
48 #include "route_app_io.h"
50 __USE_CORTEX_NAMESPACE
52 // -------------------------------------------------------- //
53 // *** ctor/dtor
54 // -------------------------------------------------------- //
56 LiveNodeIO::~LiveNodeIO() {}
58 LiveNodeIO::LiveNodeIO() :
59 m_kind(0LL),
60 m_exportValid(false) {}
62 LiveNodeIO::LiveNodeIO(
63 const NodeManager* manager,
64 const NodeSetIOContext* context,
65 media_node_id node) :
66 m_exportValid(false) {
68 status_t err;
69 ASSERT(manager);
70 ASSERT(context);
72 err = _get_node_signature(
73 manager,
74 context,
75 node,
76 m_key,
77 m_name,
78 m_kind);
79 if(err < B_OK)
80 return;
82 m_exportValid = true;
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 {
95 ASSERT(manager);
96 ASSERT(context);
97 status_t err;
99 if(hasKey()) {
100 // match key against previously imported nodes
101 err = context->getNodeFor(key(), outNode);
103 if(err < B_OK) {
104 // match key against system nodes
105 err = _match_system_node_key(key(), manager, outNode);
107 if(err < B_OK) {
108 PRINT((
109 "!!! No node found for key '%s'\n",
110 key()));
111 return B_NAME_NOT_FOUND;
115 else {
116 err = _match_node_signature(
117 name(),
118 kind(),
119 outNode);
120 if(err < B_OK) {
121 PRINT((
122 "!!! No node found named '%s' with kinds %" B_PRId64 "\n",
123 name(),
124 kind()));
125 return B_NAME_NOT_FOUND;
129 return B_OK;
132 // -------------------------------------------------------- //
133 // *** document-type setup
134 // -------------------------------------------------------- //
136 /*static*/
137 void LiveNodeIO::AddTo(
138 XML::DocumentType* docType) {
140 // map self
141 docType->addMapping(new Mapping<LiveNodeIO>(_LIVE_NODE_ELEMENT));
144 // -------------------------------------------------------- //
145 // *** IPersistent
146 // -------------------------------------------------------- //
148 // -------------------------------------------------------- //
149 // EXPORT:
150 // -------------------------------------------------------- //
152 void LiveNodeIO::xmlExportBegin(
153 ExportContext& context) const {
155 if(!m_exportValid) {
156 context.reportError(
157 "LiveNodeIO::xmlExportBegin():\n"
158 "*** invalid ***\n");
159 return;
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 // -------------------------------------------------------- //
190 // IMPORT:
191 // -------------------------------------------------------- //
193 void LiveNodeIO::xmlImportBegin(
194 ImportContext& context) {}
196 void LiveNodeIO::xmlImportAttribute(
197 const char* key,
198 const char* value,
199 ImportContext& context) {
201 if(!strcmp(key, "key")) {
202 m_key = value;
204 else {
205 BString err;
206 err << "LiveNodeIO: unknown attribute '" << key << "'\n";
207 context.reportError(err.String());
211 void LiveNodeIO::xmlImportContent(
212 const char* data,
213 uint32 length,
214 ImportContext& context) {}
216 void LiveNodeIO::xmlImportChild(
217 IPersistent* child,
218 ImportContext& context) {
220 StringContent* obj = dynamic_cast<StringContent*>(child);
221 if(!obj) {
222 BString err;
223 err << "LiveNodeIO: unexpected element '" <<
224 context.element() << "'\n";
225 context.reportError(err.String());
226 return;
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);
233 else {
234 BString err;
235 err << "LiveNodeIO: unexpected element '" <<
236 context.element() << "'\n";
237 context.reportError(err.String());
240 delete child;
243 void LiveNodeIO::xmlImportComplete(
244 ImportContext& context) {}
246 // END -- LiveNodeIO.cpp --