]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_Graph.hxx
Salome HOME
DCQ:prepare 2.0.0
[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 class Graph_Impl ;
40
41 namespace GraphBase {
42
43   class Graph : public DataNode {
44
45     private:
46
47 //      int                 _Graph_prof_debug;
48 //      ofstream          * _Graph_fdebug;
49       CORBA::ORB_ptr      _Orb ;
50       SUPERV::Graph_var   _Graph ;
51       Graph_Impl        * _GraphImpl ;
52
53 // Map of Nodes of the Graph
54       map< string , int >      _MapOfGraphNodes ;
55       long                     _GraphNodesSize ;
56       vector<bool >            _Sorted ;
57       vector<ComputingNode *>  _GraphNodes ;
58
59 // _SortedNodes[ _LevelsNumber ] : topological sort from 0 to _LevelsNumber
60 // _SortedNodes[ _level ][ _NodesNumber[ _level ] ] : _NodesNumber[ _level ] Nodes in the level
61       int                              _LevelsNumber ;
62       int                              _ThreadsMax ;
63       vector<int >                     _NodesNumber ;
64       vector<vector<ComputingNode *> > _SortedNodes ;
65
66       vector<int >             _CnxInPortsNumber ;
67       vector<int >             _DecrInPortsNumber ;
68
69       long                     _HeadNodesSize ; 
70       vector<ComputingNode *>  _HeadNodes ;
71       long                     _QueueNodesSize ; 
72       vector<ComputingNode *>  _QueueNodes ;
73       bool                     _ParallelExecutionNodes ;
74
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 ;
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             return index ; } ;
151       void SetGraphNodeIndex( const char *name , const int index ) {
152            _MapOfGraphNodes[ name ] = index + 1 ;
153            cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
154                   << index << " Node " << hex << (void *) _GraphNodes[ index ]
155                   << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
156            } ;
157       void DelGraphNodeIndex( const char *name ) {
158            _MapOfGraphNodes.erase( name ) ; } ;
159
160       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
161             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
162             return aNode ; } ;
163       ComputingNode * GetChangeGraphNode( const int index ) const {
164             if ( index >= 0 && index < _GraphNodesSize ) {
165               ComputingNode * aNode = _GraphNodes[ index ] ;
166               return aNode ;
167             }
168             else
169               return NULL ; } ;
170       const ComputingNode * GetGraphNode( const char *name ) {
171             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
172             return aNode ; } ;
173       ComputingNode * GetChangeGraphNode( const char *name ) {
174             int index = GetGraphNodeIndex( name ) ;
175             if ( index >= 0 && index < _GraphNodesSize ) {
176               ComputingNode * aNode = GetChangeGraphNode( index ) ;
177               return aNode ;
178             }
179             else
180               return NULL ; } ;
181
182       const int GraphNodesSize() const {
183             return _GraphNodesSize ; } ;
184       ComputingNode * GraphNodes( int i ) const {
185             return _GraphNodes[ i ] ; } ;
186
187       const int HeadNodesSize() const {
188             return _HeadNodesSize ; } ;
189       ComputingNode * HeadNodes( int i ) const {
190             return _HeadNodes[ i ] ; } ;
191
192       const int QueueNodesSize() const {
193             return _QueueNodesSize ; } ;
194       ComputingNode * QueueNodes( int i ) const {
195             return _QueueNodes[ i ] ; } ;
196
197       const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
198                                 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
199       GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
200                           return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
201       const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
202                                  return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
203       GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
204                            return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
205
206       const GraphBase::InPort * GetInPort( const char * ToNodeName ,
207                                           const char * ToServiceParameterName ) {
208             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
209             if ( aNode ) {
210               return aNode->GetInPort(ToServiceParameterName);
211             }
212             else
213               return NULL ; } ;
214       GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
215                                           const char * ToServiceParameterName ) {
216             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
217             if ( aNode ) {
218               return aNode->GetChangeInPort( ToServiceParameterName ) ;
219             }
220             else
221               return NULL ; } ;
222       const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
223                                     const char * FromServiceParameterName ) {
224             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
225             if ( aNode ) {
226               return aNode->GetOutPort( FromServiceParameterName ) ;
227             }
228             else
229               return NULL ; } ;
230       GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
231                                             const char * FromServiceParameterName ) {
232             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
233             if ( aNode ) {
234               return aNode->GetChangeOutPort( FromServiceParameterName );
235             }
236             else
237               return NULL ; } ;
238
239       SUPERV::GraphState PortState( const char* NodeName ,
240                                     const char* ServiceParameterName ) ;
241       bool PortDone( const char* NodeName ,
242                      const char* ServiceParameterName ) {
243         bool aRet = false ;
244         SUPERV::GraphState aState = PortState( NodeName ,
245                                                 ServiceParameterName ) ;
246         if ( aState == SUPERV::DoneState )
247           aRet = true ;
248         return aRet ; } ;
249       const CORBA::Any * PortInData( const char* ToNodeName ,
250                                      const char* ToServiceParameterName ) ;
251       const CORBA::Any * PortOutData( const char* FromNodeName ,
252                                       const char* FromServiceParameterName ) ;
253
254       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
255                     GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
256
257       GraphBase::SNode * GetInfo() const ;
258       GraphBase::ListOfSNodes * GetNodes() const ;
259       GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
260       GraphBase::ListOfSGraphs * GetGraphs() const ;
261       GraphBase::ListOfSLinks * GetDatas() const ;
262
263       bool AddNode( ComputingNode * aNode ) ;
264       bool RemoveNode( const char* NodeName ) ;
265       bool ReNameNode( const char* OldNodeName ,
266                        const char* NewNodeName ) ;
267
268       bool AddLink( const char* FromNodeName ,
269                     const char* FromServiceParameterName ,
270                     const char* ToNodeName ,
271                     const char* ToServiceParameterName ) ;
272 //                    , const CORBA::Any aValue ) ;
273       bool RemoveLink( const char* FromNodeName ,
274                        const char* FromServiceParameterName ,
275                        const char* ToNodeName ,
276                        const char* ToServiceParameterName ) ;
277       bool GetLink( const char* ToNodeName ,
278                     const char* ToServiceParameterName ,
279                     char** FromNodeName ,
280                     char** FromServiceParameterName ) ;
281       GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
282                                   GraphBase::InPort* toPort ) ;
283
284       bool AddInputData( const char* ToNodeName ,
285                          const char* ToParameterName ,
286                          const CORBA::Any aValue ) ;
287       bool ChangeInputData( const char* ToNodeName ,
288                             const char* ToParameterName ,
289                             const CORBA::Any aValue ) ;
290       bool AddInputData( const char* ToNodeName ,
291                          const char* ToParameterName ,
292                          const CORBA::Any ** aValue ) ;
293
294       bool AddOutputData( const char* FromNodeName ,
295                           const char* FromParameterName ,
296                           const CORBA::Any aValue ) ;
297
298       void SetGraphPorts() ;
299
300       bool CreateService() ;
301       bool InLineServices() ;
302
303       bool Sort( int & SubStreamGraphsNumber ) ;
304       bool ComputingNodes() const ;
305       bool LinkLoopNodes(bool & NewLink ) ;
306       bool DataServerNodes() const ;
307   
308       long LevelMax() {
309            return _LevelsNumber + 1 ; } ;
310
311       map< string , GraphBase::Service * > MapOfServiceNames() ;
312       GraphBase::Service * GetServiceOfMap( char * name ) ;
313       bool SetServiceOfMap( GraphBase::Service * aService ) ;
314       int GetServiceNameNumber( SALOME_ModuleCatalog::Service aService ) ;
315
316       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
317       long ThreadsMax() {
318            return _ThreadsMax ; } ;
319
320       long SubGraphsNumber() {
321            return _SubGraphsNumber ; } ;
322
323       int NodesNumber(const int aLevel ) {
324           return _NodesNumber[ aLevel ] ; } ;
325       GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
326              return (_SortedNodes[ aLevel ])[ index ] ; } ;
327
328       bool StartComponent( const int aThread ,
329                            const char * ComputerContainer ,
330                            const char * ComponentName ,
331                            Engines::Container_var & myContainer ,
332                            Engines::Component_var & objComponent ) ;
333
334   };
335   
336 };
337
338 #endif