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 "DataFlowBase_PortsOfNode.hxx"
21 class ComputingNode : public PortsOfNode {
26 SALOME_NamingService * _NamingService ;
27 int * _Graph_prof_debug ;
28 ostream * _Graph_fdebug ;
29 SUPERV::CNode_var _Node ;
30 void * _InNode ; // From GraphExecutor:: or GraphEditor::
36 SUPERV::KindOfNode _Kind ;
37 SUPERV::SDate _FirstCreation ;
38 SUPERV::SDate _LastModification ;
39 char * _EditorRelease ;
48 int _ConnectedInPortsNumber ;
49 int _DecrConnectedInPortsNumber ;
51 // For generated NodeNames with ServiceName : number of Nodes using
52 // the same ServiceName. It is not the same Service if it belongs to
53 // a different Interface and/or a different Component ...
54 map< string , int > _MapOfServiceNames ;
56 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
57 map< string , int > _MapOfLinkedNodes ;
58 int _LinkedNodesSize ;
59 vector<ComputingNode * > _LinkedNodes ;
60 vector<int > _LinkedInPortsNumber ;
70 ComputingNode( CORBA::ORB_ptr ORB ,
71 SALOME_NamingService* ptrNamingService ,
72 const char * DataFlowName ,
73 int * Graph_prof_debug = NULL ,
74 ostream * Graph_fdebug = NULL ) ;
75 ComputingNode( CORBA::ORB_ptr ORB ,
76 SALOME_NamingService* ptrNamingService ,
77 const SALOME_ModuleCatalog::Service& NodeService ,
78 const char *NodeName ,
79 const SUPERV::KindOfNode akind ,
80 const SUPERV::SDate NodeFirstCreation ,
81 const SUPERV::SDate NodeLastModification ,
82 const char * NodeEditorRelease ,
83 const char * NodeAuthor ,
84 const char * NodeComment ,
85 const bool GeneratedName ,
88 int * Graph_prof_debug = NULL ,
89 ostream * Graph_fdebug = NULL ) ;
90 virtual ~ComputingNode() ;
92 SALOME_NamingService * NamingService() const {
93 return _NamingService ; } ;
95 SUPERV::CNode_var ObjRef() const { return _Node ; } ;
96 void SetObjRef(SUPERV::CNode_var aNode) {
98 void InNode( void * anInNode ) {
99 // cdebug << "GraphBase::ComputingNode::InNode " << Name() << endl ;
100 _InNode = anInNode ; } ;
101 void * GetInNode() const {
104 void ObjInterface( bool k_interface ) { _ObjInterface = k_interface ; } ;
105 bool ObjInterface() { return _ObjInterface ; } ;
107 pthread_t ThreadNo() { return _ThreadNo ; } ;
108 void ThreadNo( pthread_t aThread ) { _ThreadNo = aThread ; } ;
110 char * Name() const { return my_strdup( _Name ) ; } ;
111 const char *const * NamePtr() const { return &_Name ; } ;
112 SUPERV::KindOfNode Kind() const {
114 // const SALOME_ModuleCatalog::Service * Service() const ;
115 SUPERV::SDate FirstCreation() const ;
116 SUPERV::SDate LastModification() const ;
117 char* Author() const { return my_strdup( _Author ) ; } ;
118 char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
119 char * Comment() const { return my_strdup( _Comment ) ; } ;
120 int XCoordinate() const { return _X ; } ;
121 int YCoordinate() const { return _Y ; } ;
123 bool Name( const char * aName ) ;
124 bool Kind( SUPERV::KindOfNode aKind) ;
125 // void Service( const SALOME_ModuleCatalog::Service aService ) ;
126 void FirstCreation( const SUPERV::SDate aFirstCreation ) ;
127 void LastModification( const SUPERV::SDate aLastModification ) ;
128 bool Author( const char * anAuthor ) ;
129 bool EditorRelease( const char* anEditorRelease ) ;
130 bool Comment( const char *c ) ;
131 void Coordinates( const int X , const int Y ) {
132 _X = X ; _Y = Y ; } ;
134 void NodePort( const char * NodeName ,
135 const char * ServiceParameterName ,
136 char ** aNode , char ** aPort ) ;
138 bool IsLinked(const char * ToServiceParameterName ) ;
139 bool HasInput(const char * ToServiceParameterName ) ;
141 GraphBase::SNode * GetInfo() ;
143 const bool IsComputingNode() const {
144 return (_Kind == SUPERV::ComputingNode ) ; } ;
145 const bool IsFactoryNode() const {
146 return (_Kind == SUPERV::FactoryNode ) ; } ;
147 const bool IsOneOfGOTONodes() const {
148 return (_Kind == SUPERV::LoopNode ||
149 _Kind == SUPERV::EndLoopNode ||
150 _Kind == SUPERV::SwitchNode ||
151 _Kind == SUPERV::EndSwitchNode ||
152 _Kind == SUPERV::GOTONode ) ; } ;
153 const bool IsOneOfInLineNodes() const {
154 return (_Kind == SUPERV::InLineNode || IsOneOfGOTONodes() ) ; } ;
155 const bool IsInLineNode() const {
156 return (_Kind == SUPERV::InLineNode ) ; } ;
157 const bool IsDataFlowNode() const {
158 return (_Kind == SUPERV::DataFlowNode ) ; } ;
159 const bool IsLoopNode() const {
160 return (_Kind == SUPERV::LoopNode ) ; } ;
161 const bool IsEndLoopNode() const {
162 return (_Kind == SUPERV::EndLoopNode ) ; } ;
163 const bool IsSwitchNode() const {
164 return (_Kind == SUPERV::SwitchNode ) ; } ;
165 const bool IsEndSwitchNode() const {
166 return (_Kind == SUPERV::EndSwitchNode ) ; } ;
167 const bool IsGOTONode() const {
168 return (_Kind == SUPERV::GOTONode ) ; } ;
169 void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
170 const bool IsHeadNode() const { return _HeadNode ; } ;
172 bool RemovePorts( const char* aNodeName ) ;
174 InPort * AddInPort( const char * InputParameterName ,
175 const char * InputParameterType ) ;
176 OutPort * AddOutPort( const char * OutputParameterName ,
177 const char * OutputParameterType ) ;
179 void AddLink( ComputingNode * aNode ) ;
180 void RemoveLink( ComputingNode * aNode ) ;
181 void ReNameLink( const char* OldNodeName ,
182 const char* NewNodeName ) ;
184 int GetServiceNameNumber( const char * name ) {
185 int num = _MapOfServiceNames[ name ] ;
187 _MapOfServiceNames[ name ] = 1 ;
190 _MapOfServiceNames[ name ] = num + 1 ;
192 return _MapOfServiceNames[ name ] ; } ;
194 void IncrConnectedInPortsNumber() {
195 cdebug << "IncrConnectedInPortsNumber " << Name() << " -> "
196 << _ConnectedInPortsNumber+1 << endl ;
197 _ConnectedInPortsNumber++ ; } ;
198 void DecrConnectedInPortsNumber() {
199 _ConnectedInPortsNumber-- ; } ;
200 int ConnectedInPortsNumber() const {
201 return _ConnectedInPortsNumber ; } ;
202 void ConnectedInPortsNumber( int c ) {
203 cdebug << "ConnectedInPortsNumber " << Name() << " -> " << c << endl ;
204 _ConnectedInPortsNumber = c ; } ;
206 void IncrDecrConnectedInPortsNumber(const int cnt ) {
207 _DecrConnectedInPortsNumber += cnt ; } ;
208 bool DecrIncrDecrConnectedInPortsNumber() {
209 if ( _DecrConnectedInPortsNumber ) {
210 _ConnectedInPortsNumber = _ConnectedInPortsNumber -
211 _DecrConnectedInPortsNumber ;
212 _DecrConnectedInPortsNumber = 0 ;
217 int GetLinkedNodeIndex( const char * name ) {
218 int index = _MapOfLinkedNodes[ name ] -1 ;
220 cdebug << "GetLinkedNodeIndex of " << name
221 << " in _MapOfLinkedNodes : "
222 << index << " Node " << hex << (void *) _LinkedNodes[ index ]
223 << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
227 void SetLinkedNodeIndex( const char * name , const int index ) {
228 _MapOfLinkedNodes[ name ] = index +1 ;
229 cdebug << "SetLinkedNodeIndex of " << name << " in _MapOfLinkedNodes : "
230 << index << " Node " << hex << (void *) _LinkedNodes[ index ]
231 << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
232 << " _MapOfLinkedNodes " << _MapOfLinkedNodes[ name ] - 1
235 void DelLinkedNodeIndex( const char * name ) {
236 _MapOfLinkedNodes.erase( name ) ; } ;
237 int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
238 ComputingNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
239 const int LinkedInPortsNumber( int i ) const { return _LinkedInPortsNumber[ i ] ; } ;
241 int Level() { return _LevelNumber ; } ;
242 void Level( int LevelNumber ) {
243 _LevelNumber = LevelNumber ; } ;
244 int SubGraph() { return _SubGraphNumber ; } ;
245 void SubGraph( int SubGraphNumber ) {
246 _SubGraphNumber = SubGraphNumber ; } ;
248 // const GraphBase::ListOfParameters * GetListOfParameters() const ;
250 const long CpuUsed() ;
252 bool SaveXML( QDomDocument & Graph , QDomElement & info ,
253 int X , int Y ) const {
254 ListOfFuncName aFuncNames ;
255 GraphBase::ListOfPythonFunctions aVoidList ;
256 return SaveXML( Graph , info , "" , "" , "" , "" , aFuncNames , aVoidList ,
259 bool SavePY( ostream &f , const char * aGraphName ,
260 int X , int Y ) const {
261 ListOfFuncName aFuncNames ;
262 GraphBase::ListOfPythonFunctions aVoidList ;
263 return SavePY( f , aGraphName , "" , "" , "" , NULL , aFuncNames , aVoidList ,
265 // bool SaveXML(ostream &f , char *Tabs ,
266 bool SaveXML(QDomDocument & Graph , QDomElement & info ,
267 const char * ComponentName ,
268 const char * InterfaceName ,
269 const char * Computer ,
270 const char * CoupledNode ,
271 const ListOfFuncName FuncNames ,
272 const GraphBase::ListOfPythonFunctions PythonFunctions ,
273 int X , int Y ) const ;
275 bool SavePY(ostream &f , const char * aGraphName ,
276 const char * ComponentName ,
277 const char * InterfaceName ,
278 const char * Computer ,
279 const GraphBase::InLineNode * aCoupledNode ,
280 const ListOfFuncName FuncNames ,
281 const GraphBase::ListOfPythonFunctions PythonFunctions ,
282 int X , int Y ) const ;
284 void NodeInfo(ostrstream & s) const ;
286 void ListLinks(ostream &f ) const ;
292 ostream & operator<< (ostream &,const GraphBase::ComputingNode & N );
294 ostream & operator<< (ostream &,const SUPERV::SDate & D );