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 ;
95 bool AddLink( GraphBase::ComputingNode *fromNode ,
96 GraphBase::OutPort *fromPort ,
97 GraphBase::ComputingNode *toNode ,
98 GraphBase::InPort *toPort ) ;
103 Graph( CORBA::ORB_ptr ORB ,
104 SALOME_NamingService* ptrNamingService ,
105 const char *DataFlowName ,
106 const SUPERV::KindOfNode DataFlowkind ,
107 int * Graph_prof_debug ,
108 ofstream * Graph_fdebug ) ;
109 // const char * DebugFileName ) ;
110 Graph( CORBA::ORB_ptr ORB ,
111 SALOME_NamingService* ptrNamingService ,
112 const SALOME_ModuleCatalog::Service& DataFlowService ,
113 const char *DataFlowComponentName ,
114 const char *DataFlowInterfaceName ,
115 const char *DataFlowName ,
116 const SUPERV::KindOfNode DataFlowkind ,
117 const SUPERV::SDate DataFlowFirstCreation ,
118 const SUPERV::SDate DataFlowLastModification ,
119 const char * DataFlowEditorRelease ,
120 const char * DataFlowAuthor ,
121 const char * DataFlowComputer ,
122 const char * DataFlowComment ,
123 int * Graph_prof_debug ,
124 ofstream * Graph_fdebug ) ;
125 // const char * DebugFileName ) ;
128 // void Set_prof_debug( CORBA::ORB_ptr ORB ,
129 // const char * DebugFileName ) ;
130 void Set_prof_debug( int * Graph_prof_debug ,
131 ofstream * Graph_fdebug ) ;
132 int * Graph_prof_debug() {
133 return _prof_debug ; } ;
134 ofstream * Graph_fdebug() { return _fdebug ; } ;
136 // SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
137 // void SetObjRef( SUPERV::Graph_var aGraph ) {
138 // _Graph = aGraph ; } ;
139 // Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
140 // void SetObjImpl( Graph_Impl * aGraphImpl ) {
141 // _GraphImpl = aGraphImpl ; } ;
143 void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
144 GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
146 const int GetGraphNodeIndex( const char *name ) {
147 const int index = _MapOfGraphNodes[ name ] - 1 ;
149 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
150 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
151 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
153 cdebug << "Graph::GetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
155 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
156 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
158 map< string , int >::iterator aMapOfGraphNodesIterator ;
160 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
161 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
162 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
163 << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
167 void SetGraphNodeIndex( const char *name , const int index ) {
168 _MapOfGraphNodes[ name ] = index + 1 ;
169 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
170 << index << " Node " << (void *) _GraphNodes[ index ]
171 << " '" << _GraphNodes[ index ]->Name() << "' MapOfGraphNodessize "
172 << GetGraphNodeSize() << endl ;
174 cdebug << "Graph::SetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
176 for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
177 cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
179 map< string , int >::iterator aMapOfGraphNodesIterator ;
181 for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
182 aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
183 cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
184 << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
188 void DelGraphNodeIndex( const char *name ) {
189 _MapOfGraphNodes.erase( name ) ; } ;
191 int GetGraphNodeSize() const {
192 return _MapOfGraphNodes.size() ; }
193 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
194 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
196 ComputingNode * GetChangeGraphNode( const int index ) const {
197 if ( index >= 0 && index < _GraphNodesSize ) {
198 ComputingNode * aNode = _GraphNodes[ index ] ;
203 const ComputingNode * GetGraphNode( const char *name ) {
204 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
206 ComputingNode * GetChangeGraphNode( const char *name ) {
207 int index = GetGraphNodeIndex( name ) ;
208 if ( index >= 0 && index < _GraphNodesSize ) {
209 ComputingNode * aNode = GetChangeGraphNode( index ) ;
215 const int GraphNodesSize() const {
216 return _GraphNodesSize ; } ;
217 ComputingNode * GraphNodes( int i ) const {
218 return _GraphNodes[ i ] ; } ;
220 const int HeadNodesSize() const {
221 return _HeadNodesSize ; } ;
222 ComputingNode * HeadNodes( int i ) const {
223 return _HeadNodes[ i ] ; } ;
225 const int QueueNodesSize() const {
226 return _QueueNodesSize ; } ;
227 ComputingNode * QueueNodes( int i ) const {
228 return _QueueNodes[ i ] ; } ;
230 const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
231 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
232 GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
233 return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
234 const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
235 return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
236 GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
237 return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
239 const GraphBase::InPort * GetInPort( const char * ToNodeName ,
240 const char * ToServiceParameterName ) {
241 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
243 return aNode->GetInPort(ToServiceParameterName);
247 GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
248 const char * ToServiceParameterName ) {
249 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
251 return aNode->GetChangeInPort( ToServiceParameterName ) ;
255 const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
256 const char * FromServiceParameterName ) {
257 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
259 return aNode->GetOutPort( FromServiceParameterName ) ;
263 GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
264 const char * FromServiceParameterName ) {
265 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
267 return aNode->GetChangeOutPort( FromServiceParameterName );
272 SUPERV::GraphState PortState( const char* NodeName ,
273 const char* ServiceParameterName ) ;
274 bool PortDone( const char* NodeName ,
275 const char* ServiceParameterName ) {
277 SUPERV::GraphState aState = PortState( NodeName ,
278 ServiceParameterName ) ;
279 if ( aState == SUPERV::DoneState )
282 //JR 30.03.2005 const CORBA::Any * PortInData( const char* ToNodeName ,
283 const CORBA::Any PortInData( const char* ToNodeName ,
284 const char* ToServiceParameterName ) ;
285 //JR 30.03.2005 const CORBA::Any * PortOutData( const char* FromNodeName ,
286 const CORBA::Any PortOutData( const char* FromNodeName ,
287 const char* FromServiceParameterName ) ;
289 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
290 GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
292 GraphBase::SNode * GetInfo() const ;
293 GraphBase::ListOfSNodes * GetNodes() const ;
294 GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
295 GraphBase::ListOfSGraphs * GetGraphs() const ;
296 GraphBase::ListOfSLinks * GetDatas() const ;
298 bool AddNode( ComputingNode * aNode ) ;
299 bool RemoveNode( const char* NodeName ) ;
300 bool ReNameNode( const char* OldNodeName ,
301 const char* NewNodeName ) ;
303 bool AddLink( const char* FromNodeName ,
304 const char* FromServiceParameterName ,
305 const char* ToNodeName ,
306 const char* ToServiceParameterName ) ;
307 // , const CORBA::Any aValue ) ;
308 bool RemoveLink( const char* FromNodeName ,
309 const char* FromServiceParameterName ,
310 const char* ToNodeName ,
311 const char* ToServiceParameterName ) ;
312 bool GetLink( const char* ToNodeName ,
313 const char* ToServiceParameterName ,
314 char** FromNodeName ,
315 char** FromServiceParameterName ) ;
316 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
317 GraphBase::InPort* toPort ) ;
319 bool AddInputData( const char* ToNodeName ,
320 const char* ToParameterName ,
321 const CORBA::Any aValue ) ;
322 bool ChangeInputData( const char* ToNodeName ,
323 const char* ToParameterName ,
324 const CORBA::Any aValue ) ;
325 // bool AddInputData( const char* ToNodeName ,
326 // const char* ToParameterName ,
327 // const CORBA::Any ** aValue ) ;
329 bool AddOutputData( const char* FromNodeName ,
330 const char* FromParameterName ,
331 const CORBA::Any aValue ) ;
333 void SetGraphPorts() ;
336 void ReSetMessages() ;
337 void SetMessages( string anErrorMessage ) ;
339 bool CreateService() ;
340 bool InLineServices() ;
342 bool Sort( int & SubStreamGraphsNumber ) ;
343 bool ValidLoops() const ;
344 bool ValidSwitchs() const ;
345 bool ComputingNodes() const ;
346 bool LinkLoopNodes(bool & NewLink ) ;
347 bool DataServerNodes() const ;
350 return _LevelsNumber + 1 ; } ;
352 map< string , GraphBase::Service * > MapOfServiceNames() ;
353 GraphBase::Service * GetServiceOfMap( char * name ) ;
354 bool SetServiceOfMap( GraphBase::Service * aService ) ;
355 int GetNewServiceInstanceNumber( char * aServiceName ) ;
357 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
359 return _ThreadsMax ; } ;
361 long SubGraphsNumber() {
362 return _SubGraphsNumber ; } ;
364 int NodesNumber(const int aLevel ) {
365 return _NodesNumber[ aLevel ] ; } ;
366 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
367 return (_SortedNodes[ aLevel ])[ index ] ; } ;
369 bool StartComponent( const int aThread ,
370 const char * ComputerContainer ,
371 const char * ComponentName ,
372 Engines::Container_var & myContainer ,
373 Engines::Component_var & objComponent ) ;