]> SALOME platform Git repositories - modules/superv.git/blobdiff - src/GraphExecutor/DataFlowExecutor_OutNode.cxx
Salome HOME
NRI : Merge delta [V1_2, V1_2c].
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_OutNode.cxx
index 5f30b8901841630a503e8f998cddce7f49dfb6da..1d8705d451bf3d7dcbc61eb3c5b5eb7a90fb7128 100644 (file)
@@ -1,11 +1,32 @@
+//  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"
 
@@ -13,7 +34,7 @@ using namespace std;
 
 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
 
-static const char *ComponentName = "SalomeSuperVisionComponent" ;
+// static const char *ComponentName = "SalomeSuperVisionComponent" ;
 
 extern int _ArgC ;
 extern char ** _ArgV ;
@@ -28,6 +49,7 @@ GraphExecutor::OutNode::OutNode() :
   _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 ) ;
@@ -53,6 +75,7 @@ GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
   _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 ) ;
@@ -93,6 +116,7 @@ GraphExecutor::OutNode::OutNode(
   _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 ) ;
@@ -178,7 +202,7 @@ bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfNodes &aListOfNode
   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 ,
@@ -234,7 +258,7 @@ bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfNodes &aListOfNode
     }
 #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 "
@@ -253,7 +277,7 @@ bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfLinks &aListOfLink
   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() ,
@@ -272,7 +296,7 @@ bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfLinks &aListOfData
   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() ,
@@ -354,7 +378,10 @@ bool GraphExecutor::OutNode::Valid() {
 
   _Executable = false ;
 
-  CreateService() ;
+  if ( !CreateService() ) {
+    cdebug << "This DataFlow has invalid type(s)." << endl ;
+    return false ;
+  }
 
   if ( !Sort() ) {
     cdebug << "This DataFlow is not valid." << endl ;
@@ -437,14 +464,14 @@ bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
         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 ;
       }
@@ -551,6 +578,11 @@ void GraphExecutor::OutNode::CheckAllDone() {
              << " 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 ) {
@@ -579,22 +611,22 @@ void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * er
   }
 }
 
-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() {
@@ -1008,13 +1040,22 @@ bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
   }
 //  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 ,
@@ -1038,7 +1079,7 @@ 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 ) {
@@ -1048,10 +1089,10 @@ bool GraphExecutor::OutNode::Event( char ** aNodeName ,
   }
   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() ;
@@ -1070,11 +1111,11 @@ bool GraphExecutor::OutNode::Event( char ** aNodeName ,
     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 ") ;
@@ -1250,8 +1291,8 @@ SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
     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 ;
@@ -1491,12 +1532,22 @@ bool GraphExecutor::OutNode::Suspend() {
   }
   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 ;
 }
 
@@ -1532,6 +1583,11 @@ bool GraphExecutor::OutNode::Kill() {
   }
   State( SUPERV::KilledState ) ;
   cdebug_out << "GraphExecutor::OutNode::Kill" << endl ;
+  if ( RetVal ) {
+    MESSAGE("================================================================================") ;
+    MESSAGE( Name() << " IS KILLED" ) ;
+    MESSAGE("================================================================================") ;
+  }
   return RetVal ;
 }
 
@@ -1540,6 +1596,11 @@ bool GraphExecutor::OutNode::Stop() {
   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() {
@@ -1610,7 +1671,7 @@ bool GraphExecutor::OutNode::DoneWait() {
     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() ;
@@ -1706,9 +1767,8 @@ long GraphExecutor::OutNode::LastLevelDone() {
 }
 
 
-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 ) ;
@@ -1716,9 +1776,8 @@ const CORBA::Any *GraphExecutor::OutNode::GetInData(
   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 ) ;
@@ -1726,3 +1785,19 @@ const CORBA::Any *GraphExecutor::OutNode::GetOutData(
   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 ;
+}
+
+