1 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_Graph.cxx
25 // Author : Jean Rahuel, CEA
30 #include "DataFlowBase_StreamGraph.hxx"
32 #include "SALOME_LifeCycleCORBA.hxx"
34 GraphBase::Graph::Graph() :
36 cdebug << "GraphBase::Graph::Graph" << endl ;
41 GraphBase::Graph::Graph( CORBA::ORB_ptr ORB ,
42 SALOME_NamingService* ptrNamingService ,
43 const char *DataFlowName ,
44 const SUPERV::KindOfNode DataFlowkind ,
45 int * Graph_prof_debug ,
46 ofstream * Graph_fdebug ) :
47 // const char * DebugFileName ) :
48 DataNode( ORB ,ptrNamingService , DataFlowName , DataFlowkind , Graph_prof_debug , Graph_fdebug ) {
49 _Orb = CORBA::ORB::_duplicate( ORB ) ;
50 Set_prof_debug( Graph_prof_debug , Graph_fdebug ) ;
51 cdebug << "GraphBase::Graph::Graph( " << DataFlowName << ") GraphNodesSize() " << GraphNodesSize() << endl ;
56 GraphBase::Graph::Graph( CORBA::ORB_ptr ORB ,
57 SALOME_NamingService* ptrNamingService ,
58 const SALOME_ModuleCatalog::Service& DataFlowService ,
59 const char *DataFlowComponentName ,
60 const char *DataFlowInterfaceName ,
61 const char *DataFlowName ,
62 const SUPERV::KindOfNode DataFlowkind ,
63 const SUPERV::SDate DataFlowFirstCreation ,
64 const SUPERV::SDate DataFlowLastModification ,
65 const char * DataFlowEditorRelease ,
66 const char * DataFlowAuthor ,
67 const char * DataFlowComputer ,
68 const char * DataFlowComment ,
69 int * Graph_prof_debug ,
70 ofstream * Graph_fdebug ) :
71 // const char * DebugFileName ) :
72 DataNode( ORB , ptrNamingService , DataFlowService ,
73 DataFlowName , DataFlowkind ,
74 DataFlowFirstCreation , DataFlowLastModification ,
75 DataFlowEditorRelease , DataFlowAuthor , DataFlowComment ) {
76 _Orb = CORBA::ORB::_duplicate( ORB ) ;
79 Set_prof_debug( Graph_prof_debug , Graph_fdebug ) ;
80 cdebug_in << "GraphBase::Graph::Graph" << endl ;
81 DataService( ORB , DataFlowService , Graph_prof_debug , Graph_fdebug ) ;
82 cdebug_out << "GraphBase::Graph::Graph" << endl ;
85 GraphBase::Graph::~Graph() {
86 cdebug << "GraphBase::Graph::~Graph" << endl ;
89 void GraphBase::Graph::Set_prof_debug( int * Graph_prof_debug ,
90 ofstream * Graph_fdebug ) {
91 SetDebug( _Orb , Graph_prof_debug , Graph_fdebug ) ;
92 _Graph_prof_debug = Graph_prof_debug ;
93 _Graph_fdebug = Graph_fdebug ;
96 GraphBase::SNode * GraphBase::Graph::GetInfo() const {
97 GraphBase::SNode * Info = new GraphBase::SNode ;
98 Info->theComponentName = "" ;
99 Info->theInterfaceName = "" ;
100 Info->theName = Name() ;
101 Info->theKind = Kind() ;
102 if ( IsDataStreamNode() ) {
104 SUPERV::KindOfDataStreamTrace DataStreamTrace ;
106 ((GraphBase::StreamGraph * ) this)->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
107 Info->theTimeout = Timeout ;
108 Info->theDataStreamTrace = DataStreamTrace ;
109 Info->theDeltaTime = DeltaTime ;
111 Info->theService = *GetService() ;
112 Info->theFirstCreation = FirstCreation() ;
113 Info->theLastModification = LastModification() ;
114 Info->theEditorRelease = EditorRelease() ;
115 Info->theAuthor = Author() ;
116 Info->theContainer = "" ;
117 Info->theComment = Comment() ;
118 Info->theCoords.theX = GraphBase::ComputingNode::XCoordinate() ;
119 Info->theCoords.theY = GraphBase::ComputingNode::YCoordinate() ;
123 //----------------------------------------------------------------------
124 // Function : GetNodes
125 // Purpose : get a nodes list
126 //----------------------------------------------------------------------
127 GraphBase::ListOfSNodes * GraphBase::Graph::GetNodes() const {
128 GraphBase::ListOfSNodes * _list_nodes = new GraphBase::ListOfSNodes;
130 cdebug_in << "GraphBase::Graph::GetNodes" << endl ;
131 // All the nodes from _InNodes are taken
132 // vector< InNode *> Nodes = InNodes() ;
134 _list_nodes->resize( GraphNodesSize() );
138 GraphBase::ComputingNode * aCNode = NULL ;
139 for ( igoto = 0 ; igoto < 2 ; igoto++ ) {
140 for ( ind = 0 ; ind < GraphNodesSize() ; ind++ ) {
141 aCNode = GraphNodes( ind ) ;
142 if ( ( igoto == 0 && !aCNode->IsGOTONode() ) ||
143 ( igoto == 1 && aCNode->IsGOTONode() ) ) {
144 if ( aCNode->IsFactoryNode() ) {
145 GraphBase::FactoryNode * aFNode = (GraphBase::FactoryNode * ) aCNode ;
146 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theComponentName = CORBA::string_dup( aFNode->ComponentName());
147 (*_list_nodes)[ind].theComponentName = string( aFNode->ComponentName());
148 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theInterfaceName = CORBA::string_dup( aFNode->InterfaceName());
149 (*_list_nodes)[ind].theInterfaceName = string( aFNode->InterfaceName());
152 (*_list_nodes)[ind].theComponentName = string( "" );
153 (*_list_nodes)[ind].theInterfaceName = string( "" );
155 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theName = CORBA::string_dup( aCNode->Name() );
156 (*_list_nodes)[ind].theName = string( aCNode->Name() );
157 (*_list_nodes)[ind].theKind = aCNode->Kind();
158 if ( aCNode->IsInLineNode() || aCNode->IsMacroNode() ) {
159 GraphBase::InLineNode * aINode = (GraphBase::InLineNode * ) aCNode ;
160 (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
161 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aINode->PyFuncName() ) ;
162 (*_list_nodes)[ind].theListOfFuncName[0] = string( aINode->PyFuncName() ) ;
163 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
164 (*_list_nodes)[ind].theListOfPythonFunctions[0] = aINode->PythonFunction() ;
166 if ( aCNode->IsGOTONode() ) {
167 GraphBase::GOTONode * aGNode = (GraphBase::GOTONode * ) aCNode ;
168 (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
169 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aGNode->PyFuncName() ) ;
170 (*_list_nodes)[ind].theListOfFuncName[0] = string( aGNode->PyFuncName() ) ;
171 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
172 (*_list_nodes)[ind].theListOfPythonFunctions[0] = aGNode->PythonFunction() ;
174 if ( aCNode->IsLoopNode() ) {
175 GraphBase::LoopNode * aLNode = (GraphBase::LoopNode * ) aCNode ;
176 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aLNode->CoupledNode()->Name() ) ;
177 (*_list_nodes)[ind].theCoupledNode = string( aLNode->CoupledNode()->Name() ) ;
178 (*_list_nodes)[ind].theListOfFuncName.resize( 3 ) ;
179 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aLNode->PyFuncName() ) ;
180 (*_list_nodes)[ind].theListOfFuncName[0] = string( aLNode->PyFuncName() ) ;
181 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[1] = CORBA::string_dup( aLNode->PyMoreName() ) ;
182 (*_list_nodes)[ind].theListOfFuncName[1] = string( aLNode->PyMoreName() ) ;
183 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[2] = CORBA::string_dup( aLNode->PyNextName() ) ;
184 (*_list_nodes)[ind].theListOfFuncName[2] = string( aLNode->PyNextName() ) ;
185 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 3 ) ;
186 (*_list_nodes)[ind].theListOfPythonFunctions[0] = aLNode->PythonFunction() ;
187 (*_list_nodes)[ind].theListOfPythonFunctions[1] = aLNode->MorePythonFunction() ;
188 (*_list_nodes)[ind].theListOfPythonFunctions[2] = aLNode->NextPythonFunction() ;
190 else if ( aCNode->IsSwitchNode() ) {
191 GraphBase::SwitchNode * aSNode = (GraphBase::SwitchNode * ) aCNode ;
192 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aSNode->CoupledNode()->Name() ) ;
193 (*_list_nodes)[ind].theCoupledNode = string( aSNode->CoupledNode()->Name() ) ;
194 (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
195 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aSNode->PyFuncName() ) ;
196 (*_list_nodes)[ind].theListOfFuncName[0] = string( aSNode->PyFuncName() ) ;
197 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
198 (*_list_nodes)[ind].theListOfPythonFunctions[0] = aSNode->PythonFunction() ;
200 else if ( aCNode->IsEndLoopNode() ) {
201 GraphBase::EndOfLoopNode * aELNode = (GraphBase::EndOfLoopNode * ) aCNode ;
202 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aELNode->CoupledNode()->Name() ) ;
203 (*_list_nodes)[ind].theCoupledNode = string( aELNode->CoupledNode()->Name() ) ;
204 (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
205 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aELNode->PyFuncName() ) ;
206 (*_list_nodes)[ind].theListOfFuncName[0] = string( aELNode->PyFuncName() ) ;
207 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
208 (*_list_nodes)[ind].theListOfPythonFunctions[0] = aELNode->PythonFunction() ;
210 else if ( aCNode->IsEndSwitchNode() ) {
211 GraphBase::EndOfSwitchNode * aESNode = (GraphBase::EndOfSwitchNode * ) aCNode ;
212 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aESNode->CoupledNode()->Name() ) ;
213 (*_list_nodes)[ind].theCoupledNode = string( aESNode->CoupledNode()->Name() ) ;
214 (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
215 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aESNode->PyFuncName() ) ;
216 (*_list_nodes)[ind].theListOfFuncName[0] = string( aESNode->PyFuncName() ) ;
217 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
218 (*_list_nodes)[ind].theListOfPythonFunctions[0] = aESNode->PythonFunction() ;
220 else if ( aCNode->IsMacroNode() ) {
221 GraphBase::Graph * aGraph = (GraphBase::Graph * ) aCNode ;
222 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theCoupledNode = CORBA::string_dup( aGraph->CoupledNode()->Name() ) ;
223 (*_list_nodes)[ind].theCoupledNode = string( aGraph->CoupledNode()->Name() ) ;
224 (*_list_nodes)[ind].theListOfFuncName.resize( 1 ) ;
225 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfFuncName[0] = CORBA::string_dup( aGraph->PyFuncName() ) ;
226 (*_list_nodes)[ind].theListOfFuncName[0] = string( aGraph->PyFuncName() ) ;
227 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
228 (*_list_nodes)[ind].theListOfPythonFunctions[0] = aGraph->PythonFunction() ;
231 (*_list_nodes)[ind].theCoupledNode = string( "" ) ;
233 // (*_list_nodes)[ind].theDataStreamInArgsNumber = aCNode->DataStreamInPortsNumber() ;
234 // (*_list_nodes)[ind].theDataStreamOutArgsNumber = aCNode->DataStreamOutPortsNumber() ;
236 (*_list_nodes)[ind].theListOfInDataStreams.resize( aCNode->DataStreamInPortsNumber() ) ;
237 cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << aCNode->DataStreamInPortsNumber() << " DataStreamInPortsNumber" << endl ;
240 for ( iostream = 0 ; iostream < aCNode->GetNodeInPortsSize() ; iostream++ ) {
241 const GraphBase::InPort * anInPort ;
242 anInPort = aCNode->GetNodeInPort( iostream ) ;
243 if ( anInPort->IsDataStream() ) {
244 cdebug << "GraphBase::Graph::GetNodes In" << iostream << " " << aCNode->Name() << " " << anInPort->NodeName() << " " << anInPort->PortName()
246 (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parametertype = StringToDataStreamType( anInPort->PortType() ) ;
247 (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parametername = CORBA::string_dup( anInPort->PortName() ) ;
248 (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parameterdependency = anInPort->Dependency() ;
249 SUPERV::KindOfSchema aKindOfSchema ;
250 SUPERV::KindOfInterpolation aKindOfInterpolation ;
251 SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
252 ((GraphBase::InDataStreamPort * ) anInPort)->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
253 (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfSchema = aKindOfSchema ;
254 (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfInterpolation = aKindOfInterpolation ;
255 (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfExtrapolation = aKindOfExtrapolation ;
256 cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << anInPort->NodeName() << " " << anInPort->PortName() << " "
257 << anInPort->Dependency() << " " << aKindOfSchema << " " << aKindOfInterpolation << " " << aKindOfExtrapolation << " list_nodes "
258 << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parametername << " "
259 << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parametertype << " "
260 << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theDataStreamParameter.Parameterdependency << " "
261 << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfSchema << " "
262 << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfInterpolation << " "
263 << (*_list_nodes)[ind].theListOfInDataStreams[streamind].theKindOfExtrapolation << " " << endl ;
267 cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << anInPort->NodeName() << " " << anInPort->PortName() << " "
268 << anInPort->Kind() << " IsDataStream " << anInPort->IsDataStream() << endl ;
272 (*_list_nodes)[ind].theListOfOutDataStreams.resize( aCNode->DataStreamOutPortsNumber() ) ;
273 cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << aCNode->DataStreamOutPortsNumber() << " DataStreamOutPortsNumber" << endl ;
275 for ( iostream = 0 ; iostream < aCNode->GetNodeOutPortsSize() ; iostream++ ) {
276 const GraphBase::OutPort * anOutPort ;
277 anOutPort = aCNode->GetNodeOutPort( iostream ) ;
278 if ( anOutPort->IsDataStream() ) {
279 cdebug << "GraphBase::Graph::GetNodes Out" << iostream << " " << aCNode->Name() << " " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
281 (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parametertype = StringToDataStreamType( anOutPort->PortType() ) ;
282 (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parametername = CORBA::string_dup( anOutPort->PortName() ) ;
283 (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parameterdependency = anOutPort->Dependency() ;
284 long aNumberOfValues = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
285 (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theNumberOfValues = aNumberOfValues ;
286 cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
287 << anOutPort->Dependency() << " " << aNumberOfValues << " list_nodes "
288 << (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parametername << " "
289 << (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parametertype << " "
290 << (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theDataStreamParameter.Parameterdependency << " "
291 << (*_list_nodes)[ind].theListOfOutDataStreams[streamind].theNumberOfValues << endl ;
295 cdebug << "GraphBase::Graph::GetNodes " << aCNode->Name() << " " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
296 << anOutPort->Kind() << " IsDataStream " << anOutPort->IsDataStream() << endl ;
300 (*_list_nodes)[ind].theService = *aCNode->GetService();
301 cdebug << "GraphBase::Graph::GetNodes theService " << &(*_list_nodes)[ind].theService.ServiceName << endl ;
303 for ( i = 0 ; i < (*_list_nodes)[ind].theService.ServiceinParameter.length() ; i++ ) {
304 cdebug << " In" << i << " " << &(*_list_nodes)[ind].theService.ServiceinParameter[i].Parametername
305 << " " << (*_list_nodes)[ind].theService.ServiceinParameter[i].Parametername
306 << " " << &(*_list_nodes)[ind].theService.ServiceinParameter[i].Parametertype
307 << " " << (*_list_nodes)[ind].theService.ServiceinParameter[i].Parametertype << endl ;
309 for ( i = 0 ; i < (*_list_nodes)[ind].theService.ServiceoutParameter.length() ; i++ ) {
310 cdebug << " Out" << i << " " << &(*_list_nodes)[ind].theService.ServiceoutParameter[i].Parametername
311 << " " << (*_list_nodes)[ind].theService.ServiceoutParameter[i].Parametername
312 << " " << &(*_list_nodes)[ind].theService.ServiceoutParameter[i].Parametertype
313 << " " << (*_list_nodes)[ind].theService.ServiceoutParameter[i].Parametertype << endl ;
315 for ( i = 0 ; i < (*_list_nodes)[ind].theService.ServiceinDataStreamParameter.length() ; i++ ) {
316 cdebug << " InDataStream" << i << " " << &(*_list_nodes)[ind].theService.ServiceinDataStreamParameter[i].Parametername
317 << " " << (*_list_nodes)[ind].theService.ServiceinDataStreamParameter[i].Parametername
318 << " " << &(*_list_nodes)[ind].theService.ServiceinDataStreamParameter[i].Parametertype
319 << " " << (*_list_nodes)[ind].theService.ServiceinDataStreamParameter[i].Parametertype << endl ;
321 for ( i = 0 ; i < (*_list_nodes)[ind].theService.ServiceoutDataStreamParameter.length() ; i++ ) {
322 cdebug << " OutDataStream" << i << " " << &(*_list_nodes)[ind].theService.ServiceoutDataStreamParameter[i].Parametername
323 << " " << (*_list_nodes)[ind].theService.ServiceoutDataStreamParameter[i].Parametername
324 << " " << &(*_list_nodes)[ind].theService.ServiceoutDataStreamParameter[i].Parametertype
325 << " " << (*_list_nodes)[ind].theService.ServiceoutDataStreamParameter[i].Parametertype << endl ;
327 if ( aCNode->IsOneOfInLineNodes() ) {
328 GraphBase::InLineNode * aINode = (GraphBase::InLineNode * ) aCNode ;
329 GraphBase::LoopNode * aLNode = NULL ;
330 if ( aCNode->IsLoopNode() ) {
331 aLNode = (GraphBase::LoopNode * ) aCNode ;
332 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 3 ) ;
333 (*_list_nodes)[ind].theListOfPythonFunctions[ 0 ] = aINode->PythonFunction() ;
334 (*_list_nodes)[ind].theListOfPythonFunctions[ 1 ] = aLNode->MorePythonFunction() ;
335 (*_list_nodes)[ind].theListOfPythonFunctions[ 2 ] = aLNode->NextPythonFunction() ;
337 else if ( aCNode->IsInLineNode() || aCNode->IsGOTONode() ||
338 aCNode->IsSwitchNode() || aCNode->IsEndSwitchNode() ) {
339 (*_list_nodes)[ind].theListOfPythonFunctions.resize( 1 ) ;
340 (*_list_nodes)[ind].theListOfPythonFunctions[ 0 ] = aINode->PythonFunction() ;
343 (*_list_nodes)[ind].theFirstCreation = aCNode->FirstCreation();
344 (*_list_nodes)[ind].theLastModification = aCNode->LastModification();
345 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theEditorRelease = CORBA::string_dup( aCNode->EditorRelease());
346 (*_list_nodes)[ind].theEditorRelease = string( aCNode->EditorRelease());
347 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theAuthor = CORBA::string_dup( aCNode->Author());
348 if ( aCNode->IsFactoryNode() ) {
349 GraphBase::FactoryNode * aFNode = (GraphBase::FactoryNode * ) aCNode ;
350 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theContainer = CORBA::string_dup( aFNode->Computer());
351 (*_list_nodes)[ind].theContainer = string( aFNode->Computer());
354 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theContainer = CORBA::string_dup( "" );
355 (*_list_nodes)[ind].theContainer = string( "" );
357 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theComment = CORBA::string_dup( aCNode->Comment());
358 (*_list_nodes)[ind].theComment = string( aCNode->Comment());
359 (*_list_nodes)[ind].theCoords.theX = aCNode->XCoordinate();
360 (*_list_nodes)[ind].theCoords.theY = aCNode->YCoordinate();
364 for ( i = 0 ; i < aCNode->GetNodeInPortsSize() ; i++ ) {
365 const GraphBase::InPort * anInPort = aCNode->GetNodeInPort( i ) ;
366 if ( anInPort->IsBus() ) {
368 (*_list_nodes)[ind].theListOfParameters.resize( nports ) ;
369 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
370 (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametertype = string( anInPort->PortType() ) ;
371 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametername = CORBA::string_dup( anInPort->PortName() ) ;
372 (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theInParameter.Parametername = string( anInPort->PortName() ) ;
373 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametertype = CORBA::string_dup( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortType() ) ;
374 (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametertype = string( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortType() ) ;
375 //JR 24.02.2005 Memory Leak (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametername = CORBA::string_dup( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortName() ) ;
376 (*_list_nodes)[ind].theListOfParameters[ nports-1 ].theOutParameter.Parametername = string( aCNode->GetNodeOutPort( anInPort->PortIndex() )->PortName() ) ;
383 cdebug_out << "GraphBase::Graph::GetNodes" << endl ;
388 //----------------------------------------------------------------------
389 // Function : GetLinks
390 // Purpose : get a links list
391 //----------------------------------------------------------------------
392 GraphBase::ListOfSLinks * GraphBase::Graph::GetLinks(bool AllLinks ) const {
393 GraphBase::ListOfSLinks * _list_links = new GraphBase::ListOfSLinks;
395 // All the links from _LinksList are taken
396 // vector< InNode *> Nodes = InNodes() ;
398 cdebug_in << "Graph::GetLinks( " << AllLinks << " ) " << endl ;
401 for ( k = 0 ; k < GraphNodesSize() ; k++ ) {
402 GraphBase::ComputingNode * fromNode = GraphNodes( k ) ;
403 // cdebug << "GraphBase::Graph::GetLinks k" << k << ". :" << fromNode->Name() << endl ;
405 for ( i = 0 ; i < fromNode->GetNodeOutPortsSize() ; i++ ) {
406 const GraphBase::OutPort* fromPort = fromNode->GetNodeOutPort( i ) ;
407 // cdebug << "GraphBase::Graph::GetLinks k" << k << ". :" << fromNode->Name()
408 // << " i" << i << ". : " << fromPort->PortName() << endl ;
410 for ( j = 0 ; j < fromPort->InPortsSize() ; j++ ) {
411 const GraphBase::InPort* toPort = fromPort->InPorts( j ) ;
412 // cdebug << "GraphBase::Graph::GetLinks k" << k << ". : fromNode " << fromNode << " = "
413 // << fromNode->Name() << " i" << i << ". : fromPort " << fromPort << " = "
414 // << fromPort->PortName() << " j" << j << ". : toPort " << toPort << " = "
415 // << toPort->NodeName() << "( " << toPort->PortName() << " )" << endl ;
416 if ( toPort->IsPortConnected() ) {
417 // Desole pour ce cast mais avec les maps difficile de faire const ...
418 // const GraphBase::ComputingNode * toNode = ((GraphBase::Graph * ) this)->GetGraphNode( toPort->NodeName() ) ;
419 // cdebug << "GraphBase::Graph::GetLinks " << fromNode->Name() << " ("
420 // << fromPort->PortName() << " ) IsPortConnected" << fromPort->IsPortConnected()
421 // << " --> toNode " << toNode << " " << toPort->NodeName() << "( "
422 // << toPort->PortName() << " ) " << " " << fromPort->InPortsSize() << " ports"
424 if ( !(fromPort->IsLoop() && toPort->IsLoop() ) || AllLinks ) {
425 // cdebug << "GraphBase::Graph::GetLinks " << fromNode->Name() << " ("
426 // << fromPort->PortName() << " ) IsPortConnected" << fromPort->IsPortConnected()
427 // << " --> " << toNode->Name() << "( " << toPort->PortName() << " ) "
428 // << " " << fromPort->InPortsSize() << " ports" << endl ;
429 _list_links->resize( ind+1 );
430 //JR 23.02.2005 Memory Leak (*_list_links)[ind].FromNodeName = CORBA::string_dup( fromNode->Name() );
431 (*_list_links)[ind].FromNodeName = string( fromNode->Name() );
432 (*_list_links)[ind].FromServiceParameterName = fromPort->GetServicesParameter().Parametername;
433 //JR 23.02.2005 Memory Leak (*_list_links)[ind].ToNodeName = CORBA::string_dup( toPort->NodeName() );
434 (*_list_links)[ind].ToNodeName = string( toPort->NodeName() );
435 (*_list_links)[ind].ToServiceParameterName = toPort->GetServicesParameter().Parametername;
436 //JR 30.03.2005 (*_list_links)[ind].aLinkValue = *fromPort->Value() ;
437 (*_list_links)[ind].aLinkValue = fromPort->Value() ;
438 if ( toPort->IsEndSwitch() ) {
439 (*_list_links)[ind++].aListOfCoords = *(fromPort->Coords()) ;
442 (*_list_links)[ind++].aListOfCoords = *(toPort->Coords()) ;
447 // cdebug << "GraphBase::Graph::GetLinks " << fromNode->Name() << " "
448 // << fromPort->PortName() << " ) " << fromPort->PortStatus()
449 // << " --> " << toPort->NodeName() << "( " << toPort->PortName() << " ) "
450 // << " " << toPort->PortStatus() << " " << fromPort->InPortsSize()
451 // << " ports ignored" << endl ;
457 cdebug_out << "Graph::GetLinks( " << AllLinks << " ) " << endl ;
461 GraphBase::ListOfSGraphs * GraphBase::Graph::GetGraphs() const {
462 GraphBase::ListOfSGraphs * _list_graphs = new GraphBase::ListOfSGraphs;
467 GraphBase::SLink * GraphBase::Graph::GetLink( GraphBase::ComputingNode * aNode ,
468 GraphBase::InPort* toPort ) {
469 GraphBase::SLink * _link = new GraphBase::SLink ;
470 GraphBase::OutPort* fromPort = toPort->GetOutPort() ;
471 //JR 24.02.2005 Memory Leak _link->FromNodeName = CORBA::string_dup( fromPort->NodeName() );
472 _link->FromNodeName = string( fromPort->NodeName() );
473 _link->FromServiceParameterName = fromPort->GetServicesParameter().Parametername;
474 //JR 24.02.2005 Memory Leak _link->ToNodeName = CORBA::string_dup( toPort->NodeName() );
475 _link->ToNodeName = string( toPort->NodeName() );
476 _link->ToServiceParameterName = toPort->GetServicesParameter().Parametername;
477 //JR 30.03.2005 CORBA::Any aSPValue = *fromPort->Value() ;
478 CORBA::Any aSPValue = fromPort->Value() ;
479 _link->aLinkValue = aSPValue;
480 _link->aListOfCoords = *(toPort->Coords()) ;
483 //----------------------------------------------------------------------
484 // Function : GetDatas
485 // Purpose : get the datas list
486 //----------------------------------------------------------------------
487 GraphBase::ListOfSLinks * GraphBase::Graph::GetDatas() const {
488 GraphBase::ListOfSLinks * _list_datalinks = new GraphBase::ListOfSLinks;
491 const GraphBase::DataNode * aDataNode = this ;
493 for ( i = 0 ; i < aDataNode->GetNodeInDataNodePortsSize() ; i++ ) {
494 const GraphBase::OutPort* fromDataPort = aDataNode->GetNodeInDataNodePort( i ) ;
495 if ( GraphMacroLevel() == 0 ) {
496 if ( fromDataPort->IsDataConnected() ) {
498 //We may have SharedData as input of a DataFlow : same input for one or several
499 // input ports. Input(s) of a DataFlow match one or several output-virtual-dataport
500 for ( j = 0 ; j < fromDataPort->InPortsSize() ; j++ ) {
501 _list_datalinks->resize( ind+1 );
502 //JR 24.02.2005 Memory Leak (*_list_datalinks)[ind].FromNodeName = CORBA::string_dup( aDataNode->Name() );
503 (*_list_datalinks)[ind].FromNodeName = string( aDataNode->Name() );
504 (*_list_datalinks)[ind].FromServiceParameterName = fromDataPort->GetServicesParameter().Parametername;
505 const GraphBase::InPort* toPort = fromDataPort->InPorts( j ) ;
506 //JR 24.02.2005 Memory Leak (*_list_datalinks)[ind].ToNodeName = CORBA::string_dup( toPort->NodeName() );
507 (*_list_datalinks)[ind].ToNodeName = string( toPort->NodeName() );
508 (*_list_datalinks)[ind].ToServiceParameterName = toPort->GetServicesParameter().Parametername;
509 //JR 30.03.2005 CORBA::Any aSPValue = *fromDataPort->Value() ;
510 CORBA::Any aSPValue = fromDataPort->Value() ;
511 (*_list_datalinks)[ind].aLinkValue = aSPValue;
512 (*_list_datalinks)[ind++].aListOfCoords = *(toPort->Coords()) ;
518 return _list_datalinks ;
521 bool GraphBase::Graph::AddNode( GraphBase::ComputingNode * aNode ) {
522 cdebug_in << "GraphBase::Graph::AddNode " << (void *) aNode << " " << aNode->Name() << " " << aNode->ServiceName() << endl;
523 bool RetVal = false ;
524 int index = GetGraphNodeIndex( aNode->Name() ) ;
526 cdebug << "GraphBase::Graph::AddNode " << _GraphNodesSize << " nodes + 1" << endl ;
527 _GraphNodes.resize( _GraphNodesSize+1 ) ;
528 _GraphNodes[ _GraphNodesSize ] = aNode ;
529 SetGraphNodeIndex( aNode->Name() , _GraphNodesSize ) ;
530 _GraphNodesSize += 1 ;
531 if ( SetServiceOfMap( (GraphBase::Service * ) aNode ) ) {
532 cdebug << "Graph::AddNode SetServiceOfMap " << aNode->ServiceName() << " in MapOfServices" << endl ;
535 cdebug << "Graph::AddNode SetServiceOfMap " << aNode->ServiceName()
536 << " was already in MapOfServices" << endl ;
541 cdebug << "GraphBase::Graph::AddNode " << _GraphNodesSize << " Known nodes :" << endl ;
542 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
543 const GraphBase::ComputingNode * aKnownNode = GetGraphNode( i ) ;
545 cdebug << i << ". " << aKnownNode->Name() << " " << _MapOfGraphNodes[ GetGraphNode( i )->Name() ] - 1 << endl ;
548 cdebug << i << ". ERROR" << endl ;
551 aNode->GraphOfNode( this ) ;
553 cdebug_out << "GraphBase::Graph::AddNode " << _GraphNodesSize << " Nodes. "
554 << aNode->ServiceName() << endl;
558 bool GraphBase::Graph::ReNameNode( const char* OldNodeName ,
559 const char* NewNodeName ) {
560 cdebug_in << "GraphBase::Graph::ReNameNode (" << OldNodeName << " , " << NewNodeName << ") "
565 GraphBase::ComputingNode * anOldNode = GetChangeGraphNode( OldNodeName ) ;
566 for ( i = 0 ; i < anOldNode->LinkedNodesSize() ; i++ ) {
567 cdebug << "LinkedNode " << i << " " << anOldNode->LinkedNodes( i )->Name() << endl ;
570 if ( !strcmp( OldNodeName , NewNodeName ) ) {
572 else if ( strcmp( Name() , OldNodeName ) ) {
573 int index = GetGraphNodeIndex( OldNodeName ) ;
574 int newindex = GetGraphNodeIndex( NewNodeName ) ;
575 if ( index >= 0 && index < _GraphNodesSize &&
576 ( newindex < 0 || newindex > _GraphNodesSize ) ) {
577 DelGraphNodeIndex( _GraphNodes[ index ]->Name() ) ;
578 _GraphNodes[ index ]->Name( NewNodeName ) ;
579 //JR 29.06.2005 Debug ???
580 // SetGraphNodeIndex( NewNodeName , index ) ;
581 SetGraphNodeIndex( _GraphNodes[ index ]->Name() , index ) ;
583 GraphBase::ComputingNode * aNode = GetChangeGraphNode( index ) ;
584 // Update 'ToNode's Map from 'aNode'
585 cdebug << "Graph::ReNameNode " << aNode->Name() << "/" << OldNodeName << " LinkedNodesSize : "
586 << aNode->LinkedNodesSize() << endl ;
587 for ( i = 0 ; i < aNode->LinkedNodesSize() ; i++ ) {
588 GraphBase::StreamNode * ToNode = aNode->LinkedNodes( i ) ;
589 ToNode->ReNameLinkedFromNode( OldNodeName , NewNodeName ) ;
591 // Rename in _MapOfLinkedNodes of 'FromNode'
592 cdebug << "Graph::ReNameNode " << aNode->Name() << "/" << OldNodeName
593 << " LinkedFromNodesSize : " << aNode->LinkedFromNodesSize() << endl ;
594 for ( i = 0 ; i < aNode->LinkedFromNodesSize() ; i++ ) {
595 GraphBase::StreamNode * FromNode = aNode->LinkedFromNodes( i ) ;
596 if ( FromNode->GetLinkedNodeIndex( OldNodeName ) >= 0 ) {
597 FromNode->ReNameLinkedNode( OldNodeName , NewNodeName ) ;
600 FromNode->ReNameStreamLinkedNode( OldNodeName , NewNodeName ) ;
603 // Inports 'anInPort' of 'aNode'
604 for ( i = aNode->GetNodeInPortsSize()-1 ; i >= 0 ; i-- ) {
605 GraphBase::InPort * anInPort = aNode->GetChangeNodeInPort( i ) ;
606 // OutPort 'anOutPort' linked to 'anInPort'
607 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
608 cdebug << i << ". " << aNode->Name() << "/" << OldNodeName
609 << " GraphBase::Graph::ReNameNode of LinkedNode : from " ;
611 cdebug << anOutPort->NodeName() << "( " << anOutPort->PortName() << " )" ;
614 cdebug << "without link" ;
616 cdebug << " to " << i << ". " << anInPort->PortName() << " of " << NewNodeName
617 << " OldNodeName " << OldNodeName ;
618 if ( !anInPort->IsNotConnected() ) {
619 if ( anOutPort->IsDataConnected() ) {
620 cdebug << " fromDataConnected " << anOutPort->NodeName() << endl ;
623 // Node 'FromNode' of 'anOutPort'
624 GraphBase::ComputingNode * FromNode ;
625 if ( strcmp( anOutPort->NodeName() , Name() ) ) {
626 FromNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
631 cdebug << " fromConnected " << anOutPort->NodeName() << endl ;
633 char* OldNodePortName = new char[ strlen( OldNodeName ) +
634 strlen( aNode->GetChangeNodeInPort( i )->PortName() ) + 3 ] ;
635 char* NewNodePortName = new char[ strlen( NewNodeName ) +
636 strlen( aNode->GetChangeNodeInPort( i )->PortName() ) + 3 ] ;
637 strcpy( OldNodePortName , OldNodeName ) ;
638 strcat( OldNodePortName , "__" ) ;
639 strcat( OldNodePortName , aNode->GetChangeNodeInPort( i )->PortName() ) ;
640 strcpy( NewNodePortName , NewNodeName ) ;
641 strcat( NewNodePortName , "__" ) ;
642 strcat( NewNodePortName , aNode->GetChangeNodeInPort( i )->PortName() ) ;
643 RetVal = anOutPort->ReNameInPort( OldNodePortName , NewNodePortName ) ;
644 delete [] OldNodePortName ;
645 delete [] NewNodePortName ;
650 cdebug << " not connected" << endl ;
654 //JR 02.02.2005 DEBUG : ReName in the CoupledNode was missing
655 if ( aNode->IsLoopNode() || aNode->IsEndLoopNode() ||
656 aNode->IsSwitchNode() || aNode->IsEndSwitchNode() ) {
657 GraphBase::GOTONode * theCoupledNode = NULL ;
658 theCoupledNode = (GraphBase::GOTONode * ) ((GraphBase::GOTONode * ) aNode)->CoupledNode() ;
659 theCoupledNode->CoupledNodeName( aNode->Name() ) ;
661 else if ( aNode->IsInLineNode() ) {
662 GraphBase::OutPort * anOutPort = aNode->GetNodeInGate()->GetOutPort() ;
664 GraphBase::ComputingNode * aLinkedNode ;
665 aLinkedNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
666 if ( aLinkedNode->IsGOTONode() ) {
667 ((GraphBase::GOTONode * ) aLinkedNode)->CoupledNodeName( aNode->Name() ) ;
673 cdebug << "ERROR Node not found or conflicting NodeName" << endl ;
678 cdebug << "ReNameNode with same name." << endl ;
679 // RetVal = Name( NewNodeName ) ;
683 cdebug << "Graph::ReNameNode " << _GraphNodesSize << " known nodes" << endl;
684 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
685 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
687 map< string , int >::iterator aMapOfGraphNodesIterator ;
689 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
690 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
691 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first << " --> "
692 << aMapOfGraphNodesIterator->second << " - 1" << endl ;
696 cdebug_out << "GraphBase::Graph::ReNameNode RetVal " << RetVal << endl;
700 bool GraphBase::Graph::RemoveNode( const char* aNodeName ) {
701 cdebug_in << "Graph::RemoveNode (" << aNodeName << ") " << endl;
703 bool RetVal = false ;
704 int index = GetGraphNodeIndex( aNodeName ) ;
705 GraphBase::ComputingNode * aNode = NULL ;
707 aNode = GetChangeGraphNode( index ) ;
710 cdebug << "Graph::RemoveNode " << aNode->Name() << " : " << aNode->GetNodeInPortsSize()
711 << " InPorts " << aNode->GetNodeOutPortsSize() << " OutPorts "
712 << aNode->LinkedNodesSize() << " LinkedNodes " << aNode->LinkedFromNodesSize()
713 << " LinkedFromNodes IsEndSwitchNode " << aNode->IsEndSwitchNode()
714 << " ConnectedInPortsNumber " << aNode->ConnectedInPortsNumber() << endl ;
715 for ( i = 0 ; i < aNode->LinkedNodesSize() ; i++ ) {
716 cdebug << " LinkedNode" << i << ". " << aNode->LinkedNodes( i ) << " "
717 << aNode->LinkedNodes( i )->Name() << endl ;
719 if ( !aNode->IsEndLoopNode() ) { // The LoopNode is already deleted
720 for ( i = 0 ; i < aNode->LinkedFromNodesSize() ; i++ ) {
721 cdebug << " LinkedFromNode" << i << ". " << aNode->LinkedFromNodes( i ) << " "
722 << aNode->LinkedFromNodes( i )->Name() << endl ;
726 //JR 24.03.2005 : Debug : CoupledNode field of GOTONodes was not erased
727 if ( aNode->IsInLineNode() ) {
728 GraphBase::OutPort * anOutPort = aNode->GetNodeInGate()->GetOutPort() ;
730 GraphBase::ComputingNode * aLinkedNode ;
731 aLinkedNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
732 if ( aLinkedNode->IsGOTONode() ) {
733 cdebug << "Graph::RemoveNode erase CoupledNode " << aLinkedNode->Name() << endl ;
734 ((GraphBase::GOTONode * ) aLinkedNode)->CoupledNode( NULL ) ;
735 ((GraphBase::GOTONode * ) aLinkedNode)->CoupledNodeName( "" ) ;
739 if ( !aNode->IsEndSwitchNode() ) {
740 if ( aNode->GetNodeInPortsSize() ) {
741 for ( i = aNode->GetNodeInPortsSize()-1 ; i >= 0 ; i-- ) {
742 GraphBase::InPort * anInPort = aNode->GetChangeNodeInPort( i ) ;
743 cdebug << "Graph::RemoveNode InPort" << i << ". " << aNodeName << "( "
744 << anInPort->PortName() << ") " << anInPort->PortStatus() << " <-- " ;
745 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
746 if ( anOutPort && !( aNode->IsEndLoopNode() && anInPort->IsLoop() ) ) {
747 cdebug << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
748 << anOutPort->PortStatus() ;
751 if ( !anInPort->IsNotConnected() ) {
752 GraphBase::ComputingNode * FromNode = NULL ;
754 if ( anOutPort->IsDataConnected() || anOutPort->IsExternConnected() ) {
755 cdebug << " Data/Extern ignored" << endl ;
758 FromNode = GetChangeGraphNode( anOutPort->NodeName() ) ;
761 cdebug << "FromNode " << FromNode->Name() << " LinkedNodesSize "
762 << FromNode->LinkedNodesSize() << " and " << aNode->Name()
763 << " LinkedFromNodesSize " << aNode->LinkedFromNodesSize() << endl ;
764 // asv : 04.11.04 : IsGOTO -> IsOneOfGOTO, I believe that it fixes the bug 7120.
765 // JR 05.01.05 : IsOneOfGOTO is not ok : I shall check the bug 7120 with IsGOTONode
766 // if ( !FromNode->IsOneOfGOTONodes() ) {
767 // if ( !FromNode->IsGOTONode() ) {
768 if ( !FromNode->IsGOTONode() &&
769 !( FromNode->IsEndLoopNode() && anInPort->IsLoop() ) ) {
770 if ( anInPort->IsDataStream() ) {
771 RetVal = FromNode->RemoveStreamLinkedNode( aNode ) ;
774 RetVal = FromNode->RemoveLinkedNode( aNode ) ;
777 cdebug << "Graph::RemoveNode anOutPort->RemoveLinkedNode Error RetVal "
783 RetVal = anOutPort->RemoveInPort( anInPort ) ;
785 cdebug << "Graph::RemoveNode anOutPort->RemoveInPort( anInPort ) Error RetVal "
800 // Special case of EndSwitchNodes : each Input port must be multi-connected.
801 // There is one link for each branch of the switch
802 // But in GraphBase::InPort there is only one field GraphBase::OutPort *
803 // At execution time there is no problem because only one branch of the switch
804 // may be executed and the Executor set the right OutPort in the field
805 // GraphBase::OutPort * of each InPort of the EndSwitchNode
806 // But here we must remove that node EndSwitch from the LinkedNodes field of
807 // terminal nodes of all branches.
808 // And also in the OutPorts of that terminal nodes of branches we must remove
809 // references to InPorts of the EndSwitchNode.
811 // Explore LinkedFromnodes of the EndSwitchNode :
812 for ( i = aNode->LinkedFromNodesSize() - 1 ; i >= 0 ; i-- ) {
813 GraphBase::ComputingNode * aLinkedFromNode = (GraphBase::ComputingNode * ) aNode->LinkedFromNodes( i ) ;
814 cdebug << aLinkedFromNode->Name() << " linked to " << aNode->Name() << endl ;
816 for ( j = aLinkedFromNode->GetNodeOutPortsSize() - 1 ; j >= 0 ; j-- ) {
817 GraphBase::OutPort * anOutPort = aLinkedFromNode->GetChangeNodeOutPort( j ) ;
818 cdebug << "Graph::RemoveNode OutPort" << j << ". Remove " << anOutPort->InPortsSize()
819 << " InPortsof OutPort : " << anOutPort->NodeName() << "( "
820 << anOutPort->PortName() << ") "
821 << anOutPort->PortStatus() << " :" << endl ;
823 for ( k = anOutPort->InPortsSize() - 1 ; k >= 0 ; k-- ) {
824 GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
825 if ( !strcmp( anInPort->NodeName() , aNode->Name() ) ) {
826 // InPort of the EndSwitchNode
827 cdebug << " to InPort" << j << ". " << anInPort->NodeName() << "( "
828 << anInPort->PortName() << ") "
829 << anInPort->PortStatus() << endl ;
830 anInPort->RemoveOutPort() ;
831 if ( anOutPort->IsDataStream() ) {
832 aLinkedFromNode->RemoveStreamLinkedNode( aNode ) ;
835 // false ==> No error for aNode->LinkedFromNode()
836 RetVal = aLinkedFromNode->RemoveLinkedNode( aNode , false ) ;
838 cdebug << "Graph::RemoveNode aLinkedFromNode->RemoveLinkedNode Error RetVal "
843 // the InPort of the EndSwitchNode from that OutPort was already removed by
844 // anInPort->RemoveOutPort done above :
846 RetVal = anOutPort->RemoveInPort( anInPort ) ;
848 cdebug << "Graph::RemoveNode anOutPort->RemoveInPort( anInPort ) Error RetVal "
860 for ( i = aNode->GetNodeOutPortsSize() - 1 ; i >= 0 ; i-- ) {
861 GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( i ) ;
862 cdebug << "Graph::RemoveNode OutPort" << i << ". Remove " << anOutPort->InPortsSize()
863 << " InPortsof OutPort : " << anOutPort->NodeName() << "( "
864 << anOutPort->PortName() << ") "
865 << anOutPort->PortStatus() << " :" << endl ;
867 for ( j = anOutPort->InPortsSize() - 1 ; j >= 0 ; j-- ) {
868 GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( j ) ;
869 GraphBase::ComputingNode * ToNode = NULL ;
870 cdebug << " to InPort" << j << ". " << anInPort->NodeName() << "( "
871 << anInPort->PortName() << ") "
872 << anInPort->PortStatus() ;
873 if ( anInPort->IsExternConnected() ) {
874 cdebug << " ExternConnected ignored" << endl ;
878 ToNode = GetChangeGraphNode( anInPort->NodeName() ) ;
881 RetVal = anInPort->RemoveOutPort() ;
882 // JR 04.02.2005 : Bug if it is a link to an EndSwitchNode. The InPort may be multiple linked !!!
885 cdebug << "Graph::RemoveNode anOutPort->RemoveOutPort Error RetVal " << RetVal
889 if ( ( aNode->IsGOTONode() && ToNode->IsOneOfInLineNodes() ) ||
890 ( aNode->IsEndLoopNode() && ToNode->IsLoopNode( ) ) ) {
892 else if ( anOutPort->IsDataStream() ) {
893 RetVal = aNode->RemoveStreamLinkedNode( ToNode ) ;
896 RetVal = aNode->RemoveLinkedNode( ToNode ) ;
899 cdebug << "Graph::RemoveNode anOutPort->RemoveLinkedNode Error RetVal " << RetVal
903 // the InPort of the EndSwitchNode from that OutPort was already removed by
904 // anInPort->RemoveOutPort done above :
906 RetVal = anOutPort->RemoveInPort( anInPort ) ;
908 cdebug << "Graph::RemoveNode anOutPort->RemoveInPort( anInPort ) Error RetVal "
913 if ( ToNode->IsEndSwitchNode() ) {
916 for ( i = 0 ; i < ToNode->LinkedFromNodesSize() ; i++ ) {
917 GraphBase::StreamNode * fromNode = ToNode->LinkedFromNodes( i ) ;
918 // Not the node that we are deleting ... :
919 if ( strcmp( fromNode->Name() , aNode->Name() ) ) {
921 for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
922 GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
924 for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
925 if ( strcmp( ToNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
926 if ( strcmp( anInPort->PortName() , fromOutPort->InPorts( k )->PortName() ) == 0 ) {
927 // Restore an OutPort in the InPort
928 anInPort->ChangeOutPort( fromOutPort ) ;
929 cdebug << "Graph::RemoveNode reestablish " << fromOutPort->NodeName() << "( "
930 << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
931 << ToNode->Name() << "( " << anInPort->PortName() << " )"
932 << anInPort->Kind() << " " << anInPort->PortStatus() << endl;
951 cdebug << "Error RetVal " << RetVal << endl ;
956 if ( aNode->LinkedNodesSize() || aNode->LinkedFromNodesSize() ) {
957 cdebug << "Graph::RemoveNode ERROR LinkedNodesSize " << aNode->LinkedNodesSize()
958 << " LinkedFromNodesSize " << aNode->LinkedFromNodesSize() << endl ;
961 cdebug << "Graph::RemoveNode " << aNode->Name() << " : " << aNode->GetNodeInPortsSize()
962 << " InPorts " << aNode->GetNodeOutPortsSize() << " OutPorts "
963 << aNode->LinkedNodesSize() << " LinkedNodes " << aNode->LinkedFromNodesSize()
964 << " LinkedFromNodes " << endl ;
965 for ( i = 0 ; i < aNode->LinkedNodesSize() ; i++ ) {
966 cdebug << " LinkedNode" << i << ". " << aNode->LinkedNodes( i ) << " "
967 << aNode->LinkedNodes( i )->Name() << endl ;
969 for ( i = 0 ; i < aNode->LinkedFromNodesSize() ; i++ ) {
970 cdebug << " LinkedFromNode" << i << ". " << aNode->LinkedFromNodes( i ) << " "
971 << aNode->LinkedFromNodes( i )->Name() << endl ;
973 // Delete of aNode from the Graph :
974 // The LoopNode is needed by the delete of the EndLoopNode. So the LoopNode will be deleted
975 // when the EndLoopNode is deleted. It is the same for SwitchNode & EndSwitchNode
976 if ( RetVal && !aNode->IsLoopNode() && !aNode->IsSwitchNode() ) {
977 GraphBase::InLineNode * theCoupledNode = NULL ;
978 char * theCoupledNodeName = NULL ;
979 int CoupledIndex = -1 ;
980 if ( aNode->IsEndLoopNode() || aNode->IsEndSwitchNode() ) {
981 theCoupledNodeName = ((GraphBase::GOTONode * ) aNode)->CoupledNodeName() ;
982 theCoupledNode = ((GraphBase::GOTONode * ) aNode)->CoupledNode() ;
984 cdebug << "Graph::RemoveNode Node" << index << " " << _GraphNodes[ index ]->Name()
985 << " will be deleted" << endl ;
987 _GraphNodesSize -= 1 ;
988 for ( i = index ; i < _GraphNodesSize ; i++ ) {
989 _GraphNodes[ i ] = _GraphNodes[ i+1 ] ;
990 SetGraphNodeIndex( _GraphNodes[ i ]->Name() , i ) ;
992 _GraphNodes.resize( _GraphNodesSize+1 ) ;
993 _MapOfGraphNodes.erase( aNodeName ) ;
995 // Delete of the LoopNode of that EndLoopNode or of the SwitchNode of that EndSwitchNode :
996 if ( theCoupledNode ) {
997 //JR 02.02.2005 DEBUG : CoupledIndex must be here after the delete of aNode (not before)
998 CoupledIndex = GetGraphNodeIndex( theCoupledNodeName ) ;
999 cdebug << "Graph::RemoveNode CoupledNode" << CoupledIndex << " "
1000 << _GraphNodes[ CoupledIndex ]->Name() << " will be deleted" << endl ;
1001 delete theCoupledNode ;
1002 _GraphNodesSize -= 1 ;
1003 for ( i = CoupledIndex ; i < _GraphNodesSize ; i++ ) {
1004 _GraphNodes[ i ] = _GraphNodes[ i+1 ] ;
1005 SetGraphNodeIndex( _GraphNodes[ i ]->Name() , i ) ;
1007 _GraphNodes.resize( _GraphNodesSize+1 ) ;
1008 _MapOfGraphNodes.erase( theCoupledNodeName ) ;
1014 cdebug << "Graph::RemoveNode Node not found ERROR " << index << endl ;
1018 cdebug << "Graph::RemoveNode " << _GraphNodesSize << " known nodes" << endl;
1019 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
1020 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
1022 map< string , int >::iterator aMapOfGraphNodesIterator ;
1024 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
1025 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
1026 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first << " --> "
1027 << aMapOfGraphNodesIterator->second << " - 1" << endl ;
1031 cdebug_out << "Graph::RemoveNode " << RetVal << endl;
1035 bool GraphBase::Graph::AddLink( const char* FromNodeName ,
1036 const char* FromServiceParameterName ,
1037 const char* ToNodeName ,
1038 const char* ToServiceParameterName ) {
1039 // , const CORBA::Any aValue ) {
1042 cdebug_in << "GraphBase::Graph::AddLink(" << FromNodeName << "("
1043 << FromServiceParameterName << ") ---> " << ToNodeName << "("
1044 << ToServiceParameterName << ") , aValue )" << endl;
1046 GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
1047 GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1049 GraphBase::OutPort *fromPort = NULL ;
1050 GraphBase::InPort *toPort = NULL ;
1053 // asv : 29.12.04 : as I understand, replacement of "InitLoop" by "DoLoop" was
1054 // done by JR in order to keep old graphs and batch test scripts working after change
1055 // of special Loop's port name from "InitLoop" to "DoLoop". I suppose, it is not
1056 // needed, all old graphs and tests must be changed to use "DoLoop" name for addressing
1057 // this port.. It we don't do it, ANY port with "InitLoop" name will be replaced by "DoLoop"
1058 // and it can cause unexpected bugs in future... So I comment out the replacement code.
1059 //if ( strcmp( FromServiceParameterName , "InitLoop" ) ) {
1060 //JR 12.01.05 : Yes the test is not good ; now I test that PortName only in LoopNodes ==>
1061 // + old graphs will runs normally (it is not possible to ask CEA to edit their graphs)
1062 // + in old graphs "InitLoop" and "DoLoop" were reserved parameter names (but not controlled)
1063 // + in new graphs, I have added a control at port creation of that names : they are refused
1064 if ( !(fromNode->IsLoopNode() && strcmp( FromServiceParameterName , "InitLoop" ) == 0 ) ) {
1065 fromPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1068 fromPort = fromNode->GetChangeOutPort( "DoLoop" ) ;
1071 cdebug << "ERROR AddLink fromPort " << FromServiceParameterName << " FromNode("
1072 << FromNodeName << ") not found." << endl ;
1076 cdebug << "ERROR AddLink FromNode " << FromNodeName << " not found." << endl ;
1079 // see comment above
1080 // if ( strcmp( ToServiceParameterName , "InitLoop" ) ) {
1081 if ( !(toNode->IsLoopNode() && strcmp( ToServiceParameterName , "InitLoop" ) == 0 ) ) {
1082 toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1085 toPort = toNode->GetChangeInPort( "DoLoop" ) ;
1088 cdebug << "ERROR AddLink toPort " << ToServiceParameterName << " ToNode("
1089 << ToNodeName << ") not found." << endl ;
1093 cdebug << "ERROR AddLink toNode " << ToNodeName << " not found." << endl ;
1096 RetVal = AddLink( fromNode , fromPort , toNode , toPort ) ;
1099 if ( fromPort->IsGate() && toPort->IsGate() ) {
1101 aValue <<= (long ) 1 ;
1102 fromPort->SetValue( aValue ) ;
1105 // const CORBA::Any * aDataValue = new CORBA::Any( aValue ) ;
1106 // fromPort->Value( aDataValue ) ;
1108 // fromPort->PortStatus( DataConnected );
1111 cdebug_out << "GraphBase::Graph::AddLink " << RetVal << endl;
1115 bool GraphBase::Graph::AddLink( GraphBase::ComputingNode *fromNode ,
1116 GraphBase::OutPort *fromPort ,
1117 GraphBase::ComputingNode *toNode ,
1118 GraphBase::InPort *toPort ) {
1122 cdebug << "ERROR AddLink fromNode not found." << endl ;
1126 cdebug << "ERROR AddLink fromPort not found." << endl ;
1131 cdebug << "ERROR AddLink toNode not found." << endl ;
1135 cdebug << "ERROR AddLink toPort not found." << endl ;
1138 if ( ( fromPort->IsDataStream() && !toPort->IsDataStream() ) ||
1139 ( !fromPort->IsDataStream() && toPort->IsDataStream() ) ) {
1140 cdebug << "AddLink fromPort/toPort Stream/Flow. ERROR" << endl ;
1143 if ( fromPort->IsDataStream() && fromPort->Dependency() == SALOME_ModuleCatalog::DATASTREAM_TEMPORAL &&
1144 toPort->Dependency() == SALOME_ModuleCatalog::DATASTREAM_ITERATIVE ) {
1145 cdebug << "AddLink fromPort/toPort Stream DATASTREAM_TEMPORAL --> DATASTREAM_ITERATIVE. ERROR" << endl ;
1149 cdebug_in << "Graph::AddLink( " << fromNode->Name() << "("
1150 << fromPort->PortName() << " " << fromPort->PortStatus() << ") " << fromPort->Kind()
1151 << " ---> " << toNode->Name() << "(" << toPort->PortName() << " " << toPort->PortStatus()
1152 << ") " << toPort->Kind() << " )" << endl;
1153 ostringstream LinkStrError ;
1154 LinkStrError << "Creation of link from " << fromNode->Name() << "( "
1155 << fromPort->PortName() << " " << fromPort->PortStatus() << " " << fromPort->Kind()
1156 << " ) ---> " << toNode->Name() << "( " << toPort->PortName() << " "
1157 << toPort->PortStatus() << " " << toPort->Kind() << " ) :\n" ;
1158 if ( fromPort->IsDataConnected() || fromPort->IsExternConnected() ) {
1159 if ( !fromPort->RemoveInPort() ) { // There is only one ===> RemoveOutPort()
1160 cdebug_out << "GraphBase::Graph::AddLink in OutPort ( " << fromNode->Name() << "("
1161 << fromPort->PortName() << " " << fromPort->PortStatus()
1162 << ") RemoveInPort ERROR InPortsSize " << fromPort->InPortsSize() << endl ;
1166 if ( toPort->IsDataConnected() || toPort->IsExternConnected() ) {
1167 if ( !toPort->GetOutPort()->RemoveInPort() ) { // There is only one ===> RemoveOutPort()
1168 cdebug_out << "GraphBase::Graph::AddLink in InPort connected to the OutPort ( "
1169 << toNode->Name() << "(" << toPort->PortName() << " " << toPort->PortStatus()
1170 << ") RemoveInPort ERROR InPortsSize " << toPort->GetOutPort()->InPortsSize()
1175 else if ( toPort->IsPortConnected() && !toNode->IsEndSwitchNode() ) {
1176 if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
1177 toPort->GetOutPort()->PortName() ,
1178 toNode->Name() , toPort->PortName() ) ) {
1179 cdebug_out << "RemoveLink(AddLink) toPort->GetOutPort()->NodeName() RemoveLink Error." << endl ;
1184 if ( !fromNode->IsDataFlowNode() && !fromNode->IsDataStreamNode() &&
1185 !toNode->IsDataFlowNode() && !toNode->IsDataStreamNode() &&
1186 toPort->GetOutPort() ) {
1187 //JR Debug 15.06.2005 : the case of multiple links to EndSwitchNode was missing :
1188 if ( toNode->IsEndSwitchNode() && fromPort->GetInPort( toPort ) == toPort ) {
1189 LinkStrError << "Link already exists.\n" ;
1190 SetMessages( LinkStrError.str() ) ;
1191 cdebug << "Link already exists" << endl ;
1192 cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1195 else if ( !strcmp( toPort->GetOutPort()->NodePortName() ,
1196 fromPort->NodePortName() ) ) {
1197 LinkStrError << "Link already exists.\n" ;
1198 SetMessages( LinkStrError.str() ) ;
1199 cdebug << "Link already exists" << endl ;
1200 cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1203 else if ( toPort->IsDataConnected() || toPort->IsExternConnected() ) {
1204 toPort->GetOutPort()->RemoveInPort( toPort ) ; //dbg
1206 else if ( fromNode->IsGOTONode() ) {
1207 if ( !RemoveLink( toPort->GetOutPort()->NodeName() ,
1208 toPort->GetOutPort()->PortName() ,
1209 toNode->Name() , toPort->PortName() ) ) {
1210 cdebug << "RemoveLink(AddLink) Error."
1212 cdebug_out << "GraphBase::Graph::AddLink" << endl;
1215 if ( fromPort->InPortsSize() ) {
1216 if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1217 fromPort->ChangeInPorts(0)->NodeName() ,
1218 fromPort->ChangeInPorts(0)->PortName() ) ) {
1219 cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
1220 cdebug_out << "GraphBase::Graph::AddLink" << endl;
1226 // JR 17.01.2005 : toPort is already linked : RemoveLink
1227 else if ( !toNode->IsEndSwitchNode() ) {
1228 // else if ( !toNode->IsEndSwitchNode() ||
1229 // ( toNode->IsEndSwitchNode() && toPort->IsGate() ) ) {
1230 //JR Debug : the fromPort was wrong !
1231 // if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1232 if ( !RemoveLink( toPort->GetOutPort()->NodeName() , toPort->GetOutPort()->PortName() ,
1233 toNode->Name() , toPort->PortName() ) ) {
1234 cdebug << "RemoveLink(AddLink) toNode->IsEndSwitchNode Error." << endl ;
1235 cdebug_out << "GraphBase::Graph::AddLink" << endl;
1239 //JR 15.06.2005 : disabled : GraphSwitchBranchGates ...
1240 // else if ( fromNode->IsSwitchNode() && toNode->IsEndSwitchNode() && !toPort->IsGate() ) {
1241 // cdebug << "fromNode->IsSwitchNode() && toNode->IsEndSwitchNode toPort(NotGate)Error."
1243 // LinkStrError << "Link from SwitchNode to EndSwitchNode is not allowed.\n" ;
1244 // SetMessages( LinkStrError.str() ) ;
1245 // cdebug << "Graph::AddLink ERROR Link from SwitchNode to EndSwitchNode is not allowed."
1247 // cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1250 //JR 15.06.2005 : SwitchNode(Default) may be only linked to EndSwitchNode(Default)
1252 //JR Debug 15.02.2005 : Not multiple links in that case except if toPort is the DefaultPort
1253 else if ( fromNode->IsSwitchNode() && fromPort->IsGate() &&
1254 !toNode->IsEndSwitchNode() ) {
1255 LinkStrError << "Link from SwitchNode(Default) is allowed only to EndSwitchNode(Default).\n" ;
1256 SetMessages( LinkStrError.str() ) ;
1257 cdebug << "SwitchNode(Default) may be only linked to EndSwitchNode(Default) AddLink Error."
1259 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1264 //JR 24.03.2005 : No Link between OutPort of SwitchNode to InPort of EndSwitchNode except if
1265 // they have the same name for a special case :
1266 // Switch with no branch ==> Default is applied always : GraphSyrControl example
1267 //JR 22.06.2005 : Enhancement of the behaviour :
1268 // For the DefaultBranch, if we have same PortsNames, Values are automatically
1270 // But for the DefaultBranch, if we have NOT same PortsNames, we may create links.
1271 // Look at GraphSyrControlAve* ...
1273 else if ( fromNode->IsSwitchNode() && !fromPort->IsGate() &&
1274 toNode->IsEndSwitchNode() && !toPort->IsGate() &&
1275 strcmp( fromPort->PortName() , toPort->PortName() ) ) {
1276 LinkStrError << "Link from SwitchNode to EndSwitchNode with different PortNames is not allowed.\n" ;
1277 SetMessages( LinkStrError.str() ) ;
1278 cdebug << "fromNode->IsSwitchNode() && toNode->IsEndSwitchNode with different PortNames Error."
1280 cdebug_out << "GraphBase::Graph::AddLink" << endl;
1284 else if ( fromNode->IsGOTONode() && fromPort->InPortsSize() ) {
1285 if ( !RemoveLink( fromNode->Name() , fromPort->PortName() ,
1286 fromPort->ChangeInPorts(0)->NodeName() ,
1287 fromPort->ChangeInPorts(0)->PortName() ) ) {
1288 cdebug << "RemoveLink(AddLink) fromNode->IsGOTONode Error." << endl ;
1289 cdebug_out << "GraphBase::Graph::AddLink" << endl;
1293 else if ( ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) &&
1294 ( toPort->IsDataConnected() || toPort->IsExternConnected() ) ) {
1295 fromPort->RemoveInPort( toPort ) ; //dbg
1297 else if ( ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) &&
1298 ( fromPort->IsDataConnected() || fromPort->IsExternConnected() ) ) {
1299 fromPort->RemoveInPort() ; // There is only one
1303 // JR 12.01.2005 : an OutPort of a SwitchNode connected to a Gate can be connected only to Gate
1304 if ( !toNode->IsDataFlowNode() && !toNode->IsDataStreamNode() &&
1305 fromNode->IsSwitchNode() && fromPort->IsSwitch() && !toPort->IsGate() ) {
1306 LinkStrError << "Link from SwitchNode Port linked to a Gate may be connected only to Gates.\n" ;
1307 SetMessages( LinkStrError.str() ) ;
1308 cdebug << "toPort->AddLink Error( fromPort->IsSwitch() && !toPort->IsGate())." << endl ;
1309 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1312 //JR 11.02.2005 : SwitchNode(Default) may be only linked to EndSwitchNode(Default)
1313 // SwitchNode(Param) may be linked to EndSwitchNode(Param)
1314 // SwitchNode(Param-UserDefault) may be linked to EndSwitchNode(Default)
1315 else if ( fromNode->IsSwitchNode() && toNode->IsEndSwitchNode() &&
1316 !( ( fromPort->IsGate() && toPort->IsGate() ) ||
1317 ( !fromPort->IsGate() ) ) ) {
1318 // ( !fromPort->IsGate() && !toPort->IsGate() ) ) ) {
1319 LinkStrError << "Link from SwitchNode to EndSwitchNode : different kinds of ports not allowed.\n" ;
1320 SetMessages( LinkStrError.str() ) ;
1321 cdebug << "Link ERROR from SwitchNode to EndSwitchNode : different kinds of ports not allowed."
1323 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1326 //JR 15.06.2005 : SwitchNode(Default) may be only linked to EndSwitchNode(Default)
1327 else if ( fromNode->IsSwitchNode() && fromPort->IsGate() &&
1328 !toNode->IsEndSwitchNode() ) {
1329 LinkStrError << "Link from SwitchNode(Default) is allowed only to EndSwitchNode(Default).\n" ;
1330 SetMessages( LinkStrError.str() ) ;
1331 cdebug << "SwitchNode(Default) may be only linked to EndSwitchNode(Default) AddLink Error."
1333 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1336 else if ( toNode->IsEndSwitchNode() && !toPort->IsGate() ) {
1337 // if ( !toPort->IsEndSwitch() || !fromPort->AddInPort( toPort ) ) {
1338 if ( !fromPort->AddInPort( toPort ) ) {
1339 cdebug << "toNode->IsEndSwitchNode() : !fromPort->AddInPort( toPort ) AddLink Error."
1341 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1344 if ( !toPort->IsDataStream() ) {
1345 toPort->Kind( SUPERV::EndSwitchParameter ) ;
1348 else if ( !fromPort->AddInPort( toPort ) ) { // --> MapOfInports in the OutPort
1349 cdebug << "!fromPort->AddLink Error." << endl ;
1350 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1354 if ( fromNode->IsGOTONode() && ( !fromPort->IsGate() || !toPort->IsGate() ||
1355 toNode->IsEndLoopNode() || toNode->IsEndSwitchNode() ) ) {
1356 cdebug << "toPort->AddLink Error( fromNode->IsGOTONode() && toNode->IsEndInLineNode() )." << endl ;
1357 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1360 else if ( !fromNode->IsSwitchNode() &&
1361 ( fromPort->IsParam() || fromPort->IsInLine() ) && toPort->IsGate() ) {
1362 LinkStrError << "Link from OutPort to a Gate is not allowed.\n" ;
1363 SetMessages( LinkStrError.str() ) ;
1364 cdebug << "toPort->AddLink Error( fromPort->IsParam() && toPort->IsGate())." << endl ;
1365 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1368 else if ( !toNode->IsEndSwitchNode() && !toNode->IsEndLoopNode() ) {
1369 if ( !toPort->AddOutPort( fromPort ) ) { // --> Unique OutPort of the InPort
1370 cdebug << "toPort->AddLink Error." << endl ;
1371 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1376 toPort->AddOutPort( fromPort ) ;
1379 if ( ( fromNode->IsGOTONode() && toNode->IsOneOfInLineNodes() ) ||
1380 ( fromNode->IsEndLoopNode() && toNode->IsLoopNode() ) ) {
1381 cdebug << "AddLink fromPort->PortStatus( PortConnected ) "
1382 << "GOTONode/EndLoopNode-->InLineNode/LoopNode/SwitchNode "
1383 << fromNode->Name() << " " << fromPort->PortName()
1384 << " InLineNode/LoopNode_ConnectedInPortsNumber "
1385 << toNode->ConnectedInPortsNumber() << endl;
1386 if ( fromNode->IsGOTONode() ) {
1387 fromPort->Kind( SUPERV::GOTOParameter ) ;
1389 fromPort->PortStatus( PortConnected ); // GOTO - Loop
1391 else if ( fromNode->IsDataFlowNode() || fromNode->IsDataStreamNode() ) {
1392 cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( DataConnected ) : "
1393 << fromNode->Name() << " " << fromPort->PortName() << endl ;
1394 fromPort->PortStatus( ExternConnected );
1396 else if ( toNode->IsDataFlowNode() || toNode->IsDataStreamNode() ) {
1397 cdebug << "AddLink IsDataFlow/StreamNode fromPort->PortStatus( ExternConnected ) : "
1398 << fromNode->Name() << " " << fromPort->PortName() << endl ;
1399 fromPort->PortStatus( ExternConnected ) ;
1402 cdebug << "AddLink fromPort->PortStatus( PortConnected ) & fromNode->toNode "
1403 << fromNode->Name() << " " << fromPort->PortName() << " "
1404 << fromPort->Kind() << " OldPortStatus " << fromPort->PortStatus() << " -> " << toNode->Name()
1405 << " " << " " << toPort->PortName() << " " << toPort->Kind() << endl;
1406 fromPort->PortStatus( PortConnected );
1407 if ( fromPort->IsDataStream() && toPort->IsDataStream() ) {
1408 fromNode->AddStreamLinkedNode( toNode ) ;
1411 fromNode->AddLinkedNode( toNode ) ;
1414 if ( fromNode->IsSwitchNode() ) {
1415 if ( !fromPort->IsDataStream() ) {
1416 //JR 08.02.2005 if ( fromPort->IsInLine() && toPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1417 if ( fromPort->IsInLine() && toPort->IsGate() ) {
1418 fromPort->Kind( SUPERV::SwitchParameter ) ;
1420 else if ( !fromPort->IsGate() && !toPort->IsGate() ){
1421 fromPort->Kind( SUPERV::InLineParameter ) ;
1424 if ( fromPort->IsGate() && !toNode->IsEndSwitchNode() ) {
1425 GraphBase::InLineNode * anEndSwitchNode ;
1426 anEndSwitchNode = ((GraphBase::SwitchNode * ) fromNode)->CoupledNode() ;
1427 GraphBase::InPort * anInPort = anEndSwitchNode->GetChangeNodeInGate() ;
1428 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1429 if ( anOutPort && !strcmp( fromNode->Name() , anOutPort->NodeName() ) &&
1430 !strcmp( fromPort->PortName() , anOutPort->PortName() ) &&
1431 anOutPort->IsGate() ) {
1432 if ( !RemoveLink( fromNode->Name() , anOutPort->PortName() ,
1433 anEndSwitchNode->Name() ,
1434 anInPort->PortName() ) ) {
1435 cdebug << "AddLink Error Removelink ( Switch , Default , EndSwitch , Default )"
1437 cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
1443 // cdebug << fromNode->ServiceName() << " " << toNode->ServiceName() << endl ;
1444 cdebug_out << "GraphBase::Graph::AddLink 1" << endl;
1448 bool GraphBase::Graph::RemoveLink( const char* FromNodeName ,
1449 const char* FromServiceParameterName ,
1450 const char* ToNodeName ,
1451 const char* ToServiceParameterName ) {
1452 cdebug_in << "GraphBase::Graph::RemoveLink from " << FromNodeName << "(" << FromServiceParameterName << ")"
1453 << " to " << ToNodeName << "(" << ToServiceParameterName << ")" << endl;
1454 bool RetVal = false ;
1455 GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1457 GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1458 if ( anInPort && ( anInPort->IsPortConnected() ||
1459 anInPort->IsDataConnected() ||
1460 anInPort->IsExternConnected() ) ) {
1461 // JR 13.01.2005 : DeBug : if it is a link to an EndSwitchNode. The OutPort may be an other one !!!
1462 GraphBase::ComputingNode * fromNode = GetChangeGraphNode( FromNodeName ) ;
1463 GraphBase::OutPort * anOutPort = NULL ;
1464 if ( toNode->IsEndSwitchNode() ) {
1465 anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1466 RetVal = anOutPort->RemoveInPort( anInPort ) ;
1469 anOutPort = anInPort->GetOutPort() ;
1470 RetVal = anOutPort->RemoveInPort( anInPort ) ;
1472 // anInPort->RemoveOutPort() ; // Already done in RemoveInPort
1473 // const char * FromNodeName = anOutPort->NodeName() ;
1476 if ( anInPort->IsDataStream() ) {
1477 fromNode->RemoveStreamLinkedNode( toNode ) ;
1480 fromNode->RemoveLinkedNode( toNode ) ;
1483 //JR PAL7990 : a SwitchPort is an OutPort of a SwitchNode connected to a InGate Port
1484 //Debug : change the kind only if there is no other InGate connected to the OutPort
1485 if ( fromNode->IsSwitchNode() && !anOutPort->IsGate() && anOutPort->InPortsSize() == 0 ) {
1486 if ( !toNode->IsEndSwitchNode() ) {
1487 anOutPort->Kind( SUPERV::InLineParameter ) ;
1489 else if ( !anInPort->IsGate() ) {
1490 anOutPort->Kind( SUPERV::InLineParameter ) ;
1493 // JR 13.01.2005 : DeBug : if it is a link to an EndSwitchNode. The InPort may be multiple linked !!!
1494 if ( toNode->IsEndSwitchNode() ) {
1497 for ( i = 0 ; i < toNode->LinkedFromNodesSize() ; i++ ) {
1498 GraphBase::StreamNode * fromNode = toNode->LinkedFromNodes( i ) ;
1500 for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
1501 GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
1503 for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
1504 if ( strcmp( toNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
1505 if ( strcmp( anInPort->PortName() , fromOutPort->InPorts( k )->PortName() ) == 0 ) {
1506 // Restore an OutPort in the InPort
1507 anInPort->ChangeOutPort( fromOutPort ) ;
1508 cdebug << "Graph::RemoveLink reestablish " << fromOutPort->NodeName() << "( "
1509 << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
1510 << toNode->Name() << "( " << anInPort->PortName() << " )"
1511 << anInPort->Kind() << " " << anInPort->PortStatus() << endl;
1529 cdebug_out << "GraphBase::Graph::RemoveLink " << RetVal << endl;
1533 bool GraphBase::Graph::GetLink(const char* ToNodeName ,
1534 const char* ToServiceParameterName ,
1535 char** FromNodeName ,
1536 char** FromServiceParameterName ) {
1537 // cdebug_in << "GraphBase::Graph::GetLink " << ToNodeName << "("
1538 // << ToServiceParameterName << ")" << endl;
1539 bool RetVal = false ;
1540 GraphBase::ComputingNode * toNode = GetChangeGraphNode( ToNodeName ) ;
1542 GraphBase::InPort * anInPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1543 if ( anInPort && !anInPort->IsNotConnected() ) {
1544 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1545 //JR 17.02.2005 Memory Leak *FromNodeName = my_strdup( anOutPort->NodeName() ) ;
1546 *FromNodeName = (char * ) anOutPort->NodeName() ;
1547 //JR 17.02.2005 Memory Leak *FromServiceParameterName = my_strdup( anOutPort->PortName() ) ;
1548 *FromServiceParameterName = (char * ) anOutPort->PortName() ;
1552 cdebug << "GraphBase::Graph::GetLink ERROR no InPort or NotConnected " << ToNodeName
1553 << " " << ToServiceParameterName << " " << RetVal << endl;
1557 cdebug << "GraphBase::Graph::GetLink ERROR no Node " << ToNodeName << " " << RetVal
1560 // cdebug_out << "GraphBase::Graph::GetLink " << RetVal << endl;
1564 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1565 const char* ToServiceParameterName ,
1566 const CORBA::Any aValue ) {
1567 bool RetVal = false ;
1568 cdebug_in << "GraphBase::Graph::AddInputData(" << ToNodeName << ","
1569 << ToServiceParameterName << " , Any " ;
1570 switch (aValue.type()->kind()) {
1571 case CORBA::tk_string:
1574 cdebug << t << " (string) " ;
1576 case CORBA::tk_double:
1579 cdebug << d << " (double) " ;
1581 case CORBA::tk_long:
1584 cdebug << l << " (long) " ;
1586 case CORBA::tk_objref:
1587 cdebug << "(object reference) " ;
1590 cdebug << "(other(tk_string(" << CORBA::tk_string << "),tk_double(" << CORBA::tk_double << "),tk_long("
1591 << CORBA::tk_long << "),tk_objref)(" << CORBA::tk_objref << ")) ERROR : " << aValue.type()->kind() ;
1594 cdebug << " ) in Graph " << Name() << endl;
1596 GraphBase::ComputingNode *toNode ;
1597 GraphBase::InPort *toPort ;
1600 NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1601 toNode = GetChangeGraphNode( aNodeName ) ;
1602 cdebug << "in Graph " << Name() << " aNodeName '" << aNodeName << "' aPortName '" << aPortName
1605 toPort = toNode->GetChangeInPort( aPortName ) ;
1606 if ( toPort && !toPort->IsDataConnected() && toPort->GetOutPort() ) {
1607 toPort->RemoveOutPort() ;
1615 cdebug << endl << "Graph::AddInputData ListOfInOutPorts of the Graph : " << endl ;
1616 for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1617 cdebug << "Graph::AddInputData In" << i << " " << *GetNodeOutDataNodePort(i) << endl ;
1619 for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1620 cdebug << "Graph::AddInputData Out" << i << " " << *GetNodeInDataNodePort(i) << endl ;
1623 if ( toNode && toPort ) {
1624 GraphBase::OutPort *fromDataNodePort = NULL ;
1625 fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1626 if ( fromDataNodePort && fromDataNodePort->GetInPort( toPort ) ) {
1627 fromDataNodePort->RemoveInPort( toPort ) ;
1629 cdebug << "Try AddLink " << toPort->NodePortName() << " : " << Name() << "( "
1630 << fromDataNodePort->PortName() << " ) -->" << toNode->Name() << "( "
1631 << toPort->PortName() << " )" << endl ;
1632 RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1635 fromDataNodePort->SetValue( aValue ) ;
1636 fromDataNodePort->PortStatus( DataConnected ) ;
1640 cdebug << "ERROR Node and/or Port not found : " << aNodeName << " " << aPortName << endl ;
1645 cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1649 // Used in the Executor in order to change an Input Value and ReRun
1650 bool GraphBase::Graph::ChangeInputData( const char * ToNodeName ,
1651 const char * ToServiceParameterName ,
1652 const CORBA::Any aValue ) {
1653 bool RetVal = false ;
1654 cdebug_in << "GraphBase::Graph::ChangeInputData( '" << ToNodeName << "' , '"
1655 << ToServiceParameterName << "' , Any " ;
1656 switch (aValue.type()->kind()) {
1657 case CORBA::tk_string:
1660 cdebug << t << " (string) " ;
1662 case CORBA::tk_double:
1665 cdebug << d << " (double) " ;
1667 case CORBA::tk_long:
1670 cdebug << l << " (long) " ;
1672 case CORBA::tk_objref:
1673 cdebug << "(object reference) " ;
1676 cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1679 cdebug << " ) in Graph " << Name() << endl;
1681 GraphBase::ComputingNode * toNode ;
1682 GraphBase::InPort * toPort = NULL ;
1685 NodePort( ToNodeName , ToServiceParameterName , &aNodeName , &aPortName ) ;
1686 toNode = GetChangeGraphNode( aNodeName ) ;
1687 cdebug << "in Graph " << Name() << " aNodeName " << aNodeName << " aPortName " << aPortName << endl;
1689 toPort = toNode->GetChangeInPort( aPortName ) ;
1690 if ( toPort && toPort->IsDataConnected() ) {
1691 GraphBase::OutPort * fromPort = toPort->GetOutPort();
1694 fromPort->SetValue( aValue ) ;
1695 fromPort->PortStatus( DataConnected ) ;
1696 toPort->PortState( SUPERV::ReadyState ) ;
1699 cdebug << "ERROR ChangeInputData fromPort not found" << endl ;
1703 cdebug << "ERROR ChangeInputData toPort not found" << endl ;
1707 cdebug << "ERROR ChangeInputData Node not found : " << ToNodeName << endl ;
1710 cdebug_out << "GraphBase::Graph::ChangeInputData" << endl;
1715 // To restore InputData in CreateService
1716 bool GraphBase::Graph::AddInputData( const char* ToNodeName ,
1717 const char* ToServiceParameterName ,
1718 const CORBA::Any ** aValue ) {
1719 bool RetVal = false ;
1720 cdebug_in << "GraphBase::Graph::AddInputData( " << ToNodeName << " , "
1721 << ToServiceParameterName << ", **Any " ;
1722 const CORBA::Any theValue = **aValue ;
1723 switch (theValue.type()->kind()) {
1724 case CORBA::tk_string:
1727 cdebug << t << " (string) " ;
1729 case CORBA::tk_double:
1732 cdebug << d << " (double) " ;
1734 case CORBA::tk_long:
1737 cdebug << l << " (long) " ;
1739 case CORBA::tk_objref:
1740 cdebug << "(object reference) " ;
1743 cdebug << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
1746 cdebug << ") of Graph " << Name() << endl;
1748 GraphBase::ComputingNode *toNode = GetChangeGraphNode( ToNodeName ) ;
1751 GraphBase::InPort *toPort = NULL ;
1752 GraphBase::OutPort *fromDataNodePort = NULL ;
1753 toPort = toNode->GetChangeInPort( ToServiceParameterName ) ;
1754 fromDataNodePort = GraphBase::DataNode::GetChangeInDataNodePort( toPort->NodePortName() ) ;
1755 cdebug << "Try AddLink " << Name() << "( " << fromDataNodePort << " ) -->"
1756 << toNode->Name() << "( " << toPort->PortName() << " )" << endl ;
1757 RetVal = AddLink( (GraphBase::ComputingNode * ) this , fromDataNodePort ,
1760 fromDataNodePort->Value( aValue ) ;
1761 fromDataNodePort->PortStatus( DataConnected ) ;
1765 cdebug << "ERROR Node not found " << ToNodeName << " ERROR. Known nodes :" << endl ;
1766 map< string , int >::iterator aMapOfGraphNodesIterator ;
1768 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
1769 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
1770 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first << " --> "
1771 << aMapOfGraphNodesIterator->second << endl ;
1775 cdebug_out << "GraphBase::Graph::AddInputData " << RetVal << endl;
1780 bool GraphBase::Graph::AddOutputData( const char* FromNodeName ,
1781 const char* FromServiceParameterName ,
1782 const CORBA::Any aValue ) {
1783 bool RetVal = true ;
1784 cdebug_in << "GraphBase::Graph::AddOutputData(" << FromNodeName << ","
1785 << FromServiceParameterName << ")" << endl;
1786 GraphBase::ComputingNode *fromNode = GetChangeGraphNode( FromNodeName ) ;
1788 GraphBase::OutPort *anOutPort = NULL ;
1791 anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
1792 // toDataNodePort = GraphBase::DataNode::GetChangeOutDataNodePort( fromPort->NodePortName() ) ;
1793 // RetVal = AddLink( fromNode , fromPort ,
1794 // (GraphBase::ComputingNode * ) this , toDataNodePort ) ;
1795 anOutPort->SetValue( aValue ) ;
1796 anOutPort->PortState( SUPERV::ReadyState ) ;
1797 anOutPort->PortDone( true ) ;
1798 cdebug << *anOutPort ;
1800 anOutPort->StringValue( *_fdebug ) ;
1805 cdebug << "ERROR Node not found" << endl ;
1808 cdebug_out << "GraphBase::Graph::AddOutputData " << RetVal << endl;
1812 //JR This is used by StreamGraphs to list "CODES" and after that there is instances
1813 // for each Code (Nodes).
1814 map< string , GraphBase::Service * > GraphBase::Graph::MapOfServiceNames() {
1815 return _MapOfServiceNames ; }
1817 GraphBase::Service * GraphBase::Graph::GetServiceOfMap( char * name ) {
1818 return _MapOfServiceNames[ name ] ;
1821 bool GraphBase::Graph::SetServiceOfMap( GraphBase::Service * aService ) {
1822 GraphBase::Service * theService = _MapOfServiceNames[ aService->ServiceName() ] ;
1824 cdebug << "SetServiceOfMap of " << aService->ServiceName()
1825 << " already in MapOfServiceNames : erase" << endl ;
1826 _MapOfServiceNames.erase( aService->ServiceName() ) ;
1828 _MapOfServiceNames[ (char * ) aService->ServiceName() ] = aService ;
1829 cdebug << "SetServiceOfMap of " << aService->ServiceName() << " done" << endl ;
1834 //JR Debug 25.03.2005 : with multiple instances et delete of instances, it was wrong
1835 //Bug created with the developpement of StreamGraphs
1836 int GraphBase::Graph::GetNewServiceInstanceNumber( char * aServiceName ) {
1837 int InstanceNumber = _MapOfServiceInstanceNumber[ aServiceName ] + 1 ;
1838 _MapOfServiceInstanceNumber[ aServiceName ] = InstanceNumber ;
1839 return InstanceNumber ;
1842 void GraphBase::Graph::SetGraphPorts() {
1843 cdebug_in << "GraphBase::Graph::SetGraphPorts fill ports of Graph" << endl;
1845 for ( i = 0 ; i < GetNodeInDataNodePortsSize() ; i++ ) {
1846 GraphBase::OutPort * anOutPort = GetChangeNodeInDataNodePort( i ) ;
1847 cdebug << "SetGraphPorts Out" << i << " " << anOutPort->PortName() << " " << anOutPort->PortType()
1848 << " " << anOutPort->Kind() << " " << anOutPort->PortStatus() << " " << anOutPort->PortState() << endl ;
1849 if ( !anOutPort->IsGate() ) {
1850 anOutPort->PortStatus( ExternConnected ) ;
1853 for ( i = 0 ; i < GetNodeOutDataNodePortsSize() ; i++ ) {
1854 GraphBase::InPort * anInPort = GetChangeNodeOutDataNodePort( i ) ;
1855 cdebug << "SetGraphPorts In" << i << " " << anInPort->PortName() << " " << anInPort->PortType()
1856 << " " << anInPort->Kind() << " " << anInPort->PortStatus() << " " << anInPort->PortState() << endl ;
1857 if ( !anInPort->IsGate() ) {
1858 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1859 anOutPort->PortStatus( ExternConnected ) ;
1862 cdebug_out << "GraphBase::Graph::SetGraphPorts" << endl;
1865 string GraphBase::Graph::Messages() {
1866 // cdebug_in << "Graph::Messages" << endl ;
1867 // cdebug_out << "Graph::Messages" << endl ;
1868 return ( CORBA::string_dup( _Messages.c_str() ) ) ;
1871 void GraphBase::Graph::ReSetMessages() {
1872 cdebug << "Graph::ReSetMessages" << endl ;
1873 _Messages = string( "" ) ;
1876 void GraphBase::Graph::SetMessages( string anErrorMessage ) {
1877 cdebug_in << "Graph::SetMessages" << endl ;
1878 _Messages = _Messages + anErrorMessage + string( "\n" ) ;
1879 cdebug_out << "Graph::SetMessages :" << endl << _Messages << endl ;
1882 bool GraphBase::Graph::CreateService() {
1883 cdebug_in << "GraphBase::Graph::CreateService " << Name() << " GraphMacroLevel : " << GraphMacroLevel() << endl;
1884 bool RetVal = true ;
1885 SALOME_ModuleCatalog::Service aService ;
1887 GraphBase::ComputingNode * aToNode ;
1890 int instreamnbr = 0 ;
1892 int outstreamnbr = 0 ;
1893 vector< SUPERV::KindOfPort > InPortsKind ;
1894 vector< SALOME_ModuleCatalog::DataStreamDependency > InDataStreamDependency ;
1895 vector< SUPERV::KindOfSchema > InKindOfSchema ;
1896 vector< SUPERV::KindOfInterpolation > InKindOfInterpolation ;
1897 vector< SUPERV::KindOfExtrapolation > InKindOfExtrapolation ;
1898 vector< SUPERV::KindOfPort > OutPortsKind ;
1899 vector< SALOME_ModuleCatalog::DataStreamDependency > OutDataStreamDependency ;
1900 vector< long > OutNumberOfValues ;
1901 // if ( GraphMacroLevel() == 0 ) {
1902 for ( dostore = 0 ; dostore <= 2 ; dostore++ ) {
1903 if ( dostore == 1 ) {
1904 //JR 17.02.2005 Memory Leak aService.ServiceName = Name() ;
1905 aService.ServiceName = my_strdup( Name() ) ;
1906 aService.ServiceinParameter.length( 0 ) ;
1907 aService.ServiceinParameter.length( innbr ) ;
1908 aService.ServiceoutParameter.length( 0 ) ;
1909 aService.ServiceoutParameter.length( outnbr ) ;
1910 InPortsKind.resize( innbr ) ;
1911 InDataStreamDependency.resize( innbr ) ;
1912 InKindOfSchema.resize( innbr ) ;
1913 InKindOfInterpolation.resize( innbr ) ;
1914 InKindOfExtrapolation.resize( innbr ) ;
1915 OutPortsKind.resize( outnbr ) ;
1916 OutDataStreamDependency.resize( outnbr ) ;
1917 OutNumberOfValues.resize( outnbr ) ;
1919 else if ( dostore == 2 ) {
1920 //JR Creation of the Service (and of the Ports) with GraphBase::DataNode::DataService :
1921 cdebug << "GraphBase::Graph::CreateService ->DataService innbr " << innbr
1922 << " instreamnbr " << instreamnbr << " outnbr " << outnbr
1923 << " outstreamnbr " << outstreamnbr << endl ;
1924 DataService( _Orb , aService , Graph_prof_debug() , Graph_fdebug() ) ;
1925 aService.ServiceinParameter.length( innbr + instreamnbr ) ;
1926 aService.ServiceoutParameter.length( outnbr + outstreamnbr ) ;
1927 InPortsKind.resize( innbr + instreamnbr ) ;
1928 InDataStreamDependency.resize( innbr + instreamnbr ) ;
1929 InKindOfSchema.resize( innbr + instreamnbr ) ;
1930 InKindOfInterpolation.resize( innbr + instreamnbr ) ;
1931 InKindOfExtrapolation.resize( innbr + instreamnbr ) ;
1932 OutPortsKind.resize( outnbr + outstreamnbr ) ;
1933 OutDataStreamDependency.resize( outnbr + outstreamnbr ) ;
1934 OutNumberOfValues.resize( outnbr + outstreamnbr ) ;
1936 if ( dostore == 0 ) {
1942 if ( dostore == 1 ) {
1946 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1947 aToNode = GraphNodes( i ) ;
1948 for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
1949 GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
1950 bool isfromcouplednode = false ;
1951 if ( !anInPort->IsNotConnected() ) {
1952 const char * aFromNodeName = anInPort->GetOutPort()->NodeName() ;
1953 GraphBase::ComputingNode * aFromNode = GetChangeGraphNode( aFromNodeName ) ;
1954 cdebug << "GraphBase::Graph::CreateService aFromNodeName " << aFromNodeName << " aToNode "
1955 << aToNode->Name() << " InPort" << j << " " << anInPort->PortName() << endl ;
1956 if ( aFromNode && aFromNode->IsEndLoopNode() &&
1957 ((GraphBase::EndOfLoopNode * ) aFromNode)->CoupledNode() == aToNode ) {
1958 isfromcouplednode = true ;
1961 if ( !anInPort->IsGate() && !anInPort->IsLoop() &&
1962 ( !anInPort->IsPortConnected() ||
1963 // ( anInPort->IsPortConnected() && isfromcouplednode ) ) ) {
1964 //JR PAL8914 : InPorts of EndLoopNodes may not be in the Service of the Graph
1965 ( anInPort->IsPortConnected() && isfromcouplednode ) ) &&
1966 !aToNode->IsEndLoopNode() ) {
1967 if ( dostore == 0 ) {
1968 cdebug << "CreateService " << aToNode->Name() << " Input port "
1969 << anInPort->PortName() << " " << anInPort->Kind() << " " << anInPort->PortStatus() ;
1970 if ( anInPort->GetOutPort() ) {
1971 cdebug << "DataConnected from " << *(anInPort->GetOutPort() ) ;
1974 if ( anInPort->IsDataStream() ) {
1981 else if ( ( dostore == 1 && !anInPort->IsDataStream() ) ||
1982 ( dostore == 2 && anInPort->IsDataStream() ) ) {
1983 aService.ServiceinParameter[innbr].Parametertype = CORBA::string_dup( anInPort->PortType() ) ;
1984 aService.ServiceinParameter[innbr].Parametername = CORBA::string_dup( anInPort->NodePortName() ) ;
1985 InPortsKind[ innbr ] = anInPort->Kind() ;
1986 InDataStreamDependency[ innbr ] = anInPort->Dependency() ;
1987 if ( dostore == 2 && anInPort->IsDataStream() ) {
1988 ((GraphBase::InDataStreamPort * ) anInPort)->Params( InKindOfSchema[ innbr ] ,
1989 InKindOfInterpolation[ innbr ] ,
1990 InKindOfExtrapolation[ innbr ] ) ;
1992 cdebug << "In" << innbr << " " << aService.ServiceinParameter[ innbr ].Parametername << " "
1993 << anInPort->Kind() << " " << anInPort->PortStatus() << endl ;
1997 else if ( dostore == 0 ) {
1998 cdebug << "CreateService " << aToNode->Name() << " Input port " << anInPort->PortName()
1999 << " " << anInPort->PortStatus() ;
2000 if ( anInPort->IsPortConnected() ) {
2001 cdebug << " is connected " ;
2004 cdebug << " is NOT connected " ;
2006 if ( anInPort->IsGate() ) {
2007 cdebug << " IsGate " ;
2009 if ( anInPort->GetOutPort() ) {
2010 cdebug << "DataConnected from " << *(anInPort->GetOutPort()) ;
2013 cdebug << "NOT DataConnected" ;
2018 GraphBase::ComputingNode * aFromNode = aToNode ;
2019 for ( j = 0 ; j < aFromNode->GetNodeOutPortsSize() ; j++ ) {
2020 GraphBase::OutPort *anOutPort = aFromNode->GetChangeNodeOutPort(j) ;
2021 // cdebug << "CreateService Node " << aFromNode->Name() << ". Output port[" << j << "] ";
2022 // if ( anOutPort ) {
2023 // cdebug << anOutPort->PortName() << " " << anOutPort->ServicesParameterType() << endl ;
2026 // cdebug << " NULL" << endl ;
2028 if ( !aFromNode->IsGOTONode() ) {
2029 if ( !anOutPort->IsGate() && ( anOutPort->IsNotConnected() || anOutPort->IsDataConnected() ||
2030 //JR PAL8914 : OutPorts of LoopNodes may not be in the Service of the Graph
2031 // anOutPort->IsExternConnected() ) {
2032 anOutPort->IsExternConnected() ) &&
2033 !aFromNode->IsLoopNode() ) {
2034 if ( dostore == 0 ) {
2035 // cdebug << "CreateService " << aFromNode->Name() << " Output port "
2036 // << anOutPort->PortName() << " " << anOutPort->PortStatus() << endl ;
2037 if ( anOutPort->IsDataStream() ) {
2044 else if ( ( dostore == 1 && !anOutPort->IsDataStream() ) ||
2045 ( dostore == 2 && anOutPort->IsDataStream() ) ) {
2046 aService.ServiceoutParameter[outnbr].Parametertype = CORBA::string_dup( anOutPort->PortType() ) ;
2047 aService.ServiceoutParameter[outnbr].Parametername = CORBA::string_dup( anOutPort->NodePortName() ) ;
2048 OutPortsKind[ outnbr ] = anOutPort->Kind() ;
2049 OutDataStreamDependency[ outnbr ] = anOutPort->Dependency() ;
2050 if ( dostore == 2 && anOutPort->IsDataStream() ) {
2051 OutNumberOfValues[ outnbr ] = ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues() ;
2053 // cdebug << "Out" << outnbr << " " << aService.ServiceoutParameter[ outnbr ].Parametername << " "
2054 // << anOutPort->Kind() << " " << anOutPort->PortStatus() << endl ;
2065 cdebug << "DataFlowNode ServiceName " << aService.ServiceName << " InPorts " << innbr
2066 << " OutPorts " << outnbr << endl ;
2067 for ( i = 0 ; i < innbr ; i++ ) {
2068 cdebug << "aService.ServiceinParameter[" << i << "].Parametertype "
2069 << aService.ServiceinParameter[i].Parametertype << " Parametername "
2070 << aService.ServiceinParameter[i].Parametername << " " << InPortsKind[ i ] << endl ;
2071 if ( InPortsKind[ i ] != SUPERV::DataStreamParameter ) {
2072 cdebug << "NodeInPort[" << i << "] " << *GetChangeNodeInPort( i ) << endl ;
2075 for ( i = 0 ; i < outnbr ; i++ ) {
2076 cdebug << "aService.ServiceoutParameter[" << i << "].Parametertype "
2077 << aService.ServiceoutParameter[i].Parametertype << " Parametername "
2078 << aService.ServiceoutParameter[i].Parametername << " " << OutPortsKind[ i ] << endl ;
2079 if ( OutPortsKind[ i ] != SUPERV::DataStreamParameter ) {
2080 cdebug << "NodeOutPort[" << i << "] " << *GetChangeNodeOutPort( i ) << endl ;
2085 // DataService( _Orb , aService , InPortsKind , OutPortsKind , Graph_prof_debug() , Graph_fdebug() ) ;
2086 for ( i = 0 ; i < innbr ; i++ ) {
2087 if ( InPortsKind[ i ] == SUPERV::DataStreamParameter ) {
2088 GraphBase::InDataStreamPort * anInPort = AddInDataStreamPort( aService.ServiceinParameter[ i ].Parametername ,
2089 StringToDataStreamType( aService.ServiceinParameter[ i ].Parametertype ) ,
2090 InDataStreamDependency[ i ] ,
2091 SUPERV::DataStreamParameter ) ;
2092 anInPort->SetParams( InKindOfSchema[ i ] ,
2093 InKindOfInterpolation[ i ] ,
2094 InKindOfExtrapolation[ i ] ) ;
2095 // NOT A BUG : AddOutPort for an inport (Reversed service)
2096 anInPort = (GraphBase::InDataStreamPort * ) _DataFlowDataPorts->AddOutPort(
2099 aService.ServiceinParameter[ i ].Parametername ,
2100 aService.ServiceinParameter[ i ].Parametertype ,
2101 SUPERV::DataStreamParameter ,
2103 _Graph_prof_debug , _Graph_fdebug ) ;
2104 anInPort->Dependency( InDataStreamDependency[ i ] ) ;
2105 // Attention : revoir les reversed DataStreamPorts
2106 // anInPort->SetParams( InKindOfSchema[ i ] ,
2107 // InKindOfInterpolation[ i ] ,
2108 // InKindOfExtrapolation[ i ] ) ;
2109 cdebug << "InStreamPort " << GetChangeNodeInPort( i )->PortName() << " " << GetChangeNodeInPort( i )->Kind() << endl ;
2110 cdebug << "ReversedInStreamPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind()
2114 GetChangeNodeInPort( i )->Kind( InPortsKind[ i ] ) ;
2115 _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind( InPortsKind[ i ] ) ;
2116 GetChangeNodeInPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
2117 _DataFlowDataPorts->GetChangeNodeOutPort( i )->Dependency( InDataStreamDependency[ i ] ) ;
2118 cdebug << "InPort " << GetChangeNodeInPort( i )->PortName() << " "
2119 << GetChangeNodeInPort( i )->Kind() << " " << GetChangeNodeInPort( i )->PortStatus()
2121 cdebug << "ReversedInPort " << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortName() << " "
2122 << _DataFlowDataPorts->GetChangeNodeOutPort( i )->Kind() << " "
2123 << _DataFlowDataPorts->GetChangeNodeOutPort( i )->PortStatus()
2127 for ( i = 0 ; i < outnbr ; i++ ) {
2128 if ( OutPortsKind[ i ] == SUPERV::DataStreamParameter ) {
2129 GraphBase::OutDataStreamPort * anOutPort = AddOutDataStreamPort( aService.ServiceoutParameter[ i ].Parametername ,
2130 StringToDataStreamType( aService.ServiceoutParameter[ i ].Parametertype ) ,
2131 OutDataStreamDependency[ i ] ,
2132 SUPERV::DataStreamParameter ) ;
2133 anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
2134 // NOT A BUG : AddInPort for an outport (Reversed service)
2135 anOutPort = (GraphBase::OutDataStreamPort * ) _DataFlowDataPorts->AddInPort(
2138 aService.ServiceoutParameter[ i ].Parametername ,
2139 aService.ServiceoutParameter[ i ].Parametertype ,
2140 SUPERV::DataStreamParameter ,
2142 _Graph_prof_debug , _Graph_fdebug ) ;
2143 anOutPort->Dependency( OutDataStreamDependency[ i ] ) ;
2144 // Attention : revoir les reversed DataStreamPorts
2145 // anOutPort->NumberOfValues( OutNumberOfValues[ i ] ) ;
2146 cdebug << "OutStreamPort " << GetChangeNodeOutPort( i )->PortName() << " " << GetChangeNodeOutPort( i )->Kind() << endl ;
2147 cdebug << "ReversedOutStreamPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName() << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
2151 GetChangeNodeOutPort( i )->Kind( OutPortsKind[ i ] ) ;
2152 _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind( OutPortsKind[ i ] ) ;
2153 GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2154 _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2155 GetChangeNodeOutPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2156 _DataFlowDataPorts->GetChangeNodeInPort( i )->Dependency( OutDataStreamDependency[ i ] ) ;
2157 cdebug << "OutPort " << GetChangeNodeOutPort( i )->PortName() << " "
2158 << GetChangeNodeOutPort( i )->Kind() << " " << GetChangeNodeOutPort( i )->PortStatus()
2160 cdebug << "ReversedOutPort " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortName()
2161 << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->Kind()
2162 << " " << _DataFlowDataPorts->GetChangeNodeInPort( i )->PortStatus()
2166 // Restore input datas and links :
2167 DataStreamInPortsNumber( 0 ) ;
2168 DataStreamOutPortsNumber( 0 ) ;
2169 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2170 aToNode = GraphNodes( i ) ;
2171 DataStreamInPortsNumber( DataStreamInPortsNumber() + aToNode->DataStreamInPortsNumber() ) ;
2172 DataStreamOutPortsNumber( DataStreamOutPortsNumber() + aToNode->DataStreamOutPortsNumber() ) ;
2173 for ( j = 0 ; j < aToNode->GetNodeInPortsSize() ; j++ ) {
2174 GraphBase::InPort *anInPort = aToNode->GetChangeNodeInPort(j) ;
2175 if ( !anInPort->IsGate() && anInPort->IsDataConnected() ) {
2176 if ( !AddInputData( anInPort->NodeName() ,
2177 anInPort->PortName() ,
2178 //JR 21.02.2005 Debug Memory leak : anInPort->GetOutPort()->ValuePtr() ) ) {
2179 //JR 30.03.2005 *anInPort->GetOutPort()->Value() ) ) {
2180 anInPort->GetOutPort()->Value() ) ) {
2181 cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2182 << anInPort->PortStatus() << " --> AddInputData ERROR" << endl ;
2186 cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2187 << anInPort->PortStatus() << " --> AddInputData" << endl ;
2190 //JR PAL8914 : InPorts of EndLoopNodes may not be in the Service of the Graph
2191 // else if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2192 else if ( !anInPort->IsGate() &&
2193 ( anInPort->IsNotConnected() || anInPort->IsExternConnected() ) &&
2194 !aToNode->IsEndLoopNode() ) {
2195 if ( !AddLink( this , GetChangeInDataNodePort( anInPort->NodePortName() ) , aToNode , anInPort ) ) {
2196 cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2197 << anInPort->PortStatus() << " --> AddInLink ERROR" << endl ;
2201 cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2202 << anInPort->PortStatus() << " --> AddInLink" << endl ;
2206 cdebug << "CreateService In" << j << " " << anInPort->NodeName() << "(" << anInPort->PortName() << ") "
2207 << anInPort->PortStatus() << " --> NO AddInputData/AddInLink" << endl ;
2210 for ( j = 0 ; j < aToNode->GetNodeOutPortsSize() ; j++ ) {
2211 GraphBase::OutPort *anOutPort = aToNode->GetChangeNodeOutPort(j) ;
2212 cdebug << "CreateService Out" << j << " " << anOutPort->NodeName() << "(" << anOutPort->PortName()
2213 << ") " << anOutPort->PortStatus() << " :" << endl ;
2214 //JR PAL8914 : OutPorts of LoopNodes may not be in the Service of the Graph
2215 // if ( !anOutPort->IsGate() && anOutPort->IsNotConnected() && !aToNode->IsGOTONode() ) {
2216 if ( !anOutPort->IsGate() && anOutPort->IsNotConnected() && !aToNode->IsGOTONode() &&
2217 !aToNode->IsLoopNode() ) {
2218 GraphBase::InPort *anInPort = GetChangeOutDataNodePort( anOutPort->NodePortName() ) ;
2219 if ( !AddLink( aToNode , anOutPort , this , anInPort ) ) {
2220 cdebug << " --> " << Name() << "(" << anInPort->PortName()
2221 << ") " << anInPort->PortStatus() << " AddOutLink ERROR" << endl ;
2225 cdebug << " --> " << Name() << "(" << anInPort->PortName()
2226 << ") " << anInPort->PortStatus() << " AddOutLink" << endl ;
2233 ListPorts( *_Graph_fdebug , 0 ) ;
2237 SetMessages( "Fail to create the Service of the graph.\n" ) ;
2240 cdebug_out << "GraphBase::Graph::CreateService " << RetVal << endl;
2244 bool GraphBase::Graph::InLineServices() {
2245 cdebug_in << "GraphBase::Graph::InLineServices" << endl;
2250 ListPorts( *_Graph_fdebug , 0 ) ;
2253 GraphBase::InLineNode * aINode ;
2254 SALOME_ModuleCatalog::Service aService ;
2255 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2256 aINode = (GraphBase::InLineNode * ) GraphNodes( i ) ;
2257 if ( aINode->IsOneOfInLineNodes() ) {
2258 // cdebug << "GraphBase::Graph::InLineServices " << aINode->Name() << endl;
2259 aService.ServiceName = aINode->ServiceName() ;
2260 aService.ServiceinParameter.length( 0 ) ;
2261 aService.ServiceoutParameter.length( 0 ) ;
2262 aINode->DataStreamInPortsNumber( 0 ) ;
2263 aINode->DataStreamOutPortsNumber( 0 ) ;
2265 int InStreamService = 0 ;
2266 for ( j = 0 ; j < aINode->GetNodeInPortsSize() ; j++ ) {
2267 if ( aINode->GetChangeNodeInPort(j)->IsGate() || aINode->GetChangeNodeInPort(j)->IsLoop() ) {
2269 cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2270 << aINode->GetChangeNodeInPort(j)->Kind() << " "
2271 << aINode->GetChangeNodeInPort(j)->PortType() << " "
2272 << aINode->GetChangeNodeInPort(j)->PortName() << " ignored "
2273 << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2274 << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2277 else if ( aINode->GetChangeNodeInPort(j)->IsDataStream() ) {
2278 aService.ServiceinDataStreamParameter.length( InStreamService+1 ) ;
2279 aService.ServiceinDataStreamParameter[InStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeInPort(j)->PortType() ) ;
2280 aService.ServiceinDataStreamParameter[InStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
2281 aService.ServiceinDataStreamParameter[InStreamService++].Parameterdependency = aINode->GetChangeNodeInPort(j)->Dependency() ;
2282 aINode->IncrDataStreamInPorts() ;
2284 cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2285 << aINode->GetChangeNodeInPort(j)->Kind() << " "
2286 << aINode->GetChangeNodeInPort(j)->PortType() << " "
2287 << aINode->GetChangeNodeInPort(j)->PortName() << " "
2288 << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2289 << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2293 aService.ServiceinParameter.length( InService+1 ) ;
2294 aService.ServiceinParameter[InService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortType() ) ;
2295 aService.ServiceinParameter[InService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeInPort(j)->PortName() ) ;
2297 cdebug << "GraphBase::Graph::InLineServices In" << j << " "
2298 << aINode->GetChangeNodeInPort(j)->Kind() << " "
2299 << aINode->GetChangeNodeInPort(j)->PortType() << " "
2300 << aINode->GetChangeNodeInPort(j)->PortName() << " "
2301 << aINode->GetChangeNodeInPort(j)->IsGate() << " "
2302 << aINode->GetChangeNodeInPort(j)->IsLoop() << endl;
2306 int OutService = 0 ;
2307 int OutStreamService = 0 ;
2308 for ( j = 0 ; j < aINode->GetNodeOutPortsSize() ; j++ ) {
2309 // if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() || aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
2310 if ( aINode->GetChangeNodeOutPort(j)->IsGate() || aINode->GetChangeNodeOutPort(j)->IsLoop() ) {
2312 cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2313 << aINode->GetChangeNodeOutPort(j)->Kind() << " "
2314 << aINode->GetChangeNodeOutPort(j)->PortType() << " "
2315 << aINode->GetChangeNodeOutPort(j)->PortName() << " ignored "
2316 << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2317 << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2320 else if ( aINode->GetChangeNodeOutPort(j)->IsDataStream() ) {
2321 aService.ServiceoutDataStreamParameter.length( OutStreamService+1 ) ;
2322 aService.ServiceoutDataStreamParameter[OutStreamService].Parametertype = StringToDataStreamType( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
2323 aService.ServiceoutDataStreamParameter[OutStreamService].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
2324 aService.ServiceoutDataStreamParameter[OutStreamService++].Parameterdependency = aINode->GetChangeNodeOutPort(j)->Dependency() ;
2325 aINode->IncrDataStreamOutPorts() ;
2327 cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2328 << aINode->GetChangeNodeOutPort(j)->Kind() << " "
2329 << aINode->GetChangeNodeOutPort(j)->PortType() << " "
2330 << aINode->GetChangeNodeOutPort(j)->PortName() << " "
2331 << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2332 << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2336 aService.ServiceoutParameter.length( OutService+1 ) ;
2337 aService.ServiceoutParameter[OutService].Parametertype = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortType() ) ;
2338 aService.ServiceoutParameter[OutService++].Parametername = CORBA::string_dup( aINode->GetChangeNodeOutPort(j)->PortName() ) ;
2340 cdebug << "GraphBase::Graph::InLineServices Out" << j << " "
2341 << aINode->GetChangeNodeOutPort(j)->Kind() << " "
2342 << aINode->GetChangeNodeOutPort(j)->PortType() << " "
2343 << aINode->GetChangeNodeOutPort(j)->PortName() << " "
2344 << aINode->GetChangeNodeOutPort(j)->IsGate() << " "
2345 << aINode->GetChangeNodeOutPort(j)->IsLoop() << endl;
2349 aINode->SetService( aService ) ;
2350 if ( SetServiceOfMap( (GraphBase::Service * ) aINode ) ) {
2352 cdebug << "InLineServices SetServiceOfMap " << aINode->ServiceName() << " in MapOfServices"
2353 << " InStreamPort(" << aINode->DataStreamInPortsNumber()
2354 << ") OutStreamPort(" << aINode->DataStreamOutPortsNumber() << ")" << endl ;
2357 // cdebug << "GraphBase::Graph::InLineServices" << *aINode->GetService() << endl;
2361 cdebug_out << "GraphBase::Graph::InLineServices" << endl;
2365 bool GraphBase::Graph::Sort( int & SubStreamGraphsNumber ) {
2367 ListPorts( *_Graph_fdebug , 0 ) ;
2372 int NotSortedNumber = GraphNodesSize() ;
2374 cdebug_in << "GraphBase::Graph::Sort" << endl;
2375 if ( NotSortedNumber ) {
2377 _ParallelExecutionNodes = false ;
2378 _Sorted.resize( GraphNodesSize() ) ;
2379 _CnxInPortsNumber.resize( GraphNodesSize() ) ;
2380 _DecrInPortsNumber.resize( GraphNodesSize() ) ;
2381 if ( _NodesNumber.size() ) {
2382 _NodesNumber.resize( 0 ) ;
2383 _SortedNodes.resize( 0 ) ;
2386 // This is a simulation of the computation of the graph :
2387 // The initial state of nodes is :
2388 // - Sorted = false : the node is not sorted
2389 // - CnxInPortsNumber = ConnectedInPortsNumber : the number of ports that wait for a value from a link
2390 // - DecrInPortsNumber = 0 : there is no value available.
2392 cdebug << "GraphBase::Graph::Sort initial values :" << endl ;
2393 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2394 GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2395 cdebug << aNode->Name() << " --> " << aNode->LinkedNodesSize() << " LinkedNodes :" << endl ;
2396 for ( j = 0 ; j < aNode->LinkedNodesSize() ; j++ ) {
2397 cdebug << " " << aNode->LinkedNodes( j )->Name() << endl ;
2401 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2402 _Sorted[ i ] = false ;
2403 _CnxInPortsNumber[ i ] = GraphNodes( i )->ConnectedInPortsNumber() ;
2404 _DecrInPortsNumber[ i ] = 0 ;
2405 // cdebug << "Sort Node [" << i << "] " << GraphNodes( i )->Name() << " initial count "
2406 // << _CnxInPortsNumber[ i ] << endl ;
2409 // Nodes are linked ONLY if Ports are NOT DataStream for topological sort of node
2410 // ==============================================================================
2411 while ( NotSortedNumber ) {
2414 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2415 cdebug << "Sort level " << _LevelsNumber << ". [" << i << "] "
2416 << GraphNodes( i )->Name() << " count "
2417 << _CnxInPortsNumber[ i ] << endl ;
2418 if ( !_Sorted[ i ] && _CnxInPortsNumber[ i ] == 0 ) {
2419 // All inputs of GraphNodes( i ) are available : "AllDataReady"
2420 if ( (int ) _NodesNumber.size() != _LevelsNumber+1 ) {
2421 _NodesNumber.resize( _LevelsNumber+1 ) ;
2422 _SortedNodes.resize( _LevelsNumber+1 ) ;
2423 _NodesNumber[ _LevelsNumber ] = -1 ;
2425 // There is one more node at that level
2426 _NodesNumber[ _LevelsNumber ]++ ;
2427 (_SortedNodes[ _LevelsNumber ]).resize( _NodesNumber[ _LevelsNumber ]+1 ) ;
2428 (_SortedNodes[ _LevelsNumber ])[ _NodesNumber[ _LevelsNumber ] ] = GraphNodes( i ) ;
2429 _Sorted[ i ] = true ;
2431 NotSortedNumber -= 1 ;
2432 cdebug << GraphNodes( i )->Name() << " belongs to level "
2433 << _LevelsNumber << ". " << GraphNodes( i )->LinkedNodesSize() << " linkednodes" << endl ;
2434 // GraphNodes( i ) has the state "AllDataReady". We simulate the end of its execution :
2435 // So we loop over all nodes that have a link from that node
2436 // And we increment the number of input ports of GraphNodes( i )->LinkedNodes( j ) that this
2437 // execution will give a value in DecrInPortsNumber : "SomeDataReady"
2438 for ( j = 0 ; j < GraphNodes( i )->LinkedNodesSize() ; j++ ) {
2439 // OutputPorts of GraphNodes( i ) will satisfy
2440 // GraphNodes( i )->LinkedInPortsNumber( j ) InPorts of
2441 // GraphNodes( i )->LinkedNodes( j )
2442 GraphBase::StreamNode * aLinkedNode = GraphNodes( i )->LinkedNodes( j ) ;
2443 int aLinkedInPortsNumber = GraphNodes( i )->LinkedInPortsNumber( j ) ;
2444 cdebug << j << ". LinkedNode " << aLinkedNode->Name() ;
2445 if ( !aLinkedNode->IsDataFlowNode() && !aLinkedNode->IsDataStreamNode() ) {
2446 cdebug << " _DecrInPortsNumber[ "
2447 << GetGraphNodeIndex( aLinkedNode->Name() )
2449 << _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ]
2450 << " += " << aLinkedInPortsNumber ;
2451 _DecrInPortsNumber[ GetGraphNodeIndex( aLinkedNode->Name() ) ] += aLinkedInPortsNumber ;
2457 // If no node was found, that FlowGraph is not valid : if we try to execute it, that FlowGraph
2458 // will wait for data(s) from node(s) not executed or not executing for ever
2460 SetMessages( "That graph is cyclic.\n" ) ;
2461 cdebug << "ERROR Loop detected at level " << _LevelsNumber << endl ;
2462 return false ; // Loop in the Graph
2464 // cdebug << "Bilan level " << _LevelsNumber << " : " << endl ;
2465 bool ChangeCount = false ;
2466 // We update now the number of InPorts with a link that are waiting for a value
2467 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2468 if ( _DecrInPortsNumber[ i ] ) {
2469 // int prevcount = _CnxInPortsNumber[ i ] ;
2470 _CnxInPortsNumber[ i ] -= _DecrInPortsNumber[ i ] ;
2471 _DecrInPortsNumber[ i ] = 0 ;
2472 ChangeCount = true ;
2473 // cdebug << " " << GraphNodes( i )->Name() << " count " << prevcount
2474 // << " --> new count " << _CnxInPortsNumber[ i ] << endl ;
2477 // If there is no loop and if the number of InPorts with a link that are waiting for a value
2478 // does not change, the sort is finished. But there is also NotSortedNumber ...
2479 // if ( !ChangeCount )
2481 if ( NotSortedNumber ) {
2482 _LevelsNumber += 1 ;
2486 int AllSortedNodes = 0 ;
2487 _HeadNodes = _SortedNodes[ 0 ] ;
2488 _HeadNodesSize = _SortedNodes[ 0 ].size() ;
2489 // QueueNodes was used in the past in order to know if the execution of a graph is finished
2490 // But because of loop nodes that was changed. So that part of code is a "clutter"
2491 // Now a graph has finished its execution when the number of executing threads is zero
2492 _QueueNodes = _SortedNodes[ _LevelsNumber ] ;
2493 _QueueNodesSize = _SortedNodes[ _LevelsNumber ].size() ;
2494 for ( i = 0 ; i < _QueueNodesSize ; i++ ) {
2495 if ( !_QueueNodes[ i ]->IsGOTONode() ) {
2499 if ( i == _QueueNodesSize && _LevelsNumber ) {
2500 _QueueNodes = _SortedNodes[ _LevelsNumber - 1 ] ;
2501 _QueueNodesSize = _SortedNodes[ _LevelsNumber - 1 ].size() ;
2503 // Computation of the maximum number of threads == the maximum number of nodes of all levels
2504 for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2505 AllSortedNodes += _NodesNumber[ i ]+1 ;
2506 if ( _NodesNumber[ i ] + 1 > _ThreadsMax ) {
2507 _ThreadsMax = _NodesNumber[ i ] + 1 ;
2509 cdebug << _NodesNumber[ i ]+1 << " Nodes of level " << i << " : "
2510 << (_SortedNodes[ i ])[ 0 ]->Name() << endl ;
2511 for ( j = 1 ; j <= _NodesNumber[ i ] ; j++ ) {
2512 _ParallelExecutionNodes = true ;
2513 cdebug << " " << (_SortedNodes[ i ])[ j ]->Name()
2517 if ( _ParallelExecutionNodes ) {
2518 // cdebug << "Parallel Execution Nodes detected." << endl ;
2521 // cdebug << "No Parallel Execution Nodes detected." << endl ;
2523 if ( AllSortedNodes != GraphNodesSize() ) {
2524 SetMessages( "That graph is cyclic.\n" ) ;
2525 cdebug << "ERROR Loop detected at level " << _LevelsNumber << endl ;
2526 return false ; // Loop in the Graph
2529 cdebug << "Graph::Sort " << _NodesNumber[ 0 ] << " HeadNodes :" << endl ;
2530 for ( i= 0 ; i <= _NodesNumber[ 0 ] ; i++ ) {
2531 (_SortedNodes[ 0 ])[ i ]->HeadNode( true ) ;
2532 cdebug << " " << i << ". : " << (_SortedNodes[ 0 ])[ i ]->Name() << endl ;
2535 // Give a subgraph/substreamgraph number > 0 to HeadNodes (level 0)
2536 // There is no substreamgraph for nodes without StreamPorts
2537 for ( j = 0 ; j <= _NodesNumber[ 0 ] ; j++ ) {
2538 (_SortedNodes[ 0 ])[ j ]->Level( 0 ) ;
2539 (_SortedNodes[ 0 ])[ j ]->SortedIndex( j ) ;
2540 (_SortedNodes[ 0 ])[ j ]->SubGraph( j + 1 ) ;
2541 if ( (_SortedNodes[ 0 ])[ j ]->HasDataStream() ) {
2542 (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( j + 1 ) ;
2545 (_SortedNodes[ 0 ])[ j ]->SubStreamGraph( -1 ) ;
2549 // Give a subgraph/substreamgraph number = 0 to all other nodes :
2550 // the SubGraph of that nodes is unknown
2551 // There is no substreamgraph for nodes without StreamPorts
2552 for ( i = 1 ; i <= _LevelsNumber ; i++ ) {
2553 for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2554 (_SortedNodes[ i ])[ j ]->Level( i ) ;
2555 (_SortedNodes[ i ])[ j ]->SortedIndex( j ) ;
2556 (_SortedNodes[ i ])[ j ]->SubGraph( 0 ) ;
2557 if ( (_SortedNodes[ i ])[ j ]->HasDataStream() ) {
2558 (_SortedNodes[ i ])[ j ]->SubStreamGraph( 0 ) ;
2561 (_SortedNodes[ i ])[ j ]->SubStreamGraph( -1 ) ;
2566 // Computation of independent SubGraphs which have NO link between them
2567 cdebug << endl << "Computation of SubGraphs" << endl ;
2568 bool Graphs = true ;
2570 for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2571 cdebug << endl << "LevelsNumber " << _LevelsNumber << " " << _NodesNumber[ i ]
2572 << " Nodes :" << endl ;
2573 for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2574 GraphBase::ComputingNode * aNode = (_SortedNodes[ i ])[ j ] ;
2575 cdebug << " " << aNode->Name() << " SubGraph " << aNode->SubGraph() << endl ;
2577 for ( k = 0 ; k < aNode->LinkedNodesSize() ; k++ ) {
2578 if ( aNode->LinkedNodes( k )->SubGraph() ) {
2579 if ( aNode->LinkedNodes( k )->SubGraph() != aNode->SubGraph() ) {
2580 // && aNode->LinkedNodes( k )->Level() == aNode->Level()+1 ) {
2581 // aNode->SubGraph( aNode->LinkedNodes( k )->SubGraph() ) ;
2582 int OldSub = aNode->SubGraph() ;
2583 int NewSub = aNode->LinkedNodes( k )->SubGraph() ;
2584 cdebug << " " << aNode->Name() << " changed SubGraph "
2585 << aNode->LinkedNodes( k )->SubGraph() << endl ;
2587 for ( l = 0 ; l <= _LevelsNumber ; l++ ) {
2589 for ( m = 0 ; m <= _NodesNumber[ l ] ; m++ ) {
2590 if ( (_SortedNodes[ l ])[ m ]->SubGraph() == OldSub ) {
2591 GraphBase::ComputingNode * aSubNode = (_SortedNodes[ l ])[ m ] ;
2592 aSubNode->SubGraph( NewSub ) ;
2600 cdebug << " Linked " << aNode->LinkedNodes( k )->Name()
2601 << " same SubGraph " << aNode->LinkedNodes( k )->SubGraph() << endl ;
2605 cdebug << " LinkedNode " << aNode->LinkedNodes( k )->Name()
2606 << " initial SubGraph " << aNode->SubGraph() << endl ;
2607 aNode->LinkedNodes( k )->SubGraph( aNode->SubGraph() ) ;
2619 cdebug << endl << "SubGraphs result : " << endl ;
2622 cdebug << endl << "One more time" << endl ;
2625 // Make a sequential renumbering of SubGraphs :
2626 _SubGraphsNumber = 0 ;
2627 int CurrGraphsNumber = 0;
2629 for ( k = 0 ; k <= _NodesNumber[ 0 ] ; k++ ) {
2630 if ( (_SortedNodes[ 0 ])[ k ]->SubGraph() > CurrGraphsNumber ) {
2631 CurrGraphsNumber = (_SortedNodes[ 0 ])[ k ]->SubGraph() ;
2632 _SubGraphsNumber += 1 ;
2633 for ( i = 0 ; i <= _LevelsNumber ; i++ ) {
2634 for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2635 if ( (_SortedNodes[ i ])[ j ]->SubGraph() == CurrGraphsNumber ) {
2636 (_SortedNodes[ i ])[ j ]->SubGraph( _SubGraphsNumber ) ;
2637 cdebug << "SubGraphsNumber " << _SubGraphsNumber << " " << " Level "
2638 << i << " : " << (_SortedNodes[ i ])[ j ]->Name()
2646 // cdebug << endl << "Computation of SubStreamGraphs" << endl ;
2647 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2648 GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2649 if ( aNode->SubStreamGraph() < 0 ) {
2650 // cdebug << "Graph " << aNode->Name() << " has NO streamport" << endl ;
2653 // cdebug << aNode->Name() << " SubGraph " << aNode->SubGraph() << " --> "
2654 // << aNode->LinkedStreamNodesSize() << " LinkedStreamNodes :" << endl ;
2655 for ( j = 0 ; j < aNode->LinkedStreamNodesSize() ; j++ ) {
2656 // cdebug << " " << aNode->LinkedStreamNodes( j )->Name() << endl ;
2661 // Computation of independent SubStreamGraphs which have NO StreamLink between them
2662 SubStreamGraphsNumber = 0 ;
2664 for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2665 // Loop for _NodesNumber[ ilevel ] nodes of the level ilevel
2667 for ( jnode = 0 ; jnode <= _NodesNumber[ ilevel ] ; jnode++ ) {
2668 GraphBase::ComputingNode * aNode = (_SortedNodes[ ilevel ])[ jnode ] ;
2669 if ( aNode->SubStreamGraph() < 0 ) {
2670 // cdebug << "Graph " << aNode->SubStreamGraph() << " " << aNode->Name()
2671 // << " has NO streamport" << endl ;
2674 int CurStreamGraphsNumber ;
2675 if ( aNode->SubStreamGraph() > 0 ) {
2676 // cdebug << "SubStreamGraph " << aNode->SubStreamGraph() << " " << aNode->Name()
2677 // << " has streamport LinkedStreamNodesSize already in a SubStreamGraph" << endl ;
2678 CurStreamGraphsNumber = aNode->SubStreamGraph() ;
2681 CurStreamGraphsNumber = SubStreamGraphsNumber+1 ;
2684 while ( RetVal != CurStreamGraphsNumber ) {
2685 RetVal = CurStreamGraphsNumber ;
2686 aNode->SetSubStreamGraph( CurStreamGraphsNumber , RetVal ) ;
2687 if ( RetVal != CurStreamGraphsNumber ) {
2688 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2689 GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2690 if ( aNode->SubStreamGraph() == CurStreamGraphsNumber ) {
2691 aNode->SubStreamGraph( RetVal ) ;
2694 CurStreamGraphsNumber = RetVal ;
2697 if ( CurStreamGraphsNumber > SubStreamGraphsNumber ) {
2698 SubStreamGraphsNumber = CurStreamGraphsNumber ;
2704 // Make a sequential renumbering of SubGraphs :
2705 // cdebug << endl << "Last SubStreamGraphsNumber : " << SubStreamGraphsNumber << endl ;
2706 int CurrStreamGraphsNumber = 0 ;
2708 for ( CurrStreamGraphsNumber = 0 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber ; CurrStreamGraphsNumber++ ) {
2709 bool SearchCurrStreamGraphsNumber = true ;
2710 for ( k = 0 ; k <= _LevelsNumber && SearchCurrStreamGraphsNumber ; k++ ) {
2712 for ( l = 0 ; l <= _NodesNumber[ k ] && SearchCurrStreamGraphsNumber ; l++ ) {
2713 if ( (_SortedNodes[ k ])[ l ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2714 SearchCurrStreamGraphsNumber = false ;
2716 if ( CurrStreamGraphsNumber != count ) {
2717 // cdebug << "CurrStreamGraphsNumber " << CurrStreamGraphsNumber << " count " << count
2718 // << " Level " << k << " n " << l << endl ;
2719 for ( i = k ; i <= _LevelsNumber ; i++ ) {
2720 for ( j = 0 ; j <= _NodesNumber[ i ] ; j++ ) {
2721 if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2722 (_SortedNodes[ i ])[ j ]->SubStreamGraph( count ) ;
2723 // cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " --> " << count << " "
2724 // << " Level " << i << " : " << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2726 else if ( (_SortedNodes[ i ])[ j ]->SubStreamGraph() > 0 ) {
2727 // cdebug << "SubStreamGraphsNumber " << (_SortedNodes[ i ])[ j ]->SubStreamGraph()
2728 // << " != " << CurrStreamGraphsNumber << " Level " << i << " : "
2729 // << (_SortedNodes[ i ])[ j ]->Name() << endl ;
2738 SubStreamGraphsNumber = count ;
2739 // cdebug << endl << "SubStreamGraphs result : " << SubStreamGraphsNumber << " SubStreamGraphs" << endl ;
2740 // int CurrStreamGraphsNumber ;
2741 // for ( CurrStreamGraphsNumber = 1 ; CurrStreamGraphsNumber <= SubStreamGraphsNumber ; CurrStreamGraphsNumber++ ) {
2742 // for ( ilevel = 0 ; ilevel <= _LevelsNumber ; ilevel++ ) {
2743 // for ( k = 0 ; k <= _NodesNumber[ ilevel ] ; k++ ) {
2744 // if ( (_SortedNodes[ ilevel ])[ k ]->SubStreamGraph() == CurrStreamGraphsNumber ) {
2745 // cdebug << "SubStreamGraphsNumber " << CurrStreamGraphsNumber << " : "
2746 // << (_SortedNodes[ ilevel ])[ k ]->Name() << endl ;
2754 ListPorts( *_Graph_fdebug , 0 ) ;
2757 cdebug_out << "GraphBase::Graph::Sort" << endl;
2761 bool GraphBase::Graph::ValidLoops() const {
2762 cdebug_in << "GraphBase::Graph::ValidLoops" << endl;
2763 bool RetVal = true ;
2765 GraphBase::ComputingNode * aNode ;
2766 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2767 aNode = GraphNodes( i ) ;
2768 if ( aNode->IsLoopNode() ) {
2769 GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2770 GraphBase::EndOfLoopNode * anEndLoopNode ;
2771 anEndLoopNode = (GraphBase::EndOfLoopNode * ) aLoopNode->CoupledNode() ;
2772 string anErrorMessage = string( "CheckLoop " ) + string( aLoopNode->Name() ) +
2773 string( " --> " ) + string( anEndLoopNode->Name() ) +
2775 if ( !aLoopNode->CheckLoop( aLoopNode , anEndLoopNode , anErrorMessage ) ) {
2776 ((GraphBase::Graph * ) this)->SetMessages( anErrorMessage ) ;
2777 cdebug << "GraphBase::Graph::ValidLoops false aLoopNode " << aLoopNode->Name()
2781 anErrorMessage = string( "CheckEndLoop " ) + string( aLoopNode->Name() ) +
2782 string( " --> " ) + string( anEndLoopNode->Name() ) + string( " :\n" ) ;
2783 if ( !anEndLoopNode->CheckEndLoop( aLoopNode , anEndLoopNode , anErrorMessage ) ) {
2784 ((GraphBase::Graph * ) this)->SetMessages( anErrorMessage ) ;
2785 cdebug << "GraphBase::Graph::ValidLoops false anEndLoopNode " << anEndLoopNode->Name()
2791 cdebug_out << "GraphBase::Graph::ValidLoops RetVal " << RetVal << endl;
2795 bool GraphBase::Graph::ValidSwitchs() const {
2796 cdebug_in << "GraphBase::Graph::ValidSwitchs" << endl;
2797 bool RetVal = true ;
2799 GraphBase::ComputingNode * aNode ;
2800 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2801 aNode = GraphNodes( i ) ;
2802 if ( aNode->IsSwitchNode() ) {
2803 GraphBase::SwitchNode * aSwitchNode = (GraphBase::SwitchNode * ) aNode ;
2804 if ( !aSwitchNode->CheckSwitch() ) {
2805 cdebug << "GraphBase::Graph::ValidSwitchs false aSwitchNode " << aSwitchNode->Name()
2811 cdebug_out << "GraphBase::Graph::ValidSwitchs RetVal " << RetVal << endl;
2815 // Controle de la coherence des noeuds de calcul
2816 // Enregistrement dans la liste des noeuds "tete" de graphe
2818 bool GraphBase::Graph::ComputingNodes() const {
2819 bool RetVal = true ;
2820 cdebug << "GraphExecutor::Graph::ComputingNodes ()" << endl;
2822 // list<GraphEditor::Node *> aComputingNodesList = _G->ComputingNodesList() ;
2823 // list<GraphEditor::Node *>::iterator aNode = aComputingNodesList.begin();
2824 // GraphEditor::Port * iP;
2826 // for (aNode = _G->ComputingNodesList().begin(); aNode !=_G->ComputingNodesList().end(); aNode++) {
2827 // while ( aNode != aComputingNodesList.end() ) {
2829 GraphBase::ComputingNode * aNode ;
2830 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2831 aNode = GraphNodes( i ) ;
2832 cdebug << "Graph::ComputingNodes " << i << ". " << aNode->Name() << " Head " << aNode->IsHeadNode()
2834 // Tous les ports d'entree de tous les noeuds de calcul sont bien connectes
2835 // Enregistrement eventuel dans la liste des noeuds "tete" de graphe
2836 // if ((*aNode)->GetNodeInPortsSize() == 0)
2837 // _headNodes.push_front(*aNode);
2839 for ( j = 1 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
2840 const GraphBase::InPort *iP = aNode->GetNodeInPort(j);
2841 if ( iP->IsNotConnected() ){
2842 // cdebug << "Le port d'entree " << iP->PortName()
2843 // << " du noeud de calcul " << aNode->Name() << " du graphe "
2844 // << Name() << " n'est pas connecte "<< endl;
2845 // string anErrorMessage = string( "That graph have InPort not connected " ) +
2846 // string( iP->NodeName() ) +
2847 // string( "( " ) + string( iP->PortName() ) + string( " )\n" ) ;
2848 // ((GraphBase::Graph * ) this)->SetMessages( anErrorMessage ) ;
2854 // Tous les noeuds de calcul ont au moins un port de sortie connecte
2855 bool oneOutPortConnected = false;
2856 for ( j = 1 ; j < aNode->GetNodeOutPortsSize() ; j++) {
2857 const GraphBase::OutPort *iP = aNode->GetNodeOutPort(j);
2858 if ( iP->IsPortConnected() || iP->IsDataConnected() ){
2859 oneOutPortConnected = true ;
2863 // cdebug << "Le port de sortie " << iP->PortName()
2864 // << " du noeud de calcul " << aNode->Name() << " du graphe "
2865 // << Name() << " n'est pas connecte "<< endl;
2866 // string anErrorMessage = string( "That graph have OutPort not connected " ) +
2867 // string( iP->NodeName() ) +
2868 // string( "( " ) + string( iP->PortName() ) + string( " )\n" ) ;
2869 // ((GraphBase::Graph * ) this)->SetMessages( anErrorMessage ) ;
2873 if (!oneOutPortConnected) {
2874 // cdebug << "Le noeud de calcul " << aNode->Name() << " du graphe "
2875 // << Name() << " n'a aucun port de sortie connecte "<< endl;
2876 // _computingError.push_front(2);
2879 // return _computingError.size () ;
2883 bool GraphBase::Graph::LinkLoopNodes(bool & NewLink ) {
2884 bool RetVal = true ;
2887 cdebug_in << "GraphBase::Graph::LinkLoopNodes()" << endl;
2888 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2889 GraphBase::ComputingNode * aNode = GraphNodes( i ) ;
2890 if ( aNode->IsLoopNode() ) {
2891 GraphBase::LoopNode * aLoopNode = (GraphBase::LoopNode * ) aNode ;
2892 for ( j = 0 ; j < aLoopNode->GetNodeInPortsSize() ; j++ ) {
2893 GraphBase::InPort *anInPort = aLoopNode->GetChangeNodeInPort(j) ;
2894 cdebug << "Graph::LinkLoopNodes " << aLoopNode->Name() << "( " << anInPort->PortName()
2895 << " ) InPort " << anInPort->PortStatus() << endl ;
2896 if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2897 if ( !AddLink( aLoopNode->CoupledNode() , aLoopNode->CoupledNode()->GetChangeNodeOutPort( j ) ,
2898 aLoopNode , anInPort ) ) {
2899 cdebug << "Graph::LinkLoopNodes AddLink ERROR "
2900 << aLoopNode->CoupledNode()->Name()
2901 << "( " << aLoopNode->CoupledNode()->GetChangeNodeOutPort( j )->PortName()
2902 << " ) --> " << aLoopNode->Name() << "( " << anInPort->PortName() << " )"
2911 for ( j = 0 ; j < aLoopNode->CoupledNode()->GetNodeInPortsSize() ; j++ ) {
2912 GraphBase::EndOfLoopNode * anEndLoopNode ;
2913 anEndLoopNode = (GraphBase::EndOfLoopNode * ) aLoopNode->CoupledNode() ;
2914 GraphBase::InPort *anInPort = anEndLoopNode->GetChangeNodeInPort( j ) ;
2915 cdebug << "Graph::LinkLoopNodes " << anEndLoopNode->Name() << "( " << anInPort->PortName()
2916 << " ) InPort " << anInPort->PortStatus() << endl ;
2917 if ( !anInPort->IsGate() && anInPort->IsNotConnected() ) {
2918 if ( !AddLink( aLoopNode , aLoopNode->GetChangeNodeOutPort( j ) ,
2919 anEndLoopNode , anInPort ) ) {
2920 cdebug << "Graph::LinkLoopNodes AddLink ERROR " << aLoopNode->Name() << "( "
2921 << aLoopNode->GetChangeNodeOutPort( j )->PortName() << " ) --> "
2922 << anEndLoopNode->Name() << "( " << anInPort->PortName() << " )"
2932 else if ( aNode->IsGOTONode() ) {
2933 GraphBase::GOTONode * aGOTONode = (GraphBase::GOTONode * ) aNode ;
2934 GraphBase::OutPort *anOutGate = aGOTONode->GetChangeNodeOutGate() ;
2935 if ( anOutGate->IsNotConnected() ) {
2936 if ( aGOTONode->CoupledNode() ) {
2937 cdebug << "Graph::LinkLoopNodes aNode " << aNode << " : " << aNode->Name()
2938 << aGOTONode->CoupledNode() << " : " << aGOTONode->CoupledNode()->Name()
2940 RetVal = AddLink( aGOTONode , anOutGate , aGOTONode->CoupledNode() ,
2941 aGOTONode->CoupledNode()->GetChangeNodeInGate() );
2942 cdebug << "GraphBase::Graph::LinkLoopNodes AddLink ERROR " << aGOTONode->Name() << "( "
2943 << anOutGate->PortName() << " ) --> " << aGOTONode->CoupledNode()->Name() << "( "
2944 << aGOTONode->CoupledNode()->GetChangeNodeInGate()->PortName() << " )" << endl ;
2951 cdebug_out << "GraphBase::Graph::LinkLoopNodes() NewLink " << NewLink << " returns " << RetVal
2956 // Controle de la coherence des noeuds de calcul
2957 // Enregistrement dans la liste des noeuds "tete" de graphe
2959 bool GraphBase::Graph::DataServerNodes() const {
2961 cdebug_in << "GraphBase::Graph::DataServerNodes ()" << endl;
2963 // const GraphExecutor::InNode *DataFlowDatas = GetDataFlowDatas() ;
2964 int i , j , ierr = 0 ;
2966 // if ( DataFlowDatas == NULL ) {
2967 // MESSAGE( "No input data available in the DataFlow " << _G->Name() );
2971 // const GraphExecutor::InNode *DataFlowNode = _G->GetDataFlowNode() ;
2972 // MESSAGE( "DataServerNodes DataFlowNode : " << *DataFlowNode );
2974 // MESSAGE( "DataServerNodes DataFlowDatas : " << *DataFlowDatas );
2976 // cout are inversed because DataFlowDatas is a mirror node of the DataFlow
2978 ierr = CheckDataServerNodes() ;
2980 // list<GraphExecutor::InNode *> aComputingNodesList = _G->ComputingNodesList() ;
2981 // list<GraphExecutor::InNode *>::iterator aNode = aComputingNodesList.begin();
2982 if ( GraphNodesSize() == 0 ) {
2986 GraphBase::ComputingNode * aNode ;
2987 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
2988 aNode = GraphNodes( i ) ;
2989 // while ( aNode != aComputingNodesList.end() ) {
2990 if ( aNode->IsFactoryNode() ) {
2991 GraphBase::FactoryNode * FaNode = (GraphBase::FactoryNode * ) aNode ;
2992 if ( !strlen( FaNode->Computer() ) ) {
2993 // cdebug << "ComputerName missing for node " << FaNode->Name() ;
2994 if ( !strlen( FaNode->Computer() ) ) {
2999 // cdebug << ". " << FaNode->Computer() << " will be used." << endl ;
3003 // For Outputs of the DataFlow :
3004 for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
3005 const GraphBase::OutPort * anOutPort = aNode->GetNodeOutPort(j) ;
3006 //JR Debug 06.06.2005 : if it is not a Gate !
3007 // if ( anOutPort->IsNotConnected() ) {
3008 if ( anOutPort->IsNotConnected() && !anOutPort->IsGate() ) {
3009 cdebug << "Graph::DataServerNodes Add[Stream]LinkedNode for OutPort "
3010 << aNode->Name() << "( " << anOutPort->PortName() << " , "
3011 << anOutPort->PortStatus() << " )" << endl ;
3012 if ( anOutPort->IsDataStream() ) {
3013 aNode->AddStreamLinkedNode( (GraphBase::ComputingNode *) this ) ;
3016 aNode->AddLinkedNode( (GraphBase::ComputingNode *) this ) ;
3023 // Chaque noeud dataserver ne possede qu'un seul port entree ou sortie et il est bien connecte
3025 // list<GraphExecutor::InNode *> aDataServerNodesList = _G->DataServerNodesList() ;
3026 // list<GraphExecutor::InNode *>::iterator it = aDataServerNodesList.begin() ;
3028 // for (it = _G->DataServerNodesList().begin(); it !=_G->DataServerNodesList().end(); it++){
3029 // while ( it != aDataServerNodesList.end() ) {
3030 // if ( (*it)->GetNodeOutPortsSize() && (*it)->GetNodeInPortsSize() ) {
3031 // cerr << "Erreur dans le noeud serveur de donnees "
3032 // << (*it)->Name() << " du graphe " << _G->Name() << endl;
3033 // cerr << "A la fois importation et exportation de donnees" << endl;
3034 // _dataServerError.push_front(1);
3037 // if ((*it)->GetNodeOutPortsSize()) {
3038 // if ((*it)->GetNodeOutPortsSize()==1){
3039 // if ( (*it)->GetNodeOutPort(0)->IsPortConnected() ){
3040 // _headNodes.push_front(*it);
3043 // cerr << "Le port de sortie du noeud serveur de donnees "
3044 // << (*it)->Name() << " du graphe " << _G->Name()
3045 // << " n'est pas connecte "<< endl;
3046 // _dataServerError.push_front(4);
3050 // cerr << "Plus d'une donnee importee du noeud serveur de donnees "
3051 // << (*it)->Name() << " du graphe " << _G->Name() << endl;
3052 // _dataServerError.push_front(2);
3056 // if ((*it)->GetNodeInPortsSize()) {
3057 // if ((*it)->GetNodeInPortsSize() > 1){
3058 // cerr << "Plus d'une donnee exportee vers le noeud serveur de donnees "
3059 // << (*it)->Name() << " du graphe " << _G->Name() << endl;
3060 // _dataServerError.push_front(3);
3063 // if ( !(*it)->GetNodeInPort(0)->IsPortConnected() ){
3064 // cerr << "Le port d'entree du noeud serveur de donnees "
3065 // << (*it)->Name() << " du graphe " << _G->Name()
3066 // << " n'est pas connecte "<< endl;
3067 // _dataServerError.push_front(5);
3073 // return _dataServerError.size ();
3074 cdebug_out << "GraphBase::Graph::DataServerNodes ierr " << ierr << endl;
3075 return ( ierr == 0 ) ;
3078 SUPERV::GraphState GraphBase::Graph::PortState(
3079 const char* NodeName ,
3080 const char* ServiceParameterName ) {
3081 SUPERV::GraphState aRet = SUPERV::UndefinedState ;
3082 // cdebug << "GraphBase::Graph::PortState( " << NodeName << " , "
3083 // << ServiceParameterName << " )" << endl ;
3087 NodePort( NodeName , ServiceParameterName , &theNode , &aPort ) ;
3089 GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
3091 GraphBase::OutPort *anOutPort ;
3092 anOutPort = aNode->GetChangeOutPort( aPort );
3093 if ( anOutPort == NULL ) {
3094 GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
3096 anOutPort = anInPort->GetOutPort() ;
3098 cdebug << "ERROR GraphBase::Graph::PortState OutPort/InPort not found --> "
3103 aRet = anOutPort->PortState() ;
3104 // cdebug << "GraphBase::Graph::PortState --> " << aRet << endl ;
3108 cdebug << "ERROR GraphBase::Graph::PortState Node not found --> " << aRet
3116 #define TracePortInOutData 0
3117 //JR 30.03.2005const CORBA::Any * GraphBase::Graph::PortInData( const char* ToNodeName ,
3118 const CORBA::Any GraphBase::Graph::PortInData( const char* ToNodeName ,
3119 const char* ToServiceParameterName ) {
3120 //JR 30.03.2005 const CORBA::Any * aRet = new CORBA::Any() ;
3121 CORBA::Any aRet = CORBA::Any() ;
3124 #if TracePortInOutData
3125 cdebug_in << "GraphBase::Graph::PortInData " << ToNodeName << " "
3126 << ToServiceParameterName << endl ;
3128 NodePort( ToNodeName , ToServiceParameterName , &theNode , &aPort ) ;
3130 GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
3133 GraphBase::OutPort *anOutPort = NULL ;
3134 GraphBase::InPort *anInPort = aNode->GetChangeInPort( aPort );
3136 anOutPort = anInPort->GetOutPort() ;
3138 #if TracePortInOutData
3139 cdebug << "-->PortInData " << ToNodeName << " " << ToServiceParameterName << " "
3142 aRet = anOutPort->Value() ;
3143 #if TracePortInOutData
3144 cdebug << "<--PortInData " << ToNodeName << " " << ToServiceParameterName << " " ;
3145 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3147 cdebug << "Graph::PortInData OutPort value " << anOutPort->NodeName() << "("
3148 << anOutPort->PortName() << ") --> InPort " << anInPort->NodeName()
3149 << "(" << anInPort->PortName() << ") " << anInPort->PortStatus() << endl ;
3153 cdebug << "Graph::PortInData GraphBase::Graph::PortInData " << ToNodeName << " "
3154 << ToServiceParameterName << " ERROR no OutPort" << endl ;
3158 cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
3159 << ToServiceParameterName << " ERROR no InPort" << endl ;
3163 cdebug << "GraphBase::Graph::PortInData " << ToNodeName << " "
3164 << ToServiceParameterName << " ERROR no Node" << endl ;
3168 #if TracePortInOutData
3169 cdebug_out << "GraphBase::Graph::PortInData " << endl ;
3174 //JR 30.03.2005const CORBA::Any * GraphBase::Graph::PortOutData( const char* FromNodeName ,
3175 const CORBA::Any GraphBase::Graph::PortOutData( const char* FromNodeName ,
3176 const char* FromServiceParameterName ) {
3177 //JR 30.03.2005 const CORBA::Any * aRet = new CORBA::Any() ;
3178 CORBA::Any aRet = CORBA::Any() ;
3181 #if TracePortInOutData
3182 cdebug_in << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3183 << FromServiceParameterName << endl ;
3185 NodePort( FromNodeName , FromServiceParameterName , &theNode , &aPort ) ;
3187 GraphBase::ComputingNode * aNode = GetChangeGraphNode( theNode ) ;
3190 GraphBase::OutPort *anOutPort ;
3191 anOutPort = aNode->GetChangeOutPort( aPort );
3193 #if TracePortInOutData
3194 cdebug << "-->PortOutData " << FromNodeName << " " << FromServiceParameterName << " "
3197 aRet = anOutPort->Value() ;
3198 #if TracePortInOutData
3199 cdebug << "<--PortOutData " << FromNodeName << " " << FromServiceParameterName << " " ;
3200 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3205 cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3206 << FromServiceParameterName << " ERROR no OutPort" << endl ;
3210 cdebug << "GraphBase::Graph::PortOutData " << FromNodeName << " "
3211 << FromServiceParameterName << " ERROR no Node" << endl ;
3215 #if TracePortInOutData
3216 cdebug_out << "GraphBase::Graph::PortOutData " << endl ;
3221 SUPERV::ListOfStrings * GraphBase::Graph::LevelNodes(long aLevel ) {
3222 SUPERV::ListOfStrings_var RetVal = new SUPERV::ListOfStrings;
3223 if ( aLevel >= 0 && aLevel <= _LevelsNumber ) {
3225 RetVal->length( _NodesNumber[ aLevel ] + 1 );
3226 for ( i= 0 ; i <= _NodesNumber[ aLevel ] ; i++ ) {
3227 RetVal[i] = CORBA::string_dup( (_SortedNodes[ aLevel ])[ i ]->Name() ) ;
3230 return ( RetVal._retn() ) ;
3233 bool GraphBase::Graph::StartComponent(const int aThread ,
3234 const char * aComputerContainer ,
3235 const char * ComponentName ,
3236 Engines::Container_var & myContainer ,
3237 Engines::Component_var & objComponent ) {
3238 cdebug_in << aThread
3239 << " GraphBase::Graph::StartComponent " << aComputerContainer
3240 << " " << ComponentName << endl;
3241 bool RetVal = true ;
3242 objComponent = Engines::Component::_nil() ;
3243 SALOME_LifeCycleCORBA LCC( NamingService() ) ;
3245 objComponent = LCC.FindOrLoad_Component( aComputerContainer ,
3251 if ( CORBA::is_nil( objComponent ) ) {
3252 cdebug_out << aThread
3253 << " StartComponent cannot FindOrLoad " << aComputerContainer
3254 << " " << ComponentName << " ERROR" << endl;
3257 /* asv : 24.01.05 : FindContainer() method does not exist any more. FindOrLoad_Component()
3258 starts the container for us. If it fails to start the container, then it
3259 returns nil component. We don't need to check for if the container was
3260 successfully started..
3262 myContainer = LCC.FindContainer( aComputerContainer );
3263 if ( CORBA::is_nil( myContainer ) ) {
3264 cdebug_out << aThread
3265 << " GraphBase::Graph::StartComponent myContainer = LCC.FindContainer( '"
3266 << aComputerContainer << "' ) Container does not exist ERROR"
3273 string anErrorMessage = string( "Error while FindOrLoad_Component " ) +
3274 string( ComponentName ) + string( " in Container " ) +
3275 string( aComputerContainer ) ;
3276 SetMessages( anErrorMessage ) ;
3278 cdebug_out << aThread << " GraphBase::Graph::StartComponent RetVal " << RetVal << endl;