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"
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 cdebug_in "GraphExecutor::DataFlow::InputOfAny" << endl ;
120 bool RetVal = false ;
121 cdebug << pthread_self() << "GraphExecutor::DataFlow::::InputOfAny " << Graph()->Name() << "("
122 << ToServiceParameterName << ")" << endl ;
123 if ( Graph()->GraphMacroLevel() ) {
124 GraphBase::OutPort * anOutPort ;
125 anOutPort = Graph()->GetChangeInDataNodePort( ToServiceParameterName ) ;
126 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny " << Graph()->Name()
127 << " " << ToServiceParameterName << " " << anOutPort->State() << " Done " << anOutPort->Done()
129 RetVal = AddInputData( Graph()->Name() , ToServiceParameterName , aValue ) ;
130 anOutPort->State( SUPERV::ReadyState ) ;
131 anOutPort->Done( true ) ;
132 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( anOutPort->InPorts( 0 )->NodeName() )->GetInNode() ;
133 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny : " << anInNode->Name()
134 << "->SendSomeDataReady( " << Graph()->Name() << " ) " << endl ;
135 anInNode->SendSomeDataReady( Graph()->Name() ) ;
136 if ( anInNode->IsReady() ) {
137 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny : " << anInNode->Name()
138 << "->SendEvent( GraphExecutor::ExecuteEvent ) "
139 << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
140 << anInNode->State() << endl ;
141 if ( anInNode->IsLockedDataWait() ) {
142 cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny : " << anInNode->Name()
143 << " IsLockedDataWait() ==> UnLockDataWait" << endl ;
144 anInNode->UnLockDataWait() ;
146 anInNode->CreateNewThread( true ) ;
147 anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
148 State( GraphExecutor::ExecutingState ) ;
151 cdebug_out << "GraphExecutor::DataFlow::InputOfAny " << RetVal << endl ;
155 bool GraphExecutor::DataFlow::OutputOfAny( const char * aNodeName ,
156 const char * ToServiceParameterName ,
157 const CORBA::Any & aValue ) {
158 cdebug_in << "GraphExecutor::DataFlow::OutputOfAny" << endl ;
159 bool RetVal = false ;
160 GraphBase::Graph * aMacroGraph = (GraphBase::Graph * ) Graph()->GetChangeGraphNode( aNodeName ) ;
161 // GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aMacroGraph->GetInNode() ;
162 RetVal = Graph()->AddOutputData( aNodeName , ToServiceParameterName , aValue ) ;
163 GraphBase::OutPort * anOutPort = aMacroGraph->GetChangeOutPort( ToServiceParameterName ) ;
165 for ( i = 0 ; i < anOutPort->InPortsSize() ; i++ ) {
166 if ( strcmp( anOutPort->ChangeInPorts( i )->NodeName() , Graph()->Name() ) ) {
167 cdebug << "GraphExecutor::DataFlow::OutputOfAny toNodeName " << anOutPort->ChangeInPorts( i )->NodeName()
168 << "(" << anOutPort->ChangeInPorts( i )->PortName() << ")" << endl ;
169 GraphExecutor::InNode * aLinkedNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( i )->NodeName() )->GetInNode() ;
171 if ( aLinkedNode->IsLockedDataWait() ) {
172 cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
173 << " IsLockedDataWait --> UnLockDataWait" << endl ;
175 sts = aLinkedNode->SendSomeDataReady( (char * ) aNodeName ) ;
176 cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
177 << "->SendSomeDataReady( " << aNodeName << " ) sts " << sts << endl ;
179 if ( aLinkedNode->State() == GraphExecutor::DataReadyState ) {
180 aLinkedNode->CreateNewThreadIf( true ) ;
181 aLinkedNode->UnLockDataWait() ;
182 int res = aLinkedNode->DataUndef_AllDataReadyAction() ;
186 else if ( Graph()->GraphMacroLevel() != 0 ) {
187 cdebug << "GraphExecutor::DataFlow::OutputOfAny to MacroGraph " << anOutPort->ChangeInPorts( i )->NodeName()
188 << "(" << anOutPort->ChangeInPorts( i )->PortName() << ") " << Graph()->CoupledNodeName () << endl ;
189 Graph()->CoupledNode()->GraphExecutor()->OutputOfAny( Graph()->CoupledNodeName() ,
190 anOutPort->ChangeInPorts( i )->PortName() ,
191 *anOutPort->Value() ) ;
194 cdebug << "GraphExecutor::DataFlow::OutputOfAny to Graph " << anOutPort->ChangeInPorts( i )->NodeName()
195 << "(" << anOutPort->ChangeInPorts( i )->PortName() << ") ignored" << endl ;
198 cdebug_out << "GraphExecutor::DataFlow::OutputOfAny " << RetVal << endl ;
202 bool GraphExecutor::DataFlow::Kill() {
203 cdebug_in << "GraphExecutor::DataFlow::Kill()" << endl;
204 bool RetVal = GraphExecutor::OutNode::Kill() ;
205 cdebug_out << "GraphExecutor::DataFlow::Kill()" << endl;
209 bool GraphExecutor::DataFlow::Kill( const char *aNodeName ) {
210 // cdebug_in << "GraphExecutor::DataFlow::Kill( " << aNodeName << " )"<< endl;
211 bool RetVal = false ;
212 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
214 RetVal = aNode->Kill() ;
216 // cdebug_out << "GraphExecutor::DataFlow::Kill" << endl;
220 bool GraphExecutor::DataFlow::KillDone( const char *aNodeName ) {
221 // cdebug_in << "GraphExecutor::DataFlow::KillDone( " << aNodeName << " )"<< endl;
222 bool RetVal = false ;
223 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
225 RetVal = aNode->KillDone() ;
227 // cdebug_out << "GraphExecutor::DataFlow::KillDone" << endl;
231 bool GraphExecutor::DataFlow::Suspend() {
232 cdebug_in << "GraphExecutor::DataFlow::Suspend()" << endl;
233 bool RetVal = GraphExecutor::OutNode::Suspend() ;
234 cdebug_out << "GraphExecutor::DataFlow::Suspend()" << RetVal << endl;
238 bool GraphExecutor::DataFlow::Suspend( const char *aNodeName ) {
239 // cdebug_in << "GraphExecutor::DataFlow::Suspend( " << aNodeName << " )"<< endl;
240 bool RetVal = false ;
241 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
243 RetVal = aNode->Suspend() ;
245 // cdebug_out << "GraphExecutor::DataFlow::Suspend" << endl;
249 bool GraphExecutor::DataFlow::SuspendDone() {
250 cdebug_in << "GraphExecutor::DataFlow::SuspendDone()" << endl;
251 bool RetVal = false ;
252 cdebug << "Kill not yet implemented." << endl;
253 cdebug_out << "GraphExecutor::DataFlow::SuspendDone()" << endl;
257 bool GraphExecutor::DataFlow::SuspendDone( const char *aNodeName ) {
258 // cdebug_in << "GraphExecutor::DataFlow::SuspendDone( " << aNodeName << " )"<< endl;
259 bool RetVal = false ;
260 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
262 RetVal = aNode->SuspendDone() ;
264 // cdebug_out << "GraphExecutor::DataFlow::SuspendDone" << endl;
268 bool GraphExecutor::DataFlow::Resume() {
269 cdebug_in << "GraphExecutor::DataFlow::Resume()" << endl;
270 bool RetVal = GraphExecutor::OutNode::Resume() ;
271 cdebug_out << "GraphExecutor::DataFlow::Resume()" << RetVal << endl;
275 bool GraphExecutor::DataFlow::Resume( const char *aNodeName ) {
276 // cdebug_in << "GraphExecutor::DataFlow::Resume( " << aNodeName << " )"<< endl;
277 bool RetVal = false ;
278 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
280 RetVal = aNode->Resume() ;
282 // cdebug_out << "GraphExecutor::DataFlow::Resume" << endl;
286 bool GraphExecutor::DataFlow::Stop() {
287 cdebug_in << "GraphExecutor::DataFlow::Stop()" << endl;
288 bool RetVal = GraphExecutor::OutNode::Stop() ;
289 cdebug_out << "GraphExecutor::DataFlow::Stop()" << endl;
293 bool GraphExecutor::DataFlow::Stop( const char *aNodeName ) {
294 // cdebug_in << "GraphExecutor::DataFlow::Stop( " << aNodeName << " )"<< endl;
295 bool RetVal = false ;
296 GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
298 RetVal = aNode->Stop() ;
300 // cdebug_out << "GraphExecutor::DataFlow::Stop" << endl;