]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_Graph.hxx
Salome HOME
c941f6d58d87da5044e4e44da542baec7b42fefb
[modules/superv.git] / src / GraphBase / DataFlowBase_Graph.hxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_Graph.hxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 #ifndef _DATAFLOWBASE_GRAPH_HXX
30 #define _DATAFLOWBASE_GRAPH_HXX
31
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"
38
39 namespace GraphBase {
40
41   class Graph : public DataNode {
42
43     private:
44
45 //      int                 _Graph_prof_debug;
46 //      ofstream          * _Graph_fdebug;
47       CORBA::ORB_ptr      _Orb ;
48 //      SUPERV::Graph_var   _Graph ;
49 //      Graph_Impl        * _GraphImpl ;
50
51 // Map of Nodes of the Graph
52       map< string , int >      _MapOfGraphNodes ;
53       long                     _GraphNodesSize ;
54       vector<bool >            _Sorted ;
55       vector<ComputingNode *>  _GraphNodes ;
56
57 // _SortedNodes[ _LevelsNumber ] : topological sort from 0 to _LevelsNumber
58 // _SortedNodes[ _level ][ _NodesNumber[ _level ] ] : _NodesNumber[ _level ] Nodes in the level
59       int                              _LevelsNumber ;
60       int                              _ThreadsMax ;
61       vector<int >                     _NodesNumber ;
62       vector<vector<ComputingNode *> > _SortedNodes ;
63
64       vector<int >             _CnxInPortsNumber ;
65       vector<int >             _DecrInPortsNumber ;
66
67       long                     _HeadNodesSize ; 
68       vector<ComputingNode *>  _HeadNodes ;
69       long                     _QueueNodesSize ; 
70       vector<ComputingNode *>  _QueueNodes ;
71       bool                     _ParallelExecutionNodes ;
72
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 ;
76
77 // For automactic rename of nodes if unique names in graphs
78       map< string , int >      _MapOfServiceInstanceNumber ;
79
80 // Total number of SubGraphs
81       int                              _SubGraphsNumber ;
82 // _SubGraphs[ SubGraphNumero ] [ NodeNumero ]
83 // SubGraphNumero : [ 0 , _SubGraphsSize [ ; NodeNumero : [ 0 , _SubGraphs[ SubGraphNumero ].size() [
84       int                              _SubGraphsSize ;
85       vector<vector<ComputingNode *> > _SubGraphs ;
86
87 // _SubStreamGraphs[ SubStreamGraphNumero ] [ NodeNumero ]
88 // SubStreamGraphNumero : [ 0 , _SubStreamGraphsSize [
89 // NodeNumero : [ 0 , _SubStreamGraphs[ SubStreamGraphNumero ].size() [
90 //      int                              _SubStreamGraphsSize ;
91 //      vector<vector<ComputingNode *> > _SubStreamGraphs ;
92
93       bool AddLink( GraphBase::ComputingNode *fromNode ,
94                     GraphBase::OutPort *fromPort ,
95                     GraphBase::ComputingNode *toNode ,
96                     GraphBase::InPort *toPort ) ;
97
98     public:
99
100       Graph() ;
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 ) ;
124       virtual ~Graph() ;
125
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 ; } ;
133
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 ; } ;
140
141       void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
142            GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
143
144       const int GetGraphNodeIndex( const char *name ) {
145             const int index = _MapOfGraphNodes[ name ] - 1 ;
146 //            if ( index >= 0 )
147 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
148 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
149 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
150 #if 0
151            cdebug << "Graph::GetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
152            int i ;
153            for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
154              cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
155            }
156            map< string , int >::iterator aMapOfGraphNodesIterator ;
157            i = 0 ;
158            for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
159              aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
160              cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
161                     << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
162            }
163 #endif
164             return index ; } ;
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 ;
171 #if 0
172            cdebug << "Graph::SetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
173            int i ;
174            for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
175              cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
176            }
177            map< string , int >::iterator aMapOfGraphNodesIterator ;
178            i = 0 ;
179            for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
180              aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
181              cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
182                     << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
183            }
184 #endif
185            } ;
186       void DelGraphNodeIndex( const char *name ) {
187            _MapOfGraphNodes.erase( name ) ; } ;
188
189       int GetGraphNodeSize() const {
190           return _MapOfGraphNodes.size() ; }
191       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
192             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
193             return aNode ; } ;
194       ComputingNode * GetChangeGraphNode( const int index ) const {
195             if ( index >= 0 && index < _GraphNodesSize ) {
196               ComputingNode * aNode = _GraphNodes[ index ] ;
197               return aNode ;
198             }
199             else
200               return NULL ; } ;
201       const ComputingNode * GetGraphNode( const char *name ) {
202             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
203             return aNode ; } ;
204       ComputingNode * GetChangeGraphNode( const char *name ) {
205             int index = GetGraphNodeIndex( name ) ;
206             if ( index >= 0 && index < _GraphNodesSize ) {
207               ComputingNode * aNode = GetChangeGraphNode( index ) ;
208               return aNode ;
209             }
210             else
211               return NULL ; } ;
212
213       const int GraphNodesSize() const {
214             return _GraphNodesSize ; } ;
215       ComputingNode * GraphNodes( int i ) const {
216             return _GraphNodes[ i ] ; } ;
217
218       const int HeadNodesSize() const {
219             return _HeadNodesSize ; } ;
220       ComputingNode * HeadNodes( int i ) const {
221             return _HeadNodes[ i ] ; } ;
222
223       const int QueueNodesSize() const {
224             return _QueueNodesSize ; } ;
225       ComputingNode * QueueNodes( int i ) const {
226             return _QueueNodes[ i ] ; } ;
227
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 ); } ;
236
237       const GraphBase::InPort * GetInPort( const char * ToNodeName ,
238                                           const char * ToServiceParameterName ) {
239             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
240             if ( aNode ) {
241               return aNode->GetInPort(ToServiceParameterName);
242             }
243             else
244               return NULL ; } ;
245       GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
246                                           const char * ToServiceParameterName ) {
247             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
248             if ( aNode ) {
249               return aNode->GetChangeInPort( ToServiceParameterName ) ;
250             }
251             else
252               return NULL ; } ;
253       const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
254                                     const char * FromServiceParameterName ) {
255             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
256             if ( aNode ) {
257               return aNode->GetOutPort( FromServiceParameterName ) ;
258             }
259             else
260               return NULL ; } ;
261       GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
262                                             const char * FromServiceParameterName ) {
263             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
264             if ( aNode ) {
265               return aNode->GetChangeOutPort( FromServiceParameterName );
266             }
267             else
268               return NULL ; } ;
269
270       SUPERV::GraphState PortState( const char* NodeName ,
271                                     const char* ServiceParameterName ) ;
272       bool PortDone( const char* NodeName ,
273                      const char* ServiceParameterName ) {
274         bool aRet = false ;
275         SUPERV::GraphState aState = PortState( NodeName ,
276                                                 ServiceParameterName ) ;
277         if ( aState == SUPERV::DoneState )
278           aRet = true ;
279         return aRet ; } ;
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 ) ;
286
287       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
288                     GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
289
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 ;
295
296       bool AddNode( ComputingNode * aNode ) ;
297       bool RemoveNode( const char* NodeName ) ;
298       bool ReNameNode( const char* OldNodeName ,
299                        const char* NewNodeName ) ;
300
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 ) ;
316
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 ) ;
326
327       bool AddOutputData( const char* FromNodeName ,
328                           const char* FromParameterName ,
329                           const CORBA::Any aValue ) ;
330
331       void SetGraphPorts() ;
332
333       bool CreateService() ;
334       bool InLineServices() ;
335
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 ;
342   
343       long LevelMax() {
344            return _LevelsNumber + 1 ; } ;
345
346       map< string , GraphBase::Service * > MapOfServiceNames() ;
347       GraphBase::Service * GetServiceOfMap( char * name ) ;
348       bool SetServiceOfMap( GraphBase::Service * aService ) ;
349       int GetNewServiceInstanceNumber( char * aServiceName ) ;
350
351       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
352       long ThreadsMax() {
353            return _ThreadsMax ; } ;
354
355       long SubGraphsNumber() {
356            return _SubGraphsNumber ; } ;
357
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 ] ; } ;
362
363       bool StartComponent( const int aThread ,
364                            const char * ComputerContainer ,
365                            const char * ComponentName ,
366                            Engines::Container_var & myContainer ,
367                            Engines::Component_var & objComponent ) ;
368
369   };
370   
371 };
372
373 #endif