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"
43 class Graph : public DataNode {
47 // int _Graph_prof_debug;
48 // ofstream * _Graph_fdebug;
50 SUPERV::Graph_var _Graph ;
51 Graph_Impl * _GraphImpl ;
53 // Map of Nodes of the Graph
54 map< string , int > _MapOfGraphNodes ;
55 long _GraphNodesSize ;
56 vector<bool > _Sorted ;
57 vector<ComputingNode *> _GraphNodes ;
59 // _SortedNodes[ _LevelsNumber ] : topological sort from 0 to _LevelsNumber
60 // _SortedNodes[ _level ][ _NodesNumber[ _level ] ] : _NodesNumber[ _level ] Nodes in the level
63 vector<int > _NodesNumber ;
64 vector<vector<ComputingNode *> > _SortedNodes ;
66 vector<int > _CnxInPortsNumber ;
67 vector<int > _DecrInPortsNumber ;
70 vector<ComputingNode *> _HeadNodes ;
71 long _QueueNodesSize ;
72 vector<ComputingNode *> _QueueNodes ;
73 bool _ParallelExecutionNodes ;
75 // For generated NodeNames with ServiceName : number of Nodes using
76 // the same ServiceName. It is not the same Service if it belongs to
77 // a different Interface and/or a different Component ...
78 map< string , GraphBase::Service * > _MapOfServiceNames ;
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 int * Graph_prof_debug ,
105 ofstream * Graph_fdebug ) ;
106 // const char * DebugFileName ) ;
107 Graph( CORBA::ORB_ptr ORB ,
108 SALOME_NamingService* ptrNamingService ,
109 const SALOME_ModuleCatalog::Service& DataFlowService ,
110 const char *DataFlowComponentName ,
111 const char *DataFlowInterfaceName ,
112 const char *DataFlowName ,
113 const SUPERV::KindOfNode DataFlowkind ,
114 const SUPERV::SDate DataFlowFirstCreation ,
115 const SUPERV::SDate DataFlowLastModification ,
116 const char * DataFlowEditorRelease ,
117 const char * DataFlowAuthor ,
118 const char * DataFlowComputer ,
119 const char * DataFlowComment ,
120 int * Graph_prof_debug ,
121 ofstream * Graph_fdebug ) ;
122 // const char * DebugFileName ) ;
125 // void Set_prof_debug( CORBA::ORB_ptr ORB ,
126 // const char * DebugFileName ) ;
127 void Set_prof_debug( int * Graph_prof_debug ,
128 ofstream * Graph_fdebug ) ;
129 int * Graph_prof_debug() {
130 return _prof_debug ; } ;
131 ofstream * Graph_fdebug() { return _fdebug ; } ;
133 SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
134 void SetObjRef( SUPERV::Graph_var aGraph ) {
135 _Graph = aGraph ; } ;
136 Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
137 void SetObjImpl( Graph_Impl * aGraphImpl ) {
138 _GraphImpl = aGraphImpl ; } ;
140 void AddLink( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
141 GetChangeGraphNode( FromNodeName )->AddLink( anOutNode ) ; } ;
143 const int GetGraphNodeIndex( const char *name ) {
144 const int index = _MapOfGraphNodes[ name ] - 1 ;
146 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
147 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
148 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
150 void SetGraphNodeIndex( const char *name , const int index ) {
151 _MapOfGraphNodes[ name ] = index + 1 ;
152 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
153 << index << " Node " << hex << (void *) _GraphNodes[ index ]
154 << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
156 void DelGraphNodeIndex( const char *name ) {
157 _MapOfGraphNodes.erase( name ) ; } ;
159 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
160 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
162 ComputingNode * GetChangeGraphNode( const int index ) const {
163 if ( index >= 0 && index < _GraphNodesSize ) {
164 ComputingNode * aNode = _GraphNodes[ index ] ;
169 const ComputingNode * GetGraphNode( const char *name ) {
170 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
172 ComputingNode * GetChangeGraphNode( const char *name ) {
173 int index = GetGraphNodeIndex( name ) ;
174 if ( index >= 0 && index < _GraphNodesSize ) {
175 ComputingNode * aNode = GetChangeGraphNode( index ) ;
181 const int GraphNodesSize() const {
182 return _GraphNodesSize ; } ;
183 ComputingNode * GraphNodes( int i ) const {
184 return _GraphNodes[ i ] ; } ;
186 const int HeadNodesSize() const {
187 return _HeadNodesSize ; } ;
188 ComputingNode * HeadNodes( int i ) const {
189 return _HeadNodes[ i ] ; } ;
191 const int QueueNodesSize() const {
192 return _QueueNodesSize ; } ;
193 ComputingNode * QueueNodes( int i ) const {
194 return _QueueNodes[ i ] ; } ;
196 const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
197 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
198 GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
199 return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
200 const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
201 return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
202 GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
203 return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
205 const GraphBase::InPort * GetInPort( const char * ToNodeName ,
206 const char * ToServiceParameterName ) {
207 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
209 return aNode->GetInPort(ToServiceParameterName);
213 GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
214 const char * ToServiceParameterName ) {
215 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
217 return aNode->GetChangeInPort( ToServiceParameterName ) ;
221 const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
222 const char * FromServiceParameterName ) {
223 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
225 return aNode->GetOutPort( FromServiceParameterName ) ;
229 GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
230 const char * FromServiceParameterName ) {
231 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
233 return aNode->GetChangeOutPort( FromServiceParameterName );
238 SUPERV::GraphState PortState( const char* NodeName ,
239 const char* ServiceParameterName ) ;
240 bool PortDone( const char* NodeName ,
241 const char* ServiceParameterName ) {
243 SUPERV::GraphState aState = PortState( NodeName ,
244 ServiceParameterName ) ;
245 if ( aState == SUPERV::DoneState )
248 const CORBA::Any * PortInData( const char* ToNodeName ,
249 const char* ToServiceParameterName ) ;
250 const CORBA::Any * PortOutData( const char* FromNodeName ,
251 const char* FromServiceParameterName ) ;
253 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
254 GraphBase::SGraph & aDataFlow ) ;
256 GraphBase::SNode * GetInfo() const ;
257 GraphBase::ListOfNodes * GetNodes() const ;
258 GraphBase::ListOfLinks * GetLinks(bool AllLinks = false ) const ;
259 GraphBase::ListOfGraphs * GetGraphs() const ;
260 GraphBase::ListOfLinks * GetDatas() const ;
262 bool AddNode( ComputingNode * aNode ) ;
263 bool RemoveNode( const char* NodeName ) ;
264 bool ReNameNode( const char* OldNodeName ,
265 const char* NewNodeName ) ;
267 bool AddLink( const char* FromNodeName ,
268 const char* FromServiceParameterName ,
269 const char* ToNodeName ,
270 const char* ToServiceParameterName ,
271 const CORBA::Any aValue ) ;
272 bool RemoveLink( const char* FromNodeName ,
273 const char* FromServiceParameterName ,
274 const char* ToNodeName ,
275 const char* ToServiceParameterName ) ;
276 bool GetLink( const char* ToNodeName ,
277 const char* ToServiceParameterName ,
278 char** FromNodeName ,
279 char** FromServiceParameterName ) ;
280 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
281 GraphBase::InPort* toPort ) ;
283 bool AddInputData( const char* ToNodeName ,
284 const char* ToParameterName ,
285 const CORBA::Any aValue ) ;
286 bool ChangeInputData( const char* ToNodeName ,
287 const char* ToParameterName ,
288 const CORBA::Any aValue ) ;
289 bool AddInputData( const char* ToNodeName1 ,
290 const char* ToParameterName1 ,
291 const char* ToNodeName2 ,
292 const char* ToParameterName2 ) ;
294 bool AddInputData( const char* ToNodeName ,
295 const char* ToParameterName ,
296 const CORBA::Any ** aValue ) ;
298 bool AddOutputData( const char* FromNodeName ,
299 const char* FromParameterName ,
300 const CORBA::Any aValue ) ;
302 bool CreateService() ;
303 bool InLineServices() ;
305 bool Sort( int & SubStreamGraphsNumber ) ;
306 bool ComputingNodes() const ;
307 bool LinkLoopNodes(bool & NewLink ) ;
308 bool DataServerNodes() const ;
311 return _LevelsNumber + 1 ; } ;
313 map< string , GraphBase::Service * > MapOfServiceNames() ;
314 GraphBase::Service * GetServiceOfMap( char * name ) ;
315 bool SetServiceOfMap( GraphBase::Service * aService ) ;
316 int GetServiceNameNumber( SALOME_ModuleCatalog::Service aService ) ;
318 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
320 return _ThreadsMax ; } ;
322 long SubGraphsNumber() {
323 return _SubGraphsNumber ; } ;
325 int NodesNumber(const int aLevel ) {
326 return _NodesNumber[ aLevel ] ; } ;
327 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
328 return (_SortedNodes[ aLevel ])[ index ] ; } ;
330 bool StartComponent( const int aThread ,
331 const char * ComputerContainer ,
332 const char * ComponentName ,
333 Engines::Container_var & myContainer ,
334 Engines::Component_var & objComponent ) ;