Salome HOME
The following methods and constants were removed as never being used:
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_InNode.hxx
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   : DataFlowBase_InNode.hxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 #ifndef _DATAFLOWEXECUTOR_INNODE_HXX
30 #define _DATAFLOWEXECUTOR_INNODE_HXX
31
32 #include <stdio.h>
33
34 #include <Python.h>
35
36 #include "SALOME_Container_i.hxx"
37
38 #include "DataFlowBase_Graph.hxx"
39 #include "DataFlowBase_FactoryNode.hxx"
40 #include "DataFlowBase_GOTONode.hxx"
41 #include "DataFlowBase_LoopNode.hxx"
42 #include "DataFlowBase_EndOfLoopNode.hxx"
43 #include "DataFlowBase_SwitchNode.hxx"
44 #include "DataFlowBase_EndOfSwitchNode.hxx"
45
46 #include "DataFlowExecutor_FiniteStateMachine.hxx"
47
48 #define MAXSTACKTHREADSIZE 127
49
50 void * run_function(void *p);
51
52 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
53
54 extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * args ) ;
55
56 namespace GraphExecutor {
57
58   struct ServicesAnyData {
59     string     Name;
60     CORBA::Any Value;
61   };
62
63   class OutNode ;
64
65 //  class InNode : public GraphBase::Node {
66   class InNode : public GraphBase::Base {
67
68     private:
69
70       GraphBase::ComputingNode       * _ComputingNode ;
71       GraphBase::FactoryNode         * _FactoryNode ;
72       GraphBase::InLineNode          * _InLineNode ;
73       GraphBase::GOTONode            * _GOTONode ;
74       GraphBase::LoopNode            * _LoopNode ;
75       GraphBase::EndOfLoopNode       * _EndOfLoopNode ;
76       GraphBase::SwitchNode          * _SwitchNode ;
77       GraphBase::EndOfSwitchNode     * _EndOfSwitchNode ;
78       GraphBase::Graph               * _GraphMacroNode ;
79
80       PyObject                       * _MyPyRunMethod ;
81
82       bool                             _createNewThread ;
83       bool                             _createNewThreadIf ;
84       int                              _RewindStack ;
85       GraphExecutor::AutomatonState    _OldState ;
86       GraphExecutor::AutomatonState    _currentState ;
87       GraphExecutor::NodeEvent         _CurrentEvent ;
88       SUPERV::ControlState             _ControlState ;
89       GraphExecutor::AutomatonState    _NextState ;
90       GraphExecutor::StateEventAction  _NextAction ;
91       bool                             _PyFuncRunned ;
92       bool                             _Loading ;
93     
94       pthread_mutex_t                  _MutexDataWait ;
95       bool                             _DataWait ;
96
97       pthread_mutex_t                  _MutexWait ;
98
99       pthread_cond_t                   _ReadyWait ;
100       pthread_cond_t                   _RunningWait ;
101       pthread_cond_t                   _DoneWait ;
102       pthread_cond_t                   _SuspendedWait ;
103
104       pthread_cond_t                   _SuspendWait ;
105       bool                             _SuspendSync ;
106       pthread_cond_t                   _ResumeWait ;
107       bool                             _ResumeSync ;
108       GraphExecutor::NodeEvent         _aResumeEvent ;
109       GraphExecutor::InNode *          _aReStartNode ;
110       GraphExecutor::NodeEvent         _aReStartEvent ;
111
112       pthread_cond_t                   _KillWait ;
113       bool                             _KillSync ;
114       pthread_cond_t                   _StopWait ;
115
116       pthread_cond_t                   _ThreadStartedWait ;
117       bool                             _ThreadStartedSync ;
118
119       pthread_t                        _Pythread ;
120       long                             _PyCpuUsed ;
121       long                             _PyTotCpuUsed ;
122
123       GraphExecutor::FiniteStateMachine * _Automaton ;
124     
125       CORBA::ORB_ptr                    _Orb;
126
127       GraphExecutor::OutNode          * _OutNode ;
128
129       char                            * _DataFromNode ;
130
131     public:
132
133       InNode() ;
134       InNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService,
135               const SALOME_ModuleCatalog::Service& NodeService ,
136               const char *NodeComponentName ,
137               const char* NodeInterfaceName ,
138               const char *NodeName ,
139               const SUPERV::KindOfNode akind = SUPERV::ComputingNode ,
140               GraphBase::ListOfFuncName aFuncName = GraphBase::ListOfFuncName() ,
141               GraphBase::ListOfPythonFunctions aPythonFunction = GraphBase::ListOfPythonFunctions() ,
142               const SUPERV::SDate NodeFirstCreation = SUPERV::SDate() ,
143               const SUPERV::SDate NodeLastModification = SUPERV::SDate() ,
144               const char * NodeEditorRelease = NULLSTRING ,
145               const char * NodeAuthor = NULLSTRING ,
146               const char * NodeComputer = NULLSTRING ,
147               const char * NodeComment = NULLSTRING ,
148               const bool   GeneratedName = false ,
149               const int NodeX = 0 ,
150               const int NodeY = 0 ,
151               int * Graph_prof_debug = NULL ,
152               ofstream * Graph_fdebug = NULL ) ;
153       virtual ~InNode() ;
154
155       pthread_t ThreadNo() {
156                 return _ComputingNode->ThreadNo() ; } ;
157       void ThreadNo( pthread_t aThread ) {
158            _ComputingNode->ThreadNo ( aThread ) ; } ;
159
160       char * Name() const {
161              return _ComputingNode->Name() ; } ;
162       const char *const * NamePtr() const {
163                           return _ComputingNode->NamePtr() ; } ;
164       SUPERV::KindOfNode Kind() const {
165                          return _ComputingNode->Kind() ; } ;
166       const bool IsComputingNode() const {
167                  return _ComputingNode->IsComputingNode() ; } ;
168       const bool IsFactoryNode() const {
169                  return _ComputingNode->IsFactoryNode() ; } ;
170       const bool IsInLineNode() const {
171                  return _ComputingNode->IsInLineNode() ; } ;
172       const bool IsOneOfInLineNodes() const {
173                  return _ComputingNode->IsOneOfInLineNodes() ; } ;
174       const bool IsOneOfGOTONodes() const {
175                  return _ComputingNode->IsOneOfGOTONodes() ; } ;
176       const bool IsMacroNode() const {
177                  return _ComputingNode->IsMacroNode() ; } ;
178       const bool IsDataFlowNode() const {
179                  return _ComputingNode->IsDataFlowNode() ; } ;
180       const bool IsDataStreamNode() const {
181                  return _ComputingNode->IsDataStreamNode() ; } ;
182       const bool IsLoopNode() const {
183                  return _ComputingNode->IsLoopNode() ; } ;
184       const bool IsEndLoopNode() const {
185                  return _ComputingNode->IsEndLoopNode() ; } ;
186       const bool IsSwitchNode() const {
187                  return _ComputingNode->IsSwitchNode() ; } ;
188       const bool IsEndSwitchNode() const {
189                  return _ComputingNode->IsEndSwitchNode() ; } ;
190       const bool IsGOTONode() const {
191                  return _ComputingNode->IsGOTONode() ; } ;
192       const bool IsHeadNode() const {
193                  return _ComputingNode->IsHeadNode() ; } ;
194       GraphBase::ComputingNode * ComputingNode() {
195                                  return _ComputingNode ; } ;
196       GraphBase::FactoryNode * FactoryNode() {
197                                  return _FactoryNode ; } ;
198       GraphBase::GOTONode * GOTONode() {
199                             if ( _GOTONode )
200                               return _GOTONode ;
201                             if ( _LoopNode )
202                               return _LoopNode ;
203                             if ( _EndOfLoopNode )
204                               return _EndOfLoopNode ;
205                             if ( _SwitchNode )
206                               return _SwitchNode ;
207                             if ( _EndOfSwitchNode )
208                               return _EndOfSwitchNode ;
209                             return NULL ;
210                             } ;
211       GraphBase::InLineNode * InLineNode() {
212                               GraphBase::InLineNode * aNode = GOTONode() ;
213                               if ( aNode == NULL )
214                                 return _InLineNode ;
215                               return aNode ;
216                               } ;
217       GraphBase::LoopNode * LoopNode() {
218                             return _LoopNode ; } ;
219       GraphBase::Graph * GraphMacroNode() {
220                          return _GraphMacroNode ; } ;
221
222       SUPERV::CNode_var ObjRef() const { return _ComputingNode->ObjRef() ; } ;
223       void SetObjRef( SUPERV::CNode_var aNode ) {
224                      _ComputingNode->SetObjRef( aNode ) ; } ;
225
226       CNode_Impl * ObjImpl() const { return _ComputingNode->ObjImpl() ; } ;
227       void SetObjImpl( CNode_Impl * aGraph ) {
228                        _ComputingNode->SetObjImpl( aGraph ) ; } ;
229
230       Engines::Component_var Component() const ;
231       Engines::Container_var Container() const ;
232       void SetContainer(Engines::Container_var aContainer) {
233                         _FactoryNode->SetContainer( aContainer ) ; } ;
234       void SetComponent(Engines::Component_var anObjComponent) {
235                         _FactoryNode->SetComponent( anObjComponent ) ; } ;
236       void ObjInterface( bool k_interface ) {
237                         _ComputingNode->ObjInterface( k_interface ) ; } ;
238       bool ObjInterface() {
239                         return _FactoryNode->ObjInterface() ; } ;
240       char * ComponentName() const { return _FactoryNode->ComponentName() ; } ;
241       char * InterfaceName() const { return _FactoryNode->InterfaceName() ; } ;
242       char * Computer() const { return _FactoryNode->Computer() ; } ;
243       const char * ServiceName() const {
244                    return _ComputingNode->ServiceName() ; } ;
245       const SALOME_ModuleCatalog::ListOfServicesParameter ServiceInParameter() const {
246             return _ComputingNode->ServiceInParameter() ; } ;
247       const SALOME_ModuleCatalog::ListOfServicesParameter ServiceOutParameter() const {
248             return _ComputingNode->ServiceOutParameter() ; } ;
249
250       void CoupledNode( GraphBase::InLineNode * aCoupledNode ) {
251            GOTONode()->CoupledNode( aCoupledNode ) ; } ;
252       GraphBase::InLineNode * CoupledNode() {
253                               return GOTONode()->CoupledNode() ; } ;
254
255       GraphBase::InPort * AddInPort( const char * InputParameterName ,
256                                      const char * InputParameterType ,
257                                      const SUPERV::KindOfPort aKindOfPort ) {
258                           return _ComputingNode->AddInPort( InputParameterName ,
259                                                             InputParameterType ,
260                                                             aKindOfPort ) ; } ;
261       GraphBase::OutPort * AddOutPort( const char * OutputParameterName ,
262                                        const char * OutputParameterType ,
263                                        const SUPERV::KindOfPort aKindOfPort ) {
264                            return _ComputingNode->AddOutPort( OutputParameterName ,
265                                                               OutputParameterType ,
266                                                               aKindOfPort ) ; } ;
267 //      void InOutPort( GraphBase::InPort * InputPort ,
268 //                      GraphBase::OutPort * OutputPort ) {
269 //           return _ComputingNode->InOutPort( InputPort , OutputPort ) ; } ;
270       int LinkedNodesSize() const {
271           return _ComputingNode->LinkedNodesSize() ; } ;
272 //      GraphBase::ComputingNode * LinkedNodes( int i ) const {
273       GraphBase::StreamNode * LinkedNodes( int i ) const {
274                               return _ComputingNode->LinkedNodes( i ) ; } ;
275       const int LinkedInPortsNumber( int i ) const {
276                 return _ComputingNode->LinkedInPortsNumber( i ) ; } ;
277
278       const int GetNodeInPortsSize() const {
279                 return _ComputingNode->GetNodeInPortsSize() ; } ;
280       const GraphBase::InPort *GetNodeInLoop() const {
281                               return _ComputingNode->GetNodeInLoop() ; } ;
282       const GraphBase::InPort *GetNodeInGate() const {
283                               return _ComputingNode->GetNodeInGate() ; } ;
284       const GraphBase::InPort *GetNodeInPort(int i) const {
285                               return _ComputingNode->GetNodeInPort( i ) ; } ;
286       GraphBase::InPort *GetChangeNodeInLoop() const {
287                         return _ComputingNode->GetChangeNodeInLoop() ; } ;
288       GraphBase::InPort *GetChangeNodeInGate() const {
289                         return _ComputingNode->GetChangeNodeInGate() ; } ;
290       GraphBase::InPort *GetChangeNodeInPort(int i) const {
291                         return _ComputingNode->GetChangeNodeInPort( i ) ; } ;
292       const int GetNodeOutPortsSize() const {
293                 return _ComputingNode->GetNodeOutPortsSize() ; } ;
294       const GraphBase::OutPort *GetNodeOutLoop() const {
295                                return _ComputingNode->GetNodeOutLoop() ; } ;
296       const GraphBase::OutPort *GetNodeOutGate() const {
297                                return _ComputingNode->GetNodeOutGate() ; } ;
298       const GraphBase::OutPort *GetNodeOutPort(int i) const {
299                                return _ComputingNode->GetNodeOutPort( i ) ; } ;
300       GraphBase::OutPort *GetChangeNodeOutLoop() const {
301                          return _ComputingNode->GetChangeNodeOutLoop() ; } ;
302       GraphBase::OutPort *GetChangeNodeOutGate() const {
303                          return _ComputingNode->GetChangeNodeOutGate() ; } ;
304       GraphBase::OutPort *GetChangeNodeOutPort(int i) const {
305                          return _ComputingNode->GetChangeNodeOutPort( i ) ; } ;
306
307       const GraphBase::InPort *GetInPort( const char *name ) {
308             return _ComputingNode->GetInPort( name ) ; } ;
309       const GraphBase::OutPort *GetOutPort( const char *name ) {
310             return _ComputingNode->GetOutPort( name ) ; } ;
311       GraphBase::InPort *GetChangeInPort( const char *name ) {
312                         return _ComputingNode->GetChangeInPort( name ) ; } ;
313       GraphBase::OutPort *GetChangeOutPort( const char *name ) {
314                          return _ComputingNode->GetChangeOutPort( name ) ; } ;
315
316       void PyFuncRunned( bool arunned ) {
317            _PyFuncRunned = arunned ; } ;
318       bool PyFuncRunned() {
319            return _PyFuncRunned ; } ;
320
321       void OutNode( GraphExecutor::OutNode * theOutNode ) {
322            _OutNode = theOutNode ; } ;
323
324       bool InitPython() ;
325       PyObject * InitPyDynInvoke( char * PyFuncName ,
326                                   const SUPERV::ListOfStrings * aPythonFunction ,
327                                   bool & Err ) ;
328
329       void LockDataWait() ;
330       void UnLockDataWait() ;
331       bool IsLockedDataWait() { return _DataWait ; } ;
332
333       bool Ping() ;
334       bool ContainerKill() ;
335
336       bool Kill() ;
337       bool KillDone() ;
338       bool Suspend() ;
339       bool SuspendDone() ;
340       bool Resume() ;
341       bool Stop() ;
342
343       void CreateNewThread( bool k_create ) { _createNewThread = k_create ; } ;
344       void CreateNewThreadIf( bool k_create ) { _createNewThreadIf = k_create ; } ;
345       bool CreateNewThread() { return _createNewThread ; } ;
346       bool CreateNewThreadIf() { return _createNewThreadIf ; } ;
347       void NewThread( pthread_t aThread ) ;
348       void ExitThread() ;
349       void RewindStack( int aRewindStack ) { _RewindStack = aRewindStack ; } ;
350       int RewindStack() const { return _RewindStack ; } ;
351
352       GraphExecutor::AutomatonState State() const {
353              return _currentState; };
354       void State(GraphExecutor::AutomatonState aState ) {
355 //           cdebug << "GraphExecutor::InNode::State( "
356 //                  << Automaton()->StateName( _currentState ) << " --> "
357 //                  << Automaton()->StateName( aState ) << " )"  << endl ;
358            _currentState = aState ; } ;
359       SUPERV::ControlState ControlState() const {
360              return _ControlState; };
361       void ControlState(SUPERV::ControlState aControlState ) {
362            _ControlState = aControlState ; } ;
363       void ControlClear() {
364            _ControlState = SUPERV::VoidState ; } ;
365
366       void SetAutomaton() {
367             _Automaton = theAutomaton ; } ;
368       GraphExecutor::FiniteStateMachine * Automaton() const {
369             return _Automaton ; } ;
370
371       bool IsWaiting() ;
372       bool IsReady() ;
373       bool IsRunning() ;
374       bool IsDone() ;
375       bool IsSuspended() ;
376       bool IsKilled() ;
377       bool IsStopped() ;
378       void IsLoading( bool Loading );
379       bool IsLoading() { return _Loading ; } ;
380
381       bool StateWait( SUPERV::GraphState aState ) ;
382       bool ReadyWait() ;
383       bool RunningWait() ;
384       bool DoneWait() ;
385       bool SuspendedWait() ;
386
387       void InitialState() ;
388       bool InitPythonFunctions(bool WithErr ) ;
389       void SetWaitingStates(GraphExecutor::InNode * EndNode ) ;
390
391       int SendEvent(const GraphExecutor::NodeEvent anEvent ) ;
392       void DataFromNode( char * FromNodeName ) {
393            _DataFromNode = FromNodeName ; } ;
394       const char * DataFromNode() const { return _DataFromNode ; } ;
395
396       int ErrorAction();
397       int VoidAction();
398       void ReadyAction() ;
399       void RunningAction() ;
400       void DoneAction() ;
401       void SuspendedAction() ;
402       GraphExecutor::InNode * SuspendAction() ;
403       bool ResumeAction(GraphExecutor::NodeEvent aResumeEvent ) ;
404       bool ReStartAction( GraphExecutor::InNode * aRestartNode ,
405                           GraphExecutor::NodeEvent anEvent ) ;
406       void KillAction() ;
407       void KilledAction() ;
408       void ThreadStartAction() ;
409       void ThreadStartedAction() ;
410       void StopAction() ;
411       void StoppedAction() ;
412       int executeAction() ; // New Thread or Same Thread
413       int ExecuteAction() ;
414
415       int DataWaiting_SomeDataReadyAction() ;
416       int DataUndef_NotAllDataReadyAction() ;
417       int DataUndef_AllDataReadyAction() ;
418       int DataReady_SuspendAction() ;
419       int SuspendedReady_ResumeAction() ;
420       int DataReady_KillAction() ;
421       int DataReady_StopAction() ;
422       int DataReady_ExecuteAction() ;
423       void DynInvoke( Engines::Component_ptr obj,
424                       const char *method, 
425                       ServicesAnyData * inParams, int nInParams,
426                       ServicesAnyData * outParams, int nOutParams) ;
427       void DynInvoke( Engines::Component_ptr obj,
428                       const char *method, 
429                       const char * aGraphName ,
430                       const char * aNodeName );
431       bool PyDynInvoke( PyObject * MyPyRunMethod ,
432                         const char *method , 
433                         ServicesAnyData * inParams , int nInParams ,
434                         ServicesAnyData * inParams , int nOutParams ) ;
435
436       int Executing_SuspendAction() ;
437       int SuspendedExecuting_ResumeAction() ;
438       int Executing_KillAction() ;
439       int Executing_StopAction() ;
440       int Executing_SuccessAction() ;
441       int Executing_ErrorAction() ;
442       int Successed_SuccessAction() ;
443       bool SendSomeDataReady( char * FromNodeName ) ;
444       int Errored_ErrorAction() ;
445       int Successed_SuspendAction() ;
446       int Errored_SuspendAction() ;
447       int SuspendedSuccessed_ResumeAction() ;
448       int SuspendedErrored_ResumeAction() ;
449       int Successed_KillAction() ;
450       int Errored_KillAction() ;
451       int Successed_StopAction() ;
452       int Errored_StopAction() ;
453       int SuspendedSuccessed_ReStartAction() ;
454       int SuspendedErrored_ReStartAction() ;
455       int SuspendedSuccessed_ReStartAndSuspendAction() ;
456       int SuspendedErrored_ReStartAndSuspendAction() ;
457
458       void InParametersSet( bool & Err ,
459                             int  nInParams ,
460                             ServicesAnyData * InParametersList ) ;
461       void InOutParametersSet( int nOutParams ,
462                                ServicesAnyData * OutParametersList ) ;
463       bool OutParametersSet( bool Err , SUPERV::GraphState NewState ,
464                              int nOutParams ,
465                              ServicesAnyData * OutParametersList ) ;
466       void coutbegin() ;
467       void coutexit() ;
468
469       const long CpuUsed( bool tot = false ) ;
470
471       long PyCpuUsed( bool tot = false ) ;
472       void SetPyCpuUsed() ;
473       long PyCpu() ;
474
475       bool PyRunSimpleString( char* thePyString );
476       PyObject * PyEvalCallObject( PyObject * MyPyRunMethod ,
477                                    PyObject * ArgsList ) ;
478     } ;
479
480 } ;
481
482 #endif
483