Salome HOME
Merging with JR_ASV_2_1_0_deb_with_KERNEL_Head branch, which contains many bug fixes...
[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 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 ;
77
78 // Total number of SubGraphs
79       int                              _SubGraphsNumber ;
80 // _SubGraphs[ SubGraphNumero ] [ NodeNumero ]
81 // SubGraphNumero : [ 0 , _SubGraphsSize [ ; NodeNumero : [ 0 , _SubGraphs[ SubGraphNumero ].size() [
82       int                              _SubGraphsSize ;
83       vector<vector<ComputingNode *> > _SubGraphs ;
84
85 // _SubStreamGraphs[ SubStreamGraphNumero ] [ NodeNumero ]
86 // SubStreamGraphNumero : [ 0 , _SubStreamGraphsSize [
87 // NodeNumero : [ 0 , _SubStreamGraphs[ SubStreamGraphNumero ].size() [
88 //      int                              _SubStreamGraphsSize ;
89 //      vector<vector<ComputingNode *> > _SubStreamGraphs ;
90
91       bool AddLink( GraphBase::ComputingNode *fromNode ,
92                     GraphBase::OutPort *fromPort ,
93                     GraphBase::ComputingNode *toNode ,
94                     GraphBase::InPort *toPort ) ;
95
96     public:
97
98       Graph() ;
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 ) ;
122       virtual ~Graph() ;
123
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 ; } ;
131
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 ; } ;
138
139       void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
140            GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
141
142       const int GetGraphNodeIndex( const char *name ) {
143             const int index = _MapOfGraphNodes[ name ] - 1 ;
144 //            if ( index >= 0 )
145 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
146 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
147 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
148             return index ; } ;
149       void SetGraphNodeIndex( const char *name , const int index ) {
150            _MapOfGraphNodes[ name ] = index + 1 ;
151            cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
152                   << index << " Node " << (void *) _GraphNodes[ index ]
153                   << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
154            } ;
155       void DelGraphNodeIndex( const char *name ) {
156            _MapOfGraphNodes.erase( name ) ; } ;
157
158       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
159             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
160             return aNode ; } ;
161       ComputingNode * GetChangeGraphNode( const int index ) const {
162             if ( index >= 0 && index < _GraphNodesSize ) {
163               ComputingNode * aNode = _GraphNodes[ index ] ;
164               return aNode ;
165             }
166             else
167               return NULL ; } ;
168       const ComputingNode * GetGraphNode( const char *name ) {
169             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
170             return aNode ; } ;
171       ComputingNode * GetChangeGraphNode( const char *name ) {
172             int index = GetGraphNodeIndex( name ) ;
173             if ( index >= 0 && index < _GraphNodesSize ) {
174               ComputingNode * aNode = GetChangeGraphNode( index ) ;
175               return aNode ;
176             }
177             else
178               return NULL ; } ;
179
180       const int GraphNodesSize() const {
181             return _GraphNodesSize ; } ;
182       ComputingNode * GraphNodes( int i ) const {
183             return _GraphNodes[ i ] ; } ;
184
185       const int HeadNodesSize() const {
186             return _HeadNodesSize ; } ;
187       ComputingNode * HeadNodes( int i ) const {
188             return _HeadNodes[ i ] ; } ;
189
190       const int QueueNodesSize() const {
191             return _QueueNodesSize ; } ;
192       ComputingNode * QueueNodes( int i ) const {
193             return _QueueNodes[ i ] ; } ;
194
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 ); } ;
203
204       const GraphBase::InPort * GetInPort( const char * ToNodeName ,
205                                           const char * ToServiceParameterName ) {
206             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
207             if ( aNode ) {
208               return aNode->GetInPort(ToServiceParameterName);
209             }
210             else
211               return NULL ; } ;
212       GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
213                                           const char * ToServiceParameterName ) {
214             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
215             if ( aNode ) {
216               return aNode->GetChangeInPort( ToServiceParameterName ) ;
217             }
218             else
219               return NULL ; } ;
220       const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
221                                     const char * FromServiceParameterName ) {
222             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
223             if ( aNode ) {
224               return aNode->GetOutPort( FromServiceParameterName ) ;
225             }
226             else
227               return NULL ; } ;
228       GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
229                                             const char * FromServiceParameterName ) {
230             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
231             if ( aNode ) {
232               return aNode->GetChangeOutPort( FromServiceParameterName );
233             }
234             else
235               return NULL ; } ;
236
237       SUPERV::GraphState PortState( const char* NodeName ,
238                                     const char* ServiceParameterName ) ;
239       bool PortDone( const char* NodeName ,
240                      const char* ServiceParameterName ) {
241         bool aRet = false ;
242         SUPERV::GraphState aState = PortState( NodeName ,
243                                                 ServiceParameterName ) ;
244         if ( aState == SUPERV::DoneState )
245           aRet = true ;
246         return aRet ; } ;
247       const CORBA::Any * PortInData( const char* ToNodeName ,
248                                      const char* ToServiceParameterName ) ;
249       const CORBA::Any * PortOutData( const char* FromNodeName ,
250                                       const char* FromServiceParameterName ) ;
251
252       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
253                     GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
254
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 ;
260
261       bool AddNode( ComputingNode * aNode ) ;
262       bool RemoveNode( const char* NodeName ) ;
263       bool ReNameNode( const char* OldNodeName ,
264                        const char* NewNodeName ) ;
265
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 ) ;
281
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 ) ;
291
292       bool AddOutputData( const char* FromNodeName ,
293                           const char* FromParameterName ,
294                           const CORBA::Any aValue ) ;
295
296       void SetGraphPorts() ;
297
298       bool CreateService() ;
299       bool InLineServices() ;
300
301       bool Sort( int & SubStreamGraphsNumber ) ;
302       bool ValidLoops() const ;
303       bool ComputingNodes() const ;
304       bool LinkLoopNodes(bool & NewLink ) ;
305       bool DataServerNodes() const ;
306   
307       long LevelMax() {
308            return _LevelsNumber + 1 ; } ;
309
310       map< string , GraphBase::Service * > MapOfServiceNames() ;
311       GraphBase::Service * GetServiceOfMap( char * name ) ;
312       bool SetServiceOfMap( GraphBase::Service * aService ) ;
313       int GetServiceNameNumber( SALOME_ModuleCatalog::Service aService ) ;
314
315       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
316       long ThreadsMax() {
317            return _ThreadsMax ; } ;
318
319       long SubGraphsNumber() {
320            return _SubGraphsNumber ; } ;
321
322       int NodesNumber(const int aLevel ) {
323           return _NodesNumber[ aLevel ] ; } ;
324       GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
325              return (_SortedNodes[ aLevel ])[ index ] ; } ;
326
327       bool StartComponent( const int aThread ,
328                            const char * ComputerContainer ,
329                            const char * ComponentName ,
330                            Engines::Container_var & myContainer ,
331                            Engines::Component_var & objComponent ) ;
332
333   };
334   
335 };
336
337 #endif