src/GraphBase/DataFlowBase_Graph.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 //
00023 //
00024 //  File   : DataFlowBase_Graph.hxx
00025 //  Author : Jean Rahuel, CEA
00026 //  Module : SUPERV
00027 //  $Header:
00028 
00029 #ifndef _DATAFLOWBASE_GRAPH_HXX
00030 #define _DATAFLOWBASE_GRAPH_HXX
00031 
00032 #include "DataFlowBase_FactoryNode.hxx"
00033 #include "DataFlowBase_LoopNode.hxx"
00034 #include "DataFlowBase_EndOfLoopNode.hxx"
00035 #include "DataFlowBase_SwitchNode.hxx"
00036 #include "DataFlowBase_EndOfSwitchNode.hxx"
00037 #include "DataFlowBase_DataNode.hxx"
00038 
00039 namespace GraphBase {
00040 
00041   class Graph : public DataNode {
00042 
00043     private:
00044 
00045 //      int                 _Graph_prof_debug;
00046 //      ofstream          * _Graph_fdebug;
00047       CORBA::ORB_ptr      _Orb ;
00048 //      SUPERV::Graph_var   _Graph ;
00049 //      Graph_Impl        * _GraphImpl ;
00050 
00051 // Map of Nodes of the Graph
00052       map< string , int >      _MapOfGraphNodes ;
00053       long                     _GraphNodesSize ;
00054       vector<bool >            _Sorted ;
00055       vector<ComputingNode *>  _GraphNodes ;
00056 
00057 // _SortedNodes[ _LevelsNumber ] : topological sort from 0 to _LevelsNumber
00058 // _SortedNodes[ _level ][ _NodesNumber[ _level ] ] : _NodesNumber[ _level ] Nodes in the level
00059       int                              _LevelsNumber ;
00060       int                              _ThreadsMax ;
00061       vector<int >                     _NodesNumber ;
00062       vector<vector<ComputingNode *> > _SortedNodes ;
00063 
00064       vector<int >             _CnxInPortsNumber ;
00065       vector<int >             _DecrInPortsNumber ;
00066 
00067       long                     _HeadNodesSize ; 
00068       vector<ComputingNode *>  _HeadNodes ;
00069       long                     _QueueNodesSize ; 
00070       vector<ComputingNode *>  _QueueNodes ;
00071       bool                     _ParallelExecutionNodes ;
00072 
00073 // For StreamGraphs. It is not the same Service if it belongs to
00074 // a different Interface and/or a different Component ...
00075       map< string , GraphBase::Service * > _MapOfServiceNames ;
00076 
00077 // For automactic rename of nodes if unique names in graphs
00078       map< string , int >      _MapOfServiceInstanceNumber ;
00079 
00080 // Total number of SubGraphs
00081       int                              _SubGraphsNumber ;
00082 // _SubGraphs[ SubGraphNumero ] [ NodeNumero ]
00083 // SubGraphNumero : [ 0 , _SubGraphsSize [ ; NodeNumero : [ 0 , _SubGraphs[ SubGraphNumero ].size() [
00084       int                              _SubGraphsSize ;
00085       vector<vector<ComputingNode *> > _SubGraphs ;
00086 
00087 // _SubStreamGraphs[ SubStreamGraphNumero ] [ NodeNumero ]
00088 // SubStreamGraphNumero : [ 0 , _SubStreamGraphsSize [
00089 // NodeNumero : [ 0 , _SubStreamGraphs[ SubStreamGraphNumero ].size() [
00090 //      int                              _SubStreamGraphsSize ;
00091 //      vector<vector<ComputingNode *> > _SubStreamGraphs ;
00092 
00093     string _Messages ;
00094 
00095     map< string, string > _MapOfComponentNameContainer ; // mkr : PAL13947
00096     
00097     bool AddLink( GraphBase::ComputingNode *fromNode ,
00098             GraphBase::OutPort *fromPort ,
00099             GraphBase::ComputingNode *toNode ,
00100             GraphBase::InPort *toPort ) ;
00101 
00102     public:
00103 
00104       Graph() ;
00105       Graph( CORBA::ORB_ptr ORB ,
00106              SALOME_NamingService* ptrNamingService ,
00107              const char *DataFlowName ,
00108              const SUPERV::KindOfNode DataFlowkind ,
00109              int * Graph_prof_debug ,
00110              ofstream * Graph_fdebug ) ;
00111 //             const char * DebugFileName ) ;
00112       Graph( CORBA::ORB_ptr ORB ,
00113              SALOME_NamingService* ptrNamingService ,
00114              const SALOME_ModuleCatalog::Service& DataFlowService ,
00115              const char *DataFlowComponentName ,
00116              const char *DataFlowInterfaceName ,
00117              const char *DataFlowName ,
00118              const SUPERV::KindOfNode DataFlowkind ,
00119              const SUPERV::SDate DataFlowFirstCreation ,
00120              const SUPERV::SDate DataFlowLastModification ,
00121              const char * DataFlowEditorRelease ,
00122              const char * DataFlowAuthor ,
00123              const char * DataFlowComputer ,
00124              const char * DataFlowComment ,
00125              int * Graph_prof_debug ,
00126              ofstream * Graph_fdebug ) ;
00127 //             const char * DebugFileName ) ;
00128       virtual ~Graph() ;
00129 
00130 //      void Set_prof_debug( CORBA::ORB_ptr ORB ,
00131 //                           const char * DebugFileName ) ;
00132       void Set_prof_debug( int * Graph_prof_debug ,
00133                            ofstream * Graph_fdebug ) ;
00134       int * Graph_prof_debug() {
00135             return _prof_debug ; } ;
00136       ofstream * Graph_fdebug() { return _fdebug ; } ;
00137 
00138 //      SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
00139 //      void SetObjRef( SUPERV::Graph_var aGraph ) {
00140 //                      _Graph = aGraph ; } ;
00141 //      Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
00142 //      void SetObjImpl( Graph_Impl * aGraphImpl ) {
00143 //                       _GraphImpl = aGraphImpl ; } ;
00144 
00145       void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
00146            GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
00147 
00148       const int GetGraphNodeIndex( const char *name ) {
00149             const int index = _MapOfGraphNodes[ name ] - 1 ;
00150 //            if ( index >= 0 )
00151 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
00152 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
00153 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
00154 #if 0
00155            cdebug << "Graph::GetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
00156            int i ;
00157            for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
00158              cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
00159            }
00160            map< string , int >::iterator aMapOfGraphNodesIterator ;
00161            i = 0 ;
00162            for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
00163              aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
00164              cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
00165                     << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
00166            }
00167 #endif
00168             return index ; } ;
00169       void SetGraphNodeIndex( const char *name , const int index ) {
00170            _MapOfGraphNodes[ name ] = index + 1 ;
00171            cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
00172                   << index << " Node " << (void *) _GraphNodes[ index ]
00173                   << " '" << _GraphNodes[ index ]->Name() << "' MapOfGraphNodessize "
00174                   << GetGraphNodeSize() << endl ;
00175 #if 1
00176            cdebug << "Graph::SetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
00177            int i ;
00178            for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
00179              cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
00180            }
00181            map< string , int >::iterator aMapOfGraphNodesIterator ;
00182            i = 0 ;
00183            for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
00184              aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
00185              cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
00186                     << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
00187            }
00188 #endif
00189            } ;
00190       void DelGraphNodeIndex( const char *name ) {
00191            _MapOfGraphNodes.erase( name ) ; } ;
00192 
00193       int GetGraphNodeSize() const {
00194           return _MapOfGraphNodes.size() ; }
00195       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
00196             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
00197             return aNode ; } ;
00198       ComputingNode * GetChangeGraphNode( const int index ) const {
00199             if ( index >= 0 && index < _GraphNodesSize ) {
00200               ComputingNode * aNode = _GraphNodes[ index ] ;
00201               return aNode ;
00202             }
00203             else
00204               return NULL ; } ;
00205       const ComputingNode * GetGraphNode( const char *name ) {
00206             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
00207             return aNode ; } ;
00208       ComputingNode * GetChangeGraphNode( const char *name ) {
00209             int index = GetGraphNodeIndex( name ) ;
00210             if ( index >= 0 && index < _GraphNodesSize ) {
00211               ComputingNode * aNode = GetChangeGraphNode( index ) ;
00212               return aNode ;
00213             }
00214             else
00215               return NULL ; } ;
00216 
00217       const int GraphNodesSize() const {
00218             return _GraphNodesSize ; } ;
00219       ComputingNode * GraphNodes( int i ) const {
00220             return _GraphNodes[ i ] ; } ;
00221 
00222       const int HeadNodesSize() const {
00223             return _HeadNodesSize ; } ;
00224       ComputingNode * HeadNodes( int i ) const {
00225             return _HeadNodes[ i ] ; } ;
00226 
00227       const int QueueNodesSize() const {
00228             return _QueueNodesSize ; } ;
00229       ComputingNode * QueueNodes( int i ) const {
00230             return _QueueNodes[ i ] ; } ;
00231 
00232       const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
00233                                 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
00234       GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
00235                           return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
00236       const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
00237                                  return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
00238       GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
00239                            return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
00240 
00241       const GraphBase::InPort * GetInPort( const char * ToNodeName ,
00242                                           const char * ToServiceParameterName ) {
00243             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
00244             if ( aNode ) {
00245               return aNode->GetInPort(ToServiceParameterName);
00246          }
00247             else
00248               return NULL ; } ;
00249       GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
00250                                           const char * ToServiceParameterName ) {
00251             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
00252             if ( aNode ) {
00253               return aNode->GetChangeInPort( ToServiceParameterName ) ;
00254          }
00255             else
00256               return NULL ; } ;
00257       const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
00258                                     const char * FromServiceParameterName ) {
00259             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
00260             if ( aNode ) {
00261               return aNode->GetOutPort( FromServiceParameterName ) ;
00262          }
00263             else
00264               return NULL ; } ;
00265       GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
00266                                             const char * FromServiceParameterName ) {
00267             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
00268             if ( aNode ) {
00269               return aNode->GetChangeOutPort( FromServiceParameterName );
00270          }
00271             else
00272               return NULL ; } ;
00273 
00274       SUPERV::GraphState PortState( const char* NodeName ,
00275                                     const char* ServiceParameterName ) ;
00276       bool PortDone( const char* NodeName ,
00277                      const char* ServiceParameterName ) {
00278         bool aRet = false ;
00279         SUPERV::GraphState aState = PortState( NodeName ,
00280                                                 ServiceParameterName ) ;
00281         if ( aState == SUPERV::DoneState )
00282           aRet = true ;
00283         return aRet ; } ;
00284 //JR 30.03.2005      const CORBA::Any * PortInData( const char* ToNodeName ,
00285       const CORBA::Any PortInData( const char* ToNodeName ,
00286                                    const char* ToServiceParameterName ) ;
00287 //JR 30.03.2005      const CORBA::Any * PortOutData( const char* FromNodeName ,
00288       const CORBA::Any PortOutData( const char* FromNodeName ,
00289                                     const char* FromServiceParameterName ) ;
00290 
00291       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
00292                     GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
00293 
00294       GraphBase::SNode * GetInfo() const ;
00295       GraphBase::ListOfSNodes * GetNodes() const ;
00296       GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
00297       GraphBase::ListOfSGraphs * GetGraphs() const ;
00298       GraphBase::ListOfSLinks * GetDatas() const ;
00299 
00300       bool AddNode( ComputingNode * aNode ) ;
00301       bool RemoveNode( const char* NodeName ) ;
00302       bool ReNameNode( const char* OldNodeName ,
00303                        const char* NewNodeName ) ;
00304 
00305       bool AddLink( const char* FromNodeName ,
00306                     const char* FromServiceParameterName ,
00307                  const char* ToNodeName ,
00308                     const char* ToServiceParameterName ) ;
00309 //                    , const CORBA::Any aValue ) ;
00310       bool RemoveLink( const char* FromNodeName ,
00311                        const char* FromServiceParameterName ,
00312                     const char* ToNodeName ,
00313                        const char* ToServiceParameterName ) ;
00314       bool GetLink( const char* ToNodeName ,
00315                     const char* ToServiceParameterName ,
00316                     char** FromNodeName ,
00317                     char** FromServiceParameterName ) ;
00318       GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
00319                                   GraphBase::InPort* toPort ) ;
00320 
00321       bool AddInputData( const char* ToNodeName ,
00322                          const char* ToParameterName ,
00323                          const CORBA::Any aValue ) ;
00324       bool ChangeInputData( const char* ToNodeName ,
00325                             const char* ToParameterName ,
00326                             const CORBA::Any aValue ) ;
00327 //      bool AddInputData( const char* ToNodeName ,
00328 //                         const char* ToParameterName ,
00329 //                         const CORBA::Any ** aValue ) ;
00330 
00331       bool AddOutputData( const char* FromNodeName ,
00332                           const char* FromParameterName ,
00333                           const CORBA::Any aValue ) ;
00334 
00335       void SetGraphPorts() ;
00336 
00337       string Messages() ;
00338       void ReSetMessages() ;
00339       void SetMessages( string anErrorMessage ) ;
00340 
00341       bool CreateService() ;
00342       bool InLineServices() ;
00343 
00344       bool Sort( int & SubStreamGraphsNumber ) ;
00345       bool ValidGOTO() ; // mkr : PAL12575
00346       bool ValidLoops() const ;
00347       bool ValidSwitchs() const ;
00348       bool ComputingNodes() const ;
00349       bool LinkLoopNodes(bool & NewLink ) ;
00350       bool DataServerNodes() const ;
00351   
00352       long LevelMax() {
00353            return _LevelsNumber + 1 ; } ;
00354 
00355       map< string , GraphBase::Service * > MapOfServiceNames() ;
00356       GraphBase::Service * GetServiceOfMap( char * name ) ;
00357       bool SetServiceOfMap( GraphBase::Service * aService ) ;
00358       int GetNewServiceInstanceNumber( char * aServiceName ) ;
00359 
00360       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
00361       long ThreadsMax() {
00362            return _ThreadsMax ; } ;
00363 
00364       long SubGraphsNumber() {
00365            return _SubGraphsNumber ; } ;
00366 
00367       int NodesNumber(const int aLevel ) {
00368           return _NodesNumber[ aLevel ] ; } ;
00369       GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
00370              return (_SortedNodes[ aLevel ])[ index ] ; } ;
00371 
00372       bool StartComponent( const int aThread ,
00373                            const char * ComputerContainer ,
00374                            const char * ComponentName ,
00375                            Engines::Container_var & myContainer ,
00376                            Engines::Component_var & objComponent ) ;
00377 
00378     // mkr : PAL13947
00379     void InsertToMapOfComponentNameContainer( const char * theComponentName, 
00380                                const char * theContainer) {
00381       _MapOfComponentNameContainer[ theComponentName ] = theContainer ;
00382     }
00383 
00384     // mkr : PAL13947    
00385     const char * RetrieveFromMapOfComponentNameContainer( const char * theComponentName ) {
00386       if ( _MapOfComponentNameContainer.empty() 
00387         ||
00388         _MapOfComponentNameContainer.find(theComponentName) == _MapOfComponentNameContainer.end() )
00389      return NULL ;
00390       
00391       return _MapOfComponentNameContainer[ theComponentName ].c_str() ;
00392     }
00393 
00394     // mkr : PAL13947
00395     void ClearMapOfComponentNameContainer() {
00396       if ( !_MapOfComponentNameContainer.empty() )
00397      _MapOfComponentNameContainer.clear();
00398     }
00399 
00400   };
00401   
00402 };
00403 
00404 #endif