From: rahuel Date: Tue, 30 Aug 2005 07:44:14 +0000 (+0000) Subject: PAL8624 X-Git-Tag: V_3_0_2~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=86a972c624b56fba588a70abe5004c6dcd82421f;p=modules%2Fsuperv.git PAL8624 Clarification of code for InLineNodes Error messages --- diff --git a/src/GraphExecutor/DataFlowExecutor_InNode.cxx b/src/GraphExecutor/DataFlowExecutor_InNode.cxx index c504a20..37dadbd 100644 --- a/src/GraphExecutor/DataFlowExecutor_InNode.cxx +++ b/src/GraphExecutor/DataFlowExecutor_InNode.cxx @@ -57,8 +57,9 @@ static void InitInNode( int &_RewindStack , GraphExecutor::InNode ** _aReStartNode , bool & _PyFuncRunned , PyObject ** _MyPyRunMethod , - pthread_mutex_t &_MutexDataWait , - bool &_DataWait , +// pthread_mutex_t &_MutexDataWait , +// bool &_DataWait , + pthread_mutex_t &_MutexDataReady , pthread_mutex_t &_MutexWait , pthread_cond_t &_ReadyWait , pthread_cond_t &_RunningWait , @@ -84,8 +85,9 @@ static void InitInNode( int &_RewindStack , *_aReStartNode = NULL ; _PyFuncRunned = false ; *_MyPyRunMethod = NULL ; - pthread_mutex_init( &_MutexDataWait , NULL ) ; - _DataWait = false ; +// pthread_mutex_init( &_MutexDataWait , NULL ) ; +// _DataWait = false ; + pthread_mutex_init( &_MutexDataReady , NULL ) ; pthread_mutex_init( &_MutexWait , NULL ) ; if ( pthread_cond_init( &_ReadyWait , NULL ) ) { perror("pthread_cond_init( &_ReadyWait , NULL )") ; @@ -143,8 +145,9 @@ GraphExecutor::InNode::InNode() { &_aReStartNode , _PyFuncRunned , &_MyPyRunMethod , - _MutexDataWait , - _DataWait , +// _MutexDataWait , +// _DataWait , + _MutexDataReady , _MutexWait , _ReadyWait , _RunningWait , @@ -201,8 +204,9 @@ GraphExecutor::InNode::InNode( CORBA::ORB_ptr ORB, &_aReStartNode , _PyFuncRunned , &_MyPyRunMethod , - _MutexDataWait , - _DataWait , +// _MutexDataWait , +// _DataWait , + _MutexDataReady , _MutexWait , _ReadyWait , _RunningWait , @@ -385,6 +389,8 @@ GraphExecutor::InNode::InNode( CORBA::ORB_ptr ORB, GraphExecutor::InNode::~InNode() { } +//JR 15.04.2005 Debug PAL8624 RetroConception : +#if 0 void GraphExecutor::InNode::LockDataWait() { // cdebug_in << "GraphExecutor::InNode::LockDataWait " << endl ; if ( pthread_mutex_lock( &_MutexDataWait ) ) { @@ -403,6 +409,33 @@ void GraphExecutor::InNode::UnLockDataWait() { } // cdebug_out << "GraphExecutor::InNode::UnLockDataWait " << endl ; } +#endif + +//JR 15.04.2005 Debug PAL8624 RetroConception : +void GraphExecutor::InNode::LockDataReady() { +// cdebug_in << pthread_self() << "/" << ThreadNo() +// << "GraphExecutor::InNode::LockDataReady : " << Name() << " _MutexDataReadyLocked " +// << _MutexDataReadyLocked << " HasAllDataReady " << HasAllDataReady() << endl ; + if ( pthread_mutex_lock( &_MutexDataReady ) ) { + perror("MutexDataReady pthread_mutex_lock ") ; + exit( 0 ) ; + } + _MutexDataReadyLocked = true ; +// cdebug_out << pthread_self() << "/" << ThreadNo() +// << "GraphExecutor::InNode::LockDataReady : " << Name() << endl ; +} +void GraphExecutor::InNode::UnLockDataReady() { +// cdebug_in << pthread_self() << "/" << ThreadNo() +// << "GraphExecutor::InNode::UnLockDataReady : " << Name() << " _MutexDataReadyLocked " +// << _MutexDataReadyLocked << " HasAllDataReady " << HasAllDataReady() << endl ; + if ( pthread_mutex_unlock( &_MutexDataReady ) ) { + perror("MutexDataReady pthread_mutex_unlock ") ; + exit( 0 ) ; + } + _MutexDataReadyLocked = false ; +// cdebug_out << pthread_self() << "/" << ThreadNo() +// << "GraphExecutor::InNode::UnLockDataReady : " << Name() << endl ; +} Engines::Component_var GraphExecutor::InNode::Component() const { if ( IsFactoryNode() ) { @@ -433,8 +466,8 @@ Engines::Container_var GraphExecutor::InNode::Container() const { bool GraphExecutor::InNode::Ping() { -// cdebug_in << "GraphExecutor::InNode::Ping" << endl; - bool RetVal ; + cdebug_in << "GraphExecutor::InNode::Ping" << endl; + bool RetVal = true ; if ( IsFactoryNode() ) { RetVal = !CORBA::is_nil( _FactoryNode->Component() ) ; if ( RetVal ) { @@ -453,8 +486,11 @@ bool GraphExecutor::InNode::Ping() { RetVal = false ; } } + else { + cdebug << "GraphExecutor::InNode::Ping Component ObjRef is NIL" << endl; + } } -// cdebug_out << "GraphExecutor::InNode::Ping" << endl ; + cdebug_out << "GraphExecutor::InNode::Ping" << endl ; return RetVal ; } @@ -1317,7 +1353,9 @@ void GraphExecutor::InNode::InitialState() int i; _ControlState = SUPERV::VoidState ; CreateNewThread( false ) ; - CreateNewThreadIf( false ) ; +//JR 15.04.2005 Debug PAL8624 RetroConception : +// CreateNewThreadIf( false ) ; + HasAllDataReady( false ) ; _SuspendSync = false ; _ResumeSync = false ; _InitLoop = false ; @@ -1336,15 +1374,18 @@ void GraphExecutor::InNode::InitialState() GetChangeNodeOutPort(i)->PortState( SUPERV::ReadyState ) ; GetChangeNodeOutPort(i)->PortDone( true ) ; } - else if ( i != 0 || !IsGOTONode() ) { +//JR Debug 01.07.2005 : +// else if ( i != 0 || !IsGOTONode() ) { + else { GetChangeNodeOutPort(i)->PortState( SUPERV::WaitingState ) ; GetChangeNodeOutPort(i)->PortDone( false ) ; } } - int Pc = GetNodeInPortsSize() ; + int InPortsCount = GetNodeInPortsSize() ; for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) { - const GraphBase::InPort * anInPort = GetNodeInPort(i) ; + GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ; + anInPort->PortState( SUPERV::WaitingState ) ; GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ; if ( IsHeadNode() && IsLoopNode() && anInPort->IsLoop() ) { anOutPort->PortStatus( DataConnected ); @@ -1354,7 +1395,7 @@ void GraphExecutor::InNode::InitialState() CORBA::Any anAny = CORBA::Any() ; //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ; anAny <<= (long ) 1 ; - anOutPort->Value( anAny ) ; + anOutPort->SetValue( anAny ) ; _InitLoop = true ; cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus() << " OutPort " << anOutPort->PortStatus() << theAutomaton->StateName( anOutPort->PortState() ) @@ -1379,36 +1420,41 @@ void GraphExecutor::InNode::InitialState() << " Gate HeadNode" << endl ; } else { - cdebug << Name() << " IsHeadNode " << IsHeadNode() << " InPort" << i << " " << anInPort->PortName() - << " " << anInPort->PortStatus() << endl ; + cdebug << Name() << " IsHeadNode " << IsHeadNode() << " InPort" << i << " " + << anInPort->PortName() << " " << anInPort->PortStatus() << endl ; } if ( anInPort->IsGate() && anOutPort == NULL ) { - Pc-- ; - cdebug << "InPort" << i << " " << anInPort->PortName() << " Not connected Pc " << Pc << endl ; + InPortsCount-- ; + cdebug << "InPort" << i << " " << anInPort->PortName() << " Not connected InPortsCount " + << InPortsCount << endl ; } else if ( anOutPort ) { if ( anOutPort->IsDataConnected() || anOutPort->IsDataStream() ) { - Pc-- ; + InPortsCount-- ; anOutPort->PortState( SUPERV::ReadyState ) ; anOutPort->PortDone( true ) ; cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus() - << " " << theAutomaton->StateName( anOutPort->PortState() ) << " Pc " << Pc << endl ; + << " " << theAutomaton->StateName( anOutPort->PortState() ) << " InPortsCount " + << InPortsCount << endl ; } else if ( anOutPort->IsPortConnected() ) { anOutPort->PortState( SUPERV::WaitingState ) ; anOutPort->PortDone( false ) ; - cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus() - << " " << theAutomaton->StateName( anOutPort->PortState() ) << " Pc " << Pc << endl ; + cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " + << anInPort->PortStatus() + << " " << theAutomaton->StateName( anOutPort->PortState() ) << " InPortsCount " + << InPortsCount << endl ; } else { cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus() << " OutPort " << anOutPort->NodeName() << " " << anOutPort->PortName() << " " - << theAutomaton->StateName( anOutPort->PortState() ) << " Pc " << Pc << endl ; + << theAutomaton->StateName( anOutPort->PortState() ) << " InPortsCount " + << InPortsCount << endl ; } } else { cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus() - << " no corresponding OutPort Pc " << Pc << endl ; + << " no corresponding OutPort InPortsCount " << InPortsCount << endl ; } if ( anOutPort ) { if ( !anOutPort->IsDataStream() || anInPort->IsDataStream() ) { @@ -1447,13 +1493,13 @@ void GraphExecutor::InNode::InitialState() } } - _currentState = Pc > 0 ? GraphExecutor::DataWaitingState + _currentState = InPortsCount > 0 ? GraphExecutor::DataWaitingState : GraphExecutor::DataReadyState ; - if ( Pc == GetNodeInPortsSize() ) { + if ( InPortsCount == GetNodeInPortsSize() ) { _OutNode->PushEvent( this , GraphExecutor::NoDataReadyEvent , _currentState ) ; } - else if ( Pc != 0 ) { + else if ( InPortsCount != 0 ) { _OutNode->PushEvent( this , GraphExecutor::SomeDataReadyEvent , _currentState ) ; } @@ -1468,77 +1514,114 @@ void GraphExecutor::InNode::InitialState() << " " << GetNodeOutPort(i)->Kind() << endl ; } - cdebug << "CurrentState = " << theAutomaton->StateName( _currentState ) - << endl; - - cdebug_out << "GraphExecutor::InNode::InitialState" << endl; + cdebug_out << "GraphExecutor::InNode::InitialState Node " << Name() << " CurrentState = " + << theAutomaton->StateName( _currentState ) << " HasAllDataReady " + << HasAllDataReady() << endl; } bool GraphExecutor::InNode::InitPythonFunctions(bool WithErr ) { cdebug_in << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " WithErr " << WithErr << " PyFuncRunned() " << PyFuncRunned() << endl; bool Err = false ; + bool OneErr ; if ( !PyFuncRunned() && IsOneOfInLineNodes() ) { if ( IsLoopNode() ) { PyObject * PyRunMethod = InLineNode()->PyRunMethod() ; PyObject * PyMoreMethod = NULL ; PyObject * PyNextMethod = NULL ; if ( PyRunMethod ) { + OneErr = false ; } else { PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() , InLineNode()->PythonFunction() , - Err ) ; + OneErr ) ; InLineNode()->PyRunMethod( PyRunMethod ) ; } - if ( !Err ) { - PyMoreMethod = LoopNode()->PyMoreMethod() ; - if ( PyMoreMethod ) { - } - else { - PyMoreMethod = InitPyDynInvoke( LoopNode()->PyMoreName() , - LoopNode()->MorePythonFunction() , - Err ) ; - LoopNode()->PyMoreMethod( PyMoreMethod ) ; - } + Err = Err || OneErr ; + if ( OneErr && WithErr ) { + string anErrorMessage = string( "Error while declaring the Python function " ) + + string( LoopNode()->PyFuncName() ) + string( " in Node " ) + + string( Name() ) ; + _OutNode->Graph()->SetMessages( anErrorMessage ) ; } - if ( !Err ) { - PyNextMethod = LoopNode()->PyNextMethod() ; - if ( PyNextMethod ) { - } - else { - PyNextMethod = InitPyDynInvoke( LoopNode()->PyNextName() , - LoopNode()->NextPythonFunction() , - Err ) ; - LoopNode()->PyNextMethod( PyNextMethod ) ; - } + PyMoreMethod = LoopNode()->PyMoreMethod() ; + if ( PyMoreMethod ) { + OneErr = false ; + } + else { + PyMoreMethod = InitPyDynInvoke( LoopNode()->PyMoreName() , + LoopNode()->MorePythonFunction() , + OneErr ) ; + LoopNode()->PyMoreMethod( PyMoreMethod ) ; + } + Err = Err || OneErr ; + if ( OneErr && WithErr ) { + string anErrorMessage = string( "Error while declaring the Python function " ) + + string( LoopNode()->PyMoreName() ) + string( " in Node " ) + + string( Name() ) ; + _OutNode->Graph()->SetMessages( anErrorMessage ) ; + } + PyNextMethod = LoopNode()->PyNextMethod() ; + if ( PyNextMethod ) { + OneErr = false ; } - cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod(Init) " << PyRunMethod - << " PyMoreMethod " << PyMoreMethod << " PyNextMethod " << PyNextMethod << endl; + else { + PyNextMethod = InitPyDynInvoke( LoopNode()->PyNextName() , + LoopNode()->NextPythonFunction() , + OneErr ) ; + LoopNode()->PyNextMethod( PyNextMethod ) ; + } + Err = Err || OneErr ; + if ( OneErr && WithErr ) { + string anErrorMessage = string( "Error while declaring the Python function " ) + + string( LoopNode()->PyNextName() ) + string( " in Node " ) + + string( Name() ) ; + _OutNode->Graph()->SetMessages( anErrorMessage ) ; + } + cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod(Init) " + << PyRunMethod << " PyMoreMethod " << PyMoreMethod << " PyNextMethod " << PyNextMethod + << endl; } else if ( IsInLineNode() || IsSwitchNode() ) { PyObject * PyRunMethod = InLineNode()->PyRunMethod() ; if ( PyRunMethod ) { + OneErr = false ; } else { PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() , InLineNode()->PythonFunction() , - Err ) ; + OneErr ) ; InLineNode()->PyRunMethod( PyRunMethod ) ; } + Err = Err || OneErr ; + if ( OneErr && WithErr ) { + string anErrorMessage = string( "Error while declaring the Python function " ) + + string( InLineNode()->PyFuncName() ) + string( " in Node " ) + + string( Name() ) ; + _OutNode->Graph()->SetMessages( anErrorMessage ) ; + } cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod " << PyRunMethod << endl; } else if ( ( IsEndLoopNode() || IsEndSwitchNode() || IsGOTONode() ) && (*InLineNode()->PythonFunction()).length() ) { PyObject * PyRunMethod = InLineNode()->PyRunMethod() ; if ( PyRunMethod ) { + OneErr = false ; } else { PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() , InLineNode()->PythonFunction() , - Err ) ; + OneErr ) ; InLineNode()->PyRunMethod( PyRunMethod ) ; } + Err = Err || OneErr ; + if ( OneErr && WithErr ) { + string anErrorMessage = string( "Error while declaring the Python function " ) + + string( InLineNode()->PyFuncName() ) + string( " in Node " ) + + string( Name() ) ; + _OutNode->Graph()->SetMessages( anErrorMessage ) ; + } cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod " << PyRunMethod << endl; } } @@ -1553,9 +1636,9 @@ bool GraphExecutor::InNode::InitPythonFunctions(bool WithErr ) { const long GraphExecutor::InNode::CpuUsed( bool tot ) { CORBA::Long cpu = 0 ; +// cdebug_in << "GraphExecutor::InNode::CpuUsed( " << tot << " ) " << Name() << endl ; // cout << "Begin CpuUsed " << Name() << " CpuUsed : " << cpu << " State " // << theAutomaton->StateName( _currentState ) << endl ; -// cdebug_in << "GraphExecutor::InNode::CpuUsed( " << tot << " )" << Name() << endl ; if ( IsOneOfInLineNodes() ) { // cdebug << "CpuUsed " << Name() << " --> PyCpuUsed()" << endl ; // cout << "CpuUsed " << Name() << " --> PyCpuUsed()" << endl ; @@ -1569,12 +1652,17 @@ const long GraphExecutor::InNode::CpuUsed( bool tot ) { cpu = Component()->CpuUsed_impl() ; } catch ( ... ) { - cdebug << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl() ERROR catched " << endl ; + cdebug << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl() ERROR catched " + << endl ; State( GraphExecutor::ErroredState ) ; _OutNode->State( GraphExecutor::ErroredState ) ; - cpu = 0 ; + cpu = -1 ; } } + else { + cdebug << "CpuUsed " << Name() << " Component() is NIL" << endl ; + cpu = -1 ; + } } // cdebug_out << "GraphExecutor::InNode::CpuUsed " << Name() << " CpuUsed : " << cpu << endl ; // cout << "End CpuUsed " << Name() << " CpuUsed : " << cpu << " State " diff --git a/src/GraphExecutor/DataFlowExecutor_InNode.hxx b/src/GraphExecutor/DataFlowExecutor_InNode.hxx index c8bf760..d5cfb19 100644 --- a/src/GraphExecutor/DataFlowExecutor_InNode.hxx +++ b/src/GraphExecutor/DataFlowExecutor_InNode.hxx @@ -80,7 +80,8 @@ namespace GraphExecutor { PyObject * _MyPyRunMethod ; bool _createNewThread ; - bool _createNewThreadIf ; +//JR 15.04.2005 Debug PAL8624 RetroConception : +// bool _createNewThreadIf ; int _RewindStack ; GraphExecutor::AutomatonState _OldState ; GraphExecutor::AutomatonState _currentState ; @@ -88,11 +89,17 @@ namespace GraphExecutor { SUPERV::ControlState _ControlState ; GraphExecutor::AutomatonState _NextState ; GraphExecutor::StateEventAction _NextAction ; + + pthread_mutex_t _MutexDataReady ; + bool _MutexDataReadyLocked ; + bool _HasAllDataReady ; + bool _PyFuncRunned ; bool _Loading ; - pthread_mutex_t _MutexDataWait ; - bool _DataWait ; +//JR 15.04.2005 Debug PAL8624 RetroConception : +// pthread_mutex_t _MutexDataWait ; +// bool _DataWait ; pthread_mutex_t _MutexWait ; @@ -328,9 +335,19 @@ namespace GraphExecutor { bool & Err ) ; void RemovePyDynInvoke( char * PyFuncName ) ; - void LockDataWait() ; - void UnLockDataWait() ; - bool IsLockedDataWait() { return _DataWait ; } ; +//JR 15.04.2005 Debug PAL8624 RetroConception : +// void LockDataWait() ; +// void UnLockDataWait() ; +// bool IsLockedDataWait() { return _DataWait ; } ; + void LockDataReady() ; + void UnLockDataReady() ; + void HasAllDataReady( bool hasAllDataReady ) { +// cdebug << "Executor::InNode::HasAllDataReady( " << hasAllDataReady +// << " ) " << Name() << " previous _HasAllDataReady " << _HasAllDataReady +// << endl ; + _HasAllDataReady = hasAllDataReady ; } ; + bool HasAllDataReady() const { + return _HasAllDataReady ; } bool Ping() ; bool ContainerKill() ; @@ -345,11 +362,12 @@ namespace GraphExecutor { void CreateNewThread( bool k_create ) { // cdebug << Name() << " CreateNewThread " << k_create << endl ; _createNewThread = k_create ; } ; - void CreateNewThreadIf( bool k_create ) { +//JR 15.04.2005 Debug PAL8624 RetroConception : +// void CreateNewThreadIf( bool k_create ) { // cdebug << Name() << " CreateNewThreadIf( " << k_create << " )" << endl ; - _createNewThreadIf = k_create ; } ; +// _createNewThreadIf = k_create ; } ; bool CreateNewThread() { return _createNewThread ; } ; - bool CreateNewThreadIf() { return _createNewThreadIf ; } ; +// bool CreateNewThreadIf() { return _createNewThreadIf ; } ; void NewThread( pthread_t aThread ) ; void ExitThread() ; void RewindStack( int aRewindStack ) { _RewindStack = aRewindStack ; } ; @@ -426,6 +444,10 @@ namespace GraphExecutor { int DataReady_KillAction() ; int DataReady_StopAction() ; int DataReady_ExecuteAction() ; + int DataReady_ExecuteActionInLineNodes( ServicesAnyData * InParametersList , + ServicesAnyData * OutParametersList ) ; int DataReady_ExecuteActionLoopNodes( ServicesAnyData * InParametersList , + ServicesAnyData * OutParametersList , + bool & CopyInOut ) ; void DynInvoke( Engines::Component_ptr obj, const char *method, ServicesAnyData * inParams, int nInParams, @@ -444,7 +466,8 @@ namespace GraphExecutor { int Executing_KillAction() ; int Executing_StopAction() ; int Executing_SuccessAction() ; - int Executing_ErrorAction() ; +// int Executing_ErrorAction() ; + int Errored_ExecutingAction() ; int Successed_SuccessAction() ; bool SendSomeDataReady( char * FromNodeName ) ; int Errored_ErrorAction() ; @@ -469,6 +492,8 @@ namespace GraphExecutor { bool OutParametersSet( bool Err , SUPERV::GraphState PortState , int nOutParams , ServicesAnyData * OutParametersList ) ; + void SetOutPortsOfInportsOfEndSwitch( GraphBase::OutPort * anOutPort , + const char * anEndSwitchNodeName ) ; void coutbegin() ; void coutexit() ; @@ -486,5 +511,6 @@ namespace GraphExecutor { } ; + #endif