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 void SetGraphNodeIndex( const char *name , const int index ) {
152 _MapOfGraphNodes[ name ] = index + 1 ;
153 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
154 << index << " Node " << (void *) _GraphNodes[ index ]
155 << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
157 void DelGraphNodeIndex( const char *name ) {
158 _MapOfGraphNodes.erase( name ) ; } ;
160 int GetGraphNodeSize() const {
161 return _MapOfGraphNodes.size() ; }
162 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
163 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
165 ComputingNode * GetChangeGraphNode( const int index ) const {
166 if ( index >= 0 && index < _GraphNodesSize ) {
167 ComputingNode * aNode = _GraphNodes[ index ] ;
172 const ComputingNode * GetGraphNode( const char *name ) {
173 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
175 ComputingNode * GetChangeGraphNode( const char *name ) {
176 int index = GetGraphNodeIndex( name ) ;
177 if ( index >= 0 && index < _GraphNodesSize ) {
178 ComputingNode * aNode = GetChangeGraphNode( index ) ;
184 const int GraphNodesSize() const {
185 return _GraphNodesSize ; } ;
186 ComputingNode * GraphNodes( int i ) const {
187 return _GraphNodes[ i ] ; } ;
189 const int HeadNodesSize() const {
190 return _HeadNodesSize ; } ;
191 ComputingNode * HeadNodes( int i ) const {
192 return _HeadNodes[ i ] ; } ;
194 const int QueueNodesSize() const {
195 return _QueueNodesSize ; } ;
196 ComputingNode * QueueNodes( int i ) const {
197 return _QueueNodes[ i ] ; } ;
199 const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
200 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
201 GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
202 return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
203 const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
204 return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
205 GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
206 return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
208 const GraphBase::InPort * GetInPort( const char * ToNodeName ,
209 const char * ToServiceParameterName ) {
210 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
212 return aNode->GetInPort(ToServiceParameterName);
216 GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
217 const char * ToServiceParameterName ) {
218 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
220 return aNode->GetChangeInPort( ToServiceParameterName ) ;
224 const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
225 const char * FromServiceParameterName ) {
226 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
228 return aNode->GetOutPort( FromServiceParameterName ) ;
232 GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
233 const char * FromServiceParameterName ) {
234 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
236 return aNode->GetChangeOutPort( FromServiceParameterName );
241 SUPERV::GraphState PortState( const char* NodeName ,
242 const char* ServiceParameterName ) ;
243 bool PortDone( const char* NodeName ,
244 const char* ServiceParameterName ) {
246 SUPERV::GraphState aState = PortState( NodeName ,
247 ServiceParameterName ) ;
248 if ( aState == SUPERV::DoneState )
251 //JR 30.03.2005 const CORBA::Any * PortInData( const char* ToNodeName ,
252 const CORBA::Any PortInData( const char* ToNodeName ,
253 const char* ToServiceParameterName ) ;
254 //JR 30.03.2005 const CORBA::Any * PortOutData( const char* FromNodeName ,
255 const CORBA::Any PortOutData( const char* FromNodeName ,
256 const char* FromServiceParameterName ) ;
258 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
259 GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
261 GraphBase::SNode * GetInfo() const ;
262 GraphBase::ListOfSNodes * GetNodes() const ;
263 GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
264 GraphBase::ListOfSGraphs * GetGraphs() const ;
265 GraphBase::ListOfSLinks * GetDatas() const ;
267 bool AddNode( ComputingNode * aNode ) ;
268 bool RemoveNode( const char* NodeName ) ;
269 bool ReNameNode( const char* OldNodeName ,
270 const char* NewNodeName ) ;
272 bool AddLink( const char* FromNodeName ,
273 const char* FromServiceParameterName ,
274 const char* ToNodeName ,
275 const char* ToServiceParameterName ) ;
276 // , const CORBA::Any aValue ) ;
277 bool RemoveLink( const char* FromNodeName ,
278 const char* FromServiceParameterName ,
279 const char* ToNodeName ,
280 const char* ToServiceParameterName ) ;
281 bool GetLink( const char* ToNodeName ,
282 const char* ToServiceParameterName ,
283 char** FromNodeName ,
284 char** FromServiceParameterName ) ;
285 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
286 GraphBase::InPort* toPort ) ;
288 bool AddInputData( const char* ToNodeName ,
289 const char* ToParameterName ,
290 const CORBA::Any aValue ) ;
291 bool ChangeInputData( const char* ToNodeName ,
292 const char* ToParameterName ,
293 const CORBA::Any aValue ) ;
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 void SetGraphPorts() ;
304 bool CreateService() ;
305 bool InLineServices() ;
307 bool Sort( int & SubStreamGraphsNumber ) ;
308 bool ValidLoops() const ;
309 bool ValidSwitchs() const ;
310 bool ComputingNodes() const ;
311 bool LinkLoopNodes(bool & NewLink ) ;
312 bool DataServerNodes() const ;
315 return _LevelsNumber + 1 ; } ;
317 map< string , GraphBase::Service * > MapOfServiceNames() ;
318 GraphBase::Service * GetServiceOfMap( char * name ) ;
319 bool SetServiceOfMap( GraphBase::Service * aService ) ;
320 int GetNewServiceInstanceNumber( char * aServiceName ) ;
322 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
324 return _ThreadsMax ; } ;
326 long SubGraphsNumber() {
327 return _SubGraphsNumber ; } ;
329 int NodesNumber(const int aLevel ) {
330 return _NodesNumber[ aLevel ] ; } ;
331 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
332 return (_SortedNodes[ aLevel ])[ index ] ; } ;
334 bool StartComponent( const int aThread ,
335 const char * ComputerContainer ,
336 const char * ComponentName ,
337 Engines::Container_var & myContainer ,
338 Engines::Component_var & objComponent ) ;