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.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 ;
93 bool AddLink( GraphBase::ComputingNode *fromNode ,
94 GraphBase::OutPort *fromPort ,
95 GraphBase::ComputingNode *toNode ,
96 GraphBase::InPort *toPort ) ;
101 Graph( CORBA::ORB_ptr ORB ,
102 SALOME_NamingService* ptrNamingService ,
103 const char *DataFlowName ,
104 const SUPERV::KindOfNode DataFlowkind ,
105 int * Graph_prof_debug ,
106 ofstream * Graph_fdebug ) ;
107 // const char * DebugFileName ) ;
108 Graph( CORBA::ORB_ptr ORB ,
109 SALOME_NamingService* ptrNamingService ,
110 const SALOME_ModuleCatalog::Service& DataFlowService ,
111 const char *DataFlowComponentName ,
112 const char *DataFlowInterfaceName ,
113 const char *DataFlowName ,
114 const SUPERV::KindOfNode DataFlowkind ,
115 const SUPERV::SDate DataFlowFirstCreation ,
116 const SUPERV::SDate DataFlowLastModification ,
117 const char * DataFlowEditorRelease ,
118 const char * DataFlowAuthor ,
119 const char * DataFlowComputer ,
120 const char * DataFlowComment ,
121 int * Graph_prof_debug ,
122 ofstream * Graph_fdebug ) ;
123 // const char * DebugFileName ) ;
126 // void Set_prof_debug( CORBA::ORB_ptr ORB ,
127 // const char * DebugFileName ) ;
128 void Set_prof_debug( int * Graph_prof_debug ,
129 ofstream * Graph_fdebug ) ;
130 int * Graph_prof_debug() {
131 return _prof_debug ; } ;
132 ofstream * Graph_fdebug() { return _fdebug ; } ;
134 // SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
135 // void SetObjRef( SUPERV::Graph_var aGraph ) {
136 // _Graph = aGraph ; } ;
137 // Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
138 // void SetObjImpl( Graph_Impl * aGraphImpl ) {
139 // _GraphImpl = aGraphImpl ; } ;
141 void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
142 GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
144 const int GetGraphNodeIndex( const char *name ) {
145 const int index = _MapOfGraphNodes[ name ] - 1 ;
147 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
148 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
149 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
151 cdebug << "Graph::GetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
153 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
154 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
156 map< string , int >::iterator aMapOfGraphNodesIterator ;
158 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
159 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
160 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
161 << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
165 void SetGraphNodeIndex( const char *name , const int index ) {
166 _MapOfGraphNodes[ name ] = index + 1 ;
167 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
168 << index << " Node " << (void *) _GraphNodes[ index ]
169 << " '" << _GraphNodes[ index ]->Name() << "' MapOfGraphNodessize "
170 << GetGraphNodeSize() << endl ;
172 cdebug << "Graph::SetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
174 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
175 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
177 map< string , int >::iterator aMapOfGraphNodesIterator ;
179 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
180 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
181 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
182 << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
186 void DelGraphNodeIndex( const char *name ) {
187 _MapOfGraphNodes.erase( name ) ; } ;
189 int GetGraphNodeSize() const {
190 return _MapOfGraphNodes.size() ; }
191 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
192 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
194 ComputingNode * GetChangeGraphNode( const int index ) const {
195 if ( index >= 0 && index < _GraphNodesSize ) {
196 ComputingNode * aNode = _GraphNodes[ index ] ;
201 const ComputingNode * GetGraphNode( const char *name ) {
202 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
204 ComputingNode * GetChangeGraphNode( const char *name ) {
205 int index = GetGraphNodeIndex( name ) ;
206 if ( index >= 0 && index < _GraphNodesSize ) {
207 ComputingNode * aNode = GetChangeGraphNode( index ) ;
213 const int GraphNodesSize() const {
214 return _GraphNodesSize ; } ;
215 ComputingNode * GraphNodes( int i ) const {
216 return _GraphNodes[ i ] ; } ;
218 const int HeadNodesSize() const {
219 return _HeadNodesSize ; } ;
220 ComputingNode * HeadNodes( int i ) const {
221 return _HeadNodes[ i ] ; } ;
223 const int QueueNodesSize() const {
224 return _QueueNodesSize ; } ;
225 ComputingNode * QueueNodes( int i ) const {
226 return _QueueNodes[ i ] ; } ;
228 const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
229 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
230 GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
231 return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
232 const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
233 return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
234 GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
235 return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
237 const GraphBase::InPort * GetInPort( const char * ToNodeName ,
238 const char * ToServiceParameterName ) {
239 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
241 return aNode->GetInPort(ToServiceParameterName);
245 GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
246 const char * ToServiceParameterName ) {
247 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
249 return aNode->GetChangeInPort( ToServiceParameterName ) ;
253 const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
254 const char * FromServiceParameterName ) {
255 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
257 return aNode->GetOutPort( FromServiceParameterName ) ;
261 GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
262 const char * FromServiceParameterName ) {
263 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
265 return aNode->GetChangeOutPort( FromServiceParameterName );
270 SUPERV::GraphState PortState( const char* NodeName ,
271 const char* ServiceParameterName ) ;
272 bool PortDone( const char* NodeName ,
273 const char* ServiceParameterName ) {
275 SUPERV::GraphState aState = PortState( NodeName ,
276 ServiceParameterName ) ;
277 if ( aState == SUPERV::DoneState )
280 //JR 30.03.2005 const CORBA::Any * PortInData( const char* ToNodeName ,
281 const CORBA::Any PortInData( const char* ToNodeName ,
282 const char* ToServiceParameterName ) ;
283 //JR 30.03.2005 const CORBA::Any * PortOutData( const char* FromNodeName ,
284 const CORBA::Any PortOutData( const char* FromNodeName ,
285 const char* FromServiceParameterName ) ;
287 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
288 GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
290 GraphBase::SNode * GetInfo() const ;
291 GraphBase::ListOfSNodes * GetNodes() const ;
292 GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
293 GraphBase::ListOfSGraphs * GetGraphs() const ;
294 GraphBase::ListOfSLinks * GetDatas() const ;
296 bool AddNode( ComputingNode * aNode ) ;
297 bool RemoveNode( const char* NodeName ) ;
298 bool ReNameNode( const char* OldNodeName ,
299 const char* NewNodeName ) ;
301 bool AddLink( const char* FromNodeName ,
302 const char* FromServiceParameterName ,
303 const char* ToNodeName ,
304 const char* ToServiceParameterName ) ;
305 // , const CORBA::Any aValue ) ;
306 bool RemoveLink( const char* FromNodeName ,
307 const char* FromServiceParameterName ,
308 const char* ToNodeName ,
309 const char* ToServiceParameterName ) ;
310 bool GetLink( const char* ToNodeName ,
311 const char* ToServiceParameterName ,
312 char** FromNodeName ,
313 char** FromServiceParameterName ) ;
314 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
315 GraphBase::InPort* toPort ) ;
317 bool AddInputData( const char* ToNodeName ,
318 const char* ToParameterName ,
319 const CORBA::Any aValue ) ;
320 bool ChangeInputData( const char* ToNodeName ,
321 const char* ToParameterName ,
322 const CORBA::Any aValue ) ;
323 // bool AddInputData( const char* ToNodeName ,
324 // const char* ToParameterName ,
325 // const CORBA::Any ** aValue ) ;
327 bool AddOutputData( const char* FromNodeName ,
328 const char* FromParameterName ,
329 const CORBA::Any aValue ) ;
331 void SetGraphPorts() ;
333 bool CreateService() ;
334 bool InLineServices() ;
336 bool Sort( int & SubStreamGraphsNumber ) ;
337 bool ValidLoops() const ;
338 bool ValidSwitchs() const ;
339 bool ComputingNodes() const ;
340 bool LinkLoopNodes(bool & NewLink ) ;
341 bool DataServerNodes() const ;
344 return _LevelsNumber + 1 ; } ;
346 map< string , GraphBase::Service * > MapOfServiceNames() ;
347 GraphBase::Service * GetServiceOfMap( char * name ) ;
348 bool SetServiceOfMap( GraphBase::Service * aService ) ;
349 int GetNewServiceInstanceNumber( char * aServiceName ) ;
351 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
353 return _ThreadsMax ; } ;
355 long SubGraphsNumber() {
356 return _SubGraphsNumber ; } ;
358 int NodesNumber(const int aLevel ) {
359 return _NodesNumber[ aLevel ] ; } ;
360 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
361 return (_SortedNodes[ aLevel ])[ index ] ; } ;
363 bool StartComponent( const int aThread ,
364 const char * ComputerContainer ,
365 const char * ComponentName ,
366 Engines::Container_var & myContainer ,
367 Engines::Component_var & objComponent ) ;