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" << endl ;
122 bool RetVal = false ;
123 cdebug << pthread_self() << "GraphExecutor::DataFlow::::InputOfAny " << Graph()->Name() << "("
124 << ToServiceParameterName << ")" << endl ;
125 if ( Graph()->GraphMacroLevel() ) {
126 GraphBase::OutPort * anOutPort ;
127 anOutPort = Graph()->GetChangeInDataNodePort( ToServiceParameterName ) ;
128 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny " << Graph()->Name()
129 << " " << State() << " " << ToServiceParameterName << " " << anOutPort->PortState()
130 << " Done : " << anOutPort->PortDone() << endl ;
131 RetVal = AddInputData( Graph()->Name() , ToServiceParameterName , aValue ) ;
132 anOutPort->PortState( SUPERV::ReadyState ) ;
133 // There is only one port :
134 anOutPort->ChangeInPorts( 0 )->PortState( SUPERV::ReadyState ) ;
135 anOutPort->PortDone( true ) ;
136 // There is only one inport of a Node in an ReversedOutport of a graph :
137 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( anOutPort->InPorts( 0 )->NodeName() )->GetInNode() ;
138 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny : " << anInNode->Name()
139 << "->SendSomeDataReady( " << Graph()->Name() << " ) for Port " << anOutPort->InPorts( 0 )->PortName()
141 if ( SomeDataReady ) {
142 MESSAGE( "GraphExecutor::InputOfAny " << Graph()->Name() << " SendSomeDataReady --> " << anInNode->Name()
143 << " " << anInNode->State() << " " << anOutPort->InPorts( 0 )->PortName() ) ;
144 int sts = anInNode->SendSomeDataReady( Graph()->Name() ) ;
145 cdebug << "GraphExecutor::DataFlow::InputOfAny " << anInNode->Name()
146 << "->SendSomeDataReady( " << Graph()->Name() << " ) sts " << sts << endl ;
147 if ( sts && anInNode->IsReady() ) {
148 cdebug << pthread_self() << "/" << anInNode->ThreadNo() << "GraphExecutor::DataFlow::InputOfAny : "
149 << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
150 << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
151 << anInNode->State() << endl ;
152 if ( anInNode->IsLockedDataWait() ) {
153 cdebug << pthread_self() << "/" << anInNode->ThreadNo() << "GraphExecutor::DataFlow::InputOfAny : "
154 << anInNode->Name() << " IsLockedDataWait() ==> UnLockDataWait" << endl ;
155 anInNode->UnLockDataWait() ;
157 anInNode->ThreadNo( 0 ) ;
158 anInNode->CreateNewThread( true ) ;
159 anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
160 // State( GraphExecutor::ExecutingState ) ;
165 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny GraphMacroLevel "
166 << Graph()->GraphMacroLevel() << " ERROR" << endl ;
167 MESSAGE( "GraphExecutor::DataFlow::InputOfAny GraphMacroLevel " << Graph()->GraphMacroLevel()
170 cdebug_out << pthread_self() << " GraphExecutor::DataFlow::InputOfAny " << RetVal << endl ;
174 bool GraphExecutor::DataFlow::OutputOfAny( const char * aNodeName ,
175 const char * ToServiceParameterName ,
176 const CORBA::Any & aValue ) {
177 cdebug_in << pthread_self() << "/" << ThreadNo() << "GraphExecutor::DataFlow::OutputOfAny( " << aNodeName
178 << " , " << ToServiceParameterName
179 << " , aValue ) from " << Graph()->Name() << endl ;
180 bool RetVal = false ;
181 GraphBase::Graph * aMacroNode = (GraphBase::Graph * ) Graph()->GetChangeGraphNode( aNodeName ) ;
182 // GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aMacroGraph->GetInNode() ;
183 RetVal = Graph()->AddOutputData( aNodeName , ToServiceParameterName , aValue ) ;
184 GraphBase::OutPort * anOutPort = aMacroNode->GetChangeOutPort( ToServiceParameterName ) ;
186 // Loop over Inports linked to that OutPort of the MacroNode
187 for ( i = 0 ; i < anOutPort->InPortsSize() ; i++ ) {
188 const char * ToNodeName = anOutPort->ChangeInPorts( i )->NodeName() ;
189 const char * ToParameterName = anOutPort->ChangeInPorts( i )->PortName() ;
190 GraphBase::ComputingNode * aComputingNode = Graph()->GetChangeGraphNode( ToNodeName ) ;
191 if ( strcmp( ToNodeName , Graph()->Name() ) ) {
192 GraphExecutor::InNode * aLinkedNode = (GraphExecutor::InNode * ) aComputingNode->GetInNode() ;
193 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
194 << "GraphExecutor::DataFlow::OutputOfAny to Node "
195 << ToNodeName << "(" << ToParameterName << ") from MacroNode " << aNodeName << endl ;
197 if ( aLinkedNode->IsLockedDataWait() ) {
198 cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
199 << " IsLockedDataWait --> UnLockDataWait" << endl ;
201 sts = aLinkedNode->SendSomeDataReady( (char * ) aNodeName ) ;
202 cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
203 << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
204 << "->SendSomeDataReady( " << aNodeName << " ) sts " << sts << " " << aLinkedNode->State() << endl ;
206 if ( aLinkedNode->State() == GraphExecutor::DataReadyState ) {
207 aLinkedNode->CreateNewThreadIf( true ) ;
208 aLinkedNode->UnLockDataWait() ;
209 // aLinkedNode->DataUndef_AllDataReadyAction() ;
210 aLinkedNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
214 else if ( Graph()->GraphMacroLevel() != 0 ) {
215 cdebug << pthread_self() << "/" << Graph()->CoupledNode()->ThreadNo()
216 << "GraphExecutor::DataFlow::OutputOfAny to that graph "
217 << ToNodeName << "(" << ToParameterName << ") " << State() << " " << Graph()->CoupledNodeName ()
218 << " sended recursively to the MacroNode coupled to that graph" << endl ;
219 Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( Graph()->CoupledNodeName() ,
221 *anOutPort->Value() ) ;
224 cdebug << "GraphExecutor::DataFlow::OutputOfAny to Graph " << ToNodeName
225 << "(" << ToParameterName << ") ignored" << endl ;
228 cdebug_out << pthread_self() << "/" << ThreadNo() << " GraphExecutor::DataFlow::OutputOfAny " << RetVal
233 bool GraphExecutor::DataFlow::Kill() {
234 cdebug_in << "GraphExecutor::DataFlow::Kill()" << endl;
235 bool RetVal = GraphExecutor::OutNode::Kill() ;
236 cdebug_out << "GraphExecutor::DataFlow::Kill() " << RetVal << endl;
240 bool GraphExecutor::DataFlow::Kill( const char *aNodeName ) {
241 // cdebug_in << "GraphExecutor::DataFlow::Kill( " << aNodeName << " )"<< endl;
242 bool RetVal = false ;
243 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
245 RetVal = aNode->Kill() ;
247 // cdebug_out << "GraphExecutor::DataFlow::Kill" << endl;
251 bool GraphExecutor::DataFlow::KillDone( const char *aNodeName ) {
252 // cdebug_in << "GraphExecutor::DataFlow::KillDone( " << aNodeName << " )"<< endl;
253 bool RetVal = false ;
254 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
256 RetVal = aNode->KillDone() ;
258 // cdebug_out << "GraphExecutor::DataFlow::KillDone" << endl;
262 bool GraphExecutor::DataFlow::Suspend() {
263 cdebug_in << "GraphExecutor::DataFlow::Suspend()" << endl;
264 bool RetVal = GraphExecutor::OutNode::Suspend() ;
265 cdebug_out << "GraphExecutor::DataFlow::Suspend()" << RetVal << endl;
269 bool GraphExecutor::DataFlow::Suspend( const char *aNodeName ) {
270 // cdebug_in << "GraphExecutor::DataFlow::Suspend( " << aNodeName << " )"<< endl;
271 bool RetVal = false ;
272 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
274 RetVal = aNode->Suspend() ;
276 // cdebug_out << "GraphExecutor::DataFlow::Suspend" << endl;
280 bool GraphExecutor::DataFlow::SuspendDone() {
281 cdebug_in << "GraphExecutor::DataFlow::SuspendDone()" << endl;
282 bool RetVal = false ;
283 cdebug << "Kill not yet implemented." << endl;
284 cdebug_out << "GraphExecutor::DataFlow::SuspendDone()" << endl;
288 bool GraphExecutor::DataFlow::SuspendDone( const char *aNodeName ) {
289 // cdebug_in << "GraphExecutor::DataFlow::SuspendDone( " << aNodeName << " )"<< endl;
290 bool RetVal = false ;
291 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
293 RetVal = aNode->SuspendDone() ;
295 // cdebug_out << "GraphExecutor::DataFlow::SuspendDone" << endl;
299 bool GraphExecutor::DataFlow::Resume() {
300 cdebug_in << "GraphExecutor::DataFlow::Resume()" << endl;
301 bool RetVal = GraphExecutor::OutNode::Resume() ;
302 cdebug_out << "GraphExecutor::DataFlow::Resume()" << RetVal << endl;
306 bool GraphExecutor::DataFlow::Resume( const char *aNodeName ) {
307 // cdebug_in << "GraphExecutor::DataFlow::Resume( " << aNodeName << " )"<< endl;
308 bool RetVal = false ;
309 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
311 RetVal = aNode->Resume() ;
313 // cdebug_out << "GraphExecutor::DataFlow::Resume" << endl;
317 bool GraphExecutor::DataFlow::Stop() {
318 cdebug_in << "GraphExecutor::DataFlow::Stop()" << endl;
319 bool RetVal = GraphExecutor::OutNode::Stop() ;
320 cdebug_out << "GraphExecutor::DataFlow::Stop()" << endl;
324 bool GraphExecutor::DataFlow::Stop( const char *aNodeName ) {
325 // cdebug_in << "GraphExecutor::DataFlow::Stop( " << aNodeName << " )"<< endl;
326 bool RetVal = false ;
327 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
329 RetVal = aNode->Stop() ;
331 // cdebug_out << "GraphExecutor::DataFlow::Stop" << endl;