src/GraphBase/DataFlowBase_ComputingNode.hxx

Go to the documentation of this file.
00001 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
00002 //
00003 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
00005 // 
00006 //  This library is free software; you can redistribute it and/or 
00007 //  modify it under the terms of the GNU Lesser General Public 
00008 //  License as published by the Free Software Foundation; either 
00009 //  version 2.1 of the License. 
00010 // 
00011 //  This library is distributed in the hope that it will be useful, 
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00014 //  Lesser General Public License for more details. 
00015 // 
00016 //  You should have received a copy of the GNU Lesser General Public 
00017 //  License along with this library; if not, write to the Free Software 
00018 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
00019 // 
00020 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : DataFlowBase_ComputingNode.hxx
00023 //  Author : Jean Rahuel, CEA
00024 //  Module : SUPERV
00025 
00026 #ifndef _DATAFLOWBASE_COMPUTINGNODE_HXX
00027 #define _DATAFLOWBASE_COMPUTINGNODE_HXX
00028 
00029 #include "SALOME_NamingService.hxx"
00030 
00031 #include "DataFlowBase_StreamNode.hxx"
00032 
00033 class CNode_Impl ;
00034 
00035 namespace GraphBase {
00036 
00037   class Graph ;
00038 
00039   class InLineNode ;
00040 
00041   class LoopNode ;
00042   class EndOfLoopNode ;
00043   class EndOfSwitchNode ;
00044 
00045   class ComputingNode : public StreamNode {
00046 
00047     private:
00048     
00049       CORBA::ORB_ptr         _ORB ;
00050       SALOME_NamingService * _NamingService ;
00051 //->StreamNode      int                  * _Graph_prof_debug ;
00052 //->StreamNode      ofstream             * _Graph_fdebug ;
00053       SUPERV::CNode_var      _Node_var ;
00054       CNode_Impl           * _Node_Impl ;
00055       void                 * _InNode ; // From GraphExecutor:: or GraphEditor::
00056       bool                   _ObjInterface ;
00057 
00058       pthread_t              _ThreadNo ;
00059 
00060 //->StreamNode      char                 * _Name ;
00061 //->StreamNode      SUPERV::KindOfNode     _Kind ;
00062       SUPERV::SDate          _FirstCreation ;
00063       SUPERV::SDate          _LastModification ;
00064       char                 * _EditorRelease ;
00065       char                 * _Author ;
00066       char                 * _Comment ;
00067 
00068 //->StreamNode      bool                   _HeadNode ;
00069 //->StreamNode      int                    _LevelNumber ;
00070 //->StreamNode      int                    _SubGraphNumber ;
00071       bool                   _GeneratedName ;
00072 
00073 //->StreamNode      int                    _DataStreamInPortsNumber ;
00074 //->StreamNode      int                    _DataStreamOutPortsNumber ;
00075 
00076       int                    _ConnectedInPortsNumber ;
00077       int                    _DecrConnectedInPortsNumber ;
00078 
00079 // For generated NodeNames with ServiceName : number of Nodes using
00080 // the same ServiceName. It is not the same Service if it belongs to
00081 // a different Interface and/or a different Component ...
00082 //->StreamNode      map< string , int > _MapOfServiceNames ;
00083 
00084 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
00085 //->StreamNode      map< string , int >      _MapOfLinkedNodes ;
00086 //->StreamNode      int                      _LinkedNodesSize ;
00087 //->StreamNode      vector<ComputingNode * > _LinkedNodes ;
00088 //->StreamNode      vector<int >             _LinkedInPortsNumber ;
00089 
00090     protected:
00091 
00092       long _X ;
00093       long _Y ;
00094 
00095     public:
00096 
00097       ComputingNode() ;
00098       ComputingNode( CORBA::ORB_ptr ORB ,
00099                      SALOME_NamingService* ptrNamingService ,
00100                      const char * DataFlowName ,
00101                      const SUPERV::KindOfNode DataFlowkind ,
00102                      int * Graph_prof_debug ,
00103                      ofstream * Graph_fdebug ) ;
00104       ComputingNode( CORBA::ORB_ptr ORB ,
00105                      SALOME_NamingService* ptrNamingService ,
00106                      const SALOME_ModuleCatalog::Service& NodeService ,
00107                      const char *NodeName ,
00108                      const SUPERV::KindOfNode akind ,
00109                      const SUPERV::SDate NodeFirstCreation ,
00110                      const SUPERV::SDate NodeLastModification ,
00111                      const char * NodeEditorRelease ,
00112                      const char * NodeAuthor ,
00113                      const char * NodeComment ,
00114                      const bool   GeneratedName ,
00115                      const long   X ,
00116                      const long   Y ,
00117                      int * Graph_prof_debug = NULL ,
00118                      ofstream * Graph_fdebug = NULL ) ;
00119       virtual ~ComputingNode() ;
00120 
00121       SALOME_NamingService * NamingService() const {
00122              return _NamingService ; } ;
00123 
00124       SUPERV::CNode_var ObjRef() const {
00125 //                        char * _NodeName ;
00126 //                        cdebug << "ComputingNode::ObjRef() " << _Node << " " << Name()
00127 //                               << " " << endl ;
00128 //                        SUPERV::CNode_var _NodeObjRef = SUPERV::CNode::_narrow( _Node ) ;
00129 //                        if ( CORBA::is_nil( _NodeObjRef ) ) {
00130 //                          _NodeName = "NilRef" ;
00131 //             }
00132 //             else {
00133 //                          try {
00134 //                            _NodeName = _NodeObjRef->Name() ;
00135 //               }
00136 //                          catch ( ... ) {
00137 //                            _NodeName = "Catch Error" ;
00138 //               }
00139 //             }
00140 //                        cdebug << _NodeName << " " << Name() << endl ;
00141                          return _Node_var ; } ;
00142       void SetObjRef( SUPERV::CNode_var aNode_var ) {
00143 //                        char * _NodeName ;
00144 //                        if ( CORBA::is_nil( _Node ) ) {
00145 //                          _NodeName = "NilRef" ;
00146 //             }
00147 //             else {
00148 //                          _NodeName = _Node->Name() ;
00149 //             }
00150 //                        cdebug << "ComputingNode::SetObjRef( " << _Node << " "
00151 //                               << _NodeName << " ) " << Name() << " --> " ;
00152                         _Node_var = aNode_var ;
00153 //                        cdebug << _Node << " " << _Node->Name() << " ) " << Name() << endl ;
00154                         } ;
00155 
00156       CNode_Impl * ObjImpl() const { return _Node_Impl ; } ;
00157       void SetObjImpl( CNode_Impl * aNode_Impl ) {
00158                        _Node_Impl = aNode_Impl ; } ;
00159 
00160       void InNode( void * anInNode ) {
00161 //           cdebug << "GraphBase::ComputingNode::InNode " << Name() << endl ;
00162            _InNode = anInNode ; } ;
00163       void * GetInNode() const {
00164              return _InNode ; } ;
00165 
00166       void ObjInterface( bool k_interface ) { _ObjInterface = k_interface ; } ;
00167       bool ObjInterface() { return _ObjInterface ; } ;
00168 
00169       pthread_t ThreadNo() { return _ThreadNo ; } ;
00170       void ThreadNo( pthread_t aThread ) { _ThreadNo = aThread ; } ;
00171 
00172 //->StreamNode      char * Name() const { return my_strdup( _Name ) ; } ;
00173 //->StreamNode      const char *const * NamePtr() const { return &_Name ; } ;
00174 //      const SALOME_ModuleCatalog::Service * Service() const ;
00175       SUPERV::SDate FirstCreation() const ;
00176       SUPERV::SDate LastModification() const ;
00177 //JR 17.02.2005 Memory Leak      char* Author() const { return my_strdup( _Author ) ; } ;
00178       char* Author() const { return _Author ; } ;
00179 //JR 17.02.2005 Memory Leak      char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
00180       char* EditorRelease() const { return _EditorRelease ; } ;
00181 //JR 17.02.2005 Memory Leak      char * Comment() const { return my_strdup( _Comment ) ; } ;
00182       char * Comment() const { return _Comment ; } ;
00183       int XCoordinate() const { return _X ; } ;
00184       int YCoordinate() const { return _Y ; } ;
00185 
00186 //->StreamNode      bool Name( const char * aName ) ;
00187 //      void Service( const SALOME_ModuleCatalog::Service aService ) ;
00188       void FirstCreation( const SUPERV::SDate aFirstCreation ) ;
00189       void LastModification( const SUPERV::SDate aLastModification ) ;
00190       bool Author( const char * anAuthor ) ;
00191       bool EditorRelease( const char* anEditorRelease ) ;
00192       bool Comment( const char *c ) ;
00193       void Coordinates( const int X , const int Y ) {
00194            _X = X ; _Y = Y ; } ;
00195 
00196       void NodePort( const char * NodeName ,
00197                      const char * ServiceParameterName ,
00198                      char ** aNode , char ** aPort ) ;
00199 
00200       bool IsLinked(const char * ToServiceParameterName, bool isInput ) ; // mkr : PAL8060
00201       bool HasInput(const char * ToServiceParameterName ) ;
00202 
00203       GraphBase::SNode * GetInfo() ;
00204 
00205 //      void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
00206 //      const bool IsHeadNode() const { return _HeadNode ; } ;
00207 
00208       bool RemovePorts( const char* aNodeName ) ;
00209 
00210       void SetMacroPorts( GraphBase::Graph * aGraph ) ;
00211       void UpdateMacroPorts( GraphBase::Graph * aGraph ) ;
00212       void SetMacroDatas( GraphBase::Graph * aGraph , GraphBase::Graph * aGraphOfMacroGraph ) ;
00213 
00214       void DelInPort( const char * InputParameterName ) ;
00215       void DelOutPort( const char * OutputParameterName ) ;
00216 
00217       InPort * AddInPort( const char * InputParameterName ,
00218                           const char * InputParameterType ,
00219                           const SUPERV::KindOfPort aKindOfPort ,
00220                           int index = -1 ) ;
00221       OutPort * AddOutPort( const char * OutputParameterName ,
00222                             const char * OutputParameterType ,
00223                             const SUPERV::KindOfPort aKindOfPort ,
00224                             int index = -1 ) ;
00225 
00226       void DelInDataStreamPort( const char * InputParameterName ) ;
00227       void DelOutDataStreamPort( const char * OutputParameterName ) ;
00228 
00229       InDataStreamPort * AddInDataStreamPort( const char * InputParameterName ,
00230                                               const SALOME_ModuleCatalog::DataStreamType InputParameterType ,
00231                                               const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
00232                                               const SUPERV::KindOfPort aKindOfPort ,
00233                                               int index = -1 ) ;
00234       OutDataStreamPort * AddOutDataStreamPort( const char * OutputParameterName ,
00235                                                 const SALOME_ModuleCatalog::DataStreamType OutputParameterType ,
00236                                                 const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
00237                                                 const SUPERV::KindOfPort aKindOfPort ,
00238                                                 int index = -1 ) ;
00239 
00240 //      ComputingNode * LinkedNodes( int i ) const { return (GraphBase::ComputingNode *) GraphBase::StreamNode::LinkedNodes( i ) ; } ;
00241 
00242       void AddLinkedNode( GraphBase::ComputingNode * ToNode ) {
00243            GraphBase::StreamNode::AddLinkedNode( ToNode ) ;
00244            cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
00245                   << ") ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
00246                   << " + 1 Service " << ServiceName() << endl ;
00247            ToNode->IncrConnectedInPortsNumber() ; } ;
00248 
00249       bool RemoveLinkedNode( GraphBase::ComputingNode * ToNode ,
00250                              bool DoLinkedFromNode = true ) {
00251            bool RetVal = GraphBase::StreamNode::RemoveLinkedNode( ToNode , DoLinkedFromNode ) ;
00252            if ( RetVal ) {
00253              cdebug << "ComputingNode::RemoveLinkedNode to " << ToNode->Name() << " from "
00254                     << Name() << " ConnectedInPortsNumber "
00255                     << ToNode->ConnectedInPortsNumber() - 1 << endl ;
00256              ToNode->DecrConnectedInPortsNumber() ;
00257         }
00258            return RetVal ; } ;
00259 
00260       void ReNameLinkedNode( const char* OldNodeName ,
00261                              const char* NewNodeName ) {
00262            GraphBase::StreamNode::ReNameLinkedNode( OldNodeName , NewNodeName ) ; } ;
00263 
00264       void IncrConnectedInPortsNumber() {
00265            cdebug << "ComputingNode::IncrConnectedInPortsNumber " << Name() << " -> "
00266                   << _ConnectedInPortsNumber+1 << endl ;
00267            _ConnectedInPortsNumber++ ; } ;
00268       void DecrConnectedInPortsNumber() {
00269            cdebug << "ComputingNode::DecrConnectedInPortsNumber " << Name() << " -> "
00270                   << _ConnectedInPortsNumber-1 << endl ;
00271            _ConnectedInPortsNumber-- ; } ;
00272       int ConnectedInPortsNumber() const {
00273           return _ConnectedInPortsNumber ; } ;
00274       void ConnectedInPortsNumber( int c ) {
00275            cdebug << "ConnectedInPortsNumber " << Name() << " -> " << c << endl ;
00276            _ConnectedInPortsNumber = c ; } ;
00277 
00278       void IncrDecrConnectedInPortsNumber(const int cnt ) {
00279            _DecrConnectedInPortsNumber += cnt ; } ;
00280       bool DecrIncrDecrConnectedInPortsNumber() {
00281            if ( _DecrConnectedInPortsNumber ) {
00282              _ConnectedInPortsNumber = _ConnectedInPortsNumber -
00283                                        _DecrConnectedInPortsNumber ;
00284              _DecrConnectedInPortsNumber = 0 ;
00285              return true ;
00286         }
00287            return false ; } ;
00288 
00289       bool CheckLoop( GraphBase::LoopNode * aLoopNode ,
00290                       GraphBase::EndOfLoopNode * anEndLoopNode ,
00291                       string & anErrorMessage ) const ;
00292       bool CheckEndLoop( GraphBase::LoopNode * aLoopNode ,
00293                          GraphBase::EndOfLoopNode * anEndLoopNode ,
00294                          string & anErrorMessage ) const ;
00295       bool InitBranchOfSwitchDone( bool AllInit , GraphBase::EndOfSwitchNode * anEndSwitchNode ,
00296                                    string & anErrorMessage ) ;
00297       bool CheckSwitch( GraphBase::EndOfSwitchNode * anEndSwitchNode ,
00298                         string & anErrorMessage ) ;
00299 
00300 //      const GraphBase::ListOfParameters * GetListOfParameters() const ;
00301 
00302       const long CpuUsed() ;
00303 
00304       bool SaveXML( QDomDocument & Graph , QDomElement & info , 
00305                     int X , int Y ) const {
00306                     ListOfFuncName aFuncNames ; 
00307                     GraphBase::ListOfPythonFunctions aVoidList ;
00308            return SaveXML( Graph , info , "" , "" , "" , "" , aFuncNames , aVoidList ,
00309                            X , Y ) ; } ;
00310 
00311       bool SavePY( ostream &f , const char * aGraphName ,
00312                    int X , int Y ) const {
00313            ListOfFuncName aFuncNames ; 
00314            GraphBase::ListOfPythonFunctions aVoidList ;
00315            return SavePY( f , aGraphName , "" , "" , "" , NULL , aFuncNames  , aVoidList ,
00316                           X , Y ) ; } ;
00317 //      bool SaveXML(ostream &f , char *Tabs , 
00318       bool SaveXML(QDomDocument & Graph , QDomElement & info , 
00319                    const char * ComponentName ,
00320                    const char * InterfaceName ,
00321                    const char * Computer ,
00322                    const char * CoupledNode ,
00323                    const ListOfFuncName FuncNames ,
00324                    const GraphBase::ListOfPythonFunctions PythonFunctions ,
00325                    int X , int Y ) const ;
00326 
00327       bool SavePY(ostream &f , const char * aGraphName ,
00328                                const char * ComponentName ,
00329                                const char * InterfaceName ,
00330                                const char * Computer ,
00331                                const GraphBase::InLineNode * aCoupledNode ,
00332                                const ListOfFuncName FuncNames ,
00333                                const GraphBase::ListOfPythonFunctions PythonFunctions ,
00334                                int X , int Y ) const ;
00335 
00336       void NodeInfo(ostream & s) const ;
00337 
00338       void ListLinks(ostream &f ) const ;
00339 
00340   };
00341   
00342 };
00343 
00344 ostream & operator<< (ostream &,const GraphBase::ComputingNode & N );
00345 
00346 ostream & operator<< (ostream &,const SUPERV::SDate & D );
00347 
00348 #endif