1 // LiveNodeIO.cpp 2 3 #include "LiveNodeIO.h" 4 #include "ImportContext.h" 5 #include "ExportContext.h" 6 #include "NodeSetIOContext.h" 7 #include "StringContent.h" 8 9 #include "NodeManager.h" 10 11 #include <Debug.h> 12 #include <MediaAddOn.h> 13 #include <MediaDefs.h> 14 #include <MediaRoster.h> 15 #include <Path.h> 16 17 #include "route_app_io.h" 18 19 __USE_CORTEX_NAMESPACE 20 21 // -------------------------------------------------------- // 22 // *** ctor/dtor 23 // -------------------------------------------------------- // 24 25 LiveNodeIO::~LiveNodeIO() {} 26 27 LiveNodeIO::LiveNodeIO() : 28 m_kind(0LL), 29 m_exportValid(false) {} 30 31 LiveNodeIO::LiveNodeIO( 32 const NodeManager* manager, 33 const NodeSetIOContext* context, 34 media_node_id node) : 35 m_exportValid(false) { 36 37 status_t err; 38 ASSERT(manager); 39 ASSERT(context); 40 41 err = _get_node_signature( 42 manager, 43 context, 44 node, 45 m_key, 46 m_name, 47 m_kind); 48 if(err < B_OK) 49 return; 50 51 m_exportValid = true; 52 } 53 54 // -------------------------------------------------------- // 55 // *** import operations 56 // -------------------------------------------------------- // 57 58 // locate the referenced live node 59 status_t LiveNodeIO::getNode( 60 const NodeManager* manager, 61 const NodeSetIOContext* context, 62 media_node_id* outNode) const { 63 64 ASSERT(manager); 65 ASSERT(context); 66 status_t err; 67 68 if(hasKey()) { 69 // match key against previously imported nodes 70 err = context->getNodeFor(key(), outNode); 71 72 if(err < B_OK) { 73 // match key against system nodes 74 err = _match_system_node_key(key(), manager, outNode); 75 76 if(err < B_OK) { 77 PRINT(( 78 "!!! No node found for key '%s'\n", 79 key())); 80 return B_NAME_NOT_FOUND; 81 } 82 } 83 } 84 else { 85 err = _match_node_signature( 86 name(), 87 kind(), 88 outNode); 89 if(err < B_OK) { 90 PRINT(( 91 "!!! No node found named '%s' with kinds %Ld\n", 92 name(), 93 kind())); 94 return B_NAME_NOT_FOUND; 95 } 96 } 97 98 return B_OK; 99 } 100 101 // -------------------------------------------------------- // 102 // *** document-type setup 103 // -------------------------------------------------------- // 104 105 /*static*/ 106 void LiveNodeIO::AddTo( 107 XML::DocumentType* docType) { 108 109 // map self 110 docType->addMapping(new Mapping<LiveNodeIO>(_LIVE_NODE_ELEMENT)); 111 } 112 113 // -------------------------------------------------------- // 114 // *** IPersistent 115 // -------------------------------------------------------- // 116 117 // -------------------------------------------------------- // 118 // EXPORT: 119 // -------------------------------------------------------- // 120 121 void LiveNodeIO::xmlExportBegin( 122 ExportContext& context) const { 123 124 if(!m_exportValid) { 125 context.reportError( 126 "LiveNodeIO::xmlExportBegin():\n" 127 "*** invalid ***\n"); 128 return; 129 } 130 131 context.beginElement(_LIVE_NODE_ELEMENT); 132 } 133 134 void LiveNodeIO::xmlExportAttributes( 135 ExportContext& context) const { 136 137 if(m_key.Length() > 0) 138 context.writeAttr("key", m_key.String()); 139 } 140 141 void LiveNodeIO::xmlExportContent( 142 ExportContext& context) const { 143 144 if(m_name.Length() > 0) { 145 context.beginContent(); 146 147 _write_simple(_NAME_ELEMENT, m_name.String(), context); 148 _write_node_kinds(m_kind, context); 149 } 150 } 151 152 void LiveNodeIO::xmlExportEnd( 153 ExportContext& context) const { 154 155 context.endElement(); 156 } 157 158 // -------------------------------------------------------- // 159 // IMPORT: 160 // -------------------------------------------------------- // 161 162 void LiveNodeIO::xmlImportBegin( 163 ImportContext& context) {} 164 165 void LiveNodeIO::xmlImportAttribute( 166 const char* key, 167 const char* value, 168 ImportContext& context) { 169 170 if(!strcmp(key, "key")) { 171 m_key = value; 172 } 173 else { 174 BString err; 175 err << "LiveNodeIO: unknown attribute '" << key << "'\n"; 176 context.reportError(err.String()); 177 } 178 } 179 180 void LiveNodeIO::xmlImportContent( 181 const char* data, 182 uint32 length, 183 ImportContext& context) {} 184 185 void LiveNodeIO::xmlImportChild( 186 IPersistent* child, 187 ImportContext& context) { 188 189 StringContent* obj = dynamic_cast<StringContent*>(child); 190 if(!obj) { 191 BString err; 192 err << "LiveNodeIO: unexpected element '" << 193 context.element() << "'\n"; 194 context.reportError(err.String()); 195 return; 196 } 197 198 if(!strcmp(context.element(), _NAME_ELEMENT)) 199 m_name = obj->content; 200 else if(!strcmp(context.element(), _KIND_ELEMENT)) 201 _read_node_kind(m_kind, obj->content.String(), context); 202 else { 203 BString err; 204 err << "LiveNodeIO: unexpected element '" << 205 context.element() << "'\n"; 206 context.reportError(err.String()); 207 } 208 209 delete child; 210 } 211 212 void LiveNodeIO::xmlImportComplete( 213 ImportContext& context) {} 214 215 // END -- LiveNodeIO.cpp -- 216 217