| 1 | |
|---|
| 2 | /******************************************************************************* |
|---|
| 3 | |
|---|
| 4 | Copyright 2006, Virginia Polytechnic Institute and State University |
|---|
| 5 | |
|---|
| 6 | This file is part of the OSSIE waveform loader. |
|---|
| 7 | |
|---|
| 8 | OSSIE Waveform Loader is free software; you can redistribute it and/or modify |
|---|
| 9 | it under the terms of the GNU General Public License as published by |
|---|
| 10 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | (at your option) any later version. |
|---|
| 12 | |
|---|
| 13 | OSSIE Sample Waveform is distributed in the hope that it will be useful, |
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | GNU General Public License for more details. |
|---|
| 17 | |
|---|
| 18 | You should have received a copy of the GNU General Public License |
|---|
| 19 | along with OSSIE Waveform loader; if not, write to the Free Software |
|---|
| 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | *******************************************************************************/ |
|---|
| 24 | |
|---|
| 25 | #include "ossie/debug.h" |
|---|
| 26 | #include "ossie/DASParser.h" |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | DASParser::DASParser(CF::File_ptr das_file) : num_elements(0) |
|---|
| 30 | { |
|---|
| 31 | DEBUG(4, DASParser, "In constructor."); |
|---|
| 32 | |
|---|
| 33 | das_var = new CF::DeviceAssignmentSequence; |
|---|
| 34 | |
|---|
| 35 | unsigned long fileSize = das_file->sizeOf(); |
|---|
| 36 | CF::OctetSequence_var fileData; |
|---|
| 37 | |
|---|
| 38 | das_file->read(fileData, fileSize); |
|---|
| 39 | |
|---|
| 40 | das_file->close(); |
|---|
| 41 | |
|---|
| 42 | unsigned char *fileBuffer = fileData->get_buffer(); |
|---|
| 43 | |
|---|
| 44 | XMLDoc.Parse((const char *)fileBuffer); |
|---|
| 45 | |
|---|
| 46 | root = XMLDoc.FirstChild("deploymentenforcement"); |
|---|
| 47 | if (!root) { |
|---|
| 48 | std::cerr << "ERROR: Not a deployment enforcement file" << std::endl; |
|---|
| 49 | throw 0; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | TiXmlHandle docHandle(root); |
|---|
| 53 | |
|---|
| 54 | // Handle device assignement sequence file |
|---|
| 55 | TiXmlElement *elem = docHandle.FirstChild("deviceassignmentsequence").FirstChild("deviceassignmenttype").Element(); |
|---|
| 56 | if (!root) { |
|---|
| 57 | DEBUG(4, DASParser, "could not find <deviceassignmentsequence> node"); |
|---|
| 58 | throw 0; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | DEBUG(4, DASParser, "about to parse deviceassignment types"); |
|---|
| 62 | |
|---|
| 63 | for (; elem; elem = elem->NextSiblingElement()) { |
|---|
| 64 | DEBUG(4, DASParser, "found deviceassignment type, adding element"); |
|---|
| 65 | |
|---|
| 66 | add_element(); |
|---|
| 67 | |
|---|
| 68 | // try to find <componentid> node |
|---|
| 69 | TiXmlElement *cid = elem->FirstChildElement("componentid"); |
|---|
| 70 | DEBUG(4, DASParser, "Found componentid " << cid->GetText()); |
|---|
| 71 | das_var[num_elements - 1].componentId = CORBA::string_dup(cid->GetText()); |
|---|
| 72 | |
|---|
| 73 | // try to find <assigndeviceid> node |
|---|
| 74 | TiXmlElement *adid = elem->FirstChildElement("assigndeviceid"); |
|---|
| 75 | DEBUG(4, DASParser, "Found assigndeviceid: " << adid->GetText()); |
|---|
| 76 | das_var[num_elements - 1].assignedDeviceId = CORBA::string_dup(adid->GetText()); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | DEBUG(4, DASParser, "completed parsing."); |
|---|
| 80 | |
|---|
| 81 | } |
|---|