1 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : DataFlowBase_ComputingNode.hxx
8 // Author : Jean Rahuel, CEA
12 #ifndef _DATAFLOWBASE_NODE_HXX
13 #define _DATAFLOWBASE_NODE_HXX
15 #include "SALOME_NamingService.hxx"
17 #include "DataFlowBase_PortsOfNode.hxx"
23 class ComputingNode : public PortsOfNode {
28 SALOME_NamingService * _NamingService ;
29 int * _Graph_prof_debug ;
30 ofstream * _Graph_fdebug ;
31 SUPERV::CNode_var _Node ;
32 void * _InNode ; // From GraphExecutor:: or GraphEditor::
38 SUPERV::KindOfNode _Kind ;
39 SUPERV::SDate _FirstCreation ;
40 SUPERV::SDate _LastModification ;
41 char * _EditorRelease ;
50 int _ConnectedInPortsNumber ;
51 int _DecrConnectedInPortsNumber ;
53 // For generated NodeNames with ServiceName : number of Nodes using
54 // the same ServiceName. It is not the same Service if it belongs to
55 // a different Interface and/or a different Component ...
56 map< string , int > _MapOfServiceNames ;
58 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
59 map< string , int > _MapOfLinkedNodes ;
60 int _LinkedNodesSize ;
61 vector<ComputingNode * > _LinkedNodes ;
62 vector<int > _LinkedInPortsNumber ;
72 ComputingNode( CORBA::ORB_ptr ORB ,
73 SALOME_NamingService* ptrNamingService ,
74 const char * DataFlowName ,
75 int * Graph_prof_debug = NULL ,
76 ofstream * Graph_fdebug = NULL ) ;
77 ComputingNode( CORBA::ORB_ptr ORB ,
78 SALOME_NamingService* ptrNamingService ,
79 const SALOME_ModuleCatalog::Service& NodeService ,
80 const char *NodeName ,
81 const SUPERV::KindOfNode akind ,
82 const SUPERV::SDate NodeFirstCreation ,
83 const SUPERV::SDate NodeLastModification ,
84 const char * NodeEditorRelease ,
85 const char * NodeAuthor ,
86 const char * NodeComment ,
87 const bool GeneratedName ,
90 int * Graph_prof_debug = NULL ,
91 ofstream * Graph_fdebug = NULL ) ;
92 virtual ~ComputingNode() ;
94 SALOME_NamingService * NamingService() const {
95 return _NamingService ; } ;
97 SUPERV::CNode_var ObjRef() const { return _Node ; } ;
98 void SetObjRef(SUPERV::CNode_var aNode) {
100 void InNode( void * anInNode ) {
101 // cdebug << "GraphBase::ComputingNode::InNode " << Name() << endl ;
102 _InNode = anInNode ; } ;
103 void * GetInNode() const {
106 void ObjInterface( bool k_interface ) { _ObjInterface = k_interface ; } ;
107 bool ObjInterface() { return _ObjInterface ; } ;
109 pthread_t ThreadNo() { return _ThreadNo ; } ;
110 void ThreadNo( pthread_t aThread ) { _ThreadNo = aThread ; } ;
112 char * Name() const { return my_strdup( _Name ) ; } ;
113 const char *const * NamePtr() const { return &_Name ; } ;
114 SUPERV::KindOfNode Kind() const {
116 // const SALOME_ModuleCatalog::Service * Service() const ;
117 SUPERV::SDate FirstCreation() const ;
118 SUPERV::SDate LastModification() const ;
119 char* Author() const { return my_strdup( _Author ) ; } ;
120 char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
121 char * Comment() const { return my_strdup( _Comment ) ; } ;
122 int XCoordinate() const { return _X ; } ;
123 int YCoordinate() const { return _Y ; } ;
125 bool Name( const char * aName ) ;
126 bool Kind( SUPERV::KindOfNode aKind) ;
127 // void Service( const SALOME_ModuleCatalog::Service aService ) ;
128 void FirstCreation( const SUPERV::SDate aFirstCreation ) ;
129 void LastModification( const SUPERV::SDate aLastModification ) ;
130 bool Author( const char * anAuthor ) ;
131 bool EditorRelease( const char* anEditorRelease ) ;
132 bool Comment( const char *c ) ;
133 void Coordinates( const int X , const int Y ) {
134 _X = X ; _Y = Y ; } ;
136 void NodePort( const char * NodeName ,
137 const char * ServiceParameterName ,
138 char ** aNode , char ** aPort ) ;
140 bool IsLinked(const char * ToServiceParameterName ) ;
141 bool HasInput(const char * ToServiceParameterName ) ;
143 GraphBase::SNode * GetInfo() ;
145 const bool IsComputingNode() const {
146 return (_Kind == SUPERV::ComputingNode ) ; } ;
147 const bool IsFactoryNode() const {
148 return (_Kind == SUPERV::FactoryNode ) ; } ;
149 const bool IsOneOfGOTONodes() const {
150 return (_Kind == SUPERV::LoopNode ||
151 _Kind == SUPERV::EndLoopNode ||
152 _Kind == SUPERV::SwitchNode ||
153 _Kind == SUPERV::EndSwitchNode ||
154 _Kind == SUPERV::GOTONode ) ; } ;
155 const bool IsOneOfInLineNodes() const {
156 return (_Kind == SUPERV::InLineNode || IsOneOfGOTONodes() ) ; } ;
157 const bool IsInLineNode() const {
158 return (_Kind == SUPERV::InLineNode ) ; } ;
159 const bool IsDataFlowNode() const {
160 return (_Kind == SUPERV::DataFlowNode ) ; } ;
161 const bool IsLoopNode() const {
162 return (_Kind == SUPERV::LoopNode ) ; } ;
163 const bool IsEndLoopNode() const {
164 return (_Kind == SUPERV::EndLoopNode ) ; } ;
165 const bool IsSwitchNode() const {
166 return (_Kind == SUPERV::SwitchNode ) ; } ;
167 const bool IsEndSwitchNode() const {
168 return (_Kind == SUPERV::EndSwitchNode ) ; } ;
169 const bool IsGOTONode() const {
170 return (_Kind == SUPERV::GOTONode ) ; } ;
171 void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
172 const bool IsHeadNode() const { return _HeadNode ; } ;
174 bool RemovePorts( const char* aNodeName ) ;
176 InPort * AddInPort( const char * InputParameterName ,
177 const char * InputParameterType ) ;
178 OutPort * AddOutPort( const char * OutputParameterName ,
179 const char * OutputParameterType ) ;
181 void AddLink( ComputingNode * aNode ) ;
182 void RemoveLink( ComputingNode * aNode ) ;
183 void ReNameLink( const char* OldNodeName ,
184 const char* NewNodeName ) ;
186 int GetServiceNameNumber( const char * name ) {
187 int num = _MapOfServiceNames[ name ] ;
189 _MapOfServiceNames[ name ] = 1 ;
192 _MapOfServiceNames[ name ] = num + 1 ;
194 return _MapOfServiceNames[ name ] ; } ;
196 void IncrConnectedInPortsNumber() {
197 cdebug << "IncrConnectedInPortsNumber " << Name() << " -> "
198 << _ConnectedInPortsNumber+1 << endl ;
199 _ConnectedInPortsNumber++ ; } ;
200 void DecrConnectedInPortsNumber() {
201 _ConnectedInPortsNumber-- ; } ;
202 int ConnectedInPortsNumber() const {
203 return _ConnectedInPortsNumber ; } ;
204 void ConnectedInPortsNumber( int c ) {
205 cdebug << "ConnectedInPortsNumber " << Name() << " -> " << c << endl ;
206 _ConnectedInPortsNumber = c ; } ;
208 void IncrDecrConnectedInPortsNumber(const int cnt ) {
209 _DecrConnectedInPortsNumber += cnt ; } ;
210 bool DecrIncrDecrConnectedInPortsNumber() {
211 if ( _DecrConnectedInPortsNumber ) {
212 _ConnectedInPortsNumber = _ConnectedInPortsNumber -
213 _DecrConnectedInPortsNumber ;
214 _DecrConnectedInPortsNumber = 0 ;
219 int GetLinkedNodeIndex( const char * name ) {
220 int index = _MapOfLinkedNodes[ name ] -1 ;
222 cdebug << "GetLinkedNodeIndex of " << name
223 << " in _MapOfLinkedNodes : "
224 << index << " Node " << hex << (void *) _LinkedNodes[ index ]
225 << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
229 void SetLinkedNodeIndex( const char * name , const int index ) {
230 _MapOfLinkedNodes[ name ] = index +1 ;
231 cdebug << "SetLinkedNodeIndex of " << name << " in _MapOfLinkedNodes : "
232 << index << " Node " << hex << (void *) _LinkedNodes[ index ]
233 << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
234 << " _MapOfLinkedNodes " << _MapOfLinkedNodes[ name ] - 1
237 void DelLinkedNodeIndex( const char * name ) {
238 _MapOfLinkedNodes.erase( name ) ; } ;
239 int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
240 ComputingNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
241 const int LinkedInPortsNumber( int i ) const { return _LinkedInPortsNumber[ i ] ; } ;
243 int Level() { return _LevelNumber ; } ;
244 void Level( int LevelNumber ) {
245 _LevelNumber = LevelNumber ; } ;
246 int SubGraph() { return _SubGraphNumber ; } ;
247 void SubGraph( int SubGraphNumber ) {
248 _SubGraphNumber = SubGraphNumber ; } ;
250 // const GraphBase::ListOfParameters * GetListOfParameters() const ;
252 const long CpuUsed() ;
254 bool SaveXML( QDomDocument & Graph , QDomElement & info ,
255 int X , int Y ) const {
256 ListOfFuncName aFuncNames ;
257 GraphBase::ListOfPythonFunctions aVoidList ;
258 return SaveXML( Graph , info , "" , "" , "" , "" , aFuncNames , aVoidList ,
261 bool SavePY( ostream &f , const char * aGraphName ,
262 int X , int Y ) const {
263 ListOfFuncName aFuncNames ;
264 GraphBase::ListOfPythonFunctions aVoidList ;
265 return SavePY( f , aGraphName , "" , "" , "" , NULL , aFuncNames , aVoidList ,
267 // bool SaveXML(ostream &f , char *Tabs ,
268 bool SaveXML(QDomDocument & Graph , QDomElement & info ,
269 const char * ComponentName ,
270 const char * InterfaceName ,
271 const char * Computer ,
272 const char * CoupledNode ,
273 const ListOfFuncName FuncNames ,
274 const GraphBase::ListOfPythonFunctions PythonFunctions ,
275 int X , int Y ) const ;
277 bool SavePY(ostream &f , const char * aGraphName ,
278 const char * ComponentName ,
279 const char * InterfaceName ,
280 const char * Computer ,
281 const GraphBase::InLineNode * aCoupledNode ,
282 const ListOfFuncName FuncNames ,
283 const GraphBase::ListOfPythonFunctions PythonFunctions ,
284 int X , int Y ) const ;
286 void NodeInfo(ostream & s) const ;
288 void ListLinks(ostream &f ) const ;
294 ostream & operator<< (ostream &,const GraphBase::ComputingNode & N );
296 ostream & operator<< (ostream &,const SUPERV::SDate & D );