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 InNodes of the OutNode
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
64 vector<int > _NodesNumber ;
65 vector<vector<ComputingNode *> > _SortedNodes ;
67 vector<int > _CnxInPortsNumber ;
68 vector<int > _DecrInPortsNumber ;
71 vector<ComputingNode *> _HeadNodes ;
72 long _QueueNodesSize ;
73 vector<ComputingNode *> _QueueNodes ;
74 bool _ParallelExecutionNodes ;
76 bool AddLink( GraphBase::ComputingNode *fromNode ,
77 GraphBase::OutPort *fromPort ,
78 GraphBase::ComputingNode *toNode ,
79 GraphBase::InPort *toPort ) ;
84 Graph( CORBA::ORB_ptr ORB ,
85 SALOME_NamingService* ptrNamingService ,
86 const char *DataFlowName ,
87 const char * DebugFileName ) ;
88 Graph( CORBA::ORB_ptr ORB ,
89 SALOME_NamingService* ptrNamingService ,
90 const SALOME_ModuleCatalog::Service& DataFlowService ,
91 const char *DataFlowComponentName ,
92 const char *DataFlowInterfaceName ,
93 const char *DataFlowName ,
94 const SUPERV::KindOfNode DataFlowkind ,
95 const SUPERV::SDate DataFlowFirstCreation ,
96 const SUPERV::SDate DataFlowLastModification ,
97 const char * DataFlowEditorRelease ,
98 const char * DataFlowAuthor ,
99 const char * DataFlowComputer ,
100 const char * DataFlowComment ,
101 const char * DebugFileName ) ;
104 void Set_prof_debug( CORBA::ORB_ptr ORB ,
105 const char * DebugFileName ) ;
106 int * Graph_prof_debug() {
107 // MESSAGE( "Graph_prof_debug _Graph_prof_debug " << &_Graph_prof_debug << " _Graph_fdebug "
108 // << _Graph_fdebug ) ;
109 return &_Graph_prof_debug ; } ;
110 ofstream * Graph_fdebug() { return _Graph_fdebug ; } ;
112 SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
113 void SetObjRef( SUPERV::Graph_var aGraph ) {
114 _Graph = aGraph ; } ;
115 Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
116 void SetObjImpl( Graph_Impl * aGraphImpl ) {
117 _GraphImpl = aGraphImpl ; } ;
119 void AddLink( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
120 GetChangeGraphNode( FromNodeName )->AddLink( anOutNode ) ; } ;
122 const int GetGraphNodeIndex( const char *name ) {
123 const int index = _MapOfGraphNodes[ name ] - 1 ;
125 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
126 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
127 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
129 void SetGraphNodeIndex( const char *name , const int index ) {
130 _MapOfGraphNodes[ name ] = index + 1 ;
131 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
132 << index << " Node " << hex << (void *) _GraphNodes[ index ]
133 << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
135 void DelGraphNodeIndex( const char *name ) {
136 _MapOfGraphNodes.erase( name ) ; } ;
137 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
138 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
140 ComputingNode * GetChangeGraphNode( const int index ) const {
141 if ( index >= 0 && index < _GraphNodesSize ) {
142 ComputingNode * aNode = _GraphNodes[ index ] ;
147 const ComputingNode * GetGraphNode( const char *name ) {
148 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
150 ComputingNode * GetChangeGraphNode( const char *name ) {
151 int index = GetGraphNodeIndex( name ) ;
152 if ( index >= 0 && index < _GraphNodesSize ) {
153 ComputingNode * aNode = GetChangeGraphNode( index ) ;
159 const int GraphNodesSize() const {
160 return _GraphNodesSize ; } ;
161 ComputingNode * GraphNodes( int i ) const {
162 return _GraphNodes[ i ] ; } ;
164 const int HeadNodesSize() const {
165 return _HeadNodesSize ; } ;
166 ComputingNode * HeadNodes( int i ) const {
167 return _HeadNodes[ i ] ; } ;
169 const int QueueNodesSize() const {
170 return _QueueNodesSize ; } ;
171 ComputingNode * QueueNodes( int i ) const {
172 return _QueueNodes[ i ] ; } ;
174 const GraphBase::InPort *GetInPort( const char* ToNodeName ,
175 const char* ToServiceParameterName ) {
176 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
178 return aNode->GetInPort(ToServiceParameterName);
182 GraphBase::InPort *GetChangeInPort( const char* ToNodeName ,
183 const char* ToServiceParameterName ) {
184 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
186 return aNode->GetChangeInPort(ToServiceParameterName);
190 GraphBase::OutPort *GetChangeOutPort(
191 const char* FromNodeName ,
192 const char* FromServiceParameterName ) {
193 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
195 return aNode->GetChangeOutPort( FromServiceParameterName );
200 SUPERV::GraphState PortState( const char* NodeName ,
201 const char* ServiceParameterName ) ;
202 bool PortDone( const char* NodeName ,
203 const char* ServiceParameterName ) {
205 SUPERV::GraphState aState = PortState( NodeName ,
206 ServiceParameterName ) ;
207 if ( aState == SUPERV::DoneState )
210 const CORBA::Any * PortInData( const char* ToNodeName ,
211 const char* ToServiceParameterName ) ;
212 const CORBA::Any * PortOutData( const char* FromNodeName ,
213 const char* FromServiceParameterName ) ;
215 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
216 GraphBase::SGraph & aDataFlow ) ;
218 GraphBase::SNode * GetInfo() const ;
219 GraphBase::ListOfNodes * GetNodes() const ;
220 GraphBase::ListOfLinks * GetLinks(bool AllLinks = false ) const ;
221 GraphBase::ListOfGraphs * GetGraphs() const ;
222 GraphBase::ListOfLinks * GetDatas() const ;
223 // SALOME_ModuleCatalog::Service * GetService() const ;
225 bool AddNode( ComputingNode * aNode ) ;
226 bool RemoveNode( const char* NodeName ) ;
227 bool ReNameNode( const char* OldNodeName ,
228 const char* NewNodeName ) ;
230 bool AddLink( const char* FromNodeName ,
231 const char* FromServiceParameterName ,
232 const char* ToNodeName ,
233 const char* ToServiceParameterName ,
234 const CORBA::Any aValue ) ;
235 bool RemoveLink( const char* FromNodeName ,
236 const char* FromServiceParameterName ,
237 const char* ToNodeName ,
238 const char* ToServiceParameterName ) ;
239 bool GetLink( const char* ToNodeName ,
240 const char* ToServiceParameterName ,
241 char** FromNodeName ,
242 char** FromServiceParameterName ) ;
243 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
244 GraphBase::InPort* toPort ) ;
246 bool AddInputData( const char* ToNodeName ,
247 const char* ToParameterName ,
248 const CORBA::Any aValue ) ;
249 bool ChangeInputData( const char* ToNodeName ,
250 const char* ToParameterName ,
251 const CORBA::Any aValue ) ;
252 bool AddInputData( const char* ToNodeName1 ,
253 const char* ToParameterName1 ,
254 const char* ToNodeName2 ,
255 const char* ToParameterName2 ) ;
257 bool AddInputData( const char* ToNodeName ,
258 const char* ToParameterName ,
259 const CORBA::Any ** aValue ) ;
261 bool AddOutputData( const char* FromNodeName ,
262 const char* FromParameterName ,
263 const CORBA::Any aValue ) ;
265 bool CreateService() ;
266 bool InLineServices() ;
269 bool ComputingNodes() const ;
270 bool LinkLoopNodes(bool & NewLink ) ;
271 bool DataServerNodes() const ;
274 return _LevelsNumber + 1 ; } ;
275 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
277 return _ThreadsMax ; } ;
278 long GraphsNumber() {
279 return _GraphsNumber ; } ;
281 int NodesNumber(const int aLevel ) {
282 return _NodesNumber[ aLevel ] ; } ;
283 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
284 return (_SortedNodes[ aLevel ])[ index ] ; } ;
286 bool StartComponent( const int aThread ,
287 const char * ComputerContainer ,
288 const char * ComponentName ,
289 Engines::Container_var & myContainer ,
290 Engines::Component_var & objComponent ) ;