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 //JR 30.03.2005 *anOutPort->Value() ) ;
222 anOutPort->Value() ) ;
225 cdebug << "GraphExecutor::DataFlow::OutputOfAny to Graph " << ToNodeName
226 << "(" << ToParameterName << ") ignored" << endl ;
229 cdebug_out << pthread_self() << "/" << ThreadNo() << " GraphExecutor::DataFlow::OutputOfAny " << RetVal
234 bool GraphExecutor::DataFlow::Kill() {
235 cdebug_in << "GraphExecutor::DataFlow::Kill()" << endl;
236 bool RetVal = GraphExecutor::OutNode::Kill() ;
237 cdebug_out << "GraphExecutor::DataFlow::Kill() " << RetVal << endl;
241 bool GraphExecutor::DataFlow::Kill( const char *aNodeName ) {
242 // cdebug_in << "GraphExecutor::DataFlow::Kill( " << aNodeName << " )"<< endl;
243 bool RetVal = false ;
244 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
246 RetVal = aNode->Kill() ;
248 // cdebug_out << "GraphExecutor::DataFlow::Kill" << endl;
252 bool GraphExecutor::DataFlow::KillDone( const char *aNodeName ) {
253 // cdebug_in << "GraphExecutor::DataFlow::KillDone( " << aNodeName << " )"<< endl;
254 bool RetVal = false ;
255 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
257 RetVal = aNode->KillDone() ;
259 // cdebug_out << "GraphExecutor::DataFlow::KillDone" << endl;
263 bool GraphExecutor::DataFlow::Suspend() {
264 cdebug_in << "GraphExecutor::DataFlow::Suspend()" << endl;
265 bool RetVal = GraphExecutor::OutNode::Suspend() ;
266 cdebug_out << "GraphExecutor::DataFlow::Suspend()" << RetVal << endl;
270 bool GraphExecutor::DataFlow::Suspend( const char *aNodeName ) {
271 // cdebug_in << "GraphExecutor::DataFlow::Suspend( " << aNodeName << " )"<< endl;
272 bool RetVal = false ;
273 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
275 RetVal = aNode->Suspend() ;
277 // cdebug_out << "GraphExecutor::DataFlow::Suspend" << endl;
281 bool GraphExecutor::DataFlow::SuspendDone() {
282 cdebug_in << "GraphExecutor::DataFlow::SuspendDone()" << endl;
283 bool RetVal = false ;
284 cdebug << "Kill not yet implemented." << endl;
285 cdebug_out << "GraphExecutor::DataFlow::SuspendDone()" << endl;
289 bool GraphExecutor::DataFlow::SuspendDone( const char *aNodeName ) {
290 // cdebug_in << "GraphExecutor::DataFlow::SuspendDone( " << aNodeName << " )"<< endl;
291 bool RetVal = false ;
292 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
294 RetVal = aNode->SuspendDone() ;
296 // cdebug_out << "GraphExecutor::DataFlow::SuspendDone" << endl;
300 bool GraphExecutor::DataFlow::Resume() {
301 cdebug_in << "GraphExecutor::DataFlow::Resume()" << endl;
302 bool RetVal = GraphExecutor::OutNode::Resume() ;
303 cdebug_out << "GraphExecutor::DataFlow::Resume()" << RetVal << endl;
307 bool GraphExecutor::DataFlow::Resume( const char *aNodeName ) {
308 // cdebug_in << "GraphExecutor::DataFlow::Resume( " << aNodeName << " )"<< endl;
309 bool RetVal = false ;
310 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
312 RetVal = aNode->Resume() ;
314 // cdebug_out << "GraphExecutor::DataFlow::Resume" << endl;
318 bool GraphExecutor::DataFlow::Stop() {
319 cdebug_in << "GraphExecutor::DataFlow::Stop()" << endl;
320 bool RetVal = GraphExecutor::OutNode::Stop() ;
321 cdebug_out << "GraphExecutor::DataFlow::Stop()" << endl;
325 bool GraphExecutor::DataFlow::Stop( const char *aNodeName ) {
326 // cdebug_in << "GraphExecutor::DataFlow::Stop( " << aNodeName << " )"<< endl;
327 bool RetVal = false ;
328 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
330 RetVal = aNode->Stop() ;
332 // cdebug_out << "GraphExecutor::DataFlow::Stop" << endl;