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 ostream * _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() { return &_Graph_prof_debug ; } ;
107 ostream * Graph_fdebug() { return _Graph_fdebug ; } ;
109 SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
110 void SetObjRef( SUPERV::Graph_var aGraph ) {
111 _Graph = aGraph ; } ;
112 Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
113 void SetObjImpl( Graph_Impl * aGraphImpl ) {
114 _GraphImpl = aGraphImpl ; } ;
116 void AddLink( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
117 GetChangeGraphNode( FromNodeName )->AddLink( anOutNode ) ; } ;
119 const int GetGraphNodeIndex( const char *name ) {
120 const int index = _MapOfGraphNodes[ name ] - 1 ;
122 // cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
123 // << index << " Node " << hex << (void *) _GraphNodes[ index ]
124 // << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
126 void SetGraphNodeIndex( const char *name , const int index ) {
127 _MapOfGraphNodes[ name ] = index + 1 ;
128 cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
129 << index << " Node " << hex << (void *) _GraphNodes[ index ]
130 << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
132 void DelGraphNodeIndex( const char *name ) {
133 _MapOfGraphNodes.erase( name ) ; } ;
134 const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
135 const ComputingNode * aNode = GetChangeGraphNode( index ) ;
137 ComputingNode * GetChangeGraphNode( const int index ) const {
138 if ( index >= 0 && index < _GraphNodesSize ) {
139 ComputingNode * aNode = _GraphNodes[ index ] ;
144 const ComputingNode * GetGraphNode( const char *name ) {
145 const ComputingNode * aNode = GetChangeGraphNode( name ) ;
147 ComputingNode * GetChangeGraphNode( const char *name ) {
148 int index = GetGraphNodeIndex( name ) ;
149 if ( index >= 0 && index < _GraphNodesSize ) {
150 ComputingNode * aNode = GetChangeGraphNode( index ) ;
156 const int GraphNodesSize() const {
157 return _GraphNodesSize ; } ;
158 ComputingNode * GraphNodes( int i ) const {
159 return _GraphNodes[ i ] ; } ;
161 const int HeadNodesSize() const {
162 return _HeadNodesSize ; } ;
163 ComputingNode * HeadNodes( int i ) const {
164 return _HeadNodes[ i ] ; } ;
166 const int QueueNodesSize() const {
167 return _QueueNodesSize ; } ;
168 ComputingNode * QueueNodes( int i ) const {
169 return _QueueNodes[ i ] ; } ;
171 const GraphBase::InPort *GetInPort( const char* ToNodeName ,
172 const char* ToServiceParameterName ) {
173 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
175 return aNode->GetInPort(ToServiceParameterName);
179 GraphBase::InPort *GetChangeInPort( const char* ToNodeName ,
180 const char* ToServiceParameterName ) {
181 ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
183 return aNode->GetChangeInPort(ToServiceParameterName);
187 GraphBase::OutPort *GetChangeOutPort(
188 const char* FromNodeName ,
189 const char* FromServiceParameterName ) {
190 ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
192 return aNode->GetChangeOutPort( FromServiceParameterName );
197 SUPERV::GraphState PortState( const char* NodeName ,
198 const char* ServiceParameterName ) ;
199 bool PortDone( const char* NodeName ,
200 const char* ServiceParameterName ) {
202 SUPERV::GraphState aState = PortState( NodeName ,
203 ServiceParameterName ) ;
204 if ( aState == SUPERV::DoneState )
207 const CORBA::Any * PortInData( const char* ToNodeName ,
208 const char* ToServiceParameterName ) ;
209 const CORBA::Any * PortOutData( const char* FromNodeName ,
210 const char* FromServiceParameterName ) ;
212 bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
213 GraphBase::SGraph & aDataFlow ) ;
215 GraphBase::SNode * GetInfo() const ;
216 GraphBase::ListOfNodes * GetNodes() const ;
217 GraphBase::ListOfLinks * GetLinks() const ;
218 GraphBase::ListOfGraphs * GetGraphs() const ;
219 GraphBase::ListOfLinks * GetDatas() const ;
220 // SALOME_ModuleCatalog::Service * GetService() const ;
222 bool AddNode( ComputingNode * aNode ) ;
223 bool RemoveNode( const char* NodeName ) ;
224 bool ReNameNode( const char* OldNodeName ,
225 const char* NewNodeName ) ;
227 bool AddLink( const char* FromNodeName ,
228 const char* FromServiceParameterName ,
229 const char* ToNodeName ,
230 const char* ToServiceParameterName ,
231 const CORBA::Any aValue ) ;
232 bool RemoveLink( const char* FromNodeName ,
233 const char* FromServiceParameterName ,
234 const char* ToNodeName ,
235 const char* ToServiceParameterName ) ;
236 bool GetLink( const char* ToNodeName ,
237 const char* ToServiceParameterName ,
238 char** FromNodeName ,
239 char** FromServiceParameterName ) ;
240 GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
241 GraphBase::InPort* toPort ) ;
243 bool AddInputData( const char* ToNodeName ,
244 const char* ToParameterName ,
245 const CORBA::Any aValue ) ;
246 bool ChangeInputData( const char* ToNodeName ,
247 const char* ToParameterName ,
248 const CORBA::Any aValue ) ;
249 bool AddInputData( const char* ToNodeName1 ,
250 const char* ToParameterName1 ,
251 const char* ToNodeName2 ,
252 const char* ToParameterName2 ) ;
254 bool AddInputData( const char* ToNodeName ,
255 const char* ToParameterName ,
256 const CORBA::Any ** aValue ) ;
258 bool AddOutputData( const char* FromNodeName ,
259 const char* FromParameterName ,
260 const CORBA::Any aValue ) ;
262 bool CreateService() ;
263 bool InLineServices() ;
266 bool ComputingNodes() const ;
267 bool DataServerNodes() const ;
270 return _LevelsNumber + 1 ; } ;
271 SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
273 return _ThreadsMax ; } ;
274 long GraphsNumber() {
275 return _GraphsNumber ; } ;
277 int NodesNumber(const int aLevel ) {
278 return _NodesNumber[ aLevel ] ; } ;
279 GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
280 return (_SortedNodes[ aLevel ])[ index ] ; } ;
282 bool StartComponent( const int aThread ,
283 const char * ComputerContainer ,
284 const char * ComponentName ,
285 Engines::Container_var & myContainer ,
286 Engines::Component_var & objComponent ) ;