Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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              int * Graph_prof_debug ,
105              ofstream * Graph_fdebug ) ;
106 //             const char * DebugFileName ) ;
107       Graph( CORBA::ORB_ptr ORB ,
108              SALOME_NamingService* ptrNamingService ,
109              const SALOME_ModuleCatalog::Service& DataFlowService ,
110              const char *DataFlowComponentName ,
111              const char *DataFlowInterfaceName ,
112              const char *DataFlowName ,
113              const SUPERV::KindOfNode DataFlowkind ,
114              const SUPERV::SDate DataFlowFirstCreation ,
115              const SUPERV::SDate DataFlowLastModification ,
116              const char * DataFlowEditorRelease ,
117              const char * DataFlowAuthor ,
118              const char * DataFlowComputer ,
119              const char * DataFlowComment ,
120              int * Graph_prof_debug ,
121              ofstream * Graph_fdebug ) ;
122 //             const char * DebugFileName ) ;
123       virtual ~Graph() ;
124
125 //      void Set_prof_debug( CORBA::ORB_ptr ORB ,
126 //                           const char * DebugFileName ) ;
127       void Set_prof_debug( int * Graph_prof_debug ,
128                            ofstream * Graph_fdebug ) ;
129       int * Graph_prof_debug() {
130             return _prof_debug ; } ;
131       ofstream * Graph_fdebug() { return _fdebug ; } ;
132
133       SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
134       void SetObjRef( SUPERV::Graph_var aGraph ) {
135                       _Graph = aGraph ; } ;
136       Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
137       void SetObjImpl( Graph_Impl * aGraphImpl ) {
138                        _GraphImpl = aGraphImpl ; } ;
139
140       void AddLink( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
141            GetChangeGraphNode( FromNodeName )->AddLink( anOutNode ) ; } ;
142
143       const int GetGraphNodeIndex( const char *name ) {
144             const int index = _MapOfGraphNodes[ name ] - 1 ;
145 //            if ( index >= 0 )
146 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
147 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
148 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
149             return index ; } ;
150       void SetGraphNodeIndex( const char *name , const int index ) {
151            _MapOfGraphNodes[ name ] = index + 1 ;
152            cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
153                   << index << " Node " << hex << (void *) _GraphNodes[ index ]
154                   << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
155            } ;
156       void DelGraphNodeIndex( const char *name ) {
157            _MapOfGraphNodes.erase( name ) ; } ;
158
159       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
160             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
161             return aNode ; } ;
162       ComputingNode * GetChangeGraphNode( const int index ) const {
163             if ( index >= 0 && index < _GraphNodesSize ) {
164               ComputingNode * aNode = _GraphNodes[ index ] ;
165               return aNode ;
166             }
167             else
168               return NULL ; } ;
169       const ComputingNode * GetGraphNode( const char *name ) {
170             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
171             return aNode ; } ;
172       ComputingNode * GetChangeGraphNode( const char *name ) {
173             int index = GetGraphNodeIndex( name ) ;
174             if ( index >= 0 && index < _GraphNodesSize ) {
175               ComputingNode * aNode = GetChangeGraphNode( index ) ;
176               return aNode ;
177             }
178             else
179               return NULL ; } ;
180
181       const int GraphNodesSize() const {
182             return _GraphNodesSize ; } ;
183       ComputingNode * GraphNodes( int i ) const {
184             return _GraphNodes[ i ] ; } ;
185
186       const int HeadNodesSize() const {
187             return _HeadNodesSize ; } ;
188       ComputingNode * HeadNodes( int i ) const {
189             return _HeadNodes[ i ] ; } ;
190
191       const int QueueNodesSize() const {
192             return _QueueNodesSize ; } ;
193       ComputingNode * QueueNodes( int i ) const {
194             return _QueueNodes[ i ] ; } ;
195
196       const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
197                                 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
198       GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
199                           return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
200       const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
201                                  return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
202       GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
203                            return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
204
205       const GraphBase::InPort * GetInPort( const char * ToNodeName ,
206                                           const char * ToServiceParameterName ) {
207             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
208             if ( aNode ) {
209               return aNode->GetInPort(ToServiceParameterName);
210             }
211             else
212               return NULL ; } ;
213       GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
214                                           const char * ToServiceParameterName ) {
215             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
216             if ( aNode ) {
217               return aNode->GetChangeInPort( ToServiceParameterName ) ;
218             }
219             else
220               return NULL ; } ;
221       const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
222                                     const char * FromServiceParameterName ) {
223             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
224             if ( aNode ) {
225               return aNode->GetOutPort( FromServiceParameterName ) ;
226             }
227             else
228               return NULL ; } ;
229       GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
230                                             const char * FromServiceParameterName ) {
231             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
232             if ( aNode ) {
233               return aNode->GetChangeOutPort( FromServiceParameterName );
234             }
235             else
236               return NULL ; } ;
237
238       SUPERV::GraphState PortState( const char* NodeName ,
239                                     const char* ServiceParameterName ) ;
240       bool PortDone( const char* NodeName ,
241                      const char* ServiceParameterName ) {
242         bool aRet = false ;
243         SUPERV::GraphState aState = PortState( NodeName ,
244                                                 ServiceParameterName ) ;
245         if ( aState == SUPERV::DoneState )
246           aRet = true ;
247         return aRet ; } ;
248       const CORBA::Any * PortInData( const char* ToNodeName ,
249                                      const char* ToServiceParameterName ) ;
250       const CORBA::Any * PortOutData( const char* FromNodeName ,
251                                       const char* FromServiceParameterName ) ;
252
253       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
254                     GraphBase::SGraph & aDataFlow ) ;
255
256       GraphBase::SNode * GetInfo() const ;
257       GraphBase::ListOfNodes * GetNodes() const ;
258       GraphBase::ListOfLinks * GetLinks(bool AllLinks = false ) const ;
259       GraphBase::ListOfGraphs * GetGraphs() const ;
260       GraphBase::ListOfLinks * GetDatas() const ;
261
262       bool AddNode( ComputingNode * aNode ) ;
263       bool RemoveNode( const char* NodeName ) ;
264       bool ReNameNode( const char* OldNodeName ,
265                        const char* NewNodeName ) ;
266
267       bool AddLink( const char* FromNodeName ,
268                     const char* FromServiceParameterName ,
269                     const char* ToNodeName ,
270                     const char* ToServiceParameterName ,
271                     const CORBA::Any aValue ) ;
272       bool RemoveLink( const char* FromNodeName ,
273                        const char* FromServiceParameterName ,
274                        const char* ToNodeName ,
275                        const char* ToServiceParameterName ) ;
276       bool GetLink( const char* ToNodeName ,
277                     const char* ToServiceParameterName ,
278                     char** FromNodeName ,
279                     char** FromServiceParameterName ) ;
280       GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
281                                   GraphBase::InPort* toPort ) ;
282
283       bool AddInputData( const char* ToNodeName ,
284                          const char* ToParameterName ,
285                          const CORBA::Any aValue ) ;
286       bool ChangeInputData( const char* ToNodeName ,
287                             const char* ToParameterName ,
288                             const CORBA::Any aValue ) ;
289       bool AddInputData( const char* ToNodeName1 ,
290                          const char* ToParameterName1 ,
291                          const char* ToNodeName2 ,
292                          const char* ToParameterName2 ) ;
293
294       bool AddInputData( const char* ToNodeName ,
295                          const char* ToParameterName ,
296                          const CORBA::Any ** aValue ) ;
297
298       bool AddOutputData( const char* FromNodeName ,
299                           const char* FromParameterName ,
300                           const CORBA::Any aValue ) ;
301
302       bool CreateService() ;
303       bool InLineServices() ;
304
305       bool Sort( int & SubStreamGraphsNumber ) ;
306       bool ComputingNodes() const ;
307       bool LinkLoopNodes(bool & NewLink ) ;
308       bool DataServerNodes() const ;
309   
310       long LevelMax() {
311            return _LevelsNumber + 1 ; } ;
312
313       map< string , GraphBase::Service * > MapOfServiceNames() ;
314       GraphBase::Service * GetServiceOfMap( char * name ) ;
315       bool SetServiceOfMap( GraphBase::Service * aService ) ;
316       int GetServiceNameNumber( SALOME_ModuleCatalog::Service aService ) ;
317
318       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
319       long ThreadsMax() {
320            return _ThreadsMax ; } ;
321
322       long SubGraphsNumber() {
323            return _SubGraphsNumber ; } ;
324
325       int NodesNumber(const int aLevel ) {
326           return _NodesNumber[ aLevel ] ; } ;
327       GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
328              return (_SortedNodes[ aLevel ])[ index ] ; } ;
329
330       bool StartComponent( const int aThread ,
331                            const char * ComputerContainer ,
332                            const char * ComponentName ,
333                            Engines::Container_var & myContainer ,
334                            Engines::Component_var & objComponent ) ;
335
336   };
337   
338 };
339
340 #endif