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 void * run_function(void *p);
47 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
49 extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * args ) ;
51 namespace GraphExecutor {
53 struct ServicesAnyData {
60 // class InNode : public GraphBase::Node {
61 class InNode : public GraphBase::Base {
65 GraphBase::ComputingNode * _ComputingNode ;
66 GraphBase::FactoryNode * _FactoryNode ;
67 GraphBase::InLineNode * _InLineNode ;
68 GraphBase::GOTONode * _GOTONode ;
69 GraphBase::LoopNode * _LoopNode ;
70 GraphBase::EndOfLoopNode * _EndOfLoopNode ;
71 GraphBase::SwitchNode * _SwitchNode ;
72 GraphBase::EndOfSwitchNode * _EndOfSwitchNode ;
74 PyObject * _MyPyRunMethod ;
76 bool _createNewThread ;
77 bool _createNewThreadIf ;
79 SUPERV::AutomatonState _OldState ;
80 SUPERV::AutomatonState _currentState ;
81 GraphExecutor::NodeEvent _CurrentEvent ;
82 SUPERV::ControlState _ControlState ;
83 SUPERV::AutomatonState _NextState ;
84 GraphExecutor::StateEventAction _NextAction ;
87 pthread_mutex_t _MutexDataWait ;
90 pthread_mutex_t _MutexWait ;
92 pthread_cond_t _ReadyWait ;
93 pthread_cond_t _RunningWait ;
94 pthread_cond_t _DoneWait ;
95 pthread_cond_t _SuspendedWait ;
97 pthread_cond_t _SuspendWait ;
99 pthread_cond_t _ResumeWait ;
101 GraphExecutor::NodeEvent _aResumeEvent ;
102 GraphExecutor::InNode * _aReStartNode ;
103 GraphExecutor::NodeEvent _aReStartEvent ;
105 pthread_cond_t _KillWait ;
107 pthread_cond_t _StopWait ;
109 pthread_t _Pythread ;
113 GraphExecutor::FiniteStateMachine * _Automaton ;
117 GraphExecutor::OutNode * _OutNode ;
119 char * _DataFromNode ;
124 InNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService,
125 const SALOME_ModuleCatalog::Service& NodeService ,
126 const char *NodeComponentName ,
127 const char* NodeInterfaceName ,
128 const char *NodeName ,
129 const SUPERV::KindOfNode akind = SUPERV::ComputingNode ,
130 GraphBase::ListOfFuncName aFuncName = GraphBase::ListOfFuncName() ,
131 GraphBase::ListOfPythonFunctions aPythonFunction = GraphBase::ListOfPythonFunctions() ,
132 const SUPERV::SDate NodeFirstCreation = SUPERV::SDate() ,
133 const SUPERV::SDate NodeLastModification = SUPERV::SDate() ,
134 const char * NodeEditorRelease = NULLSTRING ,
135 const char * NodeAuthor = NULLSTRING ,
136 const char * NodeComputer = NULLSTRING ,
137 const char * NodeComment = NULLSTRING ,
138 const bool GeneratedName = false ,
139 const int NodeX = 0 ,
140 const int NodeY = 0 ,
141 int * Graph_prof_debug = NULL ,
142 ofstream * Graph_fdebug = NULL ) ;
145 pthread_t ThreadNo() {
146 return _ComputingNode->ThreadNo() ; } ;
147 void ThreadNo( pthread_t aThread ) {
148 _ComputingNode->ThreadNo ( aThread ) ; } ;
150 char * Name() const {
151 return _ComputingNode->Name() ; } ;
152 const char *const * NamePtr() const {
153 return _ComputingNode->NamePtr() ; } ;
154 SUPERV::KindOfNode Kind() const {
155 return _ComputingNode->Kind() ; } ;
156 const bool IsComputingNode() const {
157 return _ComputingNode->IsComputingNode() ; } ;
158 const bool IsFactoryNode() const {
159 return _ComputingNode->IsFactoryNode() ; } ;
160 const bool IsInLineNode() const {
161 return _ComputingNode->IsInLineNode() ; } ;
162 const bool IsOneOfInLineNodes() const {
163 return _ComputingNode->IsOneOfInLineNodes() ; } ;
164 const bool IsOneOfGOTONodes() const {
165 return _ComputingNode->IsOneOfGOTONodes() ; } ;
166 const bool IsDataFlowNode() const {
167 return _ComputingNode->IsDataFlowNode() ; } ;
168 const bool IsLoopNode() const {
169 return _ComputingNode->IsLoopNode() ; } ;
170 const bool IsEndLoopNode() const {
171 return _ComputingNode->IsEndLoopNode() ; } ;
172 const bool IsSwitchNode() const {
173 return _ComputingNode->IsSwitchNode() ; } ;
174 const bool IsEndSwitchNode() const {
175 return _ComputingNode->IsEndSwitchNode() ; } ;
176 const bool IsGOTONode() const {
177 return _ComputingNode->IsGOTONode() ; } ;
178 const bool IsHeadNode() const {
179 return _ComputingNode->IsHeadNode() ; } ;
180 GraphBase::ComputingNode * ComputingNode() {
181 return _ComputingNode ; } ;
182 GraphBase::FactoryNode * FactoryNode() {
183 return _FactoryNode ; } ;
184 GraphBase::GOTONode * GOTONode() {
189 if ( _EndOfLoopNode )
190 return _EndOfLoopNode ;
193 if ( _EndOfSwitchNode )
194 return _EndOfSwitchNode ;
197 GraphBase::InLineNode * InLineNode() {
198 GraphBase::InLineNode * aNode = GOTONode() ;
203 GraphBase::LoopNode * LoopNode() {
204 return _LoopNode ; } ;
206 Engines::Component_var Component() const ;
207 Engines::Container_var Container() const ;
208 void SetContainer(Engines::Container_var aContainer) {
209 _FactoryNode->SetContainer( aContainer ) ; } ;
210 void SetComponent(Engines::Component_var anObjComponent) {
211 _FactoryNode->SetComponent( anObjComponent ) ; } ;
212 void ObjInterface( bool k_interface ) {
213 _ComputingNode->ObjInterface( k_interface ) ; } ;
214 bool ObjInterface() {
215 return _FactoryNode->ObjInterface() ; } ;
216 char * ComponentName() const { return _FactoryNode->ComponentName() ; } ;
217 char * InterfaceName() const { return _FactoryNode->InterfaceName() ; } ;
218 char * Computer() const { return _FactoryNode->Computer() ; } ;
219 const char * ServiceName() const {
220 return _ComputingNode->ServiceName() ; } ;
221 const SALOME_ModuleCatalog::ListOfServicesParameter ServiceInParameter() const {
222 return _ComputingNode->ServiceInParameter() ; } ;
223 const SALOME_ModuleCatalog::ListOfServicesParameter ServiceOutParameter() const {
224 return _ComputingNode->ServiceOutParameter() ; } ;
226 void CoupledNode( GraphBase::InLineNode * aCoupledNode ) {
227 GOTONode()->CoupledNode( aCoupledNode ) ; } ;
228 GraphBase::InLineNode * CoupledNode() {
229 return GOTONode()->CoupledNode() ; } ;
231 GraphBase::InPort * AddInPort( const char * InputParameterName ,
232 const char * InputParameterType ) {
233 return _ComputingNode->AddInPort( InputParameterName ,
234 InputParameterType ) ; } ;
235 GraphBase::OutPort * AddOutPort( const char * OutputParameterName ,
236 const char * OutputParameterType ) {
237 return _ComputingNode->AddOutPort( OutputParameterName ,
238 OutputParameterType ) ; } ;
239 // void InOutPort( GraphBase::InPort * InputPort ,
240 // GraphBase::OutPort * OutputPort ) {
241 // return _ComputingNode->InOutPort( InputPort , OutputPort ) ; } ;
242 int LinkedNodesSize() const {
243 return _ComputingNode->LinkedNodesSize() ; } ;
244 GraphBase::ComputingNode * LinkedNodes( int i ) const {
245 return _ComputingNode->LinkedNodes( i ) ; } ;
246 const int LinkedInPortsNumber( int i ) const {
247 return _ComputingNode->LinkedInPortsNumber( i ) ; } ;
249 const int GetNodeInPortsSize() const {
250 return _ComputingNode->GetNodeInPortsSize() ; } ;
251 const GraphBase::InPort *GetNodeInLoop() const {
252 return _ComputingNode->GetNodeInLoop() ; } ;
253 const GraphBase::InPort *GetNodeInGate() const {
254 return _ComputingNode->GetNodeInGate() ; } ;
255 const GraphBase::InPort *GetNodeInPort(int i) const {
256 return _ComputingNode->GetNodeInPort( i ) ; } ;
257 GraphBase::InPort *GetChangeNodeInLoop() const {
258 return _ComputingNode->GetChangeNodeInLoop() ; } ;
259 GraphBase::InPort *GetChangeNodeInGate() const {
260 return _ComputingNode->GetChangeNodeInGate() ; } ;
261 GraphBase::InPort *GetChangeNodeInPort(int i) const {
262 return _ComputingNode->GetChangeNodeInPort( i ) ; } ;
263 const int GetNodeOutPortsSize() const {
264 return _ComputingNode->GetNodeOutPortsSize() ; } ;
265 const GraphBase::OutPort *GetNodeOutLoop() const {
266 return _ComputingNode->GetNodeOutLoop() ; } ;
267 const GraphBase::OutPort *GetNodeOutGate() const {
268 return _ComputingNode->GetNodeOutGate() ; } ;
269 const GraphBase::OutPort *GetNodeOutPort(int i) const {
270 return _ComputingNode->GetNodeOutPort( i ) ; } ;
271 GraphBase::OutPort *GetChangeNodeOutLoop() const {
272 return _ComputingNode->GetChangeNodeOutLoop() ; } ;
273 GraphBase::OutPort *GetChangeNodeOutGate() const {
274 return _ComputingNode->GetChangeNodeOutGate() ; } ;
275 GraphBase::OutPort *GetChangeNodeOutPort(int i) const {
276 return _ComputingNode->GetChangeNodeOutPort( i ) ; } ;
278 const GraphBase::InPort *GetInPort( const char *name ) {
279 return _ComputingNode->GetInPort( name ) ; } ;
280 const GraphBase::OutPort *GetOutPort( const char *name ) {
281 return _ComputingNode->GetOutPort( name ) ; } ;
282 GraphBase::InPort *GetChangeInPort( const char *name ) {
283 return _ComputingNode->GetChangeInPort( name ) ; } ;
284 GraphBase::OutPort *GetChangeOutPort( const char *name ) {
285 return _ComputingNode->GetChangeOutPort( name ) ; } ;
287 void PyFuncRunned( bool arunned ) {
288 _PyFuncRunned = arunned ; } ;
289 bool PyFuncRunned() {
290 return _PyFuncRunned ; } ;
293 PyObject * InitPyDynInvoke( char * PyFuncName ,
294 const SUPERV::ListOfStrings * aPythonFunction ) ;
296 void LockDataWait() ;
297 void UnLockDataWait() ;
298 bool IsLockedDataWait() { return _DataWait ; } ;
301 bool ContainerKill() ;
308 bool ReStart( const char * AtNodeName , const bool AndSuspend ) ;
311 void CreateNewThread( bool k_create ) { _createNewThread = k_create ; } ;
312 void CreateNewThreadIf( bool k_create ) { _createNewThreadIf = k_create ; } ;
313 bool CreateNewThread() { return _createNewThread ; } ;
314 bool CreateNewThreadIf() { return _createNewThreadIf ; } ;
315 void NewThread( pthread_t aThread ) ;
317 void RewindStack( int aRewindStack ) { _RewindStack = aRewindStack ; } ;
318 int RewindStack() const { return _RewindStack ; } ;
320 SUPERV::AutomatonState State() const {
321 return _currentState; };
322 void State(SUPERV::AutomatonState aState ) {
323 // cdebug << "GraphExecutor::InNode::State( "
324 // << Automaton()->StateName( _currentState ) << " --> "
325 // << Automaton()->StateName( aState ) << " )" << endl ;
326 _currentState = aState ; } ;
327 SUPERV::ControlState ControlState() const {
328 return _ControlState; };
329 void ControlState(SUPERV::ControlState aControlState ) {
330 _ControlState = aControlState ; } ;
331 void ControlClear() {
332 _ControlState = SUPERV::VoidState ; } ;
334 void SetAutomaton() {
335 _Automaton = theAutomaton ; } ;
336 GraphExecutor::FiniteStateMachine * Automaton() const {
337 return _Automaton ; } ;
347 bool StateWait( SUPERV::GraphState aState ) ;
351 bool SuspendedWait() ;
353 void InitialState( GraphExecutor::OutNode * theOutNode );
354 void SetWaitingStates(GraphExecutor::InNode * EndNode ) ;
356 int SendEvent(const GraphExecutor::NodeEvent anEvent ) ;
357 void DataFromNode( char * FromNodeName ) {
358 _DataFromNode = FromNodeName ; } ;
359 const char * DataFromNode() const { return _DataFromNode ; } ;
364 void RunningAction() ;
366 void SuspendedAction() ;
367 GraphExecutor::InNode * SuspendAction() ;
368 bool ResumeAction(GraphExecutor::NodeEvent aResumeEvent ) ;
369 bool ReStartAction( GraphExecutor::InNode * aRestartNode ,
370 GraphExecutor::NodeEvent anEvent ) ;
372 void KilledAction() ;
374 void StoppedAction() ;
375 int executeAction() ; // New Thread or Same Thread
376 int ExecuteAction() ;
378 int DataWaiting_SomeDataReadyAction() ;
379 int DataUndef_NotAllDataReadyAction() ;
380 int DataUndef_AllDataReadyAction() ;
381 int DataReady_SuspendAction() ;
382 int SuspendedReady_ResumeAction() ;
383 int DataReady_KillAction() ;
384 int DataReady_StopAction() ;
385 int DataReady_ExecuteAction() ;
386 void DynInvoke( Engines::Component_ptr obj,
388 ServicesAnyData * inParams, int nInParams,
389 ServicesAnyData * outParams, int nOutParams) ;
390 void DynInvoke( Engines::Component_ptr obj,
392 const char * aGraphName ,
393 const char * aNodeName );
394 bool PyDynInvoke( PyObject * MyPyRunMethod ,
396 ServicesAnyData * inParams , int nInParams ,
397 ServicesAnyData * inParams , int nOutParams ) ;
399 int Executing_SuspendAction() ;
400 int SuspendedExecuting_ResumeAction() ;
401 int Executing_KillAction() ;
402 int Executing_StopAction() ;
403 int Executing_SuccessAction() ;
404 int Executing_ErrorAction() ;
405 int Successed_SuccessAction() ;
406 bool SendSomeDataReady( char * FromNodeName ) ;
407 int Errored_ErrorAction() ;
408 int Successed_SuspendAction() ;
409 int Errored_SuspendAction() ;
410 int SuspendedSuccessed_ResumeAction() ;
411 int SuspendedErrored_ResumeAction() ;
412 int Successed_KillAction() ;
413 int Errored_KillAction() ;
414 int Successed_StopAction() ;
415 int Errored_StopAction() ;
416 int SuspendedSuccessed_ReStartAction() ;
417 int SuspendedErrored_ReStartAction() ;
418 int SuspendedSuccessed_ReStartAndSuspendAction() ;
419 int SuspendedErrored_ReStartAndSuspendAction() ;
421 void InParametersSet( bool & Err ,
423 ServicesAnyData * InParametersList ) ;
424 void InOutParametersSet( int nOutParams ,
425 ServicesAnyData * OutParametersList ) ;
426 bool OutParametersSet( bool Err , SUPERV::GraphState NewState ,
428 ServicesAnyData * OutParametersList ) ;
432 const long CpuUsed( bool tot = false ) ;
434 long PyCpuUsed( bool tot = false ) ;
435 void SetPyCpuUsed() ;