]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_Graph.hxx
Salome HOME
NRI : Merge from V1_2.
[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       ostream           * _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() { return &_Graph_prof_debug ; } ;
107       ostream * Graph_fdebug() { return _Graph_fdebug ; } ;
108
109       SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
110       void SetObjRef( SUPERV::Graph_var aGraph ) {
111                       _Graph = aGraph ; } ;
112       Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
113       void SetObjImpl( Graph_Impl * aGraphImpl ) {
114                        _GraphImpl = aGraphImpl ; } ;
115
116       void AddLink( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
117            GetChangeGraphNode( FromNodeName )->AddLink( anOutNode ) ; } ;
118
119       const int GetGraphNodeIndex( const char *name ) {
120             const int index = _MapOfGraphNodes[ name ] - 1 ;
121 //            if ( index >= 0 )
122 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
123 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
124 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
125             return index ; } ;
126       void SetGraphNodeIndex( const char *name , const int index ) {
127            _MapOfGraphNodes[ name ] = index + 1 ;
128            cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
129                   << index << " Node " << hex << (void *) _GraphNodes[ index ]
130                   << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
131            } ;
132       void DelGraphNodeIndex( const char *name ) {
133            _MapOfGraphNodes.erase( name ) ; } ;
134       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
135             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
136             return aNode ; } ;
137       ComputingNode * GetChangeGraphNode( const int index ) const {
138             if ( index >= 0 && index < _GraphNodesSize ) {
139               ComputingNode * aNode = _GraphNodes[ index ] ;
140               return aNode ;
141             }
142             else
143               return NULL ; } ;
144       const ComputingNode * GetGraphNode( const char *name ) {
145             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
146             return aNode ; } ;
147       ComputingNode * GetChangeGraphNode( const char *name ) {
148             int index = GetGraphNodeIndex( name ) ;
149             if ( index >= 0 && index < _GraphNodesSize ) {
150               ComputingNode * aNode = GetChangeGraphNode( index ) ;
151               return aNode ;
152             }
153             else
154               return NULL ; } ;
155
156       const int GraphNodesSize() const {
157             return _GraphNodesSize ; } ;
158       ComputingNode * GraphNodes( int i ) const {
159             return _GraphNodes[ i ] ; } ;
160
161       const int HeadNodesSize() const {
162             return _HeadNodesSize ; } ;
163       ComputingNode * HeadNodes( int i ) const {
164             return _HeadNodes[ i ] ; } ;
165
166       const int QueueNodesSize() const {
167             return _QueueNodesSize ; } ;
168       ComputingNode * QueueNodes( int i ) const {
169             return _QueueNodes[ i ] ; } ;
170
171       const GraphBase::InPort *GetInPort( const char* ToNodeName ,
172                                           const char* ToServiceParameterName ) {
173             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
174             if ( aNode ) {
175               return aNode->GetInPort(ToServiceParameterName);
176             }
177             else
178               return NULL ; } ;
179       GraphBase::InPort *GetChangeInPort( const char* ToNodeName ,
180                                           const char* ToServiceParameterName ) {
181             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
182             if ( aNode ) {
183               return aNode->GetChangeInPort(ToServiceParameterName);
184             }
185             else
186               return NULL ; } ;
187       GraphBase::OutPort *GetChangeOutPort(
188                                       const char* FromNodeName ,
189                                       const char* FromServiceParameterName ) {
190             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
191             if ( aNode ) {
192               return aNode->GetChangeOutPort( FromServiceParameterName );
193             }
194             else
195               return NULL ; } ;
196
197       SUPERV::GraphState PortState( const char* NodeName ,
198                                     const char* ServiceParameterName ) ;
199       bool PortDone( const char* NodeName ,
200                      const char* ServiceParameterName ) {
201         bool aRet = false ;
202         SUPERV::GraphState aState = PortState( NodeName ,
203                                                 ServiceParameterName ) ;
204         if ( aState == SUPERV::DoneState )
205           aRet = true ;
206         return aRet ; } ;
207       const CORBA::Any * PortInData( const char* ToNodeName ,
208                                      const char* ToServiceParameterName ) ;
209       const CORBA::Any * PortOutData( const char* FromNodeName ,
210                                       const char* FromServiceParameterName ) ;
211
212       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
213                     GraphBase::SGraph & aDataFlow ) ;
214
215       GraphBase::SNode * GetInfo() const ;
216       GraphBase::ListOfNodes * GetNodes() const ;
217       GraphBase::ListOfLinks * GetLinks() const ;
218       GraphBase::ListOfGraphs * GetGraphs() const ;
219       GraphBase::ListOfLinks * GetDatas() const ;
220 //      SALOME_ModuleCatalog::Service * GetService() const ;
221
222       bool AddNode( ComputingNode * aNode ) ;
223       bool RemoveNode( const char* NodeName ) ;
224       bool ReNameNode( const char* OldNodeName ,
225                        const char* NewNodeName ) ;
226
227       bool AddLink( const char* FromNodeName ,
228                     const char* FromServiceParameterName ,
229                     const char* ToNodeName ,
230                     const char* ToServiceParameterName ,
231                     const CORBA::Any aValue ) ;
232       bool RemoveLink( const char* FromNodeName ,
233                        const char* FromServiceParameterName ,
234                        const char* ToNodeName ,
235                        const char* ToServiceParameterName ) ;
236       bool GetLink( const char* ToNodeName ,
237                     const char* ToServiceParameterName ,
238                     char** FromNodeName ,
239                     char** FromServiceParameterName ) ;
240       GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
241                                   GraphBase::InPort* toPort ) ;
242
243       bool AddInputData( const char* ToNodeName ,
244                          const char* ToParameterName ,
245                          const CORBA::Any aValue ) ;
246       bool ChangeInputData( const char* ToNodeName ,
247                             const char* ToParameterName ,
248                             const CORBA::Any aValue ) ;
249       bool AddInputData( const char* ToNodeName1 ,
250                          const char* ToParameterName1 ,
251                          const char* ToNodeName2 ,
252                          const char* ToParameterName2 ) ;
253
254       bool AddInputData( const char* ToNodeName ,
255                          const char* ToParameterName ,
256                          const CORBA::Any ** aValue ) ;
257
258       bool AddOutputData( const char* FromNodeName ,
259                           const char* FromParameterName ,
260                           const CORBA::Any aValue ) ;
261
262       bool CreateService() ;
263       bool InLineServices() ;
264
265       bool Sort() ;
266       bool ComputingNodes() const ;
267       bool DataServerNodes() const ;
268   
269       long LevelMax() {
270            return _LevelsNumber + 1 ; } ;
271       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
272       long ThreadsMax() {
273            return _ThreadsMax ; } ;
274       long GraphsNumber() {
275            return _GraphsNumber ; } ;
276
277       int NodesNumber(const int aLevel ) {
278           return _NodesNumber[ aLevel ] ; } ;
279       GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
280              return (_SortedNodes[ aLevel ])[ index ] ; } ;
281
282       bool StartComponent( const int aThread ,
283                            const char * ComputerContainer ,
284                            const char * ComponentName ,
285                            Engines::Container_var & myContainer ,
286                            Engines::Component_var & objComponent ) ;
287
288   };
289   
290 };
291
292 #endif