1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : DataFlowExecutor_DataFlow.cxx
28 #include "DataFlowExecutor_DataFlow.hxx"
29 #include "DataFlowEditor_DataFlow.hxx"
31 // Implementation de la classe GraphExecutor::Graph
33 GraphExecutor::DataFlow::DataFlow() :
35 cdebug_in << "GraphExecutor::DataFlow::DataFlowExecutor()" << endl;
37 _theNamingService = NULL ;
39 cdebug_out << "GraphExecutor::DataFlow::DataFlowExecutor()" << endl;
42 GraphExecutor::DataFlow::DataFlow( CORBA::ORB_ptr ORB,
43 SALOME_NamingService* ptrNamingService ,
44 const char *DataFlowName ,
45 const char * DebugFileName ,
46 const SUPERV::KindOfNode aKindOfNode ) :
47 OutNode( ORB, ptrNamingService , DataFlowName , DebugFileName , aKindOfNode ) {
48 cdebug_in << "GraphExecutor::DataFlow::DataFlow(" ;
50 cdebug << DataFlowName ;
52 cdebug << ")" << endl;
54 _theNamingService = ptrNamingService ;
56 cdebug_out << "GraphExecutor::DataFlow::DataFlow" << endl;
59 GraphExecutor::DataFlow::DataFlow( CORBA::ORB_ptr ORB,
60 SALOME_NamingService* ptrNamingService ,
61 const SALOME_ModuleCatalog::Service& DataFlowService ,
62 const char *DataFlowComponentName ,
63 const char *DataFlowInterfaceName ,
64 const char *DataFlowName ,
65 const SUPERV::KindOfNode DataFlowkind ,
66 const SUPERV::SDate DataFlowFirstCreation ,
67 const SUPERV::SDate DataFlowLastModification ,
68 const char * DataFlowExecutorRelease ,
69 const char * DataFlowAuthor ,
70 const char * DataFlowComputer ,
71 const char * DataFlowComment ,
72 const char * DebugFileName ) :
73 OutNode( ORB, ptrNamingService , DataFlowService , DataFlowComponentName ,
74 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
75 DataFlowFirstCreation , DataFlowLastModification ,
76 DataFlowExecutorRelease , DataFlowAuthor ,
77 DataFlowComputer , DataFlowComment , DebugFileName ) {
78 cdebug_in << "GraphExecutor::DataFlow::DataFlow(" << DataFlowName << ")" << endl;
80 _theNamingService = ptrNamingService ;
82 cdebug_out << "GraphExecutor::DataFlow::DataFlow" << endl;
85 GraphExecutor::DataFlow::~DataFlow() {
86 // delete _DataFlowNode ;
87 // delete _DataFlowDatas ;
91 bool GraphExecutor::DataFlow::Ping( const char *aNodeName ) {
92 cdebug_in << "GraphExecutor::DataFlow::Ping" << aNodeName << " )" << endl;
94 if ( Graph()->GetGraphNode( aNodeName ) )
95 RetVal = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode())->Ping() ;
96 cdebug_out << "GraphExecutor::DataFlow::Ping" << endl;
100 bool GraphExecutor::DataFlow::ContainerKill() {
101 cdebug_in << "GraphExecutor::DataFlow::ContainerKill()" << endl;
102 bool RetVal = GraphExecutor::OutNode::ContainerKill() ;
103 cdebug_out << "GraphExecutor::DataFlow::ContainerKill()" << endl;
107 bool GraphExecutor::DataFlow::ContainerKill( const char *aNodeName ) {
108 // cdebug_in << "GraphExecutor::DataFlow::ContainerKill( " << aNodeName << " )"<< endl;
109 bool RetVal = false ;
110 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
112 RetVal = aNode->ContainerKill() ;
114 // cdebug_out << "GraphExecutor::DataFlow::ContainerKill" << endl;
118 bool GraphExecutor::DataFlow::InputOfAny( const char * ToServiceParameterName ,
119 const CORBA::Any & aValue ,
120 bool SomeDataReady ) {
121 cdebug_in <<"GraphExecutor::DataFlow::InputOfAny( " << ToServiceParameterName
122 << " SomeDataReady " << SomeDataReady << " )" << endl ;
123 bool RetVal = false ;
124 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny " << Name() << "( "
125 << ToServiceParameterName << " , aValue , SomeDataReady " << SomeDataReady << " ) "
127 if ( Graph()->GraphMacroLevel() ) {
128 GraphBase::OutPort * anOutPort ;
129 anOutPort = Graph()->GetChangeInDataNodePort( ToServiceParameterName ) ;
130 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny " << Name()
131 << " " << State() << " " << ToServiceParameterName << " " << anOutPort->PortState()
132 << " Done : " << anOutPort->PortDone() << endl ;
133 RetVal = AddInputData( Name() , ToServiceParameterName , aValue ) ;
134 anOutPort->PortState( SUPERV::ReadyState ) ;
135 // There is only one port :
136 anOutPort->ChangeInPorts( 0 )->PortState( SUPERV::ReadyState ) ;
137 anOutPort->PortDone( true ) ;
138 // There is only one inport of a Node in an ReversedOutport of a graph :
139 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( anOutPort->InPorts( 0 )->NodeName() )->GetInNode() ;
140 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny : " << anInNode->Name()
141 << "->SendSomeDataReady( " << Name() << " ) for Port "
142 << anOutPort->InPorts( 0 )->PortName() << " SomeDataReady " << SomeDataReady << endl ;
143 if ( SomeDataReady ) {
144 MESSAGE( "GraphExecutor::InputOfAny " << Name() << " SendSomeDataReady --> " << anInNode->Name()
145 << " " << anInNode->State() << " " << anOutPort->InPorts( 0 )->PortName() ) ;
146 int sts = anInNode->SendSomeDataReady( Name() ) ;
147 cdebug << "GraphExecutor::DataFlow::InputOfAny " << anInNode->Name()
148 << "->SendSomeDataReady( " << Name() << " ) sts " << sts << " State "
149 << anInNode->State() << " IsReady " << anInNode->IsReady()
150 << " SomeDataReady " << SomeDataReady << endl ;
151 //JR 15.04.2005 Debug PAL8624 RetroConception :
152 if ( sts && anInNode->HasAllDataReady() ) {
153 cdebug << pthread_self() << "/" << anInNode->ThreadNo()
154 << "GraphExecutor::DataFlow::InputOfAny : "
155 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
156 << " " << anInNode->Name() << "->HasAllDataReady() " << anInNode->HasAllDataReady()
157 << " State " << anInNode->State() << endl ;
158 anInNode->ThreadNo( 0 ) ;
159 anInNode->CreateNewThread( true ) ;
160 if ( !anInNode->SendEvent( GraphExecutor::AllDataReadyEvent ) ) { // ==> Ready to execute
161 //JR 06.05.2005 Debug PAL8624 RetroConception :
163 if ( res && anInNode->IsReady() ) {
164 cdebug << pthread_self() << "/" << anInNode->ThreadNo() << "GraphExecutor::DataFlow::InputOfAny : "
165 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
166 << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
167 << anInNode->State() << endl ;
168 //JR 15.04.2005 Debug PAL8624 RetroConception :
169 // if ( anInNode->IsLockedDataWait() ) {
170 // cdebug << pthread_self() << "/" << anInNode->ThreadNo() << "GraphExecutor::DataFlow::InputOfAny : "
171 // << anInNode->Name() << " IsLockedDataWait() ==> UnLockDataWait" << endl ;
172 // anInNode->UnLockDataWait() ;
174 anInNode->ThreadNo( 0 ) ;
175 anInNode->CreateNewThread( true ) ;
176 anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
177 // State( GraphExecutor::ExecutingState ) ;
182 cdebug << pthread_self() << "/" << anInNode->ThreadNo()
183 << "GraphExecutor::DataFlow::InputOfAny : NotAllDataReady ERROR : "
184 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
185 << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
186 << anInNode->State() << endl ;
190 cdebug << pthread_self() << "/" << anInNode->ThreadNo()
191 << "GraphExecutor::DataFlow::InputOfAny : NotAllDataReady : "
192 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
193 << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
194 << anInNode->State() << endl ;
198 cdebug << "GraphExecutor::DataFlow::InputOfAny " << anInNode->Name()
199 << "->SendSomeDataReady( " << Name() << " ) State "
200 << anInNode->State() << " IsReady " << anInNode->IsReady()
201 << " SomeDataReady " << SomeDataReady << endl ;
205 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny GraphMacroLevel "
206 << Graph()->GraphMacroLevel() << " ERROR" << endl ;
207 MESSAGE( "GraphExecutor::DataFlow::InputOfAny GraphMacroLevel " << Graph()->GraphMacroLevel()
210 cdebug_out << pthread_self() << " GraphExecutor::DataFlow::InputOfAny " << RetVal << endl ;
214 bool GraphExecutor::DataFlow::OutputOfAny( const char * aNodeName ,
215 const char * ToServiceParameterName ,
216 const CORBA::Any & aValue ) {
217 cdebug_in << pthread_self() << "/" << ThreadNo() << "GraphExecutor::DataFlow::OutputOfAny( " << aNodeName
218 << " , " << ToServiceParameterName
219 << " , aValue ) from " << Name() << endl ;
220 bool RetVal = false ;
221 GraphBase::Graph * aMacroNode = (GraphBase::Graph * ) Graph()->GetChangeGraphNode( aNodeName ) ;
222 // GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aMacroGraph->GetInNode() ;
223 RetVal = Graph()->AddOutputData( aNodeName , ToServiceParameterName , aValue ) ;
224 GraphBase::OutPort * anOutPort = aMacroNode->GetChangeOutPort( ToServiceParameterName ) ;
226 for ( i = 0 ; i < aMacroNode->GetNodeOutPortsSize() ; i++ ) {
227 cdebug << "Out" << i << " " << aMacroNode->GetNodeOutPort( i )->PortName() << " "
228 << aMacroNode->GetChangeNodeOutPort( i )->PortState() << " Done="
229 << aMacroNode->GetChangeNodeOutPort( i )->PortDone() << " " ;
230 if ( GraphBase::Base::_prof_debug ) {
231 aMacroNode->GetNodeOutPort( i )->StringValue( *GraphBase::Base::_fdebug ) ;
233 if ( aMacroNode->GetChangeNodeOutPort( i )->IsGate() ) {
234 cdebug << " BoolValue " << aMacroNode->GetChangeNodeOutPort( i )->BoolValue() ;
238 // Loop over Inports linked to that OutPort of the MacroNode
239 for ( i = 0 ; i < anOutPort->InPortsSize() ; i++ ) {
240 const char * ToNodeName = anOutPort->ChangeInPorts( i )->NodeName() ;
241 const char * ToParameterName = anOutPort->ChangeInPorts( i )->PortName() ;
242 if ( strcmp( ToNodeName , Name() ) ) {
243 GraphBase::ComputingNode * aComputingNode = Graph()->GetChangeGraphNode( ToNodeName ) ;
244 GraphExecutor::InNode * aLinkedNode = (GraphExecutor::InNode * ) aComputingNode->GetInNode() ;
245 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
246 << "GraphExecutor::DataFlow::OutputOfAny to Node "
247 << ToNodeName << "(" << ToParameterName << ") from MacroNode " << aNodeName << endl ;
249 //JR 15.04.2005 Debug PAL8624 RetroConception :
250 // if ( aLinkedNode->IsLockedDataWait() ) {
251 // cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
252 // << " IsLockedDataWait --> UnLockDataWait" << endl ;
254 aLinkedNode->LockDataReady() ;
255 sts = aLinkedNode->SendSomeDataReady( (char * ) aNodeName ) ;
256 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
257 << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
258 << "->SendSomeDataReady( " << aNodeName << " ) sts " << sts << " " << aLinkedNode->State() << endl ;
260 // if ( aLinkedNode->State() == GraphExecutor::DataReadyState ) {
261 if ( aLinkedNode->HasAllDataReady() ) {
262 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
263 << "GraphExecutor::DataFlow::OutputOfAny SendEvent(ExecuteEvent) to "
264 << aLinkedNode->Name() << endl ;
265 //JR 15.04.2005 Debug PAL8624 RetroConception :
266 // aLinkedNode->CreateNewThreadIf( true ) ;
267 // aLinkedNode->UnLockDataWait() ;
268 aLinkedNode->CreateNewThread( true ) ;
269 aLinkedNode->UnLockDataReady() ;
270 aLinkedNode->HasAllDataReady( false ) ;
271 // aLinkedNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
272 aLinkedNode->SendEvent( GraphExecutor::AllDataReadyEvent ) ;
275 aLinkedNode->UnLockDataReady() ;
276 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
277 << "GraphExecutor::DataFlow::OutputOfAny NO SendEvent(ExecuteEvent) to "
278 << aLinkedNode->Name() << endl ;
282 aLinkedNode->UnLockDataReady() ;
285 else if ( Graph()->GraphMacroLevel() != 0 ) {
286 cdebug << pthread_self() << "/" << Graph()->CoupledNode()->ThreadNo()
287 << "GraphExecutor::DataFlow::OutputOfAny to that graph "
288 << ToNodeName << "(" << ToParameterName << ") " << State() << " " << Graph()->CoupledNodeName ()
289 << " sended recursively to the MacroNode coupled to that graph" << endl ;
290 Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( Graph()->CoupledNodeName() ,
292 //JR 30.03.2005 *anOutPort->Value() ) ;
293 anOutPort->Value() ) ;
296 cdebug << pthread_self() << "GraphExecutor::DataFlow::OutputOfAny to Node "
297 << ToNodeName << "(" << ToParameterName << ") from MacroNode " << aNodeName
298 << ") ignored" << endl ;
301 cdebug_out << pthread_self() << "/" << ThreadNo() << " GraphExecutor::DataFlow::OutputOfAny " << RetVal
306 //JR NPAL14110 09.02.2007 : SetWaitingStates was missing in SubGraph of MacroNode !...
307 bool GraphExecutor::DataFlow::SetWaitingStates( const char * ToServiceParameterName ) {
308 cdebug_in << pthread_self() << "/" << ThreadNo() << "GraphExecutor::DataFlow::SetWaitingStates( "
309 << ToServiceParameterName << " ) MacroGraph " << Name() << endl ;
311 State( GraphExecutor::DataWaitingState ) ;
313 GraphBase::OutPort * anOutPort ;
314 anOutPort = Graph()->GetChangeInDataNodePort( ToServiceParameterName ) ;
315 anOutPort->PortState( SUPERV::WaitingState ) ;
316 anOutPort->PortDone( false ) ;
317 cdebug << pthread_self() << "GraphExecutor::DataFlow::SetWaitingStates " << Name()
318 << " " << State() << " " << ToServiceParameterName << " " << anOutPort->PortState()
319 << " Done : " << anOutPort->PortDone() << endl ;
320 if ( ! anOutPort->IsGate() ) {
321 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( anOutPort->InPorts( 0 )->NodeName() )->GetInNode() ;
322 cdebug << pthread_self() << "GraphExecutor::DataFlow::SetWaitingStates : "
323 << anInNode->Name() << "->SetWaitingStates( NULL ) for Port "
324 << anOutPort->InPorts( 0 )->PortName() << endl ;
325 anInNode->SetWaitingStates( NULL ) ;
327 cdebug_out << "GraphExecutor::DataFlow::SetWaitingStates() " << RetVal << endl;
331 bool GraphExecutor::DataFlow::Kill() {
332 cdebug_in << "GraphExecutor::DataFlow::Kill()" << endl;
333 bool RetVal = GraphExecutor::OutNode::Kill() ;
334 cdebug_out << "GraphExecutor::DataFlow::Kill() " << RetVal << endl;
338 bool GraphExecutor::DataFlow::Kill( const char *aNodeName ) {
339 // cdebug_in << "GraphExecutor::DataFlow::Kill( " << aNodeName << " )"<< endl;
340 bool RetVal = false ;
341 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
343 RetVal = aNode->Kill() ;
345 // cdebug_out << "GraphExecutor::DataFlow::Kill" << endl;
349 bool GraphExecutor::DataFlow::KillDone( const char *aNodeName ) {
350 // cdebug_in << "GraphExecutor::DataFlow::KillDone( " << aNodeName << " )"<< endl;
351 bool RetVal = false ;
352 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
354 RetVal = aNode->KillDone() ;
356 // cdebug_out << "GraphExecutor::DataFlow::KillDone" << endl;
360 bool GraphExecutor::DataFlow::Suspend() {
361 cdebug_in << "GraphExecutor::DataFlow::Suspend()" << endl;
362 bool RetVal = GraphExecutor::OutNode::Suspend() ;
363 cdebug_out << "GraphExecutor::DataFlow::Suspend()" << RetVal << endl;
367 bool GraphExecutor::DataFlow::Suspend( const char *aNodeName ) {
368 // cdebug_in << "GraphExecutor::DataFlow::Suspend( " << aNodeName << " )"<< endl;
369 bool RetVal = false ;
370 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
372 RetVal = aNode->Suspend() ;
374 // cdebug_out << "GraphExecutor::DataFlow::Suspend" << endl;
378 bool GraphExecutor::DataFlow::SuspendDone() {
379 cdebug_in << "GraphExecutor::DataFlow::SuspendDone()" << endl;
380 bool RetVal = false ;
381 cdebug << "Kill not yet implemented." << endl;
382 cdebug_out << "GraphExecutor::DataFlow::SuspendDone()" << endl;
386 bool GraphExecutor::DataFlow::SuspendDone( const char *aNodeName ) {
387 // cdebug_in << "GraphExecutor::DataFlow::SuspendDone( " << aNodeName << " )"<< endl;
388 bool RetVal = false ;
389 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
391 RetVal = aNode->SuspendDone() ;
393 // cdebug_out << "GraphExecutor::DataFlow::SuspendDone" << endl;
397 bool GraphExecutor::DataFlow::Resume() {
398 cdebug_in << "GraphExecutor::DataFlow::Resume()" << endl;
399 bool RetVal = GraphExecutor::OutNode::Resume() ;
400 cdebug_out << "GraphExecutor::DataFlow::Resume()" << RetVal << endl;
404 bool GraphExecutor::DataFlow::Resume( const char *aNodeName ) {
405 // cdebug_in << "GraphExecutor::DataFlow::Resume( " << aNodeName << " )"<< endl;
406 bool RetVal = false ;
407 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
409 RetVal = aNode->Resume() ;
411 // cdebug_out << "GraphExecutor::DataFlow::Resume" << endl;
415 bool GraphExecutor::DataFlow::Stop() {
416 cdebug_in << "GraphExecutor::DataFlow::Stop()" << endl;
417 bool RetVal = GraphExecutor::OutNode::Stop() ;
418 cdebug_out << "GraphExecutor::DataFlow::Stop()" << endl;
422 bool GraphExecutor::DataFlow::Stop( const char *aNodeName ) {
423 // cdebug_in << "GraphExecutor::DataFlow::Stop( " << aNodeName << " )"<< endl;
424 bool RetVal = false ;
425 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
427 RetVal = aNode->Stop() ;
429 // cdebug_out << "GraphExecutor::DataFlow::Stop" << endl;