1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
23 // File : DataFlowExecutor_DataFlow.cxx
27 #include "DataFlowExecutor_DataFlow.hxx"
28 #include "DataFlowEditor_DataFlow.hxx"
30 // Implementation de la classe GraphExecutor::Graph
32 GraphExecutor::DataFlow::DataFlow() :
34 cdebug_in << "GraphExecutor::DataFlow::DataFlowExecutor()" << endl;
36 _theNamingService = NULL ;
38 cdebug_out << "GraphExecutor::DataFlow::DataFlowExecutor()" << endl;
41 GraphExecutor::DataFlow::DataFlow( CORBA::ORB_ptr ORB,
42 SALOME_NamingService* ptrNamingService ,
43 const char *DataFlowName ,
44 const char * DebugFileName ,
45 const SUPERV::KindOfNode aKindOfNode ) :
46 OutNode( ORB, ptrNamingService , DataFlowName , DebugFileName , aKindOfNode ) {
47 cdebug_in << "GraphExecutor::DataFlow::DataFlow(" ;
49 cdebug << DataFlowName ;
51 cdebug << ")" << endl;
53 _theNamingService = ptrNamingService ;
55 cdebug_out << "GraphExecutor::DataFlow::DataFlow" << endl;
58 GraphExecutor::DataFlow::DataFlow( CORBA::ORB_ptr ORB,
59 SALOME_NamingService* ptrNamingService ,
60 const SALOME_ModuleCatalog::Service& DataFlowService ,
61 const char *DataFlowComponentName ,
62 const char *DataFlowInterfaceName ,
63 const char *DataFlowName ,
64 const SUPERV::KindOfNode DataFlowkind ,
65 const SUPERV::SDate DataFlowFirstCreation ,
66 const SUPERV::SDate DataFlowLastModification ,
67 const char * DataFlowExecutorRelease ,
68 const char * DataFlowAuthor ,
69 const char * DataFlowComputer ,
70 const char * DataFlowComment ,
71 const char * DebugFileName ) :
72 OutNode( ORB, ptrNamingService , DataFlowService , DataFlowComponentName ,
73 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
74 DataFlowFirstCreation , DataFlowLastModification ,
75 DataFlowExecutorRelease , DataFlowAuthor ,
76 DataFlowComputer , DataFlowComment , DebugFileName ) {
77 cdebug_in << "GraphExecutor::DataFlow::DataFlow(" << DataFlowName << ")" << endl;
79 _theNamingService = ptrNamingService ;
81 cdebug_out << "GraphExecutor::DataFlow::DataFlow" << endl;
84 GraphExecutor::DataFlow::~DataFlow() {
85 // delete _DataFlowNode ;
86 // delete _DataFlowDatas ;
90 bool GraphExecutor::DataFlow::Ping( const char *aNodeName ) {
91 cdebug_in << "GraphExecutor::DataFlow::Ping" << aNodeName << " )" << endl;
93 if ( Graph()->GetGraphNode( aNodeName ) )
94 RetVal = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode())->Ping() ;
95 cdebug_out << "GraphExecutor::DataFlow::Ping" << endl;
99 bool GraphExecutor::DataFlow::ContainerKill() {
100 cdebug_in << "GraphExecutor::DataFlow::ContainerKill()" << endl;
101 bool RetVal = GraphExecutor::OutNode::ContainerKill() ;
102 cdebug_out << "GraphExecutor::DataFlow::ContainerKill()" << endl;
106 bool GraphExecutor::DataFlow::ContainerKill( const char *aNodeName ) {
107 // cdebug_in << "GraphExecutor::DataFlow::ContainerKill( " << aNodeName << " )"<< endl;
108 bool RetVal = false ;
109 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
111 RetVal = aNode->ContainerKill() ;
113 // cdebug_out << "GraphExecutor::DataFlow::ContainerKill" << endl;
117 bool GraphExecutor::DataFlow::InputOfAny( const char * ToServiceParameterName ,
118 const CORBA::Any & aValue ,
119 bool SomeDataReady ) {
120 cdebug_in <<"GraphExecutor::DataFlow::InputOfAny( " << ToServiceParameterName
121 << " SomeDataReady " << SomeDataReady << " )" << endl ;
122 bool RetVal = false ;
123 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny " << Name() << "( "
124 << ToServiceParameterName << " , aValue , SomeDataReady " << SomeDataReady << " ) "
126 if ( Graph()->GraphMacroLevel() ) {
127 GraphBase::OutPort * anOutPort ;
128 anOutPort = Graph()->GetChangeInDataNodePort( ToServiceParameterName ) ;
129 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny " << Name()
130 << " " << State() << " " << ToServiceParameterName << " " << anOutPort->PortState()
131 << " Done : " << anOutPort->PortDone() << endl ;
132 RetVal = AddInputData( Name() , ToServiceParameterName , aValue ) ;
133 anOutPort->PortState( SUPERV::ReadyState ) ;
134 // There is only one port :
135 anOutPort->ChangeInPorts( 0 )->PortState( SUPERV::ReadyState ) ;
136 anOutPort->PortDone( true ) ;
137 // There is only one inport of a Node in an ReversedOutport of a graph :
138 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( anOutPort->InPorts( 0 )->NodeName() )->GetInNode() ;
139 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny : " << anInNode->Name()
140 << "->SendSomeDataReady( " << Name() << " ) for Port "
141 << anOutPort->InPorts( 0 )->PortName() << " SomeDataReady " << SomeDataReady << endl ;
142 if ( SomeDataReady ) {
143 MESSAGE( "GraphExecutor::InputOfAny " << Name() << " SendSomeDataReady --> " << anInNode->Name()
144 << " " << anInNode->State() << " " << anOutPort->InPorts( 0 )->PortName() ) ;
145 int sts = anInNode->SendSomeDataReady( Name() ) ;
146 cdebug << "GraphExecutor::DataFlow::InputOfAny " << anInNode->Name()
147 << "->SendSomeDataReady( " << Name() << " ) sts " << sts << " State "
148 << anInNode->State() << " IsReady " << anInNode->IsReady()
149 << " SomeDataReady " << SomeDataReady << endl ;
150 //JR 15.04.2005 Debug PAL8624 RetroConception :
151 if ( sts && anInNode->HasAllDataReady() ) {
152 cdebug << pthread_self() << "/" << anInNode->ThreadNo()
153 << "GraphExecutor::DataFlow::InputOfAny : "
154 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
155 << " " << anInNode->Name() << "->HasAllDataReady() " << anInNode->HasAllDataReady()
156 << " State " << anInNode->State() << endl ;
157 anInNode->ThreadNo( 0 ) ;
158 anInNode->CreateNewThread( true ) ;
159 if ( !anInNode->SendEvent( GraphExecutor::AllDataReadyEvent ) ) { // ==> Ready to execute
160 //JR 06.05.2005 Debug PAL8624 RetroConception :
162 if ( res && anInNode->IsReady() ) {
163 cdebug << pthread_self() << "/" << anInNode->ThreadNo() << "GraphExecutor::DataFlow::InputOfAny : "
164 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
165 << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
166 << anInNode->State() << endl ;
167 //JR 15.04.2005 Debug PAL8624 RetroConception :
168 // if ( anInNode->IsLockedDataWait() ) {
169 // cdebug << pthread_self() << "/" << anInNode->ThreadNo() << "GraphExecutor::DataFlow::InputOfAny : "
170 // << anInNode->Name() << " IsLockedDataWait() ==> UnLockDataWait" << endl ;
171 // anInNode->UnLockDataWait() ;
173 anInNode->ThreadNo( 0 ) ;
174 anInNode->CreateNewThread( true ) ;
175 anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
176 // State( GraphExecutor::ExecutingState ) ;
181 cdebug << pthread_self() << "/" << anInNode->ThreadNo()
182 << "GraphExecutor::DataFlow::InputOfAny : NotAllDataReady ERROR : "
183 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
184 << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
185 << anInNode->State() << endl ;
189 cdebug << pthread_self() << "/" << anInNode->ThreadNo()
190 << "GraphExecutor::DataFlow::InputOfAny : NotAllDataReady : "
191 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
192 << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
193 << anInNode->State() << endl ;
197 cdebug << "GraphExecutor::DataFlow::InputOfAny " << anInNode->Name()
198 << "->SendSomeDataReady( " << Name() << " ) State "
199 << anInNode->State() << " IsReady " << anInNode->IsReady()
200 << " SomeDataReady " << SomeDataReady << endl ;
204 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny GraphMacroLevel "
205 << Graph()->GraphMacroLevel() << " ERROR" << endl ;
206 MESSAGE( "GraphExecutor::DataFlow::InputOfAny GraphMacroLevel " << Graph()->GraphMacroLevel()
209 cdebug_out << pthread_self() << " GraphExecutor::DataFlow::InputOfAny " << RetVal << endl ;
213 bool GraphExecutor::DataFlow::OutputOfAny( const char * aNodeName ,
214 const char * ToServiceParameterName ,
215 const CORBA::Any & aValue ) {
216 cdebug_in << pthread_self() << "/" << ThreadNo() << "GraphExecutor::DataFlow::OutputOfAny( " << aNodeName
217 << " , " << ToServiceParameterName
218 << " , aValue ) from " << Name() << endl ;
219 bool RetVal = false ;
220 GraphBase::Graph * aMacroNode = (GraphBase::Graph * ) Graph()->GetChangeGraphNode( aNodeName ) ;
221 // GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aMacroGraph->GetInNode() ;
222 RetVal = Graph()->AddOutputData( aNodeName , ToServiceParameterName , aValue ) ;
223 GraphBase::OutPort * anOutPort = aMacroNode->GetChangeOutPort( ToServiceParameterName ) ;
225 for ( i = 0 ; i < aMacroNode->GetNodeOutPortsSize() ; i++ ) {
226 cdebug << "Out" << i << " " << aMacroNode->GetNodeOutPort( i )->PortName() << " "
227 << aMacroNode->GetChangeNodeOutPort( i )->PortState() << " Done="
228 << aMacroNode->GetChangeNodeOutPort( i )->PortDone() << " " ;
229 if ( GraphBase::Base::_prof_debug ) {
230 aMacroNode->GetNodeOutPort( i )->StringValue( *GraphBase::Base::_fdebug ) ;
232 if ( aMacroNode->GetChangeNodeOutPort( i )->IsGate() ) {
233 cdebug << " BoolValue " << aMacroNode->GetChangeNodeOutPort( i )->BoolValue() ;
237 // Loop over Inports linked to that OutPort of the MacroNode
238 for ( i = 0 ; i < anOutPort->InPortsSize() ; i++ ) {
239 const char * ToNodeName = anOutPort->ChangeInPorts( i )->NodeName() ;
240 const char * ToParameterName = anOutPort->ChangeInPorts( i )->PortName() ;
241 if ( strcmp( ToNodeName , Name() ) ) {
242 GraphBase::ComputingNode * aComputingNode = Graph()->GetChangeGraphNode( ToNodeName ) ;
243 GraphExecutor::InNode * aLinkedNode = (GraphExecutor::InNode * ) aComputingNode->GetInNode() ;
244 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
245 << "GraphExecutor::DataFlow::OutputOfAny to Node "
246 << ToNodeName << "(" << ToParameterName << ") from MacroNode " << aNodeName << endl ;
248 //JR 15.04.2005 Debug PAL8624 RetroConception :
249 // if ( aLinkedNode->IsLockedDataWait() ) {
250 // cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
251 // << " IsLockedDataWait --> UnLockDataWait" << endl ;
253 aLinkedNode->LockDataReady() ;
254 sts = aLinkedNode->SendSomeDataReady( (char * ) aNodeName ) ;
255 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
256 << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
257 << "->SendSomeDataReady( " << aNodeName << " ) sts " << sts << " " << aLinkedNode->State() << endl ;
259 // if ( aLinkedNode->State() == GraphExecutor::DataReadyState ) {
260 if ( aLinkedNode->HasAllDataReady() ) {
261 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
262 << "GraphExecutor::DataFlow::OutputOfAny SendEvent(ExecuteEvent) to "
263 << aLinkedNode->Name() << endl ;
264 //JR 15.04.2005 Debug PAL8624 RetroConception :
265 // aLinkedNode->CreateNewThreadIf( true ) ;
266 // aLinkedNode->UnLockDataWait() ;
267 aLinkedNode->CreateNewThread( true ) ;
268 aLinkedNode->UnLockDataReady() ;
269 aLinkedNode->HasAllDataReady( false ) ;
270 // aLinkedNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
271 aLinkedNode->SendEvent( GraphExecutor::AllDataReadyEvent ) ;
274 aLinkedNode->UnLockDataReady() ;
275 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
276 << "GraphExecutor::DataFlow::OutputOfAny NO SendEvent(ExecuteEvent) to "
277 << aLinkedNode->Name() << endl ;
281 aLinkedNode->UnLockDataReady() ;
284 else if ( Graph()->GraphMacroLevel() != 0 ) {
285 cdebug << pthread_self() << "/" << Graph()->CoupledNode()->ThreadNo()
286 << "GraphExecutor::DataFlow::OutputOfAny to that graph "
287 << ToNodeName << "(" << ToParameterName << ") " << State() << " " << Graph()->CoupledNodeName ()
288 << " sended recursively to the MacroNode coupled to that graph" << endl ;
289 Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( Graph()->CoupledNodeName() ,
291 //JR 30.03.2005 *anOutPort->Value() ) ;
292 anOutPort->Value() ) ;
295 cdebug << pthread_self() << "GraphExecutor::DataFlow::OutputOfAny to Node "
296 << ToNodeName << "(" << ToParameterName << ") from MacroNode " << aNodeName
297 << ") ignored" << endl ;
300 cdebug_out << pthread_self() << "/" << ThreadNo() << " GraphExecutor::DataFlow::OutputOfAny " << RetVal
305 //JR NPAL14110 09.02.2007 : SetWaitingStates was missing in SubGraph of MacroNode !...
306 bool GraphExecutor::DataFlow::SetWaitingStates( const char * ToServiceParameterName ) {
307 cdebug_in << pthread_self() << "/" << ThreadNo() << "GraphExecutor::DataFlow::SetWaitingStates( "
308 << ToServiceParameterName << " ) MacroGraph " << Name() << endl ;
310 State( GraphExecutor::DataWaitingState ) ;
312 GraphBase::OutPort * anOutPort ;
313 anOutPort = Graph()->GetChangeInDataNodePort( ToServiceParameterName ) ;
314 anOutPort->PortState( SUPERV::WaitingState ) ;
315 anOutPort->PortDone( false ) ;
316 cdebug << pthread_self() << "GraphExecutor::DataFlow::SetWaitingStates " << Name()
317 << " " << State() << " " << ToServiceParameterName << " " << anOutPort->PortState()
318 << " Done : " << anOutPort->PortDone() << endl ;
319 if ( ! anOutPort->IsGate() ) {
320 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( anOutPort->InPorts( 0 )->NodeName() )->GetInNode() ;
321 cdebug << pthread_self() << "GraphExecutor::DataFlow::SetWaitingStates : "
322 << anInNode->Name() << "->SetWaitingStates( NULL ) for Port "
323 << anOutPort->InPorts( 0 )->PortName() << endl ;
324 anInNode->SetWaitingStates( NULL ) ;
326 cdebug_out << "GraphExecutor::DataFlow::SetWaitingStates() " << RetVal << endl;
330 bool GraphExecutor::DataFlow::Kill() {
331 cdebug_in << "GraphExecutor::DataFlow::Kill()" << endl;
332 bool RetVal = GraphExecutor::OutNode::Kill() ;
333 cdebug_out << "GraphExecutor::DataFlow::Kill() " << RetVal << endl;
337 bool GraphExecutor::DataFlow::Kill( const char *aNodeName ) {
338 // cdebug_in << "GraphExecutor::DataFlow::Kill( " << aNodeName << " )"<< endl;
339 bool RetVal = false ;
340 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
342 RetVal = aNode->Kill() ;
344 // cdebug_out << "GraphExecutor::DataFlow::Kill" << endl;
348 bool GraphExecutor::DataFlow::KillDone( const char *aNodeName ) {
349 // cdebug_in << "GraphExecutor::DataFlow::KillDone( " << aNodeName << " )"<< endl;
350 bool RetVal = false ;
351 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
353 RetVal = aNode->KillDone() ;
355 // cdebug_out << "GraphExecutor::DataFlow::KillDone" << endl;
359 bool GraphExecutor::DataFlow::Suspend() {
360 cdebug_in << "GraphExecutor::DataFlow::Suspend()" << endl;
361 bool RetVal = GraphExecutor::OutNode::Suspend() ;
362 cdebug_out << "GraphExecutor::DataFlow::Suspend()" << RetVal << endl;
366 bool GraphExecutor::DataFlow::Suspend( const char *aNodeName ) {
367 // cdebug_in << "GraphExecutor::DataFlow::Suspend( " << aNodeName << " )"<< endl;
368 bool RetVal = false ;
369 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
371 RetVal = aNode->Suspend() ;
373 // cdebug_out << "GraphExecutor::DataFlow::Suspend" << endl;
377 bool GraphExecutor::DataFlow::SuspendDone() {
378 cdebug_in << "GraphExecutor::DataFlow::SuspendDone()" << endl;
379 bool RetVal = false ;
380 cdebug << "Kill not yet implemented." << endl;
381 cdebug_out << "GraphExecutor::DataFlow::SuspendDone()" << endl;
385 bool GraphExecutor::DataFlow::SuspendDone( const char *aNodeName ) {
386 // cdebug_in << "GraphExecutor::DataFlow::SuspendDone( " << aNodeName << " )"<< endl;
387 bool RetVal = false ;
388 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
390 RetVal = aNode->SuspendDone() ;
392 // cdebug_out << "GraphExecutor::DataFlow::SuspendDone" << endl;
396 bool GraphExecutor::DataFlow::Resume() {
397 cdebug_in << "GraphExecutor::DataFlow::Resume()" << endl;
398 bool RetVal = GraphExecutor::OutNode::Resume() ;
399 cdebug_out << "GraphExecutor::DataFlow::Resume()" << RetVal << endl;
403 bool GraphExecutor::DataFlow::Resume( const char *aNodeName ) {
404 // cdebug_in << "GraphExecutor::DataFlow::Resume( " << aNodeName << " )"<< endl;
405 bool RetVal = false ;
406 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
408 RetVal = aNode->Resume() ;
410 // cdebug_out << "GraphExecutor::DataFlow::Resume" << endl;
414 bool GraphExecutor::DataFlow::Stop() {
415 cdebug_in << "GraphExecutor::DataFlow::Stop()" << endl;
416 bool RetVal = GraphExecutor::OutNode::Stop() ;
417 cdebug_out << "GraphExecutor::DataFlow::Stop()" << endl;
421 bool GraphExecutor::DataFlow::Stop( const char *aNodeName ) {
422 // cdebug_in << "GraphExecutor::DataFlow::Stop( " << aNodeName << " )"<< endl;
423 bool RetVal = false ;
424 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
426 RetVal = aNode->Stop() ;
428 // cdebug_out << "GraphExecutor::DataFlow::Stop" << endl;