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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 // Loop over Inports linked to that OutPort of the MacroNode
227 for ( i = 0 ; i < anOutPort->InPortsSize() ; i++ ) {
228 const char * ToNodeName = anOutPort->ChangeInPorts( i )->NodeName() ;
229 const char * ToParameterName = anOutPort->ChangeInPorts( i )->PortName() ;
230 GraphBase::ComputingNode * aComputingNode = Graph()->GetChangeGraphNode( ToNodeName ) ;
231 if ( strcmp( ToNodeName , Name() ) ) {
232 GraphExecutor::InNode * aLinkedNode = (GraphExecutor::InNode * ) aComputingNode->GetInNode() ;
233 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
234 << "GraphExecutor::DataFlow::OutputOfAny to Node "
235 << ToNodeName << "(" << ToParameterName << ") from MacroNode " << aNodeName << endl ;
237 //JR 15.04.2005 Debug PAL8624 RetroConception :
238 // if ( aLinkedNode->IsLockedDataWait() ) {
239 // cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
240 // << " IsLockedDataWait --> UnLockDataWait" << endl ;
242 sts = aLinkedNode->SendSomeDataReady( (char * ) aNodeName ) ;
243 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
244 << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
245 << "->SendSomeDataReady( " << aNodeName << " ) sts " << sts << " " << aLinkedNode->State() << endl ;
247 if ( aLinkedNode->State() == GraphExecutor::DataReadyState ) {
248 //JR 15.04.2005 Debug PAL8624 RetroConception :
249 // aLinkedNode->CreateNewThreadIf( true ) ;
250 // aLinkedNode->UnLockDataWait() ;
251 aLinkedNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
255 else if ( Graph()->GraphMacroLevel() != 0 ) {
256 cdebug << pthread_self() << "/" << Graph()->CoupledNode()->ThreadNo()
257 << "GraphExecutor::DataFlow::OutputOfAny to that graph "
258 << ToNodeName << "(" << ToParameterName << ") " << State() << " " << Graph()->CoupledNodeName ()
259 << " sended recursively to the MacroNode coupled to that graph" << endl ;
260 Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( Graph()->CoupledNodeName() ,
262 //JR 30.03.2005 *anOutPort->Value() ) ;
263 anOutPort->Value() ) ;
266 cdebug << "GraphExecutor::DataFlow::OutputOfAny to Graph " << ToNodeName
267 << "(" << ToParameterName << ") ignored" << endl ;
270 cdebug_out << pthread_self() << "/" << ThreadNo() << " GraphExecutor::DataFlow::OutputOfAny " << RetVal
275 bool GraphExecutor::DataFlow::Kill() {
276 cdebug_in << "GraphExecutor::DataFlow::Kill()" << endl;
277 bool RetVal = GraphExecutor::OutNode::Kill() ;
278 cdebug_out << "GraphExecutor::DataFlow::Kill() " << RetVal << endl;
282 bool GraphExecutor::DataFlow::Kill( const char *aNodeName ) {
283 // cdebug_in << "GraphExecutor::DataFlow::Kill( " << aNodeName << " )"<< endl;
284 bool RetVal = false ;
285 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
287 RetVal = aNode->Kill() ;
289 // cdebug_out << "GraphExecutor::DataFlow::Kill" << endl;
293 bool GraphExecutor::DataFlow::KillDone( const char *aNodeName ) {
294 // cdebug_in << "GraphExecutor::DataFlow::KillDone( " << aNodeName << " )"<< endl;
295 bool RetVal = false ;
296 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
298 RetVal = aNode->KillDone() ;
300 // cdebug_out << "GraphExecutor::DataFlow::KillDone" << endl;
304 bool GraphExecutor::DataFlow::Suspend() {
305 cdebug_in << "GraphExecutor::DataFlow::Suspend()" << endl;
306 bool RetVal = GraphExecutor::OutNode::Suspend() ;
307 cdebug_out << "GraphExecutor::DataFlow::Suspend()" << RetVal << endl;
311 bool GraphExecutor::DataFlow::Suspend( const char *aNodeName ) {
312 // cdebug_in << "GraphExecutor::DataFlow::Suspend( " << aNodeName << " )"<< endl;
313 bool RetVal = false ;
314 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
316 RetVal = aNode->Suspend() ;
318 // cdebug_out << "GraphExecutor::DataFlow::Suspend" << endl;
322 bool GraphExecutor::DataFlow::SuspendDone() {
323 cdebug_in << "GraphExecutor::DataFlow::SuspendDone()" << endl;
324 bool RetVal = false ;
325 cdebug << "Kill not yet implemented." << endl;
326 cdebug_out << "GraphExecutor::DataFlow::SuspendDone()" << endl;
330 bool GraphExecutor::DataFlow::SuspendDone( const char *aNodeName ) {
331 // cdebug_in << "GraphExecutor::DataFlow::SuspendDone( " << aNodeName << " )"<< endl;
332 bool RetVal = false ;
333 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
335 RetVal = aNode->SuspendDone() ;
337 // cdebug_out << "GraphExecutor::DataFlow::SuspendDone" << endl;
341 bool GraphExecutor::DataFlow::Resume() {
342 cdebug_in << "GraphExecutor::DataFlow::Resume()" << endl;
343 bool RetVal = GraphExecutor::OutNode::Resume() ;
344 cdebug_out << "GraphExecutor::DataFlow::Resume()" << RetVal << endl;
348 bool GraphExecutor::DataFlow::Resume( const char *aNodeName ) {
349 // cdebug_in << "GraphExecutor::DataFlow::Resume( " << aNodeName << " )"<< endl;
350 bool RetVal = false ;
351 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
353 RetVal = aNode->Resume() ;
355 // cdebug_out << "GraphExecutor::DataFlow::Resume" << endl;
359 bool GraphExecutor::DataFlow::Stop() {
360 cdebug_in << "GraphExecutor::DataFlow::Stop()" << endl;
361 bool RetVal = GraphExecutor::OutNode::Stop() ;
362 cdebug_out << "GraphExecutor::DataFlow::Stop()" << endl;
366 bool GraphExecutor::DataFlow::Stop( const char *aNodeName ) {
367 // cdebug_in << "GraphExecutor::DataFlow::Stop( " << aNodeName << " )"<< endl;
368 bool RetVal = false ;
369 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
371 RetVal = aNode->Stop() ;
373 // cdebug_out << "GraphExecutor::DataFlow::Stop" << endl;