1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
23 // File : DataFlowBase_Graph.hxx
24 // Author : Jean Rahuel, CEA
28 #ifndef _DATAFLOWBASE_GRAPH_HXX
29 #define _DATAFLOWBASE_GRAPH_HXX
31 #include "DataFlowBase_FactoryNode.hxx"
32 #include "DataFlowBase_LoopNode.hxx"
33 #include "DataFlowBase_EndOfLoopNode.hxx"
34 #include "DataFlowBase_SwitchNode.hxx"
35 #include "DataFlowBase_EndOfSwitchNode.hxx"
36 #include "DataFlowBase_DataNode.hxx"
40 class Graph : public DataNode {
44 // int _Graph_prof_debug;
45 // ofstream * _Graph_fdebug;
47 // SUPERV::Graph_var _Graph ;
48 // Graph_Impl * _GraphImpl ;
50 // Map of Nodes of the Graph
51 map< string , int > _MapOfGraphNodes ;
52 long _GraphNodesSize ;
53 vector<bool > _Sorted ;
54 vector<ComputingNode *> _GraphNodes ;
56 // _SortedNodes[ _LevelsNumber ] : topological sort from 0 to _LevelsNumber
57 // _SortedNodes[ _level ][ _NodesNumber[ _level ] ] : _NodesNumber[ _level ] Nodes in the level
60 vector<int > _NodesNumber ;
61 vector<vector<ComputingNode *> > _SortedNodes ;
63 vector<int > _CnxInPortsNumber ;
64 vector<int > _DecrInPortsNumber ;
67 vector<ComputingNode *> _HeadNodes ;
68 long _QueueNodesSize ;
69 vector<ComputingNode *> _QueueNodes ;
70 bool _ParallelExecutionNodes ;
72 // For StreamGraphs. It is not the same Service if it belongs to
73 // a different Interface and/or a different Component ...
74 map< string , GraphBase::Service * > _MapOfServiceNames ;
76 // For automactic rename of nodes if unique names in graphs
77 map< string , int > _MapOfServiceInstanceNumber ;
79 // Total number of SubGraphs
80 int _SubGraphsNumber ;
81 // _SubGraphs[ SubGraphNumero ] [ NodeNumero ]
82 // SubGraphNumero : [ 0 , _SubGraphsSize [ ; NodeNumero : [ 0 , _SubGraphs[ SubGraphNumero ].size() [
84 vector<vector<ComputingNode *> > _SubGraphs ;
86 // _SubStreamGraphs[ SubStreamGraphNumero ] [ NodeNumero ]
87 // SubStreamGraphNumero : [ 0 , _SubStreamGraphsSize [
88 // NodeNumero : [ 0 , _SubStreamGraphs[ SubStreamGraphNumero ].size() [
89 // int _SubStreamGraphsSize ;
90 // vector<vector<ComputingNode *> > _SubStreamGraphs ;
94 map< string, string > _MapOfComponentNameContainer ; // mkr : PAL13947
96 bool AddLink( GraphBase::ComputingNode *fromNode ,
97 GraphBase::OutPort *fromPort ,
98 GraphBase::ComputingNode *toNode ,
99 GraphBase::InPort *toPort ) ;
104 Graph( CORBA::ORB_ptr ORB ,
105 SALOME_NamingService* ptrNamingService ,
106 const char *DataFlowName ,
107 const SUPERV::KindOfNode DataFlowkind ,
108 int * Graph_prof_debug ,
109 ofstream * Graph_fdebug ) ;
110 // const char * DebugFileName ) ;
111 Graph( CORBA::ORB_ptr ORB ,
112 SALOME_NamingService* ptrNamingService ,
113 const SALOME_ModuleCatalog::Service& DataFlowService ,
114 const char *DataFlowComponentName ,
115 const char *DataFlowInterfaceName ,
116 const char *DataFlowName ,
117 const SUPERV::KindOfNode DataFlowkind ,
118 const SUPERV::SDate DataFlowFirstCreation ,
119 const SUPERV::SDate DataFlowLastModification ,
120 const char * DataFlowEditorRelease ,
121 const char * DataFlowAuthor ,
122 const char * DataFlowComputer ,
123 const char * DataFlowComment ,
124 int * Graph_prof_debug ,
125 ofstream * Graph_fdebug ) ;
126 // const char * DebugFileName ) ;
129 // void Set_prof_debug( CORBA::ORB_ptr ORB ,
130 // const char * DebugFileName ) ;
131 void Set_prof_debug( int * Graph_prof_debug ,
132 ofstream * Graph_fdebug ) ;
133 int * Graph_prof_debug() {
134 return _prof_debug ; } ;
135 ofstream * Graph_fdebug() { return _fdebug ; } ;
137 // SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
138 // void SetObjRef( SUPERV::Graph_var aGraph ) {
139 // _Graph = aGraph ; } ;
140 // Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
141 // void SetObjImpl( Graph_Impl * aGraphImpl ) {
142 // _GraphImpl = aGraphImpl ; } ;
144 void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
145 GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
147 const int GetGraphNodeIndex( const char *name ) {
148 const int index = _MapOfGraphNodes[ name ] - 1 ;
150 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
151 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
152 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
154 cdebug << "Graph::GetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
156 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
157 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
159 map< string , int >::iterator aMapOfGraphNodesIterator ;
161 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
162 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
163 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
164 << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
168 void SetGraphNodeIndex( const char *name , const int index ) {
169 _MapOfGraphNodes[ name ] = index + 1 ;
170 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
171 << index << " Node " << (void *) _GraphNodes[ index ]
172 << " '" << _GraphNodes[ index ]->Name() << "' MapOfGraphNodessize "
173 << GetGraphNodeSize() << endl ;
175 cdebug << "Graph::SetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
177 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
178 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
180 map< string , int >::iterator aMapOfGraphNodesIterator ;
182 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
183 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
184 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
185 << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
189 void DelGraphNodeIndex( const char *name ) {
190 _MapOfGraphNodes.erase( name ) ; } ;
192 int GetGraphNodeSize() const {
193 return _MapOfGraphNodes.size() ; }
194 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
195 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
197 ComputingNode * GetChangeGraphNode( const int index ) const {
198 if ( index >= 0 && index < _GraphNodesSize ) {
199 ComputingNode * aNode = _GraphNodes[ index ] ;
204 const ComputingNode * GetGraphNode( const char *name ) {
205 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
207 ComputingNode * GetChangeGraphNode( const char *name ) {
208 int index = GetGraphNodeIndex( name ) ;
209 if ( index >= 0 && index < _GraphNodesSize ) {
210 ComputingNode * aNode = GetChangeGraphNode( index ) ;
216 const int GraphNodesSize() const {
217 return _GraphNodesSize ; } ;
218 ComputingNode * GraphNodes( int i ) const {
219 return _GraphNodes[ i ] ; } ;
221 const int HeadNodesSize() const {
222 return _HeadNodesSize ; } ;
223 ComputingNode * HeadNodes( int i ) const {
224 return _HeadNodes[ i ] ; } ;
226 const int QueueNodesSize() const {
227 return _QueueNodesSize ; } ;
228 ComputingNode * QueueNodes( int i ) const {
229 return _QueueNodes[ i ] ; } ;
231 const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
232 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
233 GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
234 return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
235 const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
236 return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
237 GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
238 return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
240 const GraphBase::InPort * GetInPort( const char * ToNodeName ,
241 const char * ToServiceParameterName ) {
242 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
244 return aNode->GetInPort(ToServiceParameterName);
248 GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
249 const char * ToServiceParameterName ) {
250 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
252 return aNode->GetChangeInPort( ToServiceParameterName ) ;
256 const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
257 const char * FromServiceParameterName ) {
258 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
260 return aNode->GetOutPort( FromServiceParameterName ) ;
264 GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
265 const char * FromServiceParameterName ) {
266 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
268 return aNode->GetChangeOutPort( FromServiceParameterName );
273 SUPERV::GraphState PortState( const char* NodeName ,
274 const char* ServiceParameterName ) ;
275 bool PortDone( const char* NodeName ,
276 const char* ServiceParameterName ) {
278 SUPERV::GraphState aState = PortState( NodeName ,
279 ServiceParameterName ) ;
280 if ( aState == SUPERV::DoneState )
283 //JR 30.03.2005 const CORBA::Any * PortInData( const char* ToNodeName ,
284 const CORBA::Any PortInData( const char* ToNodeName ,
285 const char* ToServiceParameterName ) ;
286 //JR 30.03.2005 const CORBA::Any * PortOutData( const char* FromNodeName ,
287 const CORBA::Any PortOutData( const char* FromNodeName ,
288 const char* FromServiceParameterName ) ;
290 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
291 GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
293 GraphBase::SNode * GetInfo() const ;
294 GraphBase::ListOfSNodes * GetNodes() const ;
295 GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
296 GraphBase::ListOfSGraphs * GetGraphs() const ;
297 GraphBase::ListOfSLinks * GetDatas() const ;
299 bool AddNode( ComputingNode * aNode ) ;
300 bool RemoveNode( const char* NodeName ) ;
301 bool ReNameNode( const char* OldNodeName ,
302 const char* NewNodeName ) ;
304 bool AddLink( const char* FromNodeName ,
305 const char* FromServiceParameterName ,
306 const char* ToNodeName ,
307 const char* ToServiceParameterName ) ;
308 // , const CORBA::Any aValue ) ;
309 bool RemoveLink( const char* FromNodeName ,
310 const char* FromServiceParameterName ,
311 const char* ToNodeName ,
312 const char* ToServiceParameterName ) ;
313 bool GetLink( const char* ToNodeName ,
314 const char* ToServiceParameterName ,
315 char** FromNodeName ,
316 char** FromServiceParameterName ) ;
317 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
318 GraphBase::InPort* toPort ) ;
320 bool AddInputData( const char* ToNodeName ,
321 const char* ToParameterName ,
322 const CORBA::Any aValue ) ;
323 bool ChangeInputData( const char* ToNodeName ,
324 const char* ToParameterName ,
325 const CORBA::Any aValue ) ;
326 // bool AddInputData( const char* ToNodeName ,
327 // const char* ToParameterName ,
328 // const CORBA::Any ** aValue ) ;
330 bool AddOutputData( const char* FromNodeName ,
331 const char* FromParameterName ,
332 const CORBA::Any aValue ) ;
334 void SetGraphPorts() ;
337 void ReSetMessages() ;
338 void SetMessages( string anErrorMessage ) ;
340 bool CreateService() ;
341 bool InLineServices() ;
343 bool Sort( int & SubStreamGraphsNumber ) ;
344 bool ValidGOTO() ; // mkr : PAL12575
345 bool ValidLoops() const ;
346 bool ValidSwitchs() const ;
347 bool ComputingNodes() const ;
348 bool LinkLoopNodes(bool & NewLink ) ;
349 bool DataServerNodes() const ;
352 return _LevelsNumber + 1 ; } ;
354 map< string , GraphBase::Service * > MapOfServiceNames() ;
355 GraphBase::Service * GetServiceOfMap( char * name ) ;
356 bool SetServiceOfMap( GraphBase::Service * aService ) ;
357 int GetNewServiceInstanceNumber( char * aServiceName ) ;
359 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
361 return _ThreadsMax ; } ;
363 long SubGraphsNumber() {
364 return _SubGraphsNumber ; } ;
366 int NodesNumber(const int aLevel ) {
367 return _NodesNumber[ aLevel ] ; } ;
368 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
369 return (_SortedNodes[ aLevel ])[ index ] ; } ;
371 bool StartComponent( const int aThread ,
372 const char * ComputerContainer ,
373 const char * ComponentName ,
374 Engines::Container_var & myContainer ,
375 Engines::Component_var & objComponent ) ;
378 void InsertToMapOfComponentNameContainer( const char * theComponentName,
379 const char * theContainer) {
380 _MapOfComponentNameContainer[ theComponentName ] = theContainer ;
384 const char * RetrieveFromMapOfComponentNameContainer( const char * theComponentName ) {
385 if ( _MapOfComponentNameContainer.empty()
387 _MapOfComponentNameContainer.find(theComponentName) == _MapOfComponentNameContainer.end() )
390 return _MapOfComponentNameContainer[ theComponentName ].c_str() ;
394 void ClearMapOfComponentNameContainer() {
395 if ( !_MapOfComponentNameContainer.empty() )
396 _MapOfComponentNameContainer.clear();