1 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_Graph.hxx
25 // Author : Jean Rahuel, CEA
29 #ifndef _DATAFLOWBASE_GRAPH_HXX
30 #define _DATAFLOWBASE_GRAPH_HXX
32 #include "DataFlowBase_FactoryNode.hxx"
33 #include "DataFlowBase_LoopNode.hxx"
34 #include "DataFlowBase_EndOfLoopNode.hxx"
35 #include "DataFlowBase_SwitchNode.hxx"
36 #include "DataFlowBase_EndOfSwitchNode.hxx"
37 #include "DataFlowBase_DataNode.hxx"
43 class Graph : public DataNode {
47 // int _Graph_prof_debug;
48 // ofstream * _Graph_fdebug;
50 SUPERV::Graph_var _Graph ;
51 Graph_Impl * _GraphImpl ;
53 // Map of Nodes of the Graph
54 map< string , int > _MapOfGraphNodes ;
55 long _GraphNodesSize ;
56 vector<bool > _Sorted ;
57 vector<ComputingNode *> _GraphNodes ;
59 // _SortedNodes[ _LevelsNumber ] : topological sort from 0 to _LevelsNumber
60 // _SortedNodes[ _level ][ _NodesNumber[ _level ] ] : _NodesNumber[ _level ] Nodes in the level
63 vector<int > _NodesNumber ;
64 vector<vector<ComputingNode *> > _SortedNodes ;
66 vector<int > _CnxInPortsNumber ;
67 vector<int > _DecrInPortsNumber ;
70 vector<ComputingNode *> _HeadNodes ;
71 long _QueueNodesSize ;
72 vector<ComputingNode *> _QueueNodes ;
73 bool _ParallelExecutionNodes ;
75 // For generated NodeNames with ServiceName : number of Nodes using
76 // the same ServiceName. It is not the same Service if it belongs to
77 // a different Interface and/or a different Component ...
78 map< string , GraphBase::Service * > _MapOfServiceNames ;
80 // Total number of SubGraphs
81 int _SubGraphsNumber ;
82 // _SubGraphs[ SubGraphNumero ] [ NodeNumero ]
83 // SubGraphNumero : [ 0 , _SubGraphsSize [ ; NodeNumero : [ 0 , _SubGraphs[ SubGraphNumero ].size() [
85 vector<vector<ComputingNode *> > _SubGraphs ;
87 // _SubStreamGraphs[ SubStreamGraphNumero ] [ NodeNumero ]
88 // SubStreamGraphNumero : [ 0 , _SubStreamGraphsSize [
89 // NodeNumero : [ 0 , _SubStreamGraphs[ SubStreamGraphNumero ].size() [
90 // int _SubStreamGraphsSize ;
91 // vector<vector<ComputingNode *> > _SubStreamGraphs ;
93 bool AddLink( GraphBase::ComputingNode *fromNode ,
94 GraphBase::OutPort *fromPort ,
95 GraphBase::ComputingNode *toNode ,
96 GraphBase::InPort *toPort ) ;
101 Graph( CORBA::ORB_ptr ORB ,
102 SALOME_NamingService* ptrNamingService ,
103 const char *DataFlowName ,
104 const SUPERV::KindOfNode DataFlowkind ,
105 int * Graph_prof_debug ,
106 ofstream * Graph_fdebug ) ;
107 // const char * DebugFileName ) ;
108 Graph( CORBA::ORB_ptr ORB ,
109 SALOME_NamingService* ptrNamingService ,
110 const SALOME_ModuleCatalog::Service& DataFlowService ,
111 const char *DataFlowComponentName ,
112 const char *DataFlowInterfaceName ,
113 const char *DataFlowName ,
114 const SUPERV::KindOfNode DataFlowkind ,
115 const SUPERV::SDate DataFlowFirstCreation ,
116 const SUPERV::SDate DataFlowLastModification ,
117 const char * DataFlowEditorRelease ,
118 const char * DataFlowAuthor ,
119 const char * DataFlowComputer ,
120 const char * DataFlowComment ,
121 int * Graph_prof_debug ,
122 ofstream * Graph_fdebug ) ;
123 // const char * DebugFileName ) ;
126 // void Set_prof_debug( CORBA::ORB_ptr ORB ,
127 // const char * DebugFileName ) ;
128 void Set_prof_debug( int * Graph_prof_debug ,
129 ofstream * Graph_fdebug ) ;
130 int * Graph_prof_debug() {
131 return _prof_debug ; } ;
132 ofstream * Graph_fdebug() { return _fdebug ; } ;
134 SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
135 void SetObjRef( SUPERV::Graph_var aGraph ) {
136 _Graph = aGraph ; } ;
137 Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
138 void SetObjImpl( Graph_Impl * aGraphImpl ) {
139 _GraphImpl = aGraphImpl ; } ;
141 void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
142 GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
144 const int GetGraphNodeIndex( const char *name ) {
145 const int index = _MapOfGraphNodes[ name ] - 1 ;
147 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
148 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
149 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
151 void SetGraphNodeIndex( const char *name , const int index ) {
152 _MapOfGraphNodes[ name ] = index + 1 ;
153 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
154 << index << " Node " << hex << (void *) _GraphNodes[ index ]
155 << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
157 void DelGraphNodeIndex( const char *name ) {
158 _MapOfGraphNodes.erase( name ) ; } ;
160 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
161 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
163 ComputingNode * GetChangeGraphNode( const int index ) const {
164 if ( index >= 0 && index < _GraphNodesSize ) {
165 ComputingNode * aNode = _GraphNodes[ index ] ;
170 const ComputingNode * GetGraphNode( const char *name ) {
171 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
173 ComputingNode * GetChangeGraphNode( const char *name ) {
174 int index = GetGraphNodeIndex( name ) ;
175 if ( index >= 0 && index < _GraphNodesSize ) {
176 ComputingNode * aNode = GetChangeGraphNode( index ) ;
182 const int GraphNodesSize() const {
183 return _GraphNodesSize ; } ;
184 ComputingNode * GraphNodes( int i ) const {
185 return _GraphNodes[ i ] ; } ;
187 const int HeadNodesSize() const {
188 return _HeadNodesSize ; } ;
189 ComputingNode * HeadNodes( int i ) const {
190 return _HeadNodes[ i ] ; } ;
192 const int QueueNodesSize() const {
193 return _QueueNodesSize ; } ;
194 ComputingNode * QueueNodes( int i ) const {
195 return _QueueNodes[ i ] ; } ;
197 const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
198 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
199 GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
200 return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
201 const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
202 return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
203 GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
204 return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
206 const GraphBase::InPort * GetInPort( const char * ToNodeName ,
207 const char * ToServiceParameterName ) {
208 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
210 return aNode->GetInPort(ToServiceParameterName);
214 GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
215 const char * ToServiceParameterName ) {
216 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
218 return aNode->GetChangeInPort( ToServiceParameterName ) ;
222 const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
223 const char * FromServiceParameterName ) {
224 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
226 return aNode->GetOutPort( FromServiceParameterName ) ;
230 GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
231 const char * FromServiceParameterName ) {
232 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
234 return aNode->GetChangeOutPort( FromServiceParameterName );
239 SUPERV::GraphState PortState( const char* NodeName ,
240 const char* ServiceParameterName ) ;
241 bool PortDone( const char* NodeName ,
242 const char* ServiceParameterName ) {
244 SUPERV::GraphState aState = PortState( NodeName ,
245 ServiceParameterName ) ;
246 if ( aState == SUPERV::DoneState )
249 const CORBA::Any * PortInData( const char* ToNodeName ,
250 const char* ToServiceParameterName ) ;
251 const CORBA::Any * PortOutData( const char* FromNodeName ,
252 const char* FromServiceParameterName ) ;
254 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
255 GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
257 GraphBase::SNode * GetInfo() const ;
258 GraphBase::ListOfSNodes * GetNodes() const ;
259 GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
260 GraphBase::ListOfSGraphs * GetGraphs() const ;
261 GraphBase::ListOfSLinks * GetDatas() const ;
263 bool AddNode( ComputingNode * aNode ) ;
264 bool RemoveNode( const char* NodeName ) ;
265 bool ReNameNode( const char* OldNodeName ,
266 const char* NewNodeName ) ;
268 bool AddLink( const char* FromNodeName ,
269 const char* FromServiceParameterName ,
270 const char* ToNodeName ,
271 const char* ToServiceParameterName ) ;
272 // , const CORBA::Any aValue ) ;
273 bool RemoveLink( const char* FromNodeName ,
274 const char* FromServiceParameterName ,
275 const char* ToNodeName ,
276 const char* ToServiceParameterName ) ;
277 bool GetLink( const char* ToNodeName ,
278 const char* ToServiceParameterName ,
279 char** FromNodeName ,
280 char** FromServiceParameterName ) ;
281 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
282 GraphBase::InPort* toPort ) ;
284 bool AddInputData( const char* ToNodeName ,
285 const char* ToParameterName ,
286 const CORBA::Any aValue ) ;
287 bool ChangeInputData( const char* ToNodeName ,
288 const char* ToParameterName ,
289 const CORBA::Any aValue ) ;
290 bool AddInputData( const char* ToNodeName ,
291 const char* ToParameterName ,
292 const CORBA::Any ** aValue ) ;
294 bool AddOutputData( const char* FromNodeName ,
295 const char* FromParameterName ,
296 const CORBA::Any aValue ) ;
298 void SetGraphPorts() ;
300 bool CreateService() ;
301 bool InLineServices() ;
303 bool Sort( int & SubStreamGraphsNumber ) ;
304 bool ComputingNodes() const ;
305 bool LinkLoopNodes(bool & NewLink ) ;
306 bool DataServerNodes() const ;
309 return _LevelsNumber + 1 ; } ;
311 map< string , GraphBase::Service * > MapOfServiceNames() ;
312 GraphBase::Service * GetServiceOfMap( char * name ) ;
313 bool SetServiceOfMap( GraphBase::Service * aService ) ;
314 int GetServiceNameNumber( SALOME_ModuleCatalog::Service aService ) ;
316 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
318 return _ThreadsMax ; } ;
320 long SubGraphsNumber() {
321 return _SubGraphsNumber ; } ;
323 int NodesNumber(const int aLevel ) {
324 return _NodesNumber[ aLevel ] ; } ;
325 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
326 return (_SortedNodes[ aLevel ])[ index ] ; } ;
328 bool StartComponent( const int aThread ,
329 const char * ComputerContainer ,
330 const char * ComponentName ,
331 Engines::Container_var & myContainer ,
332 Engines::Component_var & objComponent ) ;