Salome HOME
Error messages
[modules/superv.git] / src / GraphBase / DataFlowBase_ComputingNode.hxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : DataFlowBase_ComputingNode.hxx
8 //  Author : Jean Rahuel, CEA
9 //  Module : SUPERV
10 //  $Header:
11
12 #ifndef _DATAFLOWBASE_COMPUTINGNODE_HXX
13 #define _DATAFLOWBASE_COMPUTINGNODE_HXX
14
15 #include "SALOME_NamingService.hxx"
16
17 #include "DataFlowBase_StreamNode.hxx"
18
19 class CNode_Impl ;
20
21 namespace GraphBase {
22
23   class Graph ;
24
25   class InLineNode ;
26
27   class LoopNode ;
28   class EndOfLoopNode ;
29   class EndOfSwitchNode ;
30
31   class ComputingNode : public StreamNode {
32
33     private:
34     
35       CORBA::ORB_ptr         _ORB ;
36       SALOME_NamingService * _NamingService ;
37 //->StreamNode      int                  * _Graph_prof_debug ;
38 //->StreamNode      ofstream             * _Graph_fdebug ;
39       SUPERV::CNode_var      _Node_var ;
40       CNode_Impl           * _Node_Impl ;
41       void                 * _InNode ; // From GraphExecutor:: or GraphEditor::
42       bool                   _ObjInterface ;
43
44       pthread_t              _ThreadNo ;
45
46 //->StreamNode      char                 * _Name ;
47 //->StreamNode      SUPERV::KindOfNode     _Kind ;
48       SUPERV::SDate          _FirstCreation ;
49       SUPERV::SDate          _LastModification ;
50       char                 * _EditorRelease ;
51       char                 * _Author ;
52       char                 * _Comment ;
53
54 //->StreamNode      bool                   _HeadNode ;
55 //->StreamNode      int                    _LevelNumber ;
56 //->StreamNode      int                    _SubGraphNumber ;
57       bool                   _GeneratedName ;
58
59 //->StreamNode      int                    _DataStreamInPortsNumber ;
60 //->StreamNode      int                    _DataStreamOutPortsNumber ;
61
62       int                    _ConnectedInPortsNumber ;
63       int                    _DecrConnectedInPortsNumber ;
64
65 // For generated NodeNames with ServiceName : number of Nodes using
66 // the same ServiceName. It is not the same Service if it belongs to
67 // a different Interface and/or a different Component ...
68 //->StreamNode      map< string , int > _MapOfServiceNames ;
69
70 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
71 //->StreamNode      map< string , int >      _MapOfLinkedNodes ;
72 //->StreamNode      int                      _LinkedNodesSize ;
73 //->StreamNode      vector<ComputingNode * > _LinkedNodes ;
74 //->StreamNode      vector<int >             _LinkedInPortsNumber ;
75
76     protected:
77
78       long _X ;
79       long _Y ;
80
81     public:
82
83       ComputingNode() ;
84       ComputingNode( CORBA::ORB_ptr ORB ,
85                      SALOME_NamingService* ptrNamingService ,
86                      const char * DataFlowName ,
87                      const SUPERV::KindOfNode DataFlowkind ,
88                      int * Graph_prof_debug ,
89                      ofstream * Graph_fdebug ) ;
90       ComputingNode( CORBA::ORB_ptr ORB ,
91                      SALOME_NamingService* ptrNamingService ,
92                      const SALOME_ModuleCatalog::Service& NodeService ,
93                      const char *NodeName ,
94                      const SUPERV::KindOfNode akind ,
95                      const SUPERV::SDate NodeFirstCreation ,
96                      const SUPERV::SDate NodeLastModification ,
97                      const char * NodeEditorRelease ,
98                      const char * NodeAuthor ,
99                      const char * NodeComment ,
100                      const bool   GeneratedName ,
101                      const long   X ,
102                      const long   Y ,
103                      int * Graph_prof_debug = NULL ,
104                      ofstream * Graph_fdebug = NULL ) ;
105       virtual ~ComputingNode() ;
106
107       SALOME_NamingService * NamingService() const {
108              return _NamingService ; } ;
109
110       SUPERV::CNode_var ObjRef() const {
111 //                        char * _NodeName ;
112 //                        cdebug << "ComputingNode::ObjRef() " << _Node << " " << Name()
113 //                               << " " << endl ;
114 //                        SUPERV::CNode_var _NodeObjRef = SUPERV::CNode::_narrow( _Node ) ;
115 //                        if ( CORBA::is_nil( _NodeObjRef ) ) {
116 //                          _NodeName = "NilRef" ;
117 //                      }
118 //                      else {
119 //                          try {
120 //                            _NodeName = _NodeObjRef->Name() ;
121 //                        }
122 //                          catch ( ... ) {
123 //                            _NodeName = "Catch Error" ;
124 //                        }
125 //                      }
126 //                        cdebug << _NodeName << " " << Name() << endl ;
127                          return _Node_var ; } ;
128       void SetObjRef( SUPERV::CNode_var aNode_var ) {
129 //                        char * _NodeName ;
130 //                        if ( CORBA::is_nil( _Node ) ) {
131 //                          _NodeName = "NilRef" ;
132 //                      }
133 //                      else {
134 //                          _NodeName = _Node->Name() ;
135 //                      }
136 //                        cdebug << "ComputingNode::SetObjRef( " << _Node << " "
137 //                               << _NodeName << " ) " << Name() << " --> " ;
138                         _Node_var = aNode_var ;
139 //                        cdebug << _Node << " " << _Node->Name() << " ) " << Name() << endl ;
140                         } ;
141
142       CNode_Impl * ObjImpl() const { return _Node_Impl ; } ;
143       void SetObjImpl( CNode_Impl * aNode_Impl ) {
144                        _Node_Impl = aNode_Impl ; } ;
145
146       void InNode( void * anInNode ) {
147 //           cdebug << "GraphBase::ComputingNode::InNode " << Name() << endl ;
148            _InNode = anInNode ; } ;
149       void * GetInNode() const {
150              return _InNode ; } ;
151
152       void ObjInterface( bool k_interface ) { _ObjInterface = k_interface ; } ;
153       bool ObjInterface() { return _ObjInterface ; } ;
154
155       pthread_t ThreadNo() { return _ThreadNo ; } ;
156       void ThreadNo( pthread_t aThread ) { _ThreadNo = aThread ; } ;
157
158 //->StreamNode      char * Name() const { return my_strdup( _Name ) ; } ;
159 //->StreamNode      const char *const * NamePtr() const { return &_Name ; } ;
160 //      const SALOME_ModuleCatalog::Service * Service() const ;
161       SUPERV::SDate FirstCreation() const ;
162       SUPERV::SDate LastModification() const ;
163 //JR 17.02.2005 Memory Leak      char* Author() const { return my_strdup( _Author ) ; } ;
164       char* Author() const { return _Author ; } ;
165 //JR 17.02.2005 Memory Leak      char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
166       char* EditorRelease() const { return _EditorRelease ; } ;
167 //JR 17.02.2005 Memory Leak      char * Comment() const { return my_strdup( _Comment ) ; } ;
168       char * Comment() const { return _Comment ; } ;
169       int XCoordinate() const { return _X ; } ;
170       int YCoordinate() const { return _Y ; } ;
171
172 //->StreamNode      bool Name( const char * aName ) ;
173 //      void Service( const SALOME_ModuleCatalog::Service aService ) ;
174       void FirstCreation( const SUPERV::SDate aFirstCreation ) ;
175       void LastModification( const SUPERV::SDate aLastModification ) ;
176       bool Author( const char * anAuthor ) ;
177       bool EditorRelease( const char* anEditorRelease ) ;
178       bool Comment( const char *c ) ;
179       void Coordinates( const int X , const int Y ) {
180            _X = X ; _Y = Y ; } ;
181
182       void NodePort( const char * NodeName ,
183                      const char * ServiceParameterName ,
184                      char ** aNode , char ** aPort ) ;
185
186       bool IsLinked(const char * ToServiceParameterName ) ;
187       bool HasInput(const char * ToServiceParameterName ) ;
188
189       GraphBase::SNode * GetInfo() ;
190
191 //      void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
192 //      const bool IsHeadNode() const { return _HeadNode ; } ;
193
194       bool RemovePorts( const char* aNodeName ) ;
195
196       void SetMacroPorts( GraphBase::Graph * aGraph ) ;
197       void UpdateMacroPorts( GraphBase::Graph * aGraph ) ;
198       void SetMacroDatas( GraphBase::Graph * aGraph , GraphBase::Graph * aGraphOfMacroGraph ) ;
199
200       void DelInPort( const char * InputParameterName ) ;
201       void DelOutPort( const char * OutputParameterName ) ;
202
203       InPort * AddInPort( const char * InputParameterName ,
204                           const char * InputParameterType ,
205                           const SUPERV::KindOfPort aKindOfPort ,
206                           int index = -1 ) ;
207       OutPort * AddOutPort( const char * OutputParameterName ,
208                             const char * OutputParameterType ,
209                             const SUPERV::KindOfPort aKindOfPort ,
210                             int index = -1 ) ;
211
212       void DelInDataStreamPort( const char * InputParameterName ) ;
213       void DelOutDataStreamPort( const char * OutputParameterName ) ;
214
215       InDataStreamPort * AddInDataStreamPort( const char * InputParameterName ,
216                                               const SALOME_ModuleCatalog::DataStreamType InputParameterType ,
217                                               const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
218                                               const SUPERV::KindOfPort aKindOfPort ,
219                                               int index = -1 ) ;
220       OutDataStreamPort * AddOutDataStreamPort( const char * OutputParameterName ,
221                                                 const SALOME_ModuleCatalog::DataStreamType OutputParameterType ,
222                                                 const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
223                                                 const SUPERV::KindOfPort aKindOfPort ,
224                                                 int index = -1 ) ;
225
226 //      ComputingNode * LinkedNodes( int i ) const { return (GraphBase::ComputingNode *) GraphBase::StreamNode::LinkedNodes( i ) ; } ;
227
228       void AddLinkedNode( GraphBase::ComputingNode * ToNode ) {
229            GraphBase::StreamNode::AddLinkedNode( ToNode ) ;
230            cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
231                   << ") ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
232                   << " + 1 Service " << ServiceName() << endl ;
233            ToNode->IncrConnectedInPortsNumber() ; } ;
234
235       bool RemoveLinkedNode( GraphBase::ComputingNode * ToNode ,
236                              bool DoLinkedFromNode = true ) {
237            bool RetVal = GraphBase::StreamNode::RemoveLinkedNode( ToNode , DoLinkedFromNode ) ;
238            if ( RetVal ) {
239              cdebug << "ComputingNode::RemoveLinkedNode to " << ToNode->Name() << " from "
240                     << Name() << " ConnectedInPortsNumber "
241                     << ToNode->ConnectedInPortsNumber() - 1 << endl ;
242              ToNode->DecrConnectedInPortsNumber() ;
243            }
244            return RetVal ; } ;
245
246       void ReNameLinkedNode( const char* OldNodeName ,
247                              const char* NewNodeName ) {
248            GraphBase::StreamNode::ReNameLinkedNode( OldNodeName , NewNodeName ) ; } ;
249
250       void IncrConnectedInPortsNumber() {
251            cdebug << "ComputingNode::IncrConnectedInPortsNumber " << Name() << " -> "
252                   << _ConnectedInPortsNumber+1 << endl ;
253            _ConnectedInPortsNumber++ ; } ;
254       void DecrConnectedInPortsNumber() {
255            cdebug << "ComputingNode::DecrConnectedInPortsNumber " << Name() << " -> "
256                   << _ConnectedInPortsNumber-1 << endl ;
257            _ConnectedInPortsNumber-- ; } ;
258       int ConnectedInPortsNumber() const {
259           return _ConnectedInPortsNumber ; } ;
260       void ConnectedInPortsNumber( int c ) {
261            cdebug << "ConnectedInPortsNumber " << Name() << " -> " << c << endl ;
262            _ConnectedInPortsNumber = c ; } ;
263
264       void IncrDecrConnectedInPortsNumber(const int cnt ) {
265            _DecrConnectedInPortsNumber += cnt ; } ;
266       bool DecrIncrDecrConnectedInPortsNumber() {
267            if ( _DecrConnectedInPortsNumber ) {
268              _ConnectedInPortsNumber = _ConnectedInPortsNumber -
269                                        _DecrConnectedInPortsNumber ;
270              _DecrConnectedInPortsNumber = 0 ;
271              return true ;
272            }
273            return false ; } ;
274
275       bool CheckLoop( GraphBase::LoopNode * aLoopNode ,
276                       GraphBase::EndOfLoopNode * anEndLoopNode ,
277                       string & anErrorMessage ) const ;
278       bool CheckEndLoop( GraphBase::LoopNode * aLoopNode ,
279                          GraphBase::EndOfLoopNode * anEndLoopNode ,
280                          string & anErrorMessage ) const ;
281       bool InitBranchOfSwitchDone( bool AllInit , GraphBase::EndOfSwitchNode * anEndSwitchNode ,
282                                    string & anErrorMessage ) ;
283       bool CheckSwitch( GraphBase::EndOfSwitchNode * anEndSwitchNode ,
284                         string & anErrorMessage ) ;
285
286 //      const GraphBase::ListOfParameters * GetListOfParameters() const ;
287
288       const long CpuUsed() ;
289
290       bool SaveXML( QDomDocument & Graph , QDomElement & info , 
291                     int X , int Y ) const {
292                     ListOfFuncName aFuncNames ; 
293                     GraphBase::ListOfPythonFunctions aVoidList ;
294            return SaveXML( Graph , info , "" , "" , "" , "" , aFuncNames , aVoidList ,
295                            X , Y ) ; } ;
296
297       bool SavePY( ostream &f , const char * aGraphName ,
298                    int X , int Y ) const {
299            ListOfFuncName aFuncNames ; 
300            GraphBase::ListOfPythonFunctions aVoidList ;
301            return SavePY( f , aGraphName , "" , "" , "" , NULL , aFuncNames  , aVoidList ,
302                           X , Y ) ; } ;
303 //      bool SaveXML(ostream &f , char *Tabs , 
304       bool SaveXML(QDomDocument & Graph , QDomElement & info , 
305                    const char * ComponentName ,
306                    const char * InterfaceName ,
307                    const char * Computer ,
308                    const char * CoupledNode ,
309                    const ListOfFuncName FuncNames ,
310                    const GraphBase::ListOfPythonFunctions PythonFunctions ,
311                    int X , int Y ) const ;
312
313       bool SavePY(ostream &f , const char * aGraphName ,
314                                const char * ComponentName ,
315                                const char * InterfaceName ,
316                                const char * Computer ,
317                                const GraphBase::InLineNode * aCoupledNode ,
318                                const ListOfFuncName FuncNames ,
319                                const GraphBase::ListOfPythonFunctions PythonFunctions ,
320                                int X , int Y ) const ;
321
322       void NodeInfo(ostream & s) const ;
323
324       void ListLinks(ostream &f ) const ;
325
326   };
327   
328 };
329
330 ostream & operator<< (ostream &,const GraphBase::ComputingNode & N );
331
332 ostream & operator<< (ostream &,const SUPERV::SDate & D );
333
334 #endif