Salome HOME
DCQ:prepare 2.0.0
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_DataFlow.cxx
1 //  SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowExecutor_DataFlow.cxx
25 //  Module : SUPERV
26
27 using namespace std;
28 #include "DataFlowExecutor_DataFlow.hxx"
29
30 // Implementation de la classe GraphExecutor::Graph
31
32 GraphExecutor::DataFlow::DataFlow() :
33   OutNode() {
34   cdebug_in << "GraphExecutor::DataFlow::DataFlowExecutor()" << endl;
35
36   _theNamingService = NULL ;
37   
38   cdebug_out << "GraphExecutor::DataFlow::DataFlowExecutor()" << endl;
39 }
40
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(" ;
48   if ( DataFlowName ) {
49     cdebug << DataFlowName ;
50   }
51   cdebug << ")" << endl;
52
53   _theNamingService = ptrNamingService ;
54
55   cdebug_out << "GraphExecutor::DataFlow::DataFlow" << endl;
56 }
57
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;
78
79   _theNamingService = ptrNamingService ;
80
81   cdebug_out << "GraphExecutor::DataFlow::DataFlow" << endl;
82 } ;
83
84 GraphExecutor::DataFlow::~DataFlow() {
85 //  delete _DataFlowNode ;
86 //  delete _DataFlowDatas ;
87 //  delete _GT ;
88 }
89
90 bool GraphExecutor::DataFlow::Ping( const char *aNodeName ) {
91   cdebug_in << "GraphExecutor::DataFlow::Ping" << aNodeName << " )" << endl;
92   bool RetVal = false ;
93   if ( Graph()->GetGraphNode( aNodeName ) )
94     RetVal = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode())->Ping() ;
95   cdebug_out << "GraphExecutor::DataFlow::Ping" << endl;
96   return RetVal ;
97 }
98
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;
103   return RetVal ;
104 }
105
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()) ;
110   if ( aNode ) {
111     RetVal = aNode->ContainerKill() ;
112   }
113 //  cdebug_out << "GraphExecutor::DataFlow::ContainerKill" << endl;
114   return RetVal ;
115 }
116
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()
128            << endl ;
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() ;
145       }
146       anInNode->CreateNewThread( true ) ;
147       anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
148       State( GraphExecutor::ExecutingState ) ;
149     }
150   }
151   cdebug_out << "GraphExecutor::DataFlow::InputOfAny " << RetVal << endl ;
152   return RetVal ;
153 }
154
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 ) ;
164   int i ;
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() ;
170       int sts ;
171       if ( aLinkedNode->IsLockedDataWait() ) {
172         cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
173                << " IsLockedDataWait --> UnLockDataWait" << endl ;
174       }
175       sts = aLinkedNode->SendSomeDataReady( (char * ) aNodeName ) ;
176       cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
177              << "->SendSomeDataReady( " << aNodeName << " ) sts " << sts << endl ;
178       if ( sts ) {
179         if ( aLinkedNode->State() == GraphExecutor::DataReadyState ) {
180           aLinkedNode->CreateNewThreadIf( true ) ;
181           aLinkedNode->UnLockDataWait() ;
182           int res = aLinkedNode->DataUndef_AllDataReadyAction() ;
183         }
184       }
185     }
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() ) ;
192     }
193     else {
194       cdebug << "GraphExecutor::DataFlow::OutputOfAny to Graph " << anOutPort->ChangeInPorts( i )->NodeName()
195              << "(" << anOutPort->ChangeInPorts( i )->PortName() << ") ignored" << endl ;
196     }
197   }
198   cdebug_out << "GraphExecutor::DataFlow::OutputOfAny " << RetVal << endl ;
199   return RetVal ;
200 }
201
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;
206   return RetVal ;
207 }
208
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()) ;
213   if ( aNode ) {
214     RetVal = aNode->Kill() ;
215   }
216 //  cdebug_out << "GraphExecutor::DataFlow::Kill" << endl;
217   return RetVal ;
218 }
219
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()) ;
224   if ( aNode ) {
225     RetVal = aNode->KillDone() ;
226   }
227 //  cdebug_out << "GraphExecutor::DataFlow::KillDone" << endl;
228   return RetVal ;
229 }
230
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;
235   return RetVal ;
236 }
237
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()) ;
242   if ( aNode ) {
243     RetVal = aNode->Suspend() ;
244   }
245 //  cdebug_out << "GraphExecutor::DataFlow::Suspend" << endl;
246   return RetVal ;
247 }
248
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;
254   return RetVal ;
255 }
256
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()) ;
261   if ( aNode ) {
262     RetVal = aNode->SuspendDone() ;
263   }
264 //  cdebug_out << "GraphExecutor::DataFlow::SuspendDone" << endl;
265   return RetVal ;
266 }
267
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;
272   return RetVal ;
273 }
274
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()) ;
279   if ( aNode ) {
280     RetVal = aNode->Resume() ;
281   }
282 //  cdebug_out << "GraphExecutor::DataFlow::Resume" << endl;
283   return RetVal ;
284 }
285
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;
290   return RetVal ;
291 }
292
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()) ;
297   if ( aNode ) {
298     RetVal = aNode->Stop() ;
299   }
300 //  cdebug_out << "GraphExecutor::DataFlow::Stop" << endl;
301   return RetVal ;
302 }
303