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 generated NodeNames with ServiceName : number of Nodes using
74 // the same ServiceName. It is not the same Service if it belongs to
75 // a different Interface and/or a different Component ...
76 map< string , GraphBase::Service * > _MapOfServiceNames ;
78 // Total number of SubGraphs
79 int _SubGraphsNumber ;
80 // _SubGraphs[ SubGraphNumero ] [ NodeNumero ]
81 // SubGraphNumero : [ 0 , _SubGraphsSize [ ; NodeNumero : [ 0 , _SubGraphs[ SubGraphNumero ].size() [
83 vector<vector<ComputingNode *> > _SubGraphs ;
85 // _SubStreamGraphs[ SubStreamGraphNumero ] [ NodeNumero ]
86 // SubStreamGraphNumero : [ 0 , _SubStreamGraphsSize [
87 // NodeNumero : [ 0 , _SubStreamGraphs[ SubStreamGraphNumero ].size() [
88 // int _SubStreamGraphsSize ;
89 // vector<vector<ComputingNode *> > _SubStreamGraphs ;
91 bool AddLink( GraphBase::ComputingNode *fromNode ,
92 GraphBase::OutPort *fromPort ,
93 GraphBase::ComputingNode *toNode ,
94 GraphBase::InPort *toPort ) ;
99 Graph( CORBA::ORB_ptr ORB ,
100 SALOME_NamingService* ptrNamingService ,
101 const char *DataFlowName ,
102 const SUPERV::KindOfNode DataFlowkind ,
103 int * Graph_prof_debug ,
104 ofstream * Graph_fdebug ) ;
105 // const char * DebugFileName ) ;
106 Graph( CORBA::ORB_ptr ORB ,
107 SALOME_NamingService* ptrNamingService ,
108 const SALOME_ModuleCatalog::Service& DataFlowService ,
109 const char *DataFlowComponentName ,
110 const char *DataFlowInterfaceName ,
111 const char *DataFlowName ,
112 const SUPERV::KindOfNode DataFlowkind ,
113 const SUPERV::SDate DataFlowFirstCreation ,
114 const SUPERV::SDate DataFlowLastModification ,
115 const char * DataFlowEditorRelease ,
116 const char * DataFlowAuthor ,
117 const char * DataFlowComputer ,
118 const char * DataFlowComment ,
119 int * Graph_prof_debug ,
120 ofstream * Graph_fdebug ) ;
121 // const char * DebugFileName ) ;
124 // void Set_prof_debug( CORBA::ORB_ptr ORB ,
125 // const char * DebugFileName ) ;
126 void Set_prof_debug( int * Graph_prof_debug ,
127 ofstream * Graph_fdebug ) ;
128 int * Graph_prof_debug() {
129 return _prof_debug ; } ;
130 ofstream * Graph_fdebug() { return _fdebug ; } ;
132 // SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
133 // void SetObjRef( SUPERV::Graph_var aGraph ) {
134 // _Graph = aGraph ; } ;
135 // Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
136 // void SetObjImpl( Graph_Impl * aGraphImpl ) {
137 // _GraphImpl = aGraphImpl ; } ;
139 void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
140 GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
142 const int GetGraphNodeIndex( const char *name ) {
143 const int index = _MapOfGraphNodes[ name ] - 1 ;
145 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
146 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
147 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
149 void SetGraphNodeIndex( const char *name , const int index ) {
150 _MapOfGraphNodes[ name ] = index + 1 ;
151 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
152 << index << " Node " << hex << (void *) _GraphNodes[ index ]
153 << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
155 void DelGraphNodeIndex( const char *name ) {
156 _MapOfGraphNodes.erase( name ) ; } ;
158 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
159 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
161 ComputingNode * GetChangeGraphNode( const int index ) const {
162 if ( index >= 0 && index < _GraphNodesSize ) {
163 ComputingNode * aNode = _GraphNodes[ index ] ;
168 const ComputingNode * GetGraphNode( const char *name ) {
169 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
171 ComputingNode * GetChangeGraphNode( const char *name ) {
172 int index = GetGraphNodeIndex( name ) ;
173 if ( index >= 0 && index < _GraphNodesSize ) {
174 ComputingNode * aNode = GetChangeGraphNode( index ) ;
180 const int GraphNodesSize() const {
181 return _GraphNodesSize ; } ;
182 ComputingNode * GraphNodes( int i ) const {
183 return _GraphNodes[ i ] ; } ;
185 const int HeadNodesSize() const {
186 return _HeadNodesSize ; } ;
187 ComputingNode * HeadNodes( int i ) const {
188 return _HeadNodes[ i ] ; } ;
190 const int QueueNodesSize() const {
191 return _QueueNodesSize ; } ;
192 ComputingNode * QueueNodes( int i ) const {
193 return _QueueNodes[ i ] ; } ;
195 const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
196 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
197 GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
198 return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
199 const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
200 return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
201 GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
202 return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
204 const GraphBase::InPort * GetInPort( const char * ToNodeName ,
205 const char * ToServiceParameterName ) {
206 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
208 return aNode->GetInPort(ToServiceParameterName);
212 GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
213 const char * ToServiceParameterName ) {
214 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
216 return aNode->GetChangeInPort( ToServiceParameterName ) ;
220 const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
221 const char * FromServiceParameterName ) {
222 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
224 return aNode->GetOutPort( FromServiceParameterName ) ;
228 GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
229 const char * FromServiceParameterName ) {
230 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
232 return aNode->GetChangeOutPort( FromServiceParameterName );
237 SUPERV::GraphState PortState( const char* NodeName ,
238 const char* ServiceParameterName ) ;
239 bool PortDone( const char* NodeName ,
240 const char* ServiceParameterName ) {
242 SUPERV::GraphState aState = PortState( NodeName ,
243 ServiceParameterName ) ;
244 if ( aState == SUPERV::DoneState )
247 const CORBA::Any * PortInData( const char* ToNodeName ,
248 const char* ToServiceParameterName ) ;
249 const CORBA::Any * PortOutData( const char* FromNodeName ,
250 const char* FromServiceParameterName ) ;
252 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
253 GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
255 GraphBase::SNode * GetInfo() const ;
256 GraphBase::ListOfSNodes * GetNodes() const ;
257 GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
258 GraphBase::ListOfSGraphs * GetGraphs() const ;
259 GraphBase::ListOfSLinks * GetDatas() const ;
261 bool AddNode( ComputingNode * aNode ) ;
262 bool RemoveNode( const char* NodeName ) ;
263 bool ReNameNode( const char* OldNodeName ,
264 const char* NewNodeName ) ;
266 bool AddLink( const char* FromNodeName ,
267 const char* FromServiceParameterName ,
268 const char* ToNodeName ,
269 const char* ToServiceParameterName ) ;
270 // , const CORBA::Any aValue ) ;
271 bool RemoveLink( const char* FromNodeName ,
272 const char* FromServiceParameterName ,
273 const char* ToNodeName ,
274 const char* ToServiceParameterName ) ;
275 bool GetLink( const char* ToNodeName ,
276 const char* ToServiceParameterName ,
277 char** FromNodeName ,
278 char** FromServiceParameterName ) ;
279 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
280 GraphBase::InPort* toPort ) ;
282 bool AddInputData( const char* ToNodeName ,
283 const char* ToParameterName ,
284 const CORBA::Any aValue ) ;
285 bool ChangeInputData( const char* ToNodeName ,
286 const char* ToParameterName ,
287 const CORBA::Any aValue ) ;
288 bool AddInputData( const char* ToNodeName ,
289 const char* ToParameterName ,
290 const CORBA::Any ** aValue ) ;
292 bool AddOutputData( const char* FromNodeName ,
293 const char* FromParameterName ,
294 const CORBA::Any aValue ) ;
296 void SetGraphPorts() ;
298 bool CreateService() ;
299 bool InLineServices() ;
301 bool Sort( int & SubStreamGraphsNumber ) ;
302 bool ComputingNodes() const ;
303 bool LinkLoopNodes(bool & NewLink ) ;
304 bool DataServerNodes() const ;
307 return _LevelsNumber + 1 ; } ;
309 map< string , GraphBase::Service * > MapOfServiceNames() ;
310 GraphBase::Service * GetServiceOfMap( char * name ) ;
311 bool SetServiceOfMap( GraphBase::Service * aService ) ;
312 int GetServiceNameNumber( SALOME_ModuleCatalog::Service aService ) ;
314 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
316 return _ThreadsMax ; } ;
318 long SubGraphsNumber() {
319 return _SubGraphsNumber ; } ;
321 int NodesNumber(const int aLevel ) {
322 return _NodesNumber[ aLevel ] ; } ;
323 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
324 return (_SortedNodes[ aLevel ])[ index ] ; } ;
326 bool StartComponent( const int aThread ,
327 const char * ComputerContainer ,
328 const char * ComponentName ,
329 Engines::Container_var & myContainer ,
330 Engines::Component_var & objComponent ) ;