]> SALOME platform Git repositories - modules/superv.git/blobdiff - src/GraphExecutor/DataFlowExecutor_OutNode.cxx
Salome HOME
Merging with JR_ASV_2_1_0_deb_with_KERNEL_Head branch, which contains many bug fixes...
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_OutNode.cxx
index b1d8b2c391f8247523727dfb9cf9447efe6900c8..88e0cb374d9f361f831df5b685a4061bd74a7e8b 100644 (file)
@@ -32,6 +32,9 @@ using namespace std;
 
 #include "DataFlowEditor_DataFlow.hxx"
 
+// asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL    
+//extern Engines_Container_i * _TheContainer ;
+
 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
 
 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
@@ -41,6 +44,9 @@ extern char ** _ArgV ;
 
 GraphExecutor::OutNode::OutNode() {
 //               Graph() {
+  // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL    
+  //_SuperVisionContainer = _TheContainer ;
+  //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
   _Valid = false ;
   _Executable = false ;
   _Done = false ;
@@ -80,6 +86,9 @@ GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
                                                _prof_debug , _fdebug ) ;
     _Graph = _StreamGraph ;
   }
+  // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL    
+  //_SuperVisionContainer = _TheContainer ;
+  //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
   _Valid = false ;
   _Executable = false ;
   _Done = false ;
@@ -142,6 +151,9 @@ GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
                                                _prof_debug , _fdebug ) ;
     _Graph = _StreamGraph ;
   }
+  // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL    
+  //_SuperVisionContainer = _TheContainer ;
+  //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
   _Valid = false ;
   _Executable = false ;
   _Done = false ;
@@ -440,17 +452,21 @@ bool GraphExecutor::OutNode::Valid() {
   _Executable = false ;
 
   if ( !Graph()->CreateService() ) {
-    cdebug << "This DataFlow has invalid type(s)." << endl ;
+    cdebug_out << "This DataFlow has invalid type(s)." << endl ;
     return false ;
   }
   int SubStreamGraphsNumber = 0 ;
   if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
-    cdebug << "This DataFlow is not valid." << endl ;
+    cdebug_out << "This DataFlow is not valid." << endl ;
     return false ;
   }
   if ( Graph()->IsDataStreamNode() ) {
     StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
   }
+  if ( !Graph()->ValidLoops() ) {
+    cdebug_out << "This DataFlow have not valid Loops." << endl ;
+    return false ;
+  }
 
 //  CreateService() ;
 
@@ -484,7 +500,8 @@ bool GraphExecutor::OutNode::Executable() {
 
 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
   bool RetVal = false ;
-  cdebug_in << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )" << endl;
+  cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )"
+            << endl;
 
   if ( Executable() ) {
     _ControlState = SUPERV::VoidState ;
@@ -496,15 +513,20 @@ bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
     int i ;
     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
+      anInNode->OutNode( this ) ;
+// Initialize in python interpretor the python functions
       if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
         if ( !Py_IsInitialized() ) {
+//          PyEval_InitThreads() ;
 //          Py_Initialize() ;
+         // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL  
+         //                  1 line below uncommented
           PySys_SetArgv( _ArgC , _ArgV ) ;
        }
         anInNode->InitPython() ;
         PyInitialized( true ) ;
       }
-      anInNode->InitialState( this ) ;
+      anInNode->InitialState() ;
       if ( anInNode->IsOneOfInLineNodes() ) {
         anInNode->InitPythonFunctions( false ) ;
       }
@@ -567,19 +589,25 @@ bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
         }
 //        PushEvent( anInNode , GraphExecutor::ReadyEvent ,
 //                   GraphExecutor::DataReadyState ) ; 
+// We say that we have to create a thread for that HeadNode 'anInNode'
         anInNode->CreateNewThread( true ) ;
         anInNode->DataFromNode( Graph()->Name() ) ;
+// AndSuspend == true <==> Start()
         if ( AndSuspend ) {
           anInNode->State( GraphExecutor::DataWaitingState ) ;
           anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
+// We send SomeDataReadyEvent
+// It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
           if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
             cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
                    << anInNode->Name() << endl ;
             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
             return false ;
           }
+// ==> We wait for SuspendedState
           anInNode->SuspendedWait() ;
         }
+// AndSuspend == false <==> Run()
         else if ( anInNode->IsMacroNode() ) {
           if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
             cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
@@ -589,17 +617,20 @@ bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
          }
           cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
                  << endl ;
+// ==> We wait for RunningState
           anInNode->RunningWait() ;
           cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
                  << endl ;
        }
         else if ( !anInNode->IsMacroNode() ) {
+// It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
           if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
             cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
                    << anInNode->Name() << endl ;
             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
             return false ;
          }
+// ==> We wait for RunningState
           anInNode->RunningWait() ;
         }
       }
@@ -622,25 +653,12 @@ bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
     }
   }
 
-  cdebug_out << "GraphExecutor::OutNode::Run " << Graph()->Name() << " GraphMacroLevel "
+  cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
+             << " GraphMacroLevel "
              << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
   return RetVal ;
 }
 
-bool GraphExecutor::OutNode::Run( const char * aNodeName ,
-                                  const char * AtNodeName ,
-                                  const bool AndSuspend ) {
-  bool RetVal = false ;
-  cdebug_in << "GraphExecutor::OutNode::Run( " << aNodeName << " , "
-            << AtNodeName << " , " << AndSuspend << ")" << endl;
-  GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
-  if ( anInNode ) {
-    RetVal = anInNode->ReStart( AtNodeName , AndSuspend ) ;
-  }
-  cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
-  return RetVal ;
-}
-
 void GraphExecutor::OutNode::CheckAllDone() {
   int j ;
   cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
@@ -695,8 +713,6 @@ void GraphExecutor::OutNode::CheckAllDone() {
                   aState == SUPERV::RunningState ||
                   aState == SUPERV::SuspendDoneState ||
                   aState == SUPERV::SuspendErroredState ||
-                  aState == SUPERV::ReRunState ||
-                  aState == SUPERV::ReStartState ||
                   aState == SUPERV::SuspendState ) {
           alivenodes += 1 ;
        }
@@ -740,6 +756,15 @@ void GraphExecutor::OutNode::CheckAllDone() {
              << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
 }
 
+// asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL    
+//Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
+//  return _SuperVisionContainer ;
+//}
+
+//const pthread_t GraphExecutor::OutNode::MainThreadId() const {
+//  return _MainThreadId ;
+//}
+
 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
 //    cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
@@ -924,14 +949,6 @@ SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::No
     aGraphEvent = SUPERV::ErroredEvent ;
     break ;
   }
-  case GraphExecutor::ReStartEvent : {
-    aGraphEvent = SUPERV::ReRunEvent ;
-    break ;
-  }
-  case GraphExecutor::ReStartAndSuspendEvent : {
-    aGraphEvent = SUPERV::ReStartEvent ;
-    break ;
-  }
   case GraphExecutor::NoDataReadyEvent : {
     aGraphEvent = SUPERV::WaitingEvent ;
     break ;
@@ -1020,14 +1037,6 @@ SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::No
     aGraphEvent = SUPERV::StopEvent ;
     break ;
   }
-  case GraphExecutor::ReStartedEvent : {
-    aGraphEvent = SUPERV::ReRunEvent ;
-    break ;
-  }
-  case GraphExecutor::ReStartedAndSuspendEvent : {
-    aGraphEvent = SUPERV::ReStartEvent ;
-    break ;
-  }
   case GraphExecutor::EndExecuteEvent : {
     aGraphEvent = SUPERV::DoneEvent ;
     break ;
@@ -1156,13 +1165,9 @@ SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::Au
     aGraphState = SUPERV::StopState ;
     break ;
   }
-  case GraphExecutor::ReRunnedState : {
-    aGraphState = SUPERV::ReRunState ;
-    break ;
-  }
-  case GraphExecutor::ReStartedState : {
-    aGraphState = SUPERV::ReStartState ;
-    break ;
+  case GraphExecutor::LoadingState : {
+    aGraphState = SUPERV::LoadingState ;
+    break;
   }
   default : {
     cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
@@ -1241,8 +1246,10 @@ bool GraphExecutor::OutNode::Event( char ** aNodeName ,
 
   int ThreadsNumber ;
   int SuspendedThreadsNumber ;
+  bool cdebuginout = false ;
   if ( _EventNodes.size() > 0 ) {
-    cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
+//    cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
+    cdebuginout = true ;
   }
   if ( pthread_mutex_lock( &_MutexWait ) ) {
     perror("EventLoop pthread_mutex_lock ") ;
@@ -1301,9 +1308,9 @@ bool GraphExecutor::OutNode::Event( char ** aNodeName ,
     perror("EventLoop pthread_mutex_lock ") ;
     exit( 0 ) ;
   }
-  if ( _EventNodes.size() > 0 ) {
-    cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue "
-               << *aNodeName << " " << anEvent << " " << aState << endl ;
+  if ( cdebuginout ) {
+//    cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
+//               << *aNodeName << " " << anEvent << " " << aState << endl ;
   }
   return RetVal ;
 }
@@ -1511,7 +1518,10 @@ SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
   if ( aCNode ) {
     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
     if ( anInNode ) {
-      aret = anInNode->State() ;
+      if ( anInNode->IsLoading() )
+       aret = GraphExecutor::LoadingState;
+      else
+       aret = anInNode->State() ;
 //      cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
 //             << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
     }
@@ -1614,7 +1624,8 @@ bool GraphExecutor::OutNode::IsDone() {
 bool GraphExecutor::OutNode::IsSuspended() {
 //  cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
   bool aret = false ;
-  if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
+//  if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
+  if ( AutomatonGraphState( _State ) ==  SUPERV::SuspendState ) {
     aret = true ;
   }
 //  cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
@@ -1752,12 +1763,16 @@ bool GraphExecutor::OutNode::Suspend() {
       RetVal += 1 ;
       cdebug << aNode->Name() << " Suspended" << endl ;
     }
-    else if ( aNode->IsWaiting() || aNode->IsDone() ) {
+    else if ( aNode->IsWaiting() || aNode->IsReady() ) {
+      RetVal += 1 ;
+      cdebug << aNode->Name() << " will be Suspended" << endl ;
+    }
+    else if ( aNode->IsDone() ) {
       cdebug << aNode->Name() << " not Suspended : "
              << theAutomaton->StateName( aNode->State() ) << endl ;
     }
     else {
-      RetVal += 1 ;
+//      RetVal += 1 ;
       cdebug << aNode->Name() << " cannot be Suspended : "
              << theAutomaton->StateName( aNode->State() ) << endl ;
     }
@@ -1773,13 +1788,20 @@ bool GraphExecutor::OutNode::Suspend() {
     MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
     MESSAGE("================================================================================") ;
   }
-  cdebug_out << "GraphExecutor::OutNode::Suspend" << theAutomaton->StateName( State() ) << endl ;
+  for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
+    GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
+    MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
+    cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
+  }
+  cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
+             << " EventQSize " << EventQSize() << endl ;
   return RetVal ;
 }
 
 bool GraphExecutor::OutNode::Resume() {
   int RetVal = 0 ;
-  cdebug_in << "GraphExecutor::OutNode::Resume" << endl;
+  cdebug_in << "GraphExecutor::OutNode::Resume "
+            << theAutomaton->StateName( State() ) << endl;
   if ( IsSuspended() ) {
     State( GraphExecutor::ExecutingState ) ;
     int i ;
@@ -1818,20 +1840,38 @@ bool GraphExecutor::OutNode::Resume() {
     MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
     MESSAGE("================================================================================") ;
   }
-  cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal << endl ;
+  int i ;
+  for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
+    GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
+    MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
+    cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
+  }
+  cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
+             << " EventQSize " << EventQSize() << endl ;
   return RetVal ;
 }
 
 bool GraphExecutor::OutNode::Kill() {
-  bool RetVal = true ;
-  cdebug_in << "GraphExecutor::OutNode::Kill" << endl;
+  bool RetVal = false ;
+  cdebug_in << "GraphExecutor::OutNode::Kill"
+             << " EventQSize " << EventQSize() << endl;
   _ControlState = SUPERV::ToSuspendState ;
   int i ;
   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
     bool sts = aNode->Kill() ;
-    if ( sts && aNode->IsKilled() ) {
-      cdebug << aNode->Name() << " killed" << endl ;
+    if ( sts && Threads() != 0 ) {
+      if ( !aNode->IsKilled() ) {
+        cdebug << aNode->Name() << " not killed : "
+               << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
+               << "KilledAction()" << endl ;
+        MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
+        aNode->KilledAction() ;
+      }
+      if ( aNode->IsKilled() ) {
+        cdebug << aNode->Name() << " killed" << endl ;
+        RetVal = true ;
+      }
     }
     else if ( aNode->IsWaiting() || aNode->IsDone() ) {
       cdebug << aNode->Name() << " not killed : "
@@ -1840,23 +1880,10 @@ bool GraphExecutor::OutNode::Kill() {
     else {
       cdebug << aNode->Name() << " cannot be killed : "
              << theAutomaton->StateName( aNode->State() ) << endl ;
-      RetVal = false ;
-    }
-  }
-  if ( !RetVal || Threads() != 0 ) {
-    for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
-      GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
-      if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
-        cdebug << aNode->Name() << " not killed : "
-               << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
-               << "KilledAction()" << endl ;
-        aNode->KilledAction() ;
-      }
     }
-    RetVal = true ;
   }
-  State( GraphExecutor::KilledState ) ;
   if ( RetVal ) {
+    State( GraphExecutor::KilledState ) ;
     MESSAGE("================================================================================") ;
     MESSAGE( Graph()->Name() << " IS KILLED" <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
              << EventQSize() ) ;
@@ -1867,8 +1894,14 @@ bool GraphExecutor::OutNode::Kill() {
     MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
     MESSAGE("================================================================================") ;
   }
+  for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
+    GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
+    MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
+    cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
+  }
   cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
-             << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads  << endl ;
+             << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
+             << " EventQSize " << EventQSize() << endl ;
 
   // remove "extra" events from the event queue
   siftEvents();
@@ -1891,22 +1924,6 @@ bool GraphExecutor::OutNode::Stop() {
   }
   return RetVal ;
 }
-bool GraphExecutor::OutNode::ReRun() {
-  bool RetVal = false ;
-  cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
-  if ( IsSuspended() ) {
-  }
-  cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
-  return RetVal ;
-}
-bool GraphExecutor::OutNode::ReStart() {
-  bool RetVal = false ;
-  cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
-  if ( IsSuspended() ) {
-  }
-  cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
-  return RetVal ;
-}
 
 bool GraphExecutor::OutNode::ReadyWait() {
   cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;