+// SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : DataFlowBase_OutNode.cxx
+// Author : Jean Rahuel, CEA
+// Module : SUPERV
+// $Header:
+
using namespace std;
-//=============================================================================
-// File : DataFlowBase_OutNode.cxx
-// Created : 2002
-// Author : Jean Rahuel, CEA
-// Project : SALOME
-// $Header:
-//=============================================================================
#include "DataFlowExecutor_OutNode.hxx"
extern GraphExecutor::FiniteStateMachine * theAutomaton ;
-static const char *ComponentName = "SalomeSuperVisionComponent" ;
+// static const char *ComponentName = "SalomeSuperVisionComponent" ;
extern int _ArgC ;
extern char ** _ArgV ;
_State = SUPERV::UnKnownState ;
_PyInitialized = false ;
pthread_mutex_init( &_MutexWait , NULL ) ;
+ pthread_mutex_init( &_PyMutexWait , NULL ) ;
if ( pthread_cond_init( &_EventWait , NULL ) ) {
perror("pthread_cond_init( &_EventWait , NULL )") ;
exit( 0 ) ;
_PyInitialized = false ;
_Orb = CORBA::ORB::_duplicate( ORB ) ;
pthread_mutex_init( &_MutexWait , NULL ) ;
+ pthread_mutex_init( &_PyMutexWait , NULL ) ;
if ( pthread_cond_init( &_EventWait , NULL ) ) {
perror("pthread_cond_init( &_EventWait , NULL )") ;
exit( 0 ) ;
_PyInitialized = false ;
_Orb = CORBA::ORB::_duplicate( ORB ) ;
pthread_mutex_init( &_MutexWait , NULL ) ;
+ pthread_mutex_init( &_PyMutexWait , NULL ) ;
if ( pthread_cond_init( &_EventWait , NULL ) ) {
perror("pthread_cond_init( &_EventWait , NULL )") ;
exit( 0 ) ;
GraphExecutor::InNode * anInNode ;
cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
int i ;
- for ( i = 0 ; i < aListOfNodes.size() ; i++ ) {
+ for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
GraphBase::SNode aNode = aListOfNodes[ i ] ;
anInNode = AddNode( aNode.theService ,
aNode.theListOfFuncName ,
}
#endif
}
- for ( i = 0 ; i < aListOfNodes.size() ; i++ ) {
+ for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
GraphBase::SNode aNode = aListOfNodes[ i ] ;
anInNode = (GraphExecutor::InNode * ) GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << "IsOneOfGOTONodes "
cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
<< endl ;
int i ;
- for ( i = 0 ; i < aListOfLinks.size() ; i++ ) {
+ for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
GraphBase::SLink aLink = aListOfLinks[ i ] ;
RetVal = AddLink( aLink.FromNodeName.c_str() ,
aLink.FromServiceParameterName.c_str() ,
cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
<< endl ;
int i ;
- for ( i = 0 ; i < aListOfDatas.size() ; i++ ) {
+ for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
GraphBase::SLink aLink = aListOfDatas[ i ] ;
if ( !strcmp( aLink.FromNodeName.c_str() , Name() ) )
RetVal = GraphBase::Graph::AddInputData( aLink.ToNodeName.c_str() ,
_Executable = false ;
- CreateService() ;
+ if ( !CreateService() ) {
+ cdebug << "This DataFlow has invalid type(s)." << endl ;
+ return false ;
+ }
if ( !Sort() ) {
cdebug << "This DataFlow is not valid." << endl ;
anInNode->State( SUPERV::DataWaitingState ) ;
anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
- cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
+ cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
<< anInNode->Name() << endl ;
return false ;
}
anInNode->SuspendedWait() ;
}
else if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
- cdebug << "InNode::SendEvent( RunningEvent ) Node "
+ cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
<< anInNode->Name() << endl ;
return false ;
}
<< " GraphAutomatonState " << theAutomaton->StateName( AutomatonState() )
<< " State " << State() << " Threads " << _Threads << " SuspendedThreads "
<< _SuspendedThreads << endl ;
+ if ( _Done ) {
+ MESSAGE("================================================================================") ;
+ MESSAGE( Name() << " IS DONE" ) ;
+ MESSAGE("================================================================================") ;
+ }
}
void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
}
}
-void GraphExecutor::OutNode::PThreadLock() {
- cout << " GraphExecutor::OutNode::PThreadLock " << pthread_self() << endl ;
- if ( pthread_mutex_lock( &_MutexWait ) ) {
- perror( "GraphExecutor::OutNode::PThreadLock" ) ;
+void GraphExecutor::OutNode::PyThreadLock() {
+// cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
+ if ( pthread_mutex_lock( &_PyMutexWait ) ) {
+ perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
exit( 0 ) ;
}
- cout << " GraphExecutor::OutNode::PThreadLocked " << pthread_self() << endl ;
+// cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
}
-void GraphExecutor::OutNode::PThreadUnLock() {
- cout << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << endl ;
- if ( pthread_mutex_unlock( &_MutexWait ) ) {
- perror( "GraphExecutor::OutNode::PThreadUnLock" ) ;
+void GraphExecutor::OutNode::PyThreadUnLock() {
+// cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
+ if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
+ perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
exit( 0 ) ;
}
- cout << " GraphExecutor::OutNode::PThreadUnLocked " << pthread_self() << endl ;
+// cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
}
void GraphExecutor::OutNode::NewThread() {
}
// cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
// << SuspendedThreads() << endl ;
+ if ( _EventNodes.size() > 101 ) {
+ while ( _EventNodes.size() > 31 ) {
+ _EventNodes.pop_front() ;
+ _Events.pop_front() ;
+ _States.pop_front() ;
+ }
+ }
if ( pthread_mutex_unlock( &_MutexWait ) ) {
perror("PushEvent pthread_mutex_unlock ") ;
exit( 0 ) ;
}
+ return true ;
}
bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
+ return false ;
}
bool GraphExecutor::OutNode::Event( char ** aNodeName ,
anEvent = SUPERV::UndefinedEvent ;
aState = SUPERV::UndefinedState ;
if ( ( IsDone() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
- cdebug << "EventLoop IsDone()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
+// cdebug << "EventLoop IsDone()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
RetVal = false ;
}
else if ( !WithWait && _EventNodes.size() == 0 ) {
}
else if ( RetVal ) {
while ( !IsSuspended() && _EventNodes.size() == 0 ) {
- cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
+// cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
pthread_cond_wait( &_EventWait , &_MutexWait );
- cdebug << "EventLoop pthread_cond_waited _EventWait"
- << " _EventNodes.size() " << _EventNodes.size() << endl ;
+// cdebug << "EventLoop pthread_cond_waited _EventWait"
+// << " _EventNodes.size() " << _EventNodes.size() << endl ;
}
if ( _EventNodes.size() ) {
ThreadsNumber = Threads() ;
RetVal = false ;
}
if ( anEvent != SUPERV::NoEvent ) {
- cdebug << pthread_self() << "EventLoop "
- << NodeName << " " << theAutomaton->StateName( theState )
- << " _EventNodes.size() " << _EventNodes.size()
- << " Threads " << Threads() << " SuspendedThreads "
- << SuspendedThreads() << " RetVal " << RetVal << endl ;
+// cdebug << pthread_self() << "EventLoop "
+// << NodeName << " " << theAutomaton->StateName( theState )
+// << " _EventNodes.size() " << _EventNodes.size()
+// << " Threads " << Threads() << " SuspendedThreads "
+// << SuspendedThreads() << " RetVal " << RetVal << endl ;
}
if ( pthread_mutex_unlock( &_MutexWait ) ) {
perror("EventLoop pthread_mutex_lock ") ;
GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
if ( anInNode ) {
aret = anInNode->State() ;
- cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
- << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
+// cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
+// << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
}
}
// cdebug_out << "GraphExecutor::OutNode::State" << endl ;
}
State( SUPERV::SuspendedState ) ;
cdebug_out << "GraphExecutor::OutNode::Suspend" << endl ;
+ if ( RetVal ) {
+ MESSAGE("================================================================================") ;
+ MESSAGE( Name() << " IS SUSPENDED" ) ;
+ MESSAGE("================================================================================") ;
+ }
return RetVal ;
}
bool GraphExecutor::OutNode::Resume() {
bool RetVal = false ;
cdebug_in << "GraphExecutor::OutNode::Resume" << endl;
cdebug_out << "GraphExecutor::OutNode::Resume" << endl ;
+ if ( RetVal ) {
+ MESSAGE("================================================================================") ;
+ MESSAGE( Name() << " IS RESUMED" ) ;
+ MESSAGE("================================================================================") ;
+ }
return RetVal ;
}
}
State( SUPERV::KilledState ) ;
cdebug_out << "GraphExecutor::OutNode::Kill" << endl ;
+ if ( RetVal ) {
+ MESSAGE("================================================================================") ;
+ MESSAGE( Name() << " IS KILLED" ) ;
+ MESSAGE("================================================================================") ;
+ }
return RetVal ;
}
cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
Kill() ;
cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
+ if ( RetVal ) {
+ MESSAGE("================================================================================") ;
+ MESSAGE( Name() << " IS STOPPED" ) ;
+ MESSAGE("================================================================================") ;
+ }
return RetVal ;
}
bool GraphExecutor::OutNode::ReRun() {
exit( 0 ) ;
}
aret = IsDone() ;
- while ( !aret && !IsSuspended() ) {
+ while ( !aret && !IsSuspended() && IsRunning() ) {
cdebug << "DoneWait pthread_cond_wait _EventWait" << endl;
pthread_cond_wait( &_EventWait , &_MutexWait );
aret = IsDone() ;
}
-const CORBA::Any *GraphExecutor::OutNode::GetInData(
- const char * NodeName ,
- const char * ServiceParameterName ) {
+const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
+ const char * ServiceParameterName ) {
// cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
// << ServiceParameterName << endl ;
const CORBA::Any * retdata = PortInData( NodeName , ServiceParameterName ) ;
return retdata ;
}
-const CORBA::Any *GraphExecutor::OutNode::GetOutData(
- const char * NodeName ,
- const char * ServiceParameterName ) {
+const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
+ const char * ServiceParameterName ) {
// cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
// << ServiceParameterName << endl ;
const CORBA::Any * retdata = PortOutData( NodeName , ServiceParameterName ) ;
return retdata ;
}
+const long GraphExecutor::OutNode::CpuUsed() {
+ return GraphBase::Graph::CpuUsed() ;
+}
+
+const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
+ GraphBase::ComputingNode * aNode = GetChangeGraphNode( aNodeName ) ;
+ if ( aNode ) {
+ GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
+ if ( anInNode ) {
+ return anInNode->CpuUsed() ;
+ }
+ }
+ return 0 ;
+}
+
+