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       bool AddLink( GraphBase::ComputingNode *fromNode ,
00096                     GraphBase::OutPort *fromPort ,
00097                     GraphBase::ComputingNode *toNode ,
00098                     GraphBase::InPort *toPort ) ;
00099 
00100     public:
00101 
00102       Graph() ;
00103       Graph( CORBA::ORB_ptr ORB ,
00104              SALOME_NamingService* ptrNamingService ,
00105              const char *DataFlowName ,
00106              const SUPERV::KindOfNode DataFlowkind ,
00107              int * Graph_prof_debug ,
00108              ofstream * Graph_fdebug ) ;
00109 //             const char * DebugFileName ) ;
00110       Graph( CORBA::ORB_ptr ORB ,
00111              SALOME_NamingService* ptrNamingService ,
00112              const SALOME_ModuleCatalog::Service& DataFlowService ,
00113              const char *DataFlowComponentName ,
00114              const char *DataFlowInterfaceName ,
00115              const char *DataFlowName ,
00116              const SUPERV::KindOfNode DataFlowkind ,
00117              const SUPERV::SDate DataFlowFirstCreation ,
00118              const SUPERV::SDate DataFlowLastModification ,
00119              const char * DataFlowEditorRelease ,
00120              const char * DataFlowAuthor ,
00121              const char * DataFlowComputer ,
00122              const char * DataFlowComment ,
00123              int * Graph_prof_debug ,
00124              ofstream * Graph_fdebug ) ;
00125 //             const char * DebugFileName ) ;
00126       virtual ~Graph() ;
00127 
00128 //      void Set_prof_debug( CORBA::ORB_ptr ORB ,
00129 //                           const char * DebugFileName ) ;
00130       void Set_prof_debug( int * Graph_prof_debug ,
00131                            ofstream * Graph_fdebug ) ;
00132       int * Graph_prof_debug() {
00133             return _prof_debug ; } ;
00134       ofstream * Graph_fdebug() { return _fdebug ; } ;
00135 
00136 //      SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
00137 //      void SetObjRef( SUPERV::Graph_var aGraph ) {
00138 //                      _Graph = aGraph ; } ;
00139 //      Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
00140 //      void SetObjImpl( Graph_Impl * aGraphImpl ) {
00141 //                       _GraphImpl = aGraphImpl ; } ;
00142 
00143       void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
00144            GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
00145 
00146       const int GetGraphNodeIndex( const char *name ) {
00147             const int index = _MapOfGraphNodes[ name ] - 1 ;
00148 //            if ( index >= 0 )
00149 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
00150 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
00151 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
00152 #if 0
00153            cdebug << "Graph::GetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
00154            int i ;
00155            for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
00156              cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
00157            }
00158            map< string , int >::iterator aMapOfGraphNodesIterator ;
00159            i = 0 ;
00160            for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
00161              aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
00162              cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
00163                     << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
00164            }
00165 #endif
00166             return index ; } ;
00167       void SetGraphNodeIndex( const char *name , const int index ) {
00168            _MapOfGraphNodes[ name ] = index + 1 ;
00169            cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
00170                   << index << " Node " << (void *) _GraphNodes[ index ]
00171                   << " '" << _GraphNodes[ index ]->Name() << "' MapOfGraphNodessize "
00172                   << GetGraphNodeSize() << endl ;
00173 #if 1
00174            cdebug << "Graph::SetGraphNodeIndex " << _GraphNodesSize << " known nodes" << endl;
00175            int i ;
00176            for ( i = 0 ; i < _GraphNodesSize ; i++ ) {
00177              cdebug << "Node" << i << _GraphNodes[ i ]->Name() << endl ;
00178            }
00179            map< string , int >::iterator aMapOfGraphNodesIterator ;
00180            i = 0 ;
00181            for ( aMapOfGraphNodesIterator = _MapOfGraphNodes.begin() ;
00182              aMapOfGraphNodesIterator != _MapOfGraphNodes.end() ; aMapOfGraphNodesIterator++ ) {
00183              cdebug << "MapOfGraphNodes " << i++ << " " << aMapOfGraphNodesIterator->first
00184                     << " --> " << aMapOfGraphNodesIterator->second << " - 1" << endl ;
00185            }
00186 #endif
00187            } ;
00188       void DelGraphNodeIndex( const char *name ) {
00189            _MapOfGraphNodes.erase( name ) ; } ;
00190 
00191       int GetGraphNodeSize() const {
00192           return _MapOfGraphNodes.size() ; }
00193       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
00194             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
00195             return aNode ; } ;
00196       ComputingNode * GetChangeGraphNode( const int index ) const {
00197             if ( index >= 0 && index < _GraphNodesSize ) {
00198               ComputingNode * aNode = _GraphNodes[ index ] ;
00199               return aNode ;
00200             }
00201             else
00202               return NULL ; } ;
00203       const ComputingNode * GetGraphNode( const char *name ) {
00204             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
00205             return aNode ; } ;
00206       ComputingNode * GetChangeGraphNode( const char *name ) {
00207             int index = GetGraphNodeIndex( name ) ;
00208             if ( index >= 0 && index < _GraphNodesSize ) {
00209               ComputingNode * aNode = GetChangeGraphNode( index ) ;
00210               return aNode ;
00211             }
00212             else
00213               return NULL ; } ;
00214 
00215       const int GraphNodesSize() const {
00216             return _GraphNodesSize ; } ;
00217       ComputingNode * GraphNodes( int i ) const {
00218             return _GraphNodes[ i ] ; } ;
00219 
00220       const int HeadNodesSize() const {
00221             return _HeadNodesSize ; } ;
00222       ComputingNode * HeadNodes( int i ) const {
00223             return _HeadNodes[ i ] ; } ;
00224 
00225       const int QueueNodesSize() const {
00226             return _QueueNodesSize ; } ;
00227       ComputingNode * QueueNodes( int i ) const {
00228             return _QueueNodes[ i ] ; } ;
00229 
00230       const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
00231                                 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
00232       GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
00233                           return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
00234       const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
00235                                  return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
00236       GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
00237                            return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
00238 
00239       const GraphBase::InPort * GetInPort( const char * ToNodeName ,
00240                                           const char * ToServiceParameterName ) {
00241             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
00242             if ( aNode ) {
00243               return aNode->GetInPort(ToServiceParameterName);
00244          }
00245             else
00246               return NULL ; } ;
00247       GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
00248                                           const char * ToServiceParameterName ) {
00249             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
00250             if ( aNode ) {
00251               return aNode->GetChangeInPort( ToServiceParameterName ) ;
00252          }
00253             else
00254               return NULL ; } ;
00255       const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
00256                                     const char * FromServiceParameterName ) {
00257             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
00258             if ( aNode ) {
00259               return aNode->GetOutPort( FromServiceParameterName ) ;
00260          }
00261             else
00262               return NULL ; } ;
00263       GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
00264                                             const char * FromServiceParameterName ) {
00265             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
00266             if ( aNode ) {
00267               return aNode->GetChangeOutPort( FromServiceParameterName );
00268          }
00269             else
00270               return NULL ; } ;
00271 
00272       SUPERV::GraphState PortState( const char* NodeName ,
00273                                     const char* ServiceParameterName ) ;
00274       bool PortDone( const char* NodeName ,
00275                      const char* ServiceParameterName ) {
00276         bool aRet = false ;
00277         SUPERV::GraphState aState = PortState( NodeName ,
00278                                                 ServiceParameterName ) ;
00279         if ( aState == SUPERV::DoneState )
00280           aRet = true ;
00281         return aRet ; } ;
00282 //JR 30.03.2005      const CORBA::Any * PortInData( const char* ToNodeName ,
00283       const CORBA::Any PortInData( const char* ToNodeName ,
00284                                    const char* ToServiceParameterName ) ;
00285 //JR 30.03.2005      const CORBA::Any * PortOutData( const char* FromNodeName ,
00286       const CORBA::Any PortOutData( const char* FromNodeName ,
00287                                     const char* FromServiceParameterName ) ;
00288 
00289       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
00290                     GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
00291 
00292       GraphBase::SNode * GetInfo() const ;
00293       GraphBase::ListOfSNodes * GetNodes() const ;
00294       GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
00295       GraphBase::ListOfSGraphs * GetGraphs() const ;
00296       GraphBase::ListOfSLinks * GetDatas() const ;
00297 
00298       bool AddNode( ComputingNode * aNode ) ;
00299       bool RemoveNode( const char* NodeName ) ;
00300       bool ReNameNode( const char* OldNodeName ,
00301                        const char* NewNodeName ) ;
00302 
00303       bool AddLink( const char* FromNodeName ,
00304                     const char* FromServiceParameterName ,
00305                  const char* ToNodeName ,
00306                     const char* ToServiceParameterName ) ;
00307 //                    , const CORBA::Any aValue ) ;
00308       bool RemoveLink( const char* FromNodeName ,
00309                        const char* FromServiceParameterName ,
00310                     const char* ToNodeName ,
00311                        const char* ToServiceParameterName ) ;
00312       bool GetLink( const char* ToNodeName ,
00313                     const char* ToServiceParameterName ,
00314                     char** FromNodeName ,
00315                     char** FromServiceParameterName ) ;
00316       GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
00317                                   GraphBase::InPort* toPort ) ;
00318 
00319       bool AddInputData( const char* ToNodeName ,
00320                          const char* ToParameterName ,
00321                          const CORBA::Any aValue ) ;
00322       bool ChangeInputData( const char* ToNodeName ,
00323                             const char* ToParameterName ,
00324                             const CORBA::Any aValue ) ;
00325 //      bool AddInputData( const char* ToNodeName ,
00326 //                         const char* ToParameterName ,
00327 //                         const CORBA::Any ** aValue ) ;
00328 
00329       bool AddOutputData( const char* FromNodeName ,
00330                           const char* FromParameterName ,
00331                           const CORBA::Any aValue ) ;
00332 
00333       void SetGraphPorts() ;
00334 
00335       string Messages() ;
00336       void ReSetMessages() ;
00337       void SetMessages( string anErrorMessage ) ;
00338 
00339       bool CreateService() ;
00340       bool InLineServices() ;
00341 
00342       bool Sort( int & SubStreamGraphsNumber ) ;
00343       bool ValidLoops() const ;
00344       bool ValidSwitchs() const ;
00345       bool ComputingNodes() const ;
00346       bool LinkLoopNodes(bool & NewLink ) ;
00347       bool DataServerNodes() const ;
00348   
00349       long LevelMax() {
00350            return _LevelsNumber + 1 ; } ;
00351 
00352       map< string , GraphBase::Service * > MapOfServiceNames() ;
00353       GraphBase::Service * GetServiceOfMap( char * name ) ;
00354       bool SetServiceOfMap( GraphBase::Service * aService ) ;
00355       int GetNewServiceInstanceNumber( char * aServiceName ) ;
00356 
00357       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
00358       long ThreadsMax() {
00359            return _ThreadsMax ; } ;
00360 
00361       long SubGraphsNumber() {
00362            return _SubGraphsNumber ; } ;
00363 
00364       int NodesNumber(const int aLevel ) {
00365           return _NodesNumber[ aLevel ] ; } ;
00366       GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
00367              return (_SortedNodes[ aLevel ])[ index ] ; } ;
00368 
00369       bool StartComponent( const int aThread ,
00370                            const char * ComputerContainer ,
00371                            const char * ComponentName ,
00372                            Engines::Container_var & myContainer ,
00373                            Engines::Component_var & objComponent ) ;
00374 
00375   };
00376   
00377 };
00378 
00379 #endif