root/ossie/trunk/ossie/parser/Port.cpp @ 464

Revision 464, 6.6 KB (checked in by balister, 8 years ago)

ifdef include files based on variables defined by configure HAVE_UNISTD_H HAVE_STRING_H HAVE_SYS_TYPES_H

Line 
1/*******************************************************************************
2
3Copyright 2004, Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE Parser.
6
7OSSIE Parser is free software; you can redistribute it and/or modify
8it under the terms of the Lesser GNU General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or
10(at your option) any later version.
11
12OSSIE Parser is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15Lesser GNU General Public License for more details.
16
17You should have received a copy of the Lesser GNU General Public License
18along with OSSIE Parser; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21Even though all code is original, the architecture of the OSSIE Parser is based
22on the architecture of the CRC's SCA Reference Implementation (SCARI)
23see: http://www.crc.ca/en/html/rmsc/home/sdr/projects/scari
24
25*********************************************************************************/
26// last updated: 03/11/05
27// coder: tuan pham
28// optimise constructors and fix transcode leaks
29#ifdef HAVE_STRING_H
30#include <string.h>
31#endif
32
33#include "ossie/Port.h"
34
35#define mdel(x) if (x!=NULL) delete x, x=NULL;
36#define sweetd(x) if (x!=NULL) delete []x, x=NULL;
37
38Port::Port():
39root(NULL), findBy(NULL),
40ifComponentInstantiationRef(false),
41ifDeviceThatLoadedThisComponentRef(false),
42ifDeviceUsedByThisComponentRef(false),
43ifFindBy(false),
44componentInstantiationRefId(NULL),
45deviceThatLoadedThisComponentRefId(NULL),
46deviceUsedByThisComponentRefId(NULL),
47deviceUsedByThisComponentRefUsesRefId(NULL)
48{}
49
50Port::Port (DOMElement * element):
51root(element), findBy(NULL),
52ifComponentInstantiationRef(false),
53ifDeviceThatLoadedThisComponentRef(false),
54ifDeviceUsedByThisComponentRef(false),
55ifFindBy(false),
56componentInstantiationRefId(NULL),
57deviceThatLoadedThisComponentRefId(NULL),
58deviceUsedByThisComponentRefId(NULL),
59deviceUsedByThisComponentRefUsesRefId(NULL)
60{
61        this->parseElement();
62}
63
64
65Port::Port (const Port & _port):
66root(_port.root), findBy(NULL),
67ifComponentInstantiationRef(_port.ifComponentInstantiationRef),
68ifDeviceThatLoadedThisComponentRef(_port.ifDeviceThatLoadedThisComponentRef),
69ifDeviceUsedByThisComponentRef(_port.ifDeviceUsedByThisComponentRef),
70ifFindBy(_port.ifFindBy),
71componentInstantiationRefId(NULL),
72deviceThatLoadedThisComponentRefId(NULL),
73deviceUsedByThisComponentRefId(NULL),
74deviceUsedByThisComponentRefUsesRefId(NULL)
75{
76        this->findBy = new FindBy (_port.root);
77
78        this->componentInstantiationRefId =
79        new char[strlen (_port.componentInstantiationRefId) + 1];
80        strcpy(this->componentInstantiationRefId, _port.componentInstantiationRefId);
81
82        this->deviceThatLoadedThisComponentRefId =
83        new char[strlen (_port.deviceThatLoadedThisComponentRefId) + 1];
84        strcpy (this->deviceThatLoadedThisComponentRefId, _port.deviceThatLoadedThisComponentRefId);
85
86        this->deviceUsedByThisComponentRefId =
87        new char[strlen (_port.deviceUsedByThisComponentRefId) + 1];
88        strcpy (this->deviceUsedByThisComponentRefId, _port.deviceUsedByThisComponentRefId);
89
90        this->deviceUsedByThisComponentRefUsesRefId =
91        new char[strlen (_port.deviceUsedByThisComponentRefUsesRefId) + 1];
92        strcpy (this->deviceUsedByThisComponentRefUsesRefId, _port.deviceUsedByThisComponentRefUsesRefId);
93}
94
95
96Port::~Port()
97{
98        root->release();        // it is safer to let the parser or whoever passes the DOMElement calls release() --Tuan
99        mdel(findBy);
100        sweetd(componentInstantiationRefId);
101        sweetd(deviceThatLoadedThisComponentRefId);
102        sweetd(deviceUsedByThisComponentRefId);
103        sweetd(deviceUsedByThisComponentRefUsesRefId);
104}
105
106
107void Port::parseElement()
108{
109    this->parsePort(this->root);
110}
111
112
113// \todo implement exception handling for parsePort
114void Port::parsePort (DOMElement * _elem)
115{
116        this->parseComponentInstantiationRef (_elem);
117
118        if (!this->ifComponentInstantiationRef)
119        {
120                this->parseDeviceThatLoadedThisComponentRef (_elem);
121
122                if (!this->ifDeviceThatLoadedThisComponentRef)
123                {
124                        this->parseDeviceUsedByThisComponentRef (_elem);
125
126                        if (!this->ifDeviceUsedByThisComponentRef)
127                        {
128                                this->parseFindBy (_elem);
129
130                                if (!this->ifFindBy)
131                                {
132//                                      string msg = "[Port:parsePort] Invalid XML port";
133//                                      throw new InvalidProfile( msg );
134                                }
135                        }
136                }
137        }
138}
139
140
141void Port::parseComponentInstantiationRef(DOMElement * _elem)
142{
143        tmpXMLStr = XMLString::transcode("componentinstantiationref");
144        DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr);
145        sweetd(tmpXMLStr);
146
147        if (nodeList->getLength() != 0)
148        {
149                DOMElement *elem = (DOMElement *) nodeList->item(0);
150
151                tmpXMLStr = XMLString::transcode("refid");
152                const XMLCh *refId = elem->getAttribute(tmpXMLStr);
153                sweetd(tmpXMLStr);
154
155                this->componentInstantiationRefId = XMLString::transcode(refId);
156                this->ifComponentInstantiationRef = true;
157        }
158}
159
160
161void Port::parseDeviceThatLoadedThisComponentRef (DOMElement * _elem)
162{
163        tmpXMLStr = XMLString::transcode("devicethatloadedthiscomponentref");
164        DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr);
165        sweetd(tmpXMLStr);
166
167        if (nodeList->getLength () != 0)
168        {
169                DOMElement *elem = (DOMElement*) nodeList->item (0);
170
171                tmpXMLStr = XMLString::transcode("refid");
172                const XMLCh* refId = elem->getAttribute(tmpXMLStr);
173                sweetd(tmpXMLStr);
174
175                this->deviceThatLoadedThisComponentRefId = XMLString::transcode(refId);
176                this->ifDeviceThatLoadedThisComponentRef = true;
177        }
178}
179
180
181void Port::parseFindBy(DOMElement * _elem)
182{
183        tmpXMLStr = XMLString::transcode("findby");
184        DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr);
185        sweetd(tmpXMLStr);
186
187        if (nodeList->getLength () != 0)
188        {
189                DOMElement *elem = (DOMElement *) nodeList->item (0);
190
191                this->findBy = new FindBy(elem);
192                this->ifFindBy = true;
193        }
194}
195
196
197void Port::parseDeviceUsedByThisComponentRef(DOMElement * _elem)
198{
199        tmpXMLStr = XMLString::transcode("deviceusedbythiscomponentref");
200        DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr);
201        sweetd(tmpXMLStr);
202
203        if (nodeList->getLength() != 0)
204        {
205                DOMElement* elem = (DOMElement*) nodeList->item(0);
206
207                tmpXMLStr = XMLString::transcode("refid");
208                const XMLCh *refId = elem->getAttribute (XMLString::transcode ("refid"));
209                sweetd(tmpXMLStr);
210                tmpXMLStr = XMLString::transcode("usesrefid");
211                const XMLCh *refUsesId = elem->getAttribute (XMLString::transcode ("usesrefid"));
212                sweetd(tmpXMLStr);
213
214                this->deviceUsedByThisComponentRefId = XMLString::transcode(refId);
215                this->deviceUsedByThisComponentRefUsesRefId =XMLString::transcode(refUsesId);
216                this->ifDeviceUsedByThisComponentRef = true;
217        }
218}
219
220XMLCh* Port::tmpXMLStr = NULL;
Note: See TracBrowser for help on using the browser.