Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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 namespace GraphBase {
20
21   class InLineNode ;
22
23   class ComputingNode : public StreamNode {
24
25     private:
26     
27       CORBA::ORB_ptr         _ORB ;
28       SALOME_NamingService * _NamingService ;
29 //->StreamNode      int                  * _Graph_prof_debug ;
30 //->StreamNode      ofstream             * _Graph_fdebug ;
31       SUPERV::CNode_var      _Node ;
32       void                 * _InNode ; // From GraphExecutor:: or GraphEditor::
33       bool                   _ObjInterface ;
34
35       pthread_t              _ThreadNo ;
36
37 //->StreamNode      char                 * _Name ;
38 //->StreamNode      SUPERV::KindOfNode     _Kind ;
39       SUPERV::SDate          _FirstCreation ;
40       SUPERV::SDate          _LastModification ;
41       char                 * _EditorRelease ;
42       char                 * _Author ;
43       char                 * _Comment ;
44
45 //->StreamNode      bool                   _HeadNode ;
46 //->StreamNode      int                    _LevelNumber ;
47 //->StreamNode      int                    _SubGraphNumber ;
48       bool                   _GeneratedName ;
49
50 //->StreamNode      int                    _DataStreamInPortsNumber ;
51 //->StreamNode      int                    _DataStreamOutPortsNumber ;
52
53       int                    _ConnectedInPortsNumber ;
54       int                    _DecrConnectedInPortsNumber ;
55
56 // For generated NodeNames with ServiceName : number of Nodes using
57 // the same ServiceName. It is not the same Service if it belongs to
58 // a different Interface and/or a different Component ...
59 //->StreamNode      map< string , int > _MapOfServiceNames ;
60
61 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
62 //->StreamNode      map< string , int >      _MapOfLinkedNodes ;
63 //->StreamNode      int                      _LinkedNodesSize ;
64 //->StreamNode      vector<ComputingNode * > _LinkedNodes ;
65 //->StreamNode      vector<int >             _LinkedInPortsNumber ;
66
67     protected:
68
69       long _X ;
70       long _Y ;
71
72     public:
73
74       ComputingNode() ;
75       ComputingNode( CORBA::ORB_ptr ORB ,
76                      SALOME_NamingService* ptrNamingService ,
77                      const char * DataFlowName ,
78                      int * Graph_prof_debug = NULL ,
79                      ofstream * Graph_fdebug = NULL ) ;
80       ComputingNode( CORBA::ORB_ptr ORB ,
81                      SALOME_NamingService* ptrNamingService ,
82                      const SALOME_ModuleCatalog::Service& NodeService ,
83                      const char *NodeName ,
84                      const SUPERV::KindOfNode akind ,
85                      const SUPERV::SDate NodeFirstCreation ,
86                      const SUPERV::SDate NodeLastModification ,
87                      const char * NodeEditorRelease ,
88                      const char * NodeAuthor ,
89                      const char * NodeComment ,
90                      const bool   GeneratedName ,
91                      const long   X ,
92                      const long   Y ,
93                      int * Graph_prof_debug = NULL ,
94                      ofstream * Graph_fdebug = NULL ) ;
95       virtual ~ComputingNode() ;
96
97       SALOME_NamingService * NamingService() const {
98              return _NamingService ; } ;
99
100       SUPERV::CNode_var ObjRef() const {
101 //                        char * _NodeName ;
102 //                        cdebug << "ComputingNode::ObjRef() " << _Node << " " << Name()
103 //                               << " " << endl ;
104 //                        SUPERV::CNode_var _NodeObjRef = SUPERV::CNode::_narrow( _Node ) ;
105 //                        if ( CORBA::is_nil( _NodeObjRef ) ) {
106 //                          _NodeName = "NilRef" ;
107 //                      }
108 //                      else {
109 //                          try {
110 //                            _NodeName = _NodeObjRef->Name() ;
111 //                        }
112 //                          catch ( ... ) {
113 //                            _NodeName = "Catch Error" ;
114 //                        }
115 //                      }
116 //                        cdebug << _NodeName << " " << Name() << endl ;
117                         return _Node ; } ;
118       void SetObjRef(SUPERV::CNode_var aNode) {
119 //                        char * _NodeName ;
120 //                        if ( CORBA::is_nil( _Node ) ) {
121 //                          _NodeName = "NilRef" ;
122 //                      }
123 //                      else {
124 //                          _NodeName = _Node->Name() ;
125 //                      }
126 //                        cdebug << "ComputingNode::SetObjRef( " << _Node << " "
127 //                               << _NodeName << " ) " << Name() << " --> " ;
128                         _Node = aNode ;
129 //                        cdebug << _Node << " " << _Node->Name() << " ) " << Name() << endl ;
130                         } ;
131       void InNode( void * anInNode ) {
132 //           cdebug << "GraphBase::ComputingNode::InNode " << Name() << endl ;
133            _InNode = anInNode ; } ;
134       void * GetInNode() const {
135              return _InNode ; } ;
136
137       void ObjInterface( bool k_interface ) { _ObjInterface = k_interface ; } ;
138       bool ObjInterface() { return _ObjInterface ; } ;
139
140       pthread_t ThreadNo() { return _ThreadNo ; } ;
141       void ThreadNo( pthread_t aThread ) { _ThreadNo = aThread ; } ;
142
143 //->StreamNode      char * Name() const { return my_strdup( _Name ) ; } ;
144 //->StreamNode      const char *const * NamePtr() const { return &_Name ; } ;
145 //      const SALOME_ModuleCatalog::Service * Service() const ;
146       SUPERV::SDate FirstCreation() const ;
147       SUPERV::SDate LastModification() const ;
148       char* Author() const { return my_strdup( _Author ) ; } ;
149       char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
150       char * Comment() const { return my_strdup( _Comment ) ; } ;
151       int XCoordinate() const { return _X ; } ;
152       int YCoordinate() const { return _Y ; } ;
153
154 //->StreamNode      bool Name( const char * aName ) ;
155 //      void Service( const SALOME_ModuleCatalog::Service aService ) ;
156       void FirstCreation( const SUPERV::SDate aFirstCreation ) ;
157       void LastModification( const SUPERV::SDate aLastModification ) ;
158       bool Author( const char * anAuthor ) ;
159       bool EditorRelease( const char* anEditorRelease ) ;
160       bool Comment( const char *c ) ;
161       void Coordinates( const int X , const int Y ) {
162            _X = X ; _Y = Y ; } ;
163
164       void NodePort( const char * NodeName ,
165                      const char * ServiceParameterName ,
166                      char ** aNode , char ** aPort ) ;
167
168       bool IsLinked(const char * ToServiceParameterName ) ;
169       bool HasInput(const char * ToServiceParameterName ) ;
170
171       GraphBase::SNode * GetInfo() ;
172
173 //      void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
174 //      const bool IsHeadNode() const { return _HeadNode ; } ;
175
176       bool RemovePorts( const char* aNodeName ) ;
177
178       void DelInPort( const char * InputParameterName ) ;
179       void DelOutPort( const char * OutputParameterName ) ;
180
181       InPort * AddInPort( const char * InputParameterName ,
182                           const char * InputParameterType ,
183                           const SUPERV::KindOfPort aKindOfPort ) ;
184       OutPort * AddOutPort( const char * OutputParameterName ,
185                             const char * OutputParameterType ,
186                             const SUPERV::KindOfPort aKindOfPort ) ;
187
188       void DelInDataStreamPort( const char * InputParameterName ) ;
189       void DelOutDataStreamPort( const char * OutputParameterName ) ;
190
191       InDataStreamPort * AddInDataStreamPort( const char * InputParameterName ,
192                                               const SALOME_ModuleCatalog::DataStreamType InputParameterType ,
193                                               const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
194                                               const SUPERV::KindOfPort aKindOfPort ) ;
195       OutDataStreamPort * AddOutDataStreamPort( const char * OutputParameterName ,
196                                                 const SALOME_ModuleCatalog::DataStreamType OutputParameterType ,
197                                                 const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
198                                                 const SUPERV::KindOfPort aKindOfPort ) ;
199
200 //      ComputingNode * LinkedNodes( int i ) const { return (GraphBase::ComputingNode *) GraphBase::StreamNode::LinkedNodes( i ) ; } ;
201
202       void AddLink( GraphBase::ComputingNode * ToNode ) {
203            GraphBase::StreamNode::AddLink( ToNode ) ;
204            cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
205                   << ") ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
206                   << " + 1 Service " << ServiceName() << endl ;
207            ToNode->IncrConnectedInPortsNumber() ; } ;
208
209       void RemoveLink( GraphBase::ComputingNode * ToNode ) {
210            if ( GraphBase::StreamNode::RemoveLink( ToNode ) ) {
211              cdebug << "GraphBase::StreamNode::RemoveLink to " << ToNode->Name() << " from "
212                     << Name() << " ConnectedInPortsNumber "
213                     << ToNode->ConnectedInPortsNumber() - 1 << endl ;
214              ToNode->DecrConnectedInPortsNumber() ; } } ;
215
216       void ReNameLink( const char* OldNodeName ,
217                        const char* NewNodeName ) {
218            GraphBase::StreamNode::ReNameLink( OldNodeName , NewNodeName ) ; } ;
219
220       void IncrConnectedInPortsNumber() {
221            cdebug << "IncrConnectedInPortsNumber " << Name() << " -> "
222                   << _ConnectedInPortsNumber+1 << endl ;
223            _ConnectedInPortsNumber++ ; } ;
224       void DecrConnectedInPortsNumber() {
225            _ConnectedInPortsNumber-- ; } ;
226       int ConnectedInPortsNumber() const {
227           return _ConnectedInPortsNumber ; } ;
228       void ConnectedInPortsNumber( int c ) {
229            cdebug << "ConnectedInPortsNumber " << Name() << " -> " << c << endl ;
230            _ConnectedInPortsNumber = c ; } ;
231
232       void IncrDecrConnectedInPortsNumber(const int cnt ) {
233            _DecrConnectedInPortsNumber += cnt ; } ;
234       bool DecrIncrDecrConnectedInPortsNumber() {
235            if ( _DecrConnectedInPortsNumber ) {
236              _ConnectedInPortsNumber = _ConnectedInPortsNumber -
237                                        _DecrConnectedInPortsNumber ;
238              _DecrConnectedInPortsNumber = 0 ;
239              return true ;
240            }
241            return false ; } ;
242
243 //      const GraphBase::ListOfParameters * GetListOfParameters() const ;
244
245       const long CpuUsed() ;
246
247       bool SaveXML( QDomDocument & Graph , QDomElement & info , 
248                     int X , int Y ) const {
249                     ListOfFuncName aFuncNames ; 
250                     GraphBase::ListOfPythonFunctions aVoidList ;
251            return SaveXML( Graph , info , "" , "" , "" , "" , aFuncNames , aVoidList ,
252                            X , Y ) ; } ;
253
254       bool SavePY( ostream &f , const char * aGraphName ,
255                    int X , int Y ) const {
256            ListOfFuncName aFuncNames ; 
257            GraphBase::ListOfPythonFunctions aVoidList ;
258            return SavePY( f , aGraphName , "" , "" , "" , NULL , aFuncNames  , aVoidList ,
259                           X , Y ) ; } ;
260 //      bool SaveXML(ostream &f , char *Tabs , 
261       bool SaveXML(QDomDocument & Graph , QDomElement & info , 
262                    const char * ComponentName ,
263                    const char * InterfaceName ,
264                    const char * Computer ,
265                    const char * CoupledNode ,
266                    const ListOfFuncName FuncNames ,
267                    const GraphBase::ListOfPythonFunctions PythonFunctions ,
268                    int X , int Y ) const ;
269
270       bool SavePY(ostream &f , const char * aGraphName ,
271                                const char * ComponentName ,
272                                const char * InterfaceName ,
273                                const char * Computer ,
274                                const GraphBase::InLineNode * aCoupledNode ,
275                                const ListOfFuncName FuncNames ,
276                                const GraphBase::ListOfPythonFunctions PythonFunctions ,
277                                int X , int Y ) const ;
278
279       void NodeInfo(ostream & s) const ;
280
281       void ListLinks(ostream &f ) const ;
282
283   };
284   
285 };
286
287 ostream & operator<< (ostream &,const GraphBase::ComputingNode & N );
288
289 ostream & operator<< (ostream &,const SUPERV::SDate & D );
290
291 #endif