Salome HOME
9b585d4c1c5d4c5fc882ad7802653a21dcd47cc5
[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 InNodes of the OutNode
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
61       int                              _LevelsNumber ;
62       int                              _ThreadsMax ;
63       int                              _GraphsNumber ;
64       vector<int >                     _NodesNumber ;
65       vector<vector<ComputingNode *> > _SortedNodes ;
66
67       vector<int >             _CnxInPortsNumber ;
68       vector<int >             _DecrInPortsNumber ;
69
70       long                     _HeadNodesSize ; 
71       vector<ComputingNode *>  _HeadNodes ;
72       long                     _QueueNodesSize ; 
73       vector<ComputingNode *>  _QueueNodes ;
74       bool                     _ParallelExecutionNodes ;
75
76       bool AddLink( GraphBase::ComputingNode *fromNode ,
77                     GraphBase::OutPort *fromPort ,
78                     GraphBase::ComputingNode *toNode ,
79                     GraphBase::InPort *toPort ) ;
80
81     public:
82
83       Graph() ;
84       Graph( CORBA::ORB_ptr ORB ,
85              SALOME_NamingService* ptrNamingService ,
86              const char *DataFlowName ,
87              const char * DebugFileName ) ;
88       Graph( CORBA::ORB_ptr ORB ,
89              SALOME_NamingService* ptrNamingService ,
90              const SALOME_ModuleCatalog::Service& DataFlowService ,
91              const char *DataFlowComponentName ,
92              const char *DataFlowInterfaceName ,
93              const char *DataFlowName ,
94              const SUPERV::KindOfNode DataFlowkind ,
95              const SUPERV::SDate DataFlowFirstCreation ,
96              const SUPERV::SDate DataFlowLastModification ,
97              const char * DataFlowEditorRelease ,
98              const char * DataFlowAuthor ,
99              const char * DataFlowComputer ,
100              const char * DataFlowComment ,
101              const char * DebugFileName ) ;
102       virtual ~Graph() ;
103
104       void Set_prof_debug( CORBA::ORB_ptr ORB ,
105                            const char * DebugFileName ) ;
106       int * Graph_prof_debug() {
107 //            MESSAGE( "Graph_prof_debug _Graph_prof_debug " << &_Graph_prof_debug << " _Graph_fdebug "
108 //                     << _Graph_fdebug ) ;
109             return &_Graph_prof_debug ; } ;
110       ofstream * Graph_fdebug() { return _Graph_fdebug ; } ;
111
112       SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
113       void SetObjRef( SUPERV::Graph_var aGraph ) {
114                       _Graph = aGraph ; } ;
115       Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
116       void SetObjImpl( Graph_Impl * aGraphImpl ) {
117                        _GraphImpl = aGraphImpl ; } ;
118
119       void AddLink( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
120            GetChangeGraphNode( FromNodeName )->AddLink( anOutNode ) ; } ;
121
122       const int GetGraphNodeIndex( const char *name ) {
123             const int index = _MapOfGraphNodes[ name ] - 1 ;
124 //            if ( index >= 0 )
125 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
126 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
127 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
128             return index ; } ;
129       void SetGraphNodeIndex( const char *name , const int index ) {
130            _MapOfGraphNodes[ name ] = index + 1 ;
131            cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
132                   << index << " Node " << hex << (void *) _GraphNodes[ index ]
133                   << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
134            } ;
135       void DelGraphNodeIndex( const char *name ) {
136            _MapOfGraphNodes.erase( name ) ; } ;
137       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
138             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
139             return aNode ; } ;
140       ComputingNode * GetChangeGraphNode( const int index ) const {
141             if ( index >= 0 && index < _GraphNodesSize ) {
142               ComputingNode * aNode = _GraphNodes[ index ] ;
143               return aNode ;
144             }
145             else
146               return NULL ; } ;
147       const ComputingNode * GetGraphNode( const char *name ) {
148             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
149             return aNode ; } ;
150       ComputingNode * GetChangeGraphNode( const char *name ) {
151             int index = GetGraphNodeIndex( name ) ;
152             if ( index >= 0 && index < _GraphNodesSize ) {
153               ComputingNode * aNode = GetChangeGraphNode( index ) ;
154               return aNode ;
155             }
156             else
157               return NULL ; } ;
158
159       const int GraphNodesSize() const {
160             return _GraphNodesSize ; } ;
161       ComputingNode * GraphNodes( int i ) const {
162             return _GraphNodes[ i ] ; } ;
163
164       const int HeadNodesSize() const {
165             return _HeadNodesSize ; } ;
166       ComputingNode * HeadNodes( int i ) const {
167             return _HeadNodes[ i ] ; } ;
168
169       const int QueueNodesSize() const {
170             return _QueueNodesSize ; } ;
171       ComputingNode * QueueNodes( int i ) const {
172             return _QueueNodes[ i ] ; } ;
173
174       const GraphBase::InPort *GetInPort( const char* ToNodeName ,
175                                           const char* ToServiceParameterName ) {
176             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
177             if ( aNode ) {
178               return aNode->GetInPort(ToServiceParameterName);
179             }
180             else
181               return NULL ; } ;
182       GraphBase::InPort *GetChangeInPort( const char* ToNodeName ,
183                                           const char* ToServiceParameterName ) {
184             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
185             if ( aNode ) {
186               return aNode->GetChangeInPort(ToServiceParameterName);
187             }
188             else
189               return NULL ; } ;
190       GraphBase::OutPort *GetChangeOutPort(
191                                       const char* FromNodeName ,
192                                       const char* FromServiceParameterName ) {
193             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
194             if ( aNode ) {
195               return aNode->GetChangeOutPort( FromServiceParameterName );
196             }
197             else
198               return NULL ; } ;
199
200       SUPERV::GraphState PortState( const char* NodeName ,
201                                     const char* ServiceParameterName ) ;
202       bool PortDone( const char* NodeName ,
203                      const char* ServiceParameterName ) {
204         bool aRet = false ;
205         SUPERV::GraphState aState = PortState( NodeName ,
206                                                 ServiceParameterName ) ;
207         if ( aState == SUPERV::DoneState )
208           aRet = true ;
209         return aRet ; } ;
210       const CORBA::Any * PortInData( const char* ToNodeName ,
211                                      const char* ToServiceParameterName ) ;
212       const CORBA::Any * PortOutData( const char* FromNodeName ,
213                                       const char* FromServiceParameterName ) ;
214
215       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
216                     GraphBase::SGraph & aDataFlow ) ;
217
218       GraphBase::SNode * GetInfo() const ;
219       GraphBase::ListOfNodes * GetNodes() const ;
220       GraphBase::ListOfLinks * GetLinks(bool AllLinks = false ) const ;
221       GraphBase::ListOfGraphs * GetGraphs() const ;
222       GraphBase::ListOfLinks * GetDatas() const ;
223 //      SALOME_ModuleCatalog::Service * GetService() const ;
224
225       bool AddNode( ComputingNode * aNode ) ;
226       bool RemoveNode( const char* NodeName ) ;
227       bool ReNameNode( const char* OldNodeName ,
228                        const char* NewNodeName ) ;
229
230       bool AddLink( const char* FromNodeName ,
231                     const char* FromServiceParameterName ,
232                     const char* ToNodeName ,
233                     const char* ToServiceParameterName ,
234                     const CORBA::Any aValue ) ;
235       bool RemoveLink( const char* FromNodeName ,
236                        const char* FromServiceParameterName ,
237                        const char* ToNodeName ,
238                        const char* ToServiceParameterName ) ;
239       bool GetLink( const char* ToNodeName ,
240                     const char* ToServiceParameterName ,
241                     char** FromNodeName ,
242                     char** FromServiceParameterName ) ;
243       GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
244                                   GraphBase::InPort* toPort ) ;
245
246       bool AddInputData( const char* ToNodeName ,
247                          const char* ToParameterName ,
248                          const CORBA::Any aValue ) ;
249       bool ChangeInputData( const char* ToNodeName ,
250                             const char* ToParameterName ,
251                             const CORBA::Any aValue ) ;
252       bool AddInputData( const char* ToNodeName1 ,
253                          const char* ToParameterName1 ,
254                          const char* ToNodeName2 ,
255                          const char* ToParameterName2 ) ;
256
257       bool AddInputData( const char* ToNodeName ,
258                          const char* ToParameterName ,
259                          const CORBA::Any ** aValue ) ;
260
261       bool AddOutputData( const char* FromNodeName ,
262                           const char* FromParameterName ,
263                           const CORBA::Any aValue ) ;
264
265       bool CreateService() ;
266       bool InLineServices() ;
267
268       bool Sort() ;
269       bool ComputingNodes() const ;
270       bool LinkLoopNodes(bool & NewLink ) ;
271       bool DataServerNodes() const ;
272   
273       long LevelMax() {
274            return _LevelsNumber + 1 ; } ;
275       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
276       long ThreadsMax() {
277            return _ThreadsMax ; } ;
278       long GraphsNumber() {
279            return _GraphsNumber ; } ;
280
281       int NodesNumber(const int aLevel ) {
282           return _NodesNumber[ aLevel ] ; } ;
283       GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
284              return (_SortedNodes[ aLevel ])[ index ] ; } ;
285
286       bool StartComponent( const int aThread ,
287                            const char * ComputerContainer ,
288                            const char * ComponentName ,
289                            Engines::Container_var & myContainer ,
290                            Engines::Component_var & objComponent ) ;
291
292   };
293   
294 };
295
296 #endif