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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : DataFlowBase_Graph.hxx
25 // Author : Jean Rahuel, CEA
29 #ifndef _DATAFLOWBASE_GRAPH_HXX
30 #define _DATAFLOWBASE_GRAPH_HXX
32 #include "DataFlowBase_FactoryNode.hxx"
33 #include "DataFlowBase_LoopNode.hxx"
34 #include "DataFlowBase_EndOfLoopNode.hxx"
35 #include "DataFlowBase_SwitchNode.hxx"
36 #include "DataFlowBase_EndOfSwitchNode.hxx"
37 #include "DataFlowBase_DataNode.hxx"
41 class Graph : public DataNode {
45 // int _Graph_prof_debug;
46 // ofstream * _Graph_fdebug;
48 // SUPERV::Graph_var _Graph ;
49 // Graph_Impl * _GraphImpl ;
51 // Map of Nodes of the Graph
52 map< string , int > _MapOfGraphNodes ;
53 long _GraphNodesSize ;
54 vector<bool > _Sorted ;
55 vector<ComputingNode *> _GraphNodes ;
57 // _SortedNodes[ _LevelsNumber ] : topological sort from 0 to _LevelsNumber
58 // _SortedNodes[ _level ][ _NodesNumber[ _level ] ] : _NodesNumber[ _level ] Nodes in the level
61 vector<int > _NodesNumber ;
62 vector<vector<ComputingNode *> > _SortedNodes ;
64 vector<int > _CnxInPortsNumber ;
65 vector<int > _DecrInPortsNumber ;
68 vector<ComputingNode *> _HeadNodes ;
69 long _QueueNodesSize ;
70 vector<ComputingNode *> _QueueNodes ;
71 bool _ParallelExecutionNodes ;
73 // For StreamGraphs. It is not the same Service if it belongs to
74 // a different Interface and/or a different Component ...
75 map< string , GraphBase::Service * > _MapOfServiceNames ;
77 // For automactic rename of nodes if unique names in graphs
78 map< string , int > _MapOfServiceInstanceNumber ;
80 // Total number of SubGraphs
81 int _SubGraphsNumber ;
82 // _SubGraphs[ SubGraphNumero ] [ NodeNumero ]
83 // SubGraphNumero : [ 0 , _SubGraphsSize [ ; NodeNumero : [ 0 , _SubGraphs[ SubGraphNumero ].size() [
85 vector<vector<ComputingNode *> > _SubGraphs ;
87 // _SubStreamGraphs[ SubStreamGraphNumero ] [ NodeNumero ]
88 // SubStreamGraphNumero : [ 0 , _SubStreamGraphsSize [
89 // NodeNumero : [ 0 , _SubStreamGraphs[ SubStreamGraphNumero ].size() [
90 // int _SubStreamGraphsSize ;
91 // vector<vector<ComputingNode *> > _SubStreamGraphs ;
95 map< string, string > _MapOfComponentNameContainer ; // mkr : PAL13947
97 bool AddLink( GraphBase::ComputingNode *fromNode ,
98 GraphBase::OutPort *fromPort ,
99 GraphBase::ComputingNode *toNode ,
100 GraphBase::InPort *toPort ) ;
105 Graph( CORBA::ORB_ptr ORB ,
106 SALOME_NamingService* ptrNamingService ,
107 const char *DataFlowName ,
108 const SUPERV::KindOfNode DataFlowkind ,
109 int * Graph_prof_debug ,
110 ofstream * Graph_fdebug ) ;
111 // const char * DebugFileName ) ;
112 Graph( CORBA::ORB_ptr ORB ,
113 SALOME_NamingService* ptrNamingService ,
114 const SALOME_ModuleCatalog::Service& DataFlowService ,
115 const char *DataFlowComponentName ,
116 const char *DataFlowInterfaceName ,
117 const char *DataFlowName ,
118 const SUPERV::KindOfNode DataFlowkind ,
119 const SUPERV::SDate DataFlowFirstCreation ,
120 const SUPERV::SDate DataFlowLastModification ,
121 const char * DataFlowEditorRelease ,
122 const char * DataFlowAuthor ,
123 const char * DataFlowComputer ,
124 const char * DataFlowComment ,
125 int * Graph_prof_debug ,
126 ofstream * Graph_fdebug ) ;
127 // const char * DebugFileName ) ;
130 // void Set_prof_debug( CORBA::ORB_ptr ORB ,
131 // const char * DebugFileName ) ;
132 void Set_prof_debug( int * Graph_prof_debug ,
133 ofstream * Graph_fdebug ) ;
134 int * Graph_prof_debug() {
135 return _prof_debug ; } ;
136 ofstream * Graph_fdebug() { return _fdebug ; } ;
138 // SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
139 // void SetObjRef( SUPERV::Graph_var aGraph ) {
140 // _Graph = aGraph ; } ;
141 // Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
142 // void SetObjImpl( Graph_Impl * aGraphImpl ) {
143 // _GraphImpl = aGraphImpl ; } ;
145 void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
146 GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
148 const int GetGraphNodeIndex( const char *name ) {
149 const int index = _MapOfGraphNodes[ name ] - 1 ;
151 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
152 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
153 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
155 cdebug << "Graph::GetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
157 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
158 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
160 map< string , int >::iterator aMapOfGraphNodesIterator ;
162 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
163 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
164 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
165 << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
169 void SetGraphNodeIndex( const char *name , const int index ) {
170 _MapOfGraphNodes[ name ] = index + 1 ;
171 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
172 << index << " Node " << (void *) _GraphNodes[ index ]
173 << " '" << _GraphNodes[ index ]->Name() << "' MapOfGraphNodessize "
174 << GetGraphNodeSize() << endl ;
176 cdebug << "Graph::SetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
178 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
179 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
181 map< string , int >::iterator aMapOfGraphNodesIterator ;
183 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
184 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
185 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
186 << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
190 void DelGraphNodeIndex( const char *name ) {
191 _MapOfGraphNodes.erase( name ) ; } ;
193 int GetGraphNodeSize() const {
194 return _MapOfGraphNodes.size() ; }
195 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
196 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
198 ComputingNode * GetChangeGraphNode( const int index ) const {
199 if ( index >= 0 && index < _GraphNodesSize ) {
200 ComputingNode * aNode = _GraphNodes[ index ] ;
205 const ComputingNode * GetGraphNode( const char *name ) {
206 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
208 ComputingNode * GetChangeGraphNode( const char *name ) {
209 int index = GetGraphNodeIndex( name ) ;
210 if ( index >= 0 && index < _GraphNodesSize ) {
211 ComputingNode * aNode = GetChangeGraphNode( index ) ;
217 const int GraphNodesSize() const {
218 return _GraphNodesSize ; } ;
219 ComputingNode * GraphNodes( int i ) const {
220 return _GraphNodes[ i ] ; } ;
222 const int HeadNodesSize() const {
223 return _HeadNodesSize ; } ;
224 ComputingNode * HeadNodes( int i ) const {
225 return _HeadNodes[ i ] ; } ;
227 const int QueueNodesSize() const {
228 return _QueueNodesSize ; } ;
229 ComputingNode * QueueNodes( int i ) const {
230 return _QueueNodes[ i ] ; } ;
232 const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
233 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
234 GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
235 return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
236 const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
237 return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
238 GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
239 return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
241 const GraphBase::InPort * GetInPort( const char * ToNodeName ,
242 const char * ToServiceParameterName ) {
243 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
245 return aNode->GetInPort(ToServiceParameterName);
249 GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
250 const char * ToServiceParameterName ) {
251 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
253 return aNode->GetChangeInPort( ToServiceParameterName ) ;
257 const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
258 const char * FromServiceParameterName ) {
259 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
261 return aNode->GetOutPort( FromServiceParameterName ) ;
265 GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
266 const char * FromServiceParameterName ) {
267 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
269 return aNode->GetChangeOutPort( FromServiceParameterName );
274 SUPERV::GraphState PortState( const char* NodeName ,
275 const char* ServiceParameterName ) ;
276 bool PortDone( const char* NodeName ,
277 const char* ServiceParameterName ) {
279 SUPERV::GraphState aState = PortState( NodeName ,
280 ServiceParameterName ) ;
281 if ( aState == SUPERV::DoneState )
284 //JR 30.03.2005 const CORBA::Any * PortInData( const char* ToNodeName ,
285 const CORBA::Any PortInData( const char* ToNodeName ,
286 const char* ToServiceParameterName ) ;
287 //JR 30.03.2005 const CORBA::Any * PortOutData( const char* FromNodeName ,
288 const CORBA::Any PortOutData( const char* FromNodeName ,
289 const char* FromServiceParameterName ) ;
291 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
292 GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
294 GraphBase::SNode * GetInfo() const ;
295 GraphBase::ListOfSNodes * GetNodes() const ;
296 GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
297 GraphBase::ListOfSGraphs * GetGraphs() const ;
298 GraphBase::ListOfSLinks * GetDatas() const ;
300 bool AddNode( ComputingNode * aNode ) ;
301 bool RemoveNode( const char* NodeName ) ;
302 bool ReNameNode( const char* OldNodeName ,
303 const char* NewNodeName ) ;
305 bool AddLink( const char* FromNodeName ,
306 const char* FromServiceParameterName ,
307 const char* ToNodeName ,
308 const char* ToServiceParameterName ) ;
309 // , const CORBA::Any aValue ) ;
310 bool RemoveLink( const char* FromNodeName ,
311 const char* FromServiceParameterName ,
312 const char* ToNodeName ,
313 const char* ToServiceParameterName ) ;
314 bool GetLink( const char* ToNodeName ,
315 const char* ToServiceParameterName ,
316 char** FromNodeName ,
317 char** FromServiceParameterName ) ;
318 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
319 GraphBase::InPort* toPort ) ;
321 bool AddInputData( const char* ToNodeName ,
322 const char* ToParameterName ,
323 const CORBA::Any aValue ) ;
324 bool ChangeInputData( const char* ToNodeName ,
325 const char* ToParameterName ,
326 const CORBA::Any aValue ) ;
327 // bool AddInputData( const char* ToNodeName ,
328 // const char* ToParameterName ,
329 // const CORBA::Any ** aValue ) ;
331 bool AddOutputData( const char* FromNodeName ,
332 const char* FromParameterName ,
333 const CORBA::Any aValue ) ;
335 void SetGraphPorts() ;
338 void ReSetMessages() ;
339 void SetMessages( string anErrorMessage ) ;
341 bool CreateService() ;
342 bool InLineServices() ;
344 bool Sort( int & SubStreamGraphsNumber ) ;
345 bool ValidGOTO() ; // mkr : PAL12575
346 bool ValidLoops() const ;
347 bool ValidSwitchs() const ;
348 bool ComputingNodes() const ;
349 bool LinkLoopNodes(bool & NewLink ) ;
350 bool DataServerNodes() const ;
353 return _LevelsNumber + 1 ; } ;
355 map< string , GraphBase::Service * > MapOfServiceNames() ;
356 GraphBase::Service * GetServiceOfMap( char * name ) ;
357 bool SetServiceOfMap( GraphBase::Service * aService ) ;
358 int GetNewServiceInstanceNumber( char * aServiceName ) ;
360 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
362 return _ThreadsMax ; } ;
364 long SubGraphsNumber() {
365 return _SubGraphsNumber ; } ;
367 int NodesNumber(const int aLevel ) {
368 return _NodesNumber[ aLevel ] ; } ;
369 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
370 return (_SortedNodes[ aLevel ])[ index ] ; } ;
372 bool StartComponent( const int aThread ,
373 const char * ComputerContainer ,
374 const char * ComponentName ,
375 Engines::Container_var & myContainer ,
376 Engines::Component_var & objComponent ) ;
379 void InsertToMapOfComponentNameContainer( const char * theComponentName,
380 const char * theContainer) {
381 _MapOfComponentNameContainer[ theComponentName ] = theContainer ;
385 const char * RetrieveFromMapOfComponentNameContainer( const char * theComponentName ) {
386 if ( _MapOfComponentNameContainer.empty()
388 _MapOfComponentNameContainer.find(theComponentName) == _MapOfComponentNameContainer.end() )
391 return _MapOfComponentNameContainer[ theComponentName ].c_str() ;
395 void ClearMapOfComponentNameContainer() {
396 if ( !_MapOfComponentNameContainer.empty() )
397 _MapOfComponentNameContainer.clear();