1 //=============================================================================
2 // File : DataFlowBase_InNode.hxx
4 // Author : Jean Rahuel, CEA
7 //=============================================================================
9 #ifndef _DATAFLOWEXECUTOR_INNODE_HXX
10 #define _DATAFLOWEXECUTOR_INNODE_HXX
16 #include "DataFlowBase_FactoryNode.hxx"
17 #include "DataFlowBase_GOTONode.hxx"
18 #include "DataFlowBase_LoopNode.hxx"
19 #include "DataFlowBase_EndOfLoopNode.hxx"
20 #include "DataFlowBase_SwitchNode.hxx"
21 #include "DataFlowBase_EndOfSwitchNode.hxx"
23 #include "DataFlowExecutor_FiniteStateMachine.hxx"
25 void * run_function(void *p);
27 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
29 extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * args ) ;
31 namespace GraphExecutor {
33 struct ServicesAnyData {
40 // class InNode : public GraphBase::Node {
41 class InNode : public GraphBase::Base {
45 GraphBase::ComputingNode * _ComputingNode ;
46 GraphBase::FactoryNode * _FactoryNode ;
47 GraphBase::InLineNode * _InLineNode ;
48 GraphBase::GOTONode * _GOTONode ;
49 GraphBase::LoopNode * _LoopNode ;
50 GraphBase::EndOfLoopNode * _EndOfLoopNode ;
51 GraphBase::SwitchNode * _SwitchNode ;
52 GraphBase::EndOfSwitchNode * _EndOfSwitchNode ;
54 PyObject * _MyPyRunMethod ;
56 bool _createNewThread ;
57 bool _createNewThreadIf ;
58 SUPERV::AutomatonState _currentState ;
59 SUPERV::ControlState _ControlState ;
60 SUPERV::AutomatonState _NextState ;
61 GraphExecutor::StateEventAction _NextAction ;
64 pthread_mutex_t _MutexDataWait ;
67 pthread_mutex_t _MutexWait ;
69 pthread_cond_t _ReadyWait ;
70 pthread_cond_t _RunningWait ;
71 pthread_cond_t _DoneWait ;
72 pthread_cond_t _SuspendedWait ;
74 pthread_cond_t _SuspendWait ;
76 pthread_cond_t _ResumeWait ;
78 GraphExecutor::NodeEvent _aResumeEvent ;
79 GraphExecutor::InNode * _aReStartNode ;
80 GraphExecutor::NodeEvent _aReStartEvent ;
82 pthread_cond_t _KillWait ;
84 pthread_cond_t _StopWait ;
86 GraphExecutor::FiniteStateMachine * _Automaton ;
90 GraphExecutor::OutNode * _OutNode ;
92 char * _DataFromNode ;
97 InNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService,
98 const SALOME_ModuleCatalog::Service& NodeService ,
99 const char *NodeComponentName ,
100 const char* NodeInterfaceName ,
101 const char *NodeName ,
102 const SUPERV::KindOfNode akind = SUPERV::ComputingNode ,
103 GraphBase::ListOfFuncName aFuncName = GraphBase::ListOfFuncName() ,
104 GraphBase::ListOfPythonFunctions aPythonFunction = GraphBase::ListOfPythonFunctions() ,
105 const SUPERV::SDate NodeFirstCreation = SUPERV::SDate() ,
106 const SUPERV::SDate NodeLastModification = SUPERV::SDate() ,
107 const char * NodeEditorRelease = NULL ,
108 const char * NodeAuthor = NULL ,
109 const char * NodeComputer = NULL ,
110 const char * NodeComment = NULL ,
111 const bool GeneratedName = false ,
112 const int NodeX = 0 ,
113 const int NodeY = 0 ,
114 int * Graph_prof_debug = NULL ,
115 ostream * Graph_fdebug = NULL ) ;
118 pthread_t ThreadNo() {
119 return _ComputingNode->ThreadNo() ; } ;
120 void ThreadNo( pthread_t aThread ) {
121 _ComputingNode->ThreadNo ( aThread ) ; } ;
123 char * Name() const {
124 return _ComputingNode->Name() ; } ;
125 const char *const * NamePtr() const {
126 return _ComputingNode->NamePtr() ; } ;
127 SUPERV::KindOfNode Kind() const {
128 return _ComputingNode->Kind() ; } ;
129 const bool IsComputingNode() const {
130 return _ComputingNode->IsComputingNode() ; } ;
131 const bool IsFactoryNode() const {
132 return _ComputingNode->IsFactoryNode() ; } ;
133 const bool IsInLineNode() const {
134 return _ComputingNode->IsInLineNode() ; } ;
135 const bool IsOneOfInLineNodes() const {
136 return _ComputingNode->IsOneOfInLineNodes() ; } ;
137 const bool IsOneOfGOTONodes() const {
138 return _ComputingNode->IsOneOfGOTONodes() ; } ;
139 const bool IsDataFlowNode() const {
140 return _ComputingNode->IsDataFlowNode() ; } ;
141 const bool IsLoopNode() const {
142 return _ComputingNode->IsLoopNode() ; } ;
143 const bool IsEndLoopNode() const {
144 return _ComputingNode->IsEndLoopNode() ; } ;
145 const bool IsSwitchNode() const {
146 return _ComputingNode->IsSwitchNode() ; } ;
147 const bool IsEndSwitchNode() const {
148 return _ComputingNode->IsEndSwitchNode() ; } ;
149 const bool IsGOTONode() const {
150 return _ComputingNode->IsGOTONode() ; } ;
151 const bool IsHeadNode() const {
152 return _ComputingNode->IsHeadNode() ; } ;
153 GraphBase::ComputingNode * ComputingNode() {
154 return _ComputingNode ; } ;
155 GraphBase::FactoryNode * FactoryNode() {
156 return _FactoryNode ; } ;
157 GraphBase::GOTONode * GOTONode() {
162 if ( _EndOfLoopNode )
163 return _EndOfLoopNode ;
166 if ( _EndOfSwitchNode )
167 return _EndOfSwitchNode ;
170 GraphBase::InLineNode * InLineNode() {
171 GraphBase::InLineNode * aNode = GOTONode() ;
176 GraphBase::LoopNode * LoopNode() {
177 return _LoopNode ; } ;
179 Engines::Component_var Component() const {
180 return _FactoryNode->Component() ; } ;
181 Engines::Container_var Container() const {
182 return _FactoryNode->Container() ; } ;
183 void SetContainer(Engines::Container_var aContainer) {
184 _FactoryNode->SetContainer( aContainer ) ; } ;
185 void SetComponent(Engines::Component_var anObjComponent) {
186 _FactoryNode->SetComponent( anObjComponent ) ; } ;
187 void ObjInterface( bool k_interface ) {
188 _ComputingNode->ObjInterface( k_interface ) ; } ;
189 bool ObjInterface() {
190 return _FactoryNode->ObjInterface() ; } ;
191 char * ComponentName() const { return _FactoryNode->ComponentName() ; } ;
192 char * InterfaceName() const { return _FactoryNode->InterfaceName() ; } ;
193 char * Computer() const { return _FactoryNode->Computer() ; } ;
194 const char * ServiceName() const {
195 return _ComputingNode->ServiceName() ; } ;
196 const SALOME_ModuleCatalog::ListOfServicesParameter ServiceInParameter() const {
197 return _ComputingNode->ServiceInParameter() ; } ;
198 const SALOME_ModuleCatalog::ListOfServicesParameter ServiceOutParameter() const {
199 return _ComputingNode->ServiceOutParameter() ; } ;
201 void CoupledNode( GraphBase::InLineNode * aCoupledNode ) {
202 GOTONode()->CoupledNode( aCoupledNode ) ; } ;
203 GraphBase::InLineNode * CoupledNode() {
204 return GOTONode()->CoupledNode() ; } ;
206 GraphBase::InPort * AddInPort( const char * InputParameterName ,
207 const char * InputParameterType ) {
208 return _ComputingNode->AddInPort( InputParameterName ,
209 InputParameterType ) ; } ;
210 GraphBase::OutPort * AddOutPort( const char * OutputParameterName ,
211 const char * OutputParameterType ) {
212 return _ComputingNode->AddOutPort( OutputParameterName ,
213 OutputParameterType ) ; } ;
214 // void InOutPort( GraphBase::InPort * InputPort ,
215 // GraphBase::OutPort * OutputPort ) {
216 // return _ComputingNode->InOutPort( InputPort , OutputPort ) ; } ;
217 int LinkedNodesSize() const {
218 return _ComputingNode->LinkedNodesSize() ; } ;
219 GraphBase::ComputingNode * LinkedNodes( int i ) const {
220 return _ComputingNode->LinkedNodes( i ) ; } ;
221 const int LinkedInPortsNumber( int i ) const {
222 return _ComputingNode->LinkedInPortsNumber( i ) ; } ;
224 const int GetNodeInPortsSize() const {
225 return _ComputingNode->GetNodeInPortsSize() ; } ;
226 const GraphBase::InPort *GetNodeInPort(int i) const {
227 return _ComputingNode->GetNodeInPort( i ) ; } ;
228 GraphBase::InPort *GetChangeNodeInPort(int i) const {
229 return _ComputingNode->GetChangeNodeInPort( i ) ; } ;
230 const int GetNodeOutPortsSize() const {
231 return _ComputingNode->GetNodeOutPortsSize() ; } ;
232 const GraphBase::OutPort *GetNodeOutPort(int i) const {
233 return _ComputingNode->GetNodeOutPort( i ) ; } ;
234 GraphBase::OutPort *GetChangeNodeOutPort(int i) const {
235 return _ComputingNode->GetChangeNodeOutPort( i ) ; } ;
237 const GraphBase::InPort *GetInPort( const char *name ) {
238 return _ComputingNode->GetInPort( name ) ; } ;
239 const GraphBase::OutPort *GetOutPort( const char *name ) {
240 return _ComputingNode->GetOutPort( name ) ; } ;
241 GraphBase::InPort *GetChangeInPort( const char *name ) {
242 return _ComputingNode->GetChangeInPort( name ) ; } ;
243 GraphBase::OutPort *GetChangeOutPort( const char *name ) {
244 return _ComputingNode->GetChangeOutPort( name ) ; } ;
246 void PyFuncRunned( bool arunned ) {
247 _PyFuncRunned = arunned ; } ;
248 bool PyFuncRunned() {
249 return _PyFuncRunned ; } ;
252 PyObject * InitPyDynInvoke( char * PyFuncName ,
253 const SUPERV::ListOfStrings * aPythonFunction ) ;
255 void LockDataWait() ;
256 void UnLockDataWait() ;
257 bool IsLockedDataWait() { return _DataWait ; } ;
260 bool ContainerKill() ;
267 bool ReStart( const char * AtNodeName , const bool AndSuspend ) ;
270 void CreateNewThread( bool k_create ) { _createNewThread = k_create ; } ;
271 void CreateNewThreadIf( bool k_create ) { _createNewThreadIf = k_create ; } ;
272 bool CreateNewThread() { return _createNewThread ; } ;
273 bool CreateNewThreadIf() { return _createNewThreadIf ; } ;
274 void NewThread( pthread_t aThread ) ;
277 SUPERV::AutomatonState State() const {
278 return _currentState; };
279 void State(SUPERV::AutomatonState aState ) {
280 cdebug << "GraphExecutor::InNode::State( "
281 << Automaton()->StateName( _currentState ) << " --> "
282 << Automaton()->StateName( aState ) << " )" << endl ;
283 _currentState = aState ; } ;
284 SUPERV::ControlState ControlState() const {
285 return _ControlState; };
286 void ControlState(SUPERV::ControlState aControlState ) {
287 _ControlState = aControlState ; } ;
288 void ControlClear() {
289 _ControlState = SUPERV::VoidState ; } ;
291 void SetAutomaton() {
292 _Automaton = theAutomaton ; } ;
293 GraphExecutor::FiniteStateMachine * Automaton() const {
294 return _Automaton ; } ;
304 bool StateWait( SUPERV::GraphState aState ) ;
308 bool SuspendedWait() ;
310 void InitialState( GraphExecutor::OutNode * theOutNode );
311 void SetWaitingStates(GraphExecutor::InNode * EndNode ) ;
313 int SendEvent(const GraphExecutor::NodeEvent anEvent ) ;
314 void DataFromNode( char * FromNodeName ) {
315 _DataFromNode = FromNodeName ; } ;
316 const char * DataFromNode() const { return _DataFromNode ; } ;
321 void RunningAction() ;
323 void SuspendedAction() ;
324 GraphExecutor::InNode * SuspendAction() ;
325 bool ResumeAction(GraphExecutor::NodeEvent aResumeEvent ) ;
326 bool ReStartAction( GraphExecutor::InNode * aRestartNode ,
327 GraphExecutor::NodeEvent anEvent ) ;
329 void KilledAction() ;
331 void StoppedAction() ;
332 int executeAction() ; // New Thread or Same Thread
333 int ExecuteAction() ;
335 int DataWaiting_SomeDataReadyAction() ;
336 int DataUndef_NotAllDataReadyAction() ;
337 int DataUndef_AllDataReadyAction() ;
338 int DataReady_SuspendAction() ;
339 int SuspendedReady_ResumeAction() ;
340 int DataReady_KillAction() ;
341 int DataReady_StopAction() ;
342 int DataReady_ExecuteAction() ;
343 void DynInvoke( Engines::Component_ptr obj,
345 ServicesAnyData * inParams, int nInParams,
346 ServicesAnyData * outParams, int nOutParams) ;
347 void DynInvoke( Engines::Component_ptr obj,
349 const char * aGraphName ,
350 const char * aNodeName );
351 bool PyDynInvoke( PyObject * MyPyRunMethod ,
353 ServicesAnyData * inParams , int nInParams ,
354 ServicesAnyData * inParams , int nOutParams ) ;
356 int Executing_SuspendAction() ;
357 int SuspendedExecuting_ResumeAction() ;
358 int Executing_KillAction() ;
359 int Executing_StopAction() ;
360 int Executing_SuccessAction() ;
361 int Executing_ErrorAction() ;
362 int Successed_SuccessAction() ;
363 bool SendSomeDataReady( char * FromNodeName ) ;
364 int Errored_ErrorAction() ;
365 int Successed_SuspendAction() ;
366 int Errored_SuspendAction() ;
367 int SuspendedSuccessed_ResumeAction() ;
368 int SuspendedErrored_ResumeAction() ;
369 int Successed_KillAction() ;
370 int Errored_KillAction() ;
371 int Successed_StopAction() ;
372 int Errored_StopAction() ;
373 int SuspendedSuccessed_ReStartAction() ;
374 int SuspendedErrored_ReStartAction() ;
375 int SuspendedSuccessed_ReStartAndSuspendAction() ;
376 int SuspendedErrored_ReStartAndSuspendAction() ;
378 void InParametersSet( bool & Err ,
380 ServicesAnyData * aListOfInParameters ) ;
381 void InOutParameters( int nOutParams ,
382 ServicesAnyData * aListOfOutParameters ) ;
383 bool OutParameters( bool Err , SUPERV::GraphState NewState ,
385 ServicesAnyData * aListOfOutParameters ) ;