| 1 | /******************************************************************************* |
|---|
| 2 | |
|---|
| 3 | Copyright 2004, Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE Parser. |
|---|
| 6 | |
|---|
| 7 | OSSIE Parser is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the Lesser GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2.1 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE Parser is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | Lesser GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the Lesser GNU General Public License |
|---|
| 18 | along with OSSIE Parser; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | Even though all code is original, the architecture of the OSSIE Parser is based |
|---|
| 22 | on the architecture of the CRC's SCA Reference Implementation(SCARI) |
|---|
| 23 | see: http://www.crc.ca/en/html/rmsc/home/sdr/projects/scari |
|---|
| 24 | |
|---|
| 25 | *********************************************************************************/ |
|---|
| 26 | |
|---|
| 27 | #include "ossie/DCDParser.h" |
|---|
| 28 | |
|---|
| 29 | #ifdef HAVE_STRING_H |
|---|
| 30 | #include <string.h> // using POSIX strcpy |
|---|
| 31 | #endif |
|---|
| 32 | |
|---|
| 33 | #define DELPTR(x) if(x!=NULL) delete x, x=NULL; |
|---|
| 34 | #define DELARRAY(x) if(x!=NULL) delete []x, x=NULL; |
|---|
| 35 | |
|---|
| 36 | /** default constructor |
|---|
| 37 | * |
|---|
| 38 | */ |
|---|
| 39 | DCDParser::DCDParser(): |
|---|
| 40 | deviceManagerSoftPkg(NULL), domainManagerName(NULL), |
|---|
| 41 | domainManagerIOR(NULL),domainManagerComponent(NULL) |
|---|
| 42 | {} |
|---|
| 43 | |
|---|
| 44 | /** default constructor with initialised value |
|---|
| 45 | */ |
|---|
| 46 | DCDParser::DCDParser(const char* _DCDFile):ComponentAssemblyParser(_DCDFile) |
|---|
| 47 | { |
|---|
| 48 | initializeDCD(); |
|---|
| 49 | this->parseFile(); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | /** default copy constructor |
|---|
| 53 | */ |
|---|
| 54 | DCDParser::DCDParser(const DCDParser & _dcdP) |
|---|
| 55 | { |
|---|
| 56 | this->doc = _dcdP.doc; |
|---|
| 57 | |
|---|
| 58 | this->fileName = new char[strlen(_dcdP.fileName) + 1]; |
|---|
| 59 | strcpy(this->fileName, _dcdP.fileName); |
|---|
| 60 | |
|---|
| 61 | this->id = new char[strlen(_dcdP.id) + 1]; |
|---|
| 62 | strcpy(this->id, _dcdP.id); |
|---|
| 63 | |
|---|
| 64 | this->name = new char[strlen(_dcdP.name) + 1]; |
|---|
| 65 | strcpy(this->name, _dcdP.name); |
|---|
| 66 | |
|---|
| 67 | this->deviceManagerSoftPkg = |
|---|
| 68 | new char[strlen(_dcdP.deviceManagerSoftPkg) + 1]; |
|---|
| 69 | strcpy(this->deviceManagerSoftPkg, _dcdP.deviceManagerSoftPkg); |
|---|
| 70 | |
|---|
| 71 | this->domainManagerName = new char[strlen(_dcdP.domainManagerName) + 1]; |
|---|
| 72 | strcpy(this->domainManagerName, _dcdP.domainManagerName); |
|---|
| 73 | |
|---|
| 74 | this->domainManagerIOR = new char[strlen(_dcdP.domainManagerIOR) + 1]; |
|---|
| 75 | strcpy(this->domainManagerIOR, _dcdP.domainManagerIOR); |
|---|
| 76 | |
|---|
| 77 | if(_dcdP.domainManagerComponent == NULL) |
|---|
| 78 | { |
|---|
| 79 | this->domainManagerComponent = NULL; |
|---|
| 80 | } |
|---|
| 81 | else |
|---|
| 82 | { |
|---|
| 83 | this->domainManagerComponent = new DCDComponentPlacement; |
|---|
| 84 | *(this->domainManagerComponent) =*(_dcdP.domainManagerComponent); |
|---|
| 85 | } |
|---|
| 86 | /* |
|---|
| 87 | { |
|---|
| 88 | for(unsigned int i = 0; i < _dcdP.localComponents.size(); i++) |
|---|
| 89 | this->localComponents.push_back(_dcdP.localComponents[i]); |
|---|
| 90 | } |
|---|
| 91 | */ |
|---|
| 92 | for (unsigned int i = 0; i < _dcdP.localComponents.size(); i++) |
|---|
| 93 | { |
|---|
| 94 | char *tmpStr = XMLString::replicate(_dcdP.localComponents[i]); |
|---|
| 95 | this->localComponents.push_back(tmpStr); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | // Pointer copy leaves no way to maintain heap storage. See below. -TT 07-14-2005 |
|---|
| 99 | for (unsigned int i = 0; i < _dcdP.deployOnComponents.size(); i++) |
|---|
| 100 | { |
|---|
| 101 | this->deployOnComponents.push_back(_dcdP.deployOnComponents[i]); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | /* // This requires a working copy constructor for DCDComponentPlacement. -TT |
|---|
| 105 | for (unsigned int i = 0; i < _dcdP.deployOnComponents.size(); i++) |
|---|
| 106 | { |
|---|
| 107 | DCDComponentPlacement* tmpDCDcomponent = new DCDComponentPlacement(); |
|---|
| 108 | tmpDCDcomponent = _dcdP.deployOnComponents[i]; |
|---|
| 109 | this->deployOnComponents.push_back(tmpDCDcomponent); |
|---|
| 110 | } |
|---|
| 111 | */ |
|---|
| 112 | /* |
|---|
| 113 | for (unsigned int i = 0; i < _dcdP.connections.size(); i++) |
|---|
| 114 | { |
|---|
| 115 | this->connections.push_back(_dcdP.connections[i]); |
|---|
| 116 | } |
|---|
| 117 | */ |
|---|
| 118 | for (unsigned int i = 0; i < _dcdP.connections.size(); i++) |
|---|
| 119 | { |
|---|
| 120 | Connection *tmpConnection = new Connection(); |
|---|
| 121 | tmpConnection = _dcdP.connections[i]; |
|---|
| 122 | this->connections.push_back(tmpConnection); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | DCDParser::~DCDParser() |
|---|
| 128 | { |
|---|
| 129 | DELPTR(domainManagerComponent); |
|---|
| 130 | DELARRAY(deviceManagerSoftPkg); |
|---|
| 131 | DELARRAY(domainManagerName); |
|---|
| 132 | DELARRAY(domainManagerIOR); |
|---|
| 133 | |
|---|
| 134 | /* // This shouldn't cause seg faults. But it does. Need to find out why. -TT |
|---|
| 135 | for (unsigned int i=0; localComponents.size(); i++) |
|---|
| 136 | { |
|---|
| 137 | XMLString::release(&(localComponents[i])); |
|---|
| 138 | } |
|---|
| 139 | */ |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | /* // This will cause seg faults. See copy constructor. -TT |
|---|
| 143 | for (unsigned int i=0; deployOnComponents.size(); i++) |
|---|
| 144 | { |
|---|
| 145 | DELPTR(deployOnComponents[i]); |
|---|
| 146 | } |
|---|
| 147 | */ |
|---|
| 148 | |
|---|
| 149 | localComponents.clear(); |
|---|
| 150 | // deployOnComponents.clear(); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | // \todo implement exception handling |
|---|
| 155 | void DCDParser::initializeDCD() |
|---|
| 156 | { |
|---|
| 157 | deviceManagerSoftPkg = NULL; |
|---|
| 158 | domainManagerName = NULL; |
|---|
| 159 | domainManagerIOR = NULL; |
|---|
| 160 | domainManagerComponent = NULL; |
|---|
| 161 | |
|---|
| 162 | // Testing -TT |
|---|
| 163 | localComponents.clear(); |
|---|
| 164 | deployOnComponents.clear(); |
|---|
| 165 | |
|---|
| 166 | char* tmp = XMLString::transcode(doc->getDocumentElement()->getNodeName()); |
|---|
| 167 | |
|---|
| 168 | if(strcmp(tmp, "deviceconfiguration") != 0) |
|---|
| 169 | { |
|---|
| 170 | //InvalidProfile |
|---|
| 171 | } |
|---|
| 172 | delete []tmp; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | void DCDParser::parseFile() |
|---|
| 177 | { |
|---|
| 178 | DOMElement* _root = doc->getDocumentElement(); |
|---|
| 179 | this->parseIdAndName(_root); |
|---|
| 180 | this->parseDeviceManagerSoftPkg(_root); |
|---|
| 181 | this->parseComponentPlacement(_root); |
|---|
| 182 | this->parseDomainManager(_root); |
|---|
| 183 | this->parseConnections(_root); |
|---|
| 184 | this->parseLocalComponents(_root); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | void DCDParser::parseDeviceManagerSoftPkg(DOMElement* _elem) |
|---|
| 189 | { |
|---|
| 190 | XMLCh* tmpXMLStr = XMLString::transcode("devicemanagersoftpkg"); |
|---|
| 191 | DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 192 | DELARRAY(tmpXMLStr); |
|---|
| 193 | |
|---|
| 194 | DOMElement* tmpElement = (DOMElement*) nodeList->item(0); |
|---|
| 195 | tmpXMLStr = XMLString::transcode("localfile"); |
|---|
| 196 | nodeList = tmpElement->getElementsByTagName(tmpXMLStr); |
|---|
| 197 | DELARRAY(tmpXMLStr); |
|---|
| 198 | tmpElement =(DOMElement* ) nodeList->item(0); |
|---|
| 199 | |
|---|
| 200 | tmpXMLStr = XMLString::transcode("name"); |
|---|
| 201 | const XMLCh* _tmp = tmpElement->getAttribute(tmpXMLStr); |
|---|
| 202 | DELARRAY(tmpXMLStr); |
|---|
| 203 | deviceManagerSoftPkg = XMLString::transcode(_tmp); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | void DCDParser::parseLocalComponents(DOMElement* _elem) |
|---|
| 208 | { |
|---|
| 209 | XMLCh* tmpXMLStr = XMLString::transcode("componentfile"); |
|---|
| 210 | DOMNodeList* nodeList =_elem->getElementsByTagName(tmpXMLStr); |
|---|
| 211 | DELARRAY(tmpXMLStr); |
|---|
| 212 | |
|---|
| 213 | DOMNodeList* nodeList2; |
|---|
| 214 | DOMElement* tmpElement; |
|---|
| 215 | |
|---|
| 216 | for(unsigned int i = 0; i < nodeList->getLength(); i++) |
|---|
| 217 | { |
|---|
| 218 | tmpElement =(DOMElement* ) nodeList->item(i); |
|---|
| 219 | tmpXMLStr = XMLString::transcode("localfile"); |
|---|
| 220 | nodeList2 = tmpElement->getElementsByTagName(tmpXMLStr); |
|---|
| 221 | DELARRAY(tmpXMLStr); |
|---|
| 222 | tmpElement =(DOMElement* ) nodeList2->item(0); |
|---|
| 223 | tmpXMLStr = XMLString::transcode("name"); |
|---|
| 224 | const XMLCh* _tmp = tmpElement->getAttribute(tmpXMLStr); |
|---|
| 225 | DELARRAY(tmpXMLStr); |
|---|
| 226 | localComponents.push_back(XMLString::transcode(_tmp)); |
|---|
| 227 | } |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | void DCDParser::parseComponentPlacement(DOMElement* _elem) |
|---|
| 232 | { |
|---|
| 233 | XMLCh* tmpXMLStr = XMLString::transcode("componentplacement"); |
|---|
| 234 | DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 235 | DELARRAY(tmpXMLStr); |
|---|
| 236 | |
|---|
| 237 | DOMElement* tmpElement; |
|---|
| 238 | |
|---|
| 239 | for(unsigned int i = 0; i < nodeList->getLength(); i++) |
|---|
| 240 | { |
|---|
| 241 | tmpElement =(DOMElement*) nodeList->item(i); |
|---|
| 242 | DCDComponentPlacement* dcdComponent = new DCDComponentPlacement(tmpElement, doc); |
|---|
| 243 | |
|---|
| 244 | if(dcdComponent->isDomainManager()) |
|---|
| 245 | { |
|---|
| 246 | domainManagerComponent = dcdComponent; |
|---|
| 247 | } |
|---|
| 248 | else if(dcdComponent->isDeployOn()) |
|---|
| 249 | { |
|---|
| 250 | deployOnComponents.push_back(dcdComponent); |
|---|
| 251 | } |
|---|
| 252 | else |
|---|
| 253 | { |
|---|
| 254 | //localComponents.push_back(*dcdComponent); |
|---|
| 255 | } |
|---|
| 256 | } |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | void DCDParser::parseDomainManager(DOMElement* _elem) |
|---|
| 261 | { |
|---|
| 262 | tmpXMLStr = XMLString::transcode("domainmanager"); |
|---|
| 263 | DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr); |
|---|
| 264 | DELARRAY(tmpXMLStr); |
|---|
| 265 | |
|---|
| 266 | DOMElement* tmpElement =(DOMElement* ) nodeList->item(0); |
|---|
| 267 | tmpXMLStr = XMLString::transcode("namingservice"); |
|---|
| 268 | nodeList = tmpElement->getElementsByTagName(tmpXMLStr); |
|---|
| 269 | DELARRAY(tmpXMLStr); |
|---|
| 270 | |
|---|
| 271 | if(nodeList->getLength() != 0) |
|---|
| 272 | { |
|---|
| 273 | tmpElement =(DOMElement* ) nodeList->item(0); |
|---|
| 274 | |
|---|
| 275 | tmpXMLStr = XMLString::transcode("name"); |
|---|
| 276 | const XMLCh* _name = tmpElement->getAttribute(tmpXMLStr); |
|---|
| 277 | DELARRAY(tmpXMLStr); |
|---|
| 278 | domainManagerName = XMLString::transcode(_name); |
|---|
| 279 | } |
|---|
| 280 | else |
|---|
| 281 | { |
|---|
| 282 | tmpXMLStr = XMLString::transcode("stringifiedobjectref"); |
|---|
| 283 | nodeList = tmpElement->getElementsByTagName(tmpXMLStr); |
|---|
| 284 | DELARRAY(tmpXMLStr); |
|---|
| 285 | |
|---|
| 286 | if(nodeList->getLength() != 0) |
|---|
| 287 | { |
|---|
| 288 | tmpElement =(DOMElement*) nodeList->item(0); |
|---|
| 289 | domainManagerIOR = getTextNode(tmpElement); |
|---|
| 290 | } |
|---|
| 291 | //else //invalid profile |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | char* DCDParser::getDCDFilename() const |
|---|
| 297 | { |
|---|
| 298 | return fileName; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | char* DCDParser::getDeviceManagerSoftPkg() const |
|---|
| 303 | { |
|---|
| 304 | return deviceManagerSoftPkg; |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | char* DCDParser::getDomainManagerName() const |
|---|
| 309 | { |
|---|
| 310 | return domainManagerName; |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | char* DCDParser::getDomainManagerIOR() const |
|---|
| 315 | { |
|---|
| 316 | return domainManagerIOR; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | DCDComponentPlacement* DCDParser::getDomainManagerComponent() const |
|---|
| 321 | { |
|---|
| 322 | return domainManagerComponent; |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | std::vector <char*>* |
|---|
| 327 | DCDParser::getLocalComponents() |
|---|
| 328 | { |
|---|
| 329 | return &localComponents; |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | std::vector <DCDComponentPlacement*>* |
|---|
| 334 | DCDParser::getDeployOnComponents() |
|---|
| 335 | { |
|---|
| 336 | return &deployOnComponents; |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | char* DCDParser::toString() |
|---|
| 341 | { |
|---|
| 342 | std::vector < DCDComponentPlacement* >*dcdComponentArray = NULL; |
|---|
| 343 | std::vector < char* >*dcdLocalComponentsArray = NULL; |
|---|
| 344 | char* str = new char[MAX_DCD_BUF]; |
|---|
| 345 | |
|---|
| 346 | str = strcat(str, "\n DCDFilename="); |
|---|
| 347 | str = strcat(str, getDCDFilename()); |
|---|
| 348 | str = strcat(str, "\n ID="); |
|---|
| 349 | str = strcat(str, getID()); |
|---|
| 350 | str = strcat(str, "\n Name="); |
|---|
| 351 | str = strcat(str, getName()); |
|---|
| 352 | str = strcat(str, "\n deviceManagerSoftPkg="); |
|---|
| 353 | str = strcat(str, getDeviceManagerSoftPkg()); |
|---|
| 354 | |
|---|
| 355 | if(domainManagerName != "") |
|---|
| 356 | { |
|---|
| 357 | str = strcat(str, "\n domainManagerName="); |
|---|
| 358 | str = strcat(str, getDomainManagerName()); |
|---|
| 359 | } |
|---|
| 360 | else |
|---|
| 361 | { |
|---|
| 362 | str = strcat(str, "\n domainManagerIOR="); |
|---|
| 363 | str = strcat(str, getDomainManagerIOR()); |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | if(domainManagerComponent != NULL) |
|---|
| 367 | str = strcat(str, "\n domainManagerComponent"); |
|---|
| 368 | |
|---|
| 369 | dcdLocalComponentsArray = getLocalComponents(); |
|---|
| 370 | |
|---|
| 371 | if(dcdLocalComponentsArray->size() > 0) |
|---|
| 372 | { |
|---|
| 373 | for(unsigned int i = 0; i < dcdLocalComponentsArray->size(); i++) |
|---|
| 374 | { |
|---|
| 375 | char _tmp; |
|---|
| 376 | str = strcat(str, "\n LocalComponent["); |
|---|
| 377 | //str = strcat(str, ACE_OS::itoa(i, &_tmp, 10)); // ACE_OS::itoa has a different format than stdlib atoi |
|---|
| 378 | str = strcat(str, "]"); |
|---|
| 379 | str = strcat(str,(*dcdLocalComponentsArray)[i]); |
|---|
| 380 | } |
|---|
| 381 | } |
|---|
| 382 | else |
|---|
| 383 | str = strcat(str, "\n There are no local components"); |
|---|
| 384 | |
|---|
| 385 | dcdComponentArray = getDeployOnComponents(); |
|---|
| 386 | |
|---|
| 387 | if(dcdComponentArray->size() > 0) |
|---|
| 388 | { |
|---|
| 389 | for(unsigned int i = 0; i < dcdComponentArray->size(); i++) |
|---|
| 390 | { |
|---|
| 391 | char _tmp; |
|---|
| 392 | str = strcat(str, "\n DeployOnComponent["); |
|---|
| 393 | //str = strcat(str, ACE_OS::itoa(i, &_tmp, 10)); |
|---|
| 394 | str = strcat(str, "]"); |
|---|
| 395 | str = strcat(str,(*dcdComponentArray)[i]->getSPDFile()); |
|---|
| 396 | } |
|---|
| 397 | } |
|---|
| 398 | else |
|---|
| 399 | str = strcat(str, "\n There are no Deploy Components"); |
|---|
| 400 | /* |
|---|
| 401 | std::vector<Connection*> _connections = getConnections(); |
|---|
| 402 | |
|---|
| 403 | if(_connections.size()>0) |
|---|
| 404 | { |
|---|
| 405 | |
|---|
| 406 | for(int i = 0; i < _connections.size(); i++) |
|---|
| 407 | { |
|---|
| 408 | str = str + "\n Connections[" +(char* )i + "]" + _connections[i].getID(); |
|---|
| 409 | } |
|---|
| 410 | } |
|---|
| 411 | else |
|---|
| 412 | { |
|---|
| 413 | str = str + "\n There are no connections"; |
|---|
| 414 | } |
|---|
| 415 | */ |
|---|
| 416 | return str; |
|---|
| 417 | } |
|---|
| 418 | XMLCh* DCDParser::tmpXMLStr = NULL; |
|---|