]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_Graph.hxx
Salome HOME
Error Messages
[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       string _Messages ;
94
95       bool AddLink( GraphBase::ComputingNode *fromNode ,
96                     GraphBase::OutPort *fromPort ,
97                     GraphBase::ComputingNode *toNode ,
98                     GraphBase::InPort *toPort ) ;
99
100     public:
101
102       Graph() ;
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 ) ;
126       virtual ~Graph() ;
127
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 ; } ;
135
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 ; } ;
142
143       void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
144            GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
145
146       const int GetGraphNodeIndex( const char *name ) {
147             const int index = _MapOfGraphNodes[ name ] - 1 ;
148 //            if ( index >= 0 )
149 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
150 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
151 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
152 #if 0
153            cdebug << "Graph::GetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
154            int i ;
155            for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
156              cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
157            }
158            map< string , int >::iterator aMapOfGraphNodesIterator ;
159            i = 0 ;
160            for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
161              aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
162              cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
163                     << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
164            }
165 #endif
166             return index ; } ;
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 ;
173 #if 1
174            cdebug << "Graph::SetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
175            int i ;
176            for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
177              cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
178            }
179            map< string , int >::iterator aMapOfGraphNodesIterator ;
180            i = 0 ;
181            for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
182              aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
183              cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
184                     << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
185            }
186 #endif
187            } ;
188       void DelGraphNodeIndex( const char *name ) {
189            _MapOfGraphNodes.erase( name ) ; } ;
190
191       int GetGraphNodeSize() const {
192           return _MapOfGraphNodes.size() ; }
193       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
194             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
195             return aNode ; } ;
196       ComputingNode * GetChangeGraphNode( const int index ) const {
197             if ( index >= 0 && index < _GraphNodesSize ) {
198               ComputingNode * aNode = _GraphNodes[ index ] ;
199               return aNode ;
200             }
201             else
202               return NULL ; } ;
203       const ComputingNode * GetGraphNode( const char *name ) {
204             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
205             return aNode ; } ;
206       ComputingNode * GetChangeGraphNode( const char *name ) {
207             int index = GetGraphNodeIndex( name ) ;
208             if ( index >= 0 && index < _GraphNodesSize ) {
209               ComputingNode * aNode = GetChangeGraphNode( index ) ;
210               return aNode ;
211             }
212             else
213               return NULL ; } ;
214
215       const int GraphNodesSize() const {
216             return _GraphNodesSize ; } ;
217       ComputingNode * GraphNodes( int i ) const {
218             return _GraphNodes[ i ] ; } ;
219
220       const int HeadNodesSize() const {
221             return _HeadNodesSize ; } ;
222       ComputingNode * HeadNodes( int i ) const {
223             return _HeadNodes[ i ] ; } ;
224
225       const int QueueNodesSize() const {
226             return _QueueNodesSize ; } ;
227       ComputingNode * QueueNodes( int i ) const {
228             return _QueueNodes[ i ] ; } ;
229
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 ); } ;
238
239       const GraphBase::InPort * GetInPort( const char * ToNodeName ,
240                                           const char * ToServiceParameterName ) {
241             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
242             if ( aNode ) {
243               return aNode->GetInPort(ToServiceParameterName);
244             }
245             else
246               return NULL ; } ;
247       GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
248                                           const char * ToServiceParameterName ) {
249             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
250             if ( aNode ) {
251               return aNode->GetChangeInPort( ToServiceParameterName ) ;
252             }
253             else
254               return NULL ; } ;
255       const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
256                                     const char * FromServiceParameterName ) {
257             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
258             if ( aNode ) {
259               return aNode->GetOutPort( FromServiceParameterName ) ;
260             }
261             else
262               return NULL ; } ;
263       GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
264                                             const char * FromServiceParameterName ) {
265             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
266             if ( aNode ) {
267               return aNode->GetChangeOutPort( FromServiceParameterName );
268             }
269             else
270               return NULL ; } ;
271
272       SUPERV::GraphState PortState( const char* NodeName ,
273                                     const char* ServiceParameterName ) ;
274       bool PortDone( const char* NodeName ,
275                      const char* ServiceParameterName ) {
276         bool aRet = false ;
277         SUPERV::GraphState aState = PortState( NodeName ,
278                                                 ServiceParameterName ) ;
279         if ( aState == SUPERV::DoneState )
280           aRet = true ;
281         return aRet ; } ;
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 ) ;
288
289       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
290                     GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
291
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 ;
297
298       bool AddNode( ComputingNode * aNode ) ;
299       bool RemoveNode( const char* NodeName ) ;
300       bool ReNameNode( const char* OldNodeName ,
301                        const char* NewNodeName ) ;
302
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 ) ;
318
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 ) ;
328
329       bool AddOutputData( const char* FromNodeName ,
330                           const char* FromParameterName ,
331                           const CORBA::Any aValue ) ;
332
333       void SetGraphPorts() ;
334
335       string Messages() ;
336       void ReSetMessages() ;
337       void SetMessages( string anErrorMessage ) ;
338
339       bool CreateService() ;
340       bool InLineServices() ;
341
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 ;
348   
349       long LevelMax() {
350            return _LevelsNumber + 1 ; } ;
351
352       map< string , GraphBase::Service * > MapOfServiceNames() ;
353       GraphBase::Service * GetServiceOfMap( char * name ) ;
354       bool SetServiceOfMap( GraphBase::Service * aService ) ;
355       int GetNewServiceInstanceNumber( char * aServiceName ) ;
356
357       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
358       long ThreadsMax() {
359            return _ThreadsMax ; } ;
360
361       long SubGraphsNumber() {
362            return _SubGraphsNumber ; } ;
363
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 ] ; } ;
368
369       bool StartComponent( const int aThread ,
370                            const char * ComputerContainer ,
371                            const char * ComponentName ,
372                            Engines::Container_var & myContainer ,
373                            Engines::Component_var & objComponent ) ;
374
375   };
376   
377 };
378
379 #endif