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

Revision 604, 7.0 KB (checked in by tuan, 8 years ago)

Fix up format and some Terminate stuffs

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 DELPTR(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// copy constructor
65// deep copy
66Port::Port (const Port &aPort):
67root(aPort.root), findBy(NULL),
68ifComponentInstantiationRef(aPort.ifComponentInstantiationRef),
69ifDeviceThatLoadedThisComponentRef(aPort.ifDeviceThatLoadedThisComponentRef),
70ifDeviceUsedByThisComponentRef(aPort.ifDeviceUsedByThisComponentRef),
71ifFindBy(aPort.ifFindBy),
72componentInstantiationRefId(NULL),
73deviceThatLoadedThisComponentRefId(NULL),
74deviceUsedByThisComponentRefId(NULL),
75deviceUsedByThisComponentRefUsesRefId(NULL)
76{
77    this->findBy = new FindBy (aPort.root);
78
79    this->componentInstantiationRefId =
80    new char[strlen (aPort.componentInstantiationRefId) + 1];
81    strcpy(this->componentInstantiationRefId, aPort.componentInstantiationRefId);
82
83    this->deviceThatLoadedThisComponentRefId =
84    new char[strlen (aPort.deviceThatLoadedThisComponentRefId) + 1];
85    strcpy (this->deviceThatLoadedThisComponentRefId,
86            aPort.deviceThatLoadedThisComponentRefId);
87
88    this->deviceUsedByThisComponentRefId =
89    new char[strlen (aPort.deviceUsedByThisComponentRefId) + 1];
90    strcpy (this->deviceUsedByThisComponentRefId, aPort.deviceUsedByThisComponentRefId);
91
92    this->deviceUsedByThisComponentRefUsesRefId =
93    new char[strlen (aPort.deviceUsedByThisComponentRefUsesRefId) + 1];
94    strcpy (this->deviceUsedByThisComponentRefUsesRefId,
95            aPort.deviceUsedByThisComponentRefUsesRefId);
96}
97
98
99Port::~Port()
100{
101//    it is safer to let the parser
102// or whoever passes the DOMElement calls release() --Tuan
103//    root->release();
104   
105    DELPTR(findBy);
106    sweetd(componentInstantiationRefId);
107    sweetd(deviceThatLoadedThisComponentRefId);
108    sweetd(deviceUsedByThisComponentRefId);
109    sweetd(deviceUsedByThisComponentRefUsesRefId);
110}
111
112
113void Port::parseElement()
114{
115    parsePort(root);
116}
117
118
119// \todo implement exception handling for parsePort
120void Port::parsePort (DOMElement * _elem)
121{
122    this->parseComponentInstantiationRef (_elem);
123
124    if (!this->ifComponentInstantiationRef)
125    {
126        this->parseDeviceThatLoadedThisComponentRef (_elem);
127
128        if (!this->ifDeviceThatLoadedThisComponentRef)
129        {
130                this->parseDeviceUsedByThisComponentRef (_elem);
131
132                if (!this->ifDeviceUsedByThisComponentRef)
133                {
134                        this->parseFindBy (_elem);
135
136                        if (!this->ifFindBy)
137                        {
138//                                      string msg = "[Port:parsePort] Invalid XML port";
139//                                      throw new InvalidProfile( msg );
140                        }
141                }
142        }
143    }
144}
145
146
147void Port::parseComponentInstantiationRef(DOMElement * _elem)
148{
149    tmpXMLStr = XMLString::transcode("componentinstantiationref");
150    DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr);
151    XMLString::release(&tmpXMLStr);
152
153    if (nodeList->getLength() != 0)
154    {
155        DOMElement *elem = (DOMElement *) nodeList->item(0);
156
157        tmpXMLStr = XMLString::transcode("refid");
158        const XMLCh *refId = elem->getAttribute(tmpXMLStr);
159        XMLString::release(&tmpXMLStr);
160
161        this->componentInstantiationRefId = XMLString::transcode(refId);
162        this->ifComponentInstantiationRef = true;
163    }
164}
165
166
167void Port::parseDeviceThatLoadedThisComponentRef (DOMElement * _elem)
168{
169    tmpXMLStr = XMLString::transcode("devicethatloadedthiscomponentref");
170    DOMNodeList* nodeList = _elem->getElementsByTagName(tmpXMLStr);
171    XMLString::release(&tmpXMLStr);
172
173    if (nodeList->getLength () != 0)
174    {
175        DOMElement *elem = (DOMElement*) nodeList->item (0);
176
177        tmpXMLStr = XMLString::transcode("refid");
178        const XMLCh* refId = elem->getAttribute(tmpXMLStr);
179        XMLString::release(&tmpXMLStr);
180
181        this->deviceThatLoadedThisComponentRefId = XMLString::transcode(refId);
182        this->ifDeviceThatLoadedThisComponentRef = true;
183    }
184}
185
186
187void Port::parseFindBy(DOMElement * _elem)
188{
189    tmpXMLStr = XMLString::transcode("findby");
190    DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr);
191    XMLString::release(&tmpXMLStr);
192
193    if (nodeList->getLength () != 0)
194    {
195        DOMElement *elem = (DOMElement *) nodeList->item (0);
196
197        this->findBy = new FindBy(elem);
198        this->ifFindBy = true;
199    }
200}
201
202
203void Port::parseDeviceUsedByThisComponentRef(DOMElement * _elem)
204{
205    tmpXMLStr = XMLString::transcode("deviceusedbythiscomponentref");
206    DOMNodeList *nodeList = _elem->getElementsByTagName(tmpXMLStr);
207    XMLString::release(&tmpXMLStr);
208
209    if (nodeList->getLength() != 0)
210    {
211        DOMElement* elem = (DOMElement*) nodeList->item(0);
212
213        tmpXMLStr = XMLString::transcode("refid");
214        const XMLCh *refId = elem->getAttribute(tmpXMLStr);
215        XMLString::release(&tmpXMLStr);
216        tmpXMLStr = XMLString::transcode("usesrefid");
217        const XMLCh *refUsesId = elem->getAttribute(tmpXMLStr);
218        XMLString::release(&tmpXMLStr);
219
220        this->deviceUsedByThisComponentRefId = XMLString::transcode(refId);
221        this->deviceUsedByThisComponentRefUsesRefId =XMLString::transcode(refUsesId);
222        this->ifDeviceUsedByThisComponentRef = true;
223    }
224}
225
226XMLCh* Port::tmpXMLStr = NULL;
Note: See TracBrowser for help on using the browser.