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 : DataFlowBase_InNode.hxx
25 // Author : Jean Rahuel, CEA
29 #ifndef _DATAFLOWEXECUTOR_INNODE_HXX
30 #define _DATAFLOWEXECUTOR_INNODE_HXX
36 #include "DataFlowBase_FactoryNode.hxx"
37 #include "DataFlowBase_GOTONode.hxx"
38 #include "DataFlowBase_LoopNode.hxx"
39 #include "DataFlowBase_EndOfLoopNode.hxx"
40 #include "DataFlowBase_SwitchNode.hxx"
41 #include "DataFlowBase_EndOfSwitchNode.hxx"
43 #include "DataFlowExecutor_FiniteStateMachine.hxx"
45 #define MAXSTACKTHREADSIZE 8191
47 void * run_function(void *p);
49 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
51 extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * args ) ;
53 namespace GraphExecutor {
55 struct ServicesAnyData {
62 // class InNode : public GraphBase::Node {
63 class InNode : public GraphBase::Base {
67 GraphBase::ComputingNode * _ComputingNode ;
68 GraphBase::FactoryNode * _FactoryNode ;
69 GraphBase::InLineNode * _InLineNode ;
70 GraphBase::GOTONode * _GOTONode ;
71 GraphBase::LoopNode * _LoopNode ;
72 GraphBase::EndOfLoopNode * _EndOfLoopNode ;
73 GraphBase::SwitchNode * _SwitchNode ;
74 GraphBase::EndOfSwitchNode * _EndOfSwitchNode ;
76 PyObject * _MyPyRunMethod ;
78 bool _createNewThread ;
79 bool _createNewThreadIf ;
81 SUPERV::AutomatonState _OldState ;
82 SUPERV::AutomatonState _currentState ;
83 GraphExecutor::NodeEvent _CurrentEvent ;
84 SUPERV::ControlState _ControlState ;
85 SUPERV::AutomatonState _NextState ;
86 GraphExecutor::StateEventAction _NextAction ;
89 pthread_mutex_t _MutexDataWait ;
92 pthread_mutex_t _MutexWait ;
94 pthread_cond_t _ReadyWait ;
95 pthread_cond_t _RunningWait ;
96 pthread_cond_t _DoneWait ;
97 pthread_cond_t _SuspendedWait ;
99 pthread_cond_t _SuspendWait ;
101 pthread_cond_t _ResumeWait ;
103 GraphExecutor::NodeEvent _aResumeEvent ;
104 GraphExecutor::InNode * _aReStartNode ;
105 GraphExecutor::NodeEvent _aReStartEvent ;
107 pthread_cond_t _KillWait ;
109 pthread_cond_t _StopWait ;
111 pthread_cond_t _ThreadStartedWait ;
112 bool _ThreadStartedSync ;
114 pthread_t _Pythread ;
118 GraphExecutor::FiniteStateMachine * _Automaton ;
122 GraphExecutor::OutNode * _OutNode ;
124 char * _DataFromNode ;
129 InNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService,
130 const SALOME_ModuleCatalog::Service& NodeService ,
131 const char *NodeComponentName ,
132 const char* NodeInterfaceName ,
133 const char *NodeName ,
134 const SUPERV::KindOfNode akind = SUPERV::ComputingNode ,
135 GraphBase::ListOfFuncName aFuncName = GraphBase::ListOfFuncName() ,
136 GraphBase::ListOfPythonFunctions aPythonFunction = GraphBase::ListOfPythonFunctions() ,
137 const SUPERV::SDate NodeFirstCreation = SUPERV::SDate() ,
138 const SUPERV::SDate NodeLastModification = SUPERV::SDate() ,
139 const char * NodeEditorRelease = NULLSTRING ,
140 const char * NodeAuthor = NULLSTRING ,
141 const char * NodeComputer = NULLSTRING ,
142 const char * NodeComment = NULLSTRING ,
143 const bool GeneratedName = false ,
144 const int NodeX = 0 ,
145 const int NodeY = 0 ,
146 int * Graph_prof_debug = NULL ,
147 ofstream * Graph_fdebug = NULL ) ;
150 pthread_t ThreadNo() {
151 return _ComputingNode->ThreadNo() ; } ;
152 void ThreadNo( pthread_t aThread ) {
153 _ComputingNode->ThreadNo ( aThread ) ; } ;
155 char * Name() const {
156 return _ComputingNode->Name() ; } ;
157 const char *const * NamePtr() const {
158 return _ComputingNode->NamePtr() ; } ;
159 SUPERV::KindOfNode Kind() const {
160 return _ComputingNode->Kind() ; } ;
161 const bool IsComputingNode() const {
162 return _ComputingNode->IsComputingNode() ; } ;
163 const bool IsFactoryNode() const {
164 return _ComputingNode->IsFactoryNode() ; } ;
165 const bool IsInLineNode() const {
166 return _ComputingNode->IsInLineNode() ; } ;
167 const bool IsOneOfInLineNodes() const {
168 return _ComputingNode->IsOneOfInLineNodes() ; } ;
169 const bool IsOneOfGOTONodes() const {
170 return _ComputingNode->IsOneOfGOTONodes() ; } ;
171 const bool IsDataFlowNode() const {
172 return _ComputingNode->IsDataFlowNode() ; } ;
173 const bool IsLoopNode() const {
174 return _ComputingNode->IsLoopNode() ; } ;
175 const bool IsEndLoopNode() const {
176 return _ComputingNode->IsEndLoopNode() ; } ;
177 const bool IsSwitchNode() const {
178 return _ComputingNode->IsSwitchNode() ; } ;
179 const bool IsEndSwitchNode() const {
180 return _ComputingNode->IsEndSwitchNode() ; } ;
181 const bool IsGOTONode() const {
182 return _ComputingNode->IsGOTONode() ; } ;
183 const bool IsHeadNode() const {
184 return _ComputingNode->IsHeadNode() ; } ;
185 GraphBase::ComputingNode * ComputingNode() {
186 return _ComputingNode ; } ;
187 GraphBase::FactoryNode * FactoryNode() {
188 return _FactoryNode ; } ;
189 GraphBase::GOTONode * GOTONode() {
194 if ( _EndOfLoopNode )
195 return _EndOfLoopNode ;
198 if ( _EndOfSwitchNode )
199 return _EndOfSwitchNode ;
202 GraphBase::InLineNode * InLineNode() {
203 GraphBase::InLineNode * aNode = GOTONode() ;
208 GraphBase::LoopNode * LoopNode() {
209 return _LoopNode ; } ;
211 Engines::Component_var Component() const ;
212 Engines::Container_var Container() const ;
213 void SetContainer(Engines::Container_var aContainer) {
214 _FactoryNode->SetContainer( aContainer ) ; } ;
215 void SetComponent(Engines::Component_var anObjComponent) {
216 _FactoryNode->SetComponent( anObjComponent ) ; } ;
217 void ObjInterface( bool k_interface ) {
218 _ComputingNode->ObjInterface( k_interface ) ; } ;
219 bool ObjInterface() {
220 return _FactoryNode->ObjInterface() ; } ;
221 char * ComponentName() const { return _FactoryNode->ComponentName() ; } ;
222 char * InterfaceName() const { return _FactoryNode->InterfaceName() ; } ;
223 char * Computer() const { return _FactoryNode->Computer() ; } ;
224 const char * ServiceName() const {
225 return _ComputingNode->ServiceName() ; } ;
226 const SALOME_ModuleCatalog::ListOfServicesParameter ServiceInParameter() const {
227 return _ComputingNode->ServiceInParameter() ; } ;
228 const SALOME_ModuleCatalog::ListOfServicesParameter ServiceOutParameter() const {
229 return _ComputingNode->ServiceOutParameter() ; } ;
231 void CoupledNode( GraphBase::InLineNode * aCoupledNode ) {
232 GOTONode()->CoupledNode( aCoupledNode ) ; } ;
233 GraphBase::InLineNode * CoupledNode() {
234 return GOTONode()->CoupledNode() ; } ;
236 GraphBase::InPort * AddInPort( const char * InputParameterName ,
237 const char * InputParameterType ,
238 const SUPERV::KindOfPort aKindOfPort ) {
239 return _ComputingNode->AddInPort( InputParameterName ,
242 GraphBase::OutPort * AddOutPort( const char * OutputParameterName ,
243 const char * OutputParameterType ,
244 const SUPERV::KindOfPort aKindOfPort ) {
245 return _ComputingNode->AddOutPort( OutputParameterName ,
246 OutputParameterType ,
248 // void InOutPort( GraphBase::InPort * InputPort ,
249 // GraphBase::OutPort * OutputPort ) {
250 // return _ComputingNode->InOutPort( InputPort , OutputPort ) ; } ;
251 int LinkedNodesSize() const {
252 return _ComputingNode->LinkedNodesSize() ; } ;
253 // GraphBase::ComputingNode * LinkedNodes( int i ) const {
254 GraphBase::StreamNode * LinkedNodes( int i ) const {
255 return _ComputingNode->LinkedNodes( i ) ; } ;
256 const int LinkedInPortsNumber( int i ) const {
257 return _ComputingNode->LinkedInPortsNumber( i ) ; } ;
259 const int GetNodeInPortsSize() const {
260 return _ComputingNode->GetNodeInPortsSize() ; } ;
261 const GraphBase::InPort *GetNodeInLoop() const {
262 return _ComputingNode->GetNodeInLoop() ; } ;
263 const GraphBase::InPort *GetNodeInGate() const {
264 return _ComputingNode->GetNodeInGate() ; } ;
265 const GraphBase::InPort *GetNodeInPort(int i) const {
266 return _ComputingNode->GetNodeInPort( i ) ; } ;
267 GraphBase::InPort *GetChangeNodeInLoop() const {
268 return _ComputingNode->GetChangeNodeInLoop() ; } ;
269 GraphBase::InPort *GetChangeNodeInGate() const {
270 return _ComputingNode->GetChangeNodeInGate() ; } ;
271 GraphBase::InPort *GetChangeNodeInPort(int i) const {
272 return _ComputingNode->GetChangeNodeInPort( i ) ; } ;
273 const int GetNodeOutPortsSize() const {
274 return _ComputingNode->GetNodeOutPortsSize() ; } ;
275 const GraphBase::OutPort *GetNodeOutLoop() const {
276 return _ComputingNode->GetNodeOutLoop() ; } ;
277 const GraphBase::OutPort *GetNodeOutGate() const {
278 return _ComputingNode->GetNodeOutGate() ; } ;
279 const GraphBase::OutPort *GetNodeOutPort(int i) const {
280 return _ComputingNode->GetNodeOutPort( i ) ; } ;
281 GraphBase::OutPort *GetChangeNodeOutLoop() const {
282 return _ComputingNode->GetChangeNodeOutLoop() ; } ;
283 GraphBase::OutPort *GetChangeNodeOutGate() const {
284 return _ComputingNode->GetChangeNodeOutGate() ; } ;
285 GraphBase::OutPort *GetChangeNodeOutPort(int i) const {
286 return _ComputingNode->GetChangeNodeOutPort( i ) ; } ;
288 const GraphBase::InPort *GetInPort( const char *name ) {
289 return _ComputingNode->GetInPort( name ) ; } ;
290 const GraphBase::OutPort *GetOutPort( const char *name ) {
291 return _ComputingNode->GetOutPort( name ) ; } ;
292 GraphBase::InPort *GetChangeInPort( const char *name ) {
293 return _ComputingNode->GetChangeInPort( name ) ; } ;
294 GraphBase::OutPort *GetChangeOutPort( const char *name ) {
295 return _ComputingNode->GetChangeOutPort( name ) ; } ;
297 void PyFuncRunned( bool arunned ) {
298 _PyFuncRunned = arunned ; } ;
299 bool PyFuncRunned() {
300 return _PyFuncRunned ; } ;
303 PyObject * InitPyDynInvoke( char * PyFuncName ,
304 const SUPERV::ListOfStrings * aPythonFunction ,
307 void LockDataWait() ;
308 void UnLockDataWait() ;
309 bool IsLockedDataWait() { return _DataWait ; } ;
312 bool ContainerKill() ;
319 bool ReStart( const char * AtNodeName , const bool AndSuspend ) ;
322 void CreateNewThread( bool k_create ) { _createNewThread = k_create ; } ;
323 void CreateNewThreadIf( bool k_create ) { _createNewThreadIf = k_create ; } ;
324 bool CreateNewThread() { return _createNewThread ; } ;
325 bool CreateNewThreadIf() { return _createNewThreadIf ; } ;
326 void NewThread( pthread_t aThread ) ;
328 void RewindStack( int aRewindStack ) { _RewindStack = aRewindStack ; } ;
329 int RewindStack() const { return _RewindStack ; } ;
331 SUPERV::AutomatonState State() const {
332 return _currentState; };
333 void State(SUPERV::AutomatonState aState ) {
334 // cdebug << "GraphExecutor::InNode::State( "
335 // << Automaton()->StateName( _currentState ) << " --> "
336 // << Automaton()->StateName( aState ) << " )" << endl ;
337 _currentState = aState ; } ;
338 SUPERV::ControlState ControlState() const {
339 return _ControlState; };
340 void ControlState(SUPERV::ControlState aControlState ) {
341 _ControlState = aControlState ; } ;
342 void ControlClear() {
343 _ControlState = SUPERV::VoidState ; } ;
345 void SetAutomaton() {
346 _Automaton = theAutomaton ; } ;
347 GraphExecutor::FiniteStateMachine * Automaton() const {
348 return _Automaton ; } ;
358 bool StateWait( SUPERV::GraphState aState ) ;
362 bool SuspendedWait() ;
364 void InitialState( GraphExecutor::OutNode * theOutNode ) ;
365 bool InitPythonFunctions(bool WithErr ) ;
366 void SetWaitingStates(GraphExecutor::InNode * EndNode ) ;
368 int SendEvent(const GraphExecutor::NodeEvent anEvent ) ;
369 void DataFromNode( char * FromNodeName ) {
370 _DataFromNode = FromNodeName ; } ;
371 const char * DataFromNode() const { return _DataFromNode ; } ;
376 void RunningAction() ;
378 void SuspendedAction() ;
379 GraphExecutor::InNode * SuspendAction() ;
380 bool ResumeAction(GraphExecutor::NodeEvent aResumeEvent ) ;
381 bool ReStartAction( GraphExecutor::InNode * aRestartNode ,
382 GraphExecutor::NodeEvent anEvent ) ;
384 void KilledAction() ;
385 void ThreadStartAction() ;
386 void ThreadStartedAction() ;
388 void StoppedAction() ;
389 int executeAction() ; // New Thread or Same Thread
390 int ExecuteAction() ;
392 int DataWaiting_SomeDataReadyAction() ;
393 int DataUndef_NotAllDataReadyAction() ;
394 int DataUndef_AllDataReadyAction() ;
395 int DataReady_SuspendAction() ;
396 int SuspendedReady_ResumeAction() ;
397 int DataReady_KillAction() ;
398 int DataReady_StopAction() ;
399 int DataReady_ExecuteAction() ;
400 void DynInvoke( Engines::Component_ptr obj,
402 ServicesAnyData * inParams, int nInParams,
403 ServicesAnyData * outParams, int nOutParams) ;
404 void DynInvoke( Engines::Component_ptr obj,
406 const char * aGraphName ,
407 const char * aNodeName );
408 bool PyDynInvoke( PyObject * MyPyRunMethod ,
410 ServicesAnyData * inParams , int nInParams ,
411 ServicesAnyData * inParams , int nOutParams ) ;
413 int Executing_SuspendAction() ;
414 int SuspendedExecuting_ResumeAction() ;
415 int Executing_KillAction() ;
416 int Executing_StopAction() ;
417 int Executing_SuccessAction() ;
418 int Executing_ErrorAction() ;
419 int Successed_SuccessAction() ;
420 bool SendSomeDataReady( char * FromNodeName ) ;
421 int Errored_ErrorAction() ;
422 int Successed_SuspendAction() ;
423 int Errored_SuspendAction() ;
424 int SuspendedSuccessed_ResumeAction() ;
425 int SuspendedErrored_ResumeAction() ;
426 int Successed_KillAction() ;
427 int Errored_KillAction() ;
428 int Successed_StopAction() ;
429 int Errored_StopAction() ;
430 int SuspendedSuccessed_ReStartAction() ;
431 int SuspendedErrored_ReStartAction() ;
432 int SuspendedSuccessed_ReStartAndSuspendAction() ;
433 int SuspendedErrored_ReStartAndSuspendAction() ;
435 void InParametersSet( bool & Err ,
437 ServicesAnyData * InParametersList ) ;
438 void InOutParametersSet( int nOutParams ,
439 ServicesAnyData * OutParametersList ) ;
440 bool OutParametersSet( bool Err , SUPERV::GraphState NewState ,
442 ServicesAnyData * OutParametersList ) ;
446 const long CpuUsed( bool tot = false ) ;
448 long PyCpuUsed( bool tot = false ) ;
449 void SetPyCpuUsed() ;