Salome HOME
SMH: 3.0.0 preparation = merged version (POLYWORK + RTVDEBUG01) + adopation for new GUI
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_DataFlow.cxx
index ce7121885365b7c08f5967903e1551071063cf21..801e9f1145b8ab7dcd9690f83e66f2425b685d87 100644 (file)
@@ -26,6 +26,7 @@
 
 using namespace std;
 #include "DataFlowExecutor_DataFlow.hxx"
+#include "DataFlowEditor_DataFlow.hxx"
 
 // Implementation de la classe GraphExecutor::Graph
 
@@ -41,8 +42,9 @@ GraphExecutor::DataFlow::DataFlow() :
 GraphExecutor::DataFlow::DataFlow( CORBA::ORB_ptr ORB,
                                   SALOME_NamingService* ptrNamingService ,
                                    const char *DataFlowName ,
-                                   const char * DebugFileName ) :
-  OutNode( ORB, ptrNamingService , DataFlowName , DebugFileName ) {
+                                   const char * DebugFileName ,
+                                   const SUPERV::KindOfNode aKindOfNode ) :
+  OutNode( ORB, ptrNamingService , DataFlowName , DebugFileName , aKindOfNode ) {
   cdebug_in << "GraphExecutor::DataFlow::DataFlow(" ;
   if ( DataFlowName ) {
     cdebug << DataFlowName ;
@@ -54,21 +56,20 @@ GraphExecutor::DataFlow::DataFlow( CORBA::ORB_ptr ORB,
   cdebug_out << "GraphExecutor::DataFlow::DataFlow" << endl;
 }
 
-GraphExecutor::DataFlow::DataFlow(
-                     CORBA::ORB_ptr ORB,
-                    SALOME_NamingService* ptrNamingService ,
-                     const SALOME_ModuleCatalog::Service& DataFlowService ,
-                     const char *DataFlowComponentName ,
-                     const char *DataFlowInterfaceName ,
-                     const char *DataFlowName ,
-                     const SUPERV::KindOfNode DataFlowkind ,
-                     const SUPERV::SDate DataFlowFirstCreation ,
-                     const SUPERV::SDate DataFlowLastModification ,
-                     const char * DataFlowExecutorRelease ,
-                     const char * DataFlowAuthor ,
-                     const char * DataFlowComputer ,
-                     const char * DataFlowComment ,
-                     const char * DebugFileName ) :
+GraphExecutor::DataFlow::DataFlow( CORBA::ORB_ptr ORB,
+                                  SALOME_NamingService* ptrNamingService ,
+                                   const SALOME_ModuleCatalog::Service& DataFlowService ,
+                                   const char *DataFlowComponentName ,
+                                   const char *DataFlowInterfaceName ,
+                                   const char *DataFlowName ,
+                                   const SUPERV::KindOfNode DataFlowkind ,
+                                   const SUPERV::SDate DataFlowFirstCreation ,
+                                   const SUPERV::SDate DataFlowLastModification ,
+                                   const char * DataFlowExecutorRelease ,
+                                   const char * DataFlowAuthor ,
+                                   const char * DataFlowComputer ,
+                                   const char * DataFlowComment ,
+                                   const char * DebugFileName ) :
      OutNode( ORB, ptrNamingService , DataFlowService , DataFlowComponentName ,
               DataFlowInterfaceName , DataFlowName , DataFlowkind ,
               DataFlowFirstCreation , DataFlowLastModification  ,
@@ -90,8 +91,8 @@ GraphExecutor::DataFlow::~DataFlow() {
 bool GraphExecutor::DataFlow::Ping( const char *aNodeName ) {
   cdebug_in << "GraphExecutor::DataFlow::Ping" << aNodeName << " )" << endl;
   bool RetVal = false ;
-  if ( GetGraphNode( aNodeName ) )
-    RetVal = ((GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode())->Ping() ;
+  if ( Graph()->GetGraphNode( aNodeName ) )
+    RetVal = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode())->Ping() ;
   cdebug_out << "GraphExecutor::DataFlow::Ping" << endl;
   return RetVal ;
 }
@@ -106,7 +107,7 @@ bool GraphExecutor::DataFlow::ContainerKill() {
 bool GraphExecutor::DataFlow::ContainerKill( const char *aNodeName ) {
 //  cdebug_in << "GraphExecutor::DataFlow::ContainerKill( " << aNodeName << " )"<< endl;
   bool RetVal = false ;
-  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode()) ;
+  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
   if ( aNode ) {
     RetVal = aNode->ContainerKill() ;
   }
@@ -114,17 +115,133 @@ bool GraphExecutor::DataFlow::ContainerKill( const char *aNodeName ) {
   return RetVal ;
 }
 
+bool GraphExecutor::DataFlow::InputOfAny( const char * ToServiceParameterName ,
+                                          const CORBA::Any & aValue ,
+                                          bool SomeDataReady ) {
+  cdebug_in <<"GraphExecutor::DataFlow::InputOfAny" << endl ;
+  bool RetVal = false ;
+  cdebug << pthread_self() << "GraphExecutor::DataFlow::::InputOfAny " << Graph()->Name() << "("
+         << ToServiceParameterName << ")" << endl ;
+  if ( Graph()->GraphMacroLevel() ) {
+    GraphBase::OutPort * anOutPort ;
+    anOutPort = Graph()->GetChangeInDataNodePort( ToServiceParameterName ) ;
+    cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny " << Graph()->Name()
+           << " " << State() << " " << ToServiceParameterName << " " << anOutPort->PortState()
+           << " Done : " << anOutPort->PortDone() << endl ;
+    RetVal = AddInputData( Graph()->Name() , ToServiceParameterName , aValue ) ;
+    anOutPort->PortState(  SUPERV::ReadyState ) ;
+// There is only one port :
+    anOutPort->ChangeInPorts( 0 )->PortState( SUPERV::ReadyState ) ;
+    anOutPort->PortDone( true ) ;
+// There is only one inport of a Node in an ReversedOutport of a graph :
+    GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( anOutPort->InPorts( 0 )->NodeName() )->GetInNode() ;
+    cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny : " << anInNode->Name()
+           << "->SendSomeDataReady( " << Graph()->Name() << " ) for Port " << anOutPort->InPorts( 0 )->PortName()
+           << endl ;
+    if ( SomeDataReady ) {
+      MESSAGE( "GraphExecutor::InputOfAny " << Graph()->Name() << " SendSomeDataReady --> " << anInNode->Name()
+               << " " << anInNode->State() << " " << anOutPort->InPorts( 0 )->PortName() ) ;
+      int sts = anInNode->SendSomeDataReady( Graph()->Name() ) ;
+      cdebug << "GraphExecutor::DataFlow::InputOfAny " << anInNode->Name()
+             << "->SendSomeDataReady( " << Graph()->Name() << " ) sts " << sts << endl ;
+      if ( sts && anInNode->IsReady() ) {
+        cdebug << pthread_self() << "/" << anInNode->ThreadNo() << "GraphExecutor::DataFlow::InputOfAny : "
+               << anInNode->Name() << "->SendEvent( GraphExecutor::ExecuteEvent ) "
+               << " " << anInNode->Name() << "->IsReady() " << anInNode->IsReady() << " State "
+               << anInNode->State() << endl ;
+        if ( anInNode->IsLockedDataWait() ) {
+          cdebug << pthread_self() << "/" << anInNode->ThreadNo() << "GraphExecutor::DataFlow::InputOfAny : "
+                 << anInNode->Name() << " IsLockedDataWait() ==> UnLockDataWait" << endl ;
+          anInNode->UnLockDataWait() ;
+        }
+        anInNode->ThreadNo( 0 ) ;
+        anInNode->CreateNewThread( true ) ;
+        anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
+//        State( GraphExecutor::ExecutingState ) ;
+      }
+    }
+  }
+  else {
+    cdebug << pthread_self() << "GraphExecutor::DataFlow::InputOfAny GraphMacroLevel "
+           << Graph()->GraphMacroLevel() << " ERROR" << endl ;
+    MESSAGE( "GraphExecutor::DataFlow::InputOfAny GraphMacroLevel " << Graph()->GraphMacroLevel()
+             << " ERROR" ) ;
+  }
+  cdebug_out << pthread_self() << " GraphExecutor::DataFlow::InputOfAny " << RetVal << endl ;
+  return RetVal ;
+}
+
+bool GraphExecutor::DataFlow::OutputOfAny( const char * aNodeName ,
+                                           const char * ToServiceParameterName ,
+                                           const CORBA::Any & aValue ) {
+  cdebug_in << pthread_self() << "/" << ThreadNo() << "GraphExecutor::DataFlow::OutputOfAny( " << aNodeName
+            << " , " << ToServiceParameterName
+            << " , aValue ) from " << Graph()->Name() << endl ;
+  bool RetVal = false ;
+  GraphBase::Graph * aMacroNode = (GraphBase::Graph * ) Graph()->GetChangeGraphNode( aNodeName ) ;
+//  GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aMacroGraph->GetInNode() ;
+  RetVal = Graph()->AddOutputData( aNodeName , ToServiceParameterName , aValue ) ;
+  GraphBase::OutPort * anOutPort = aMacroNode->GetChangeOutPort( ToServiceParameterName ) ;
+  int i ;
+// Loop over Inports linked to that OutPort of the MacroNode
+  for ( i = 0 ; i < anOutPort->InPortsSize() ; i++ ) {
+    const char * ToNodeName = anOutPort->ChangeInPorts( i )->NodeName() ;
+    const char * ToParameterName = anOutPort->ChangeInPorts( i )->PortName() ;
+    GraphBase::ComputingNode * aComputingNode = Graph()->GetChangeGraphNode( ToNodeName ) ;
+    if ( strcmp( ToNodeName , Graph()->Name() ) ) {
+      GraphExecutor::InNode * aLinkedNode = (GraphExecutor::InNode * ) aComputingNode->GetInNode() ;
+      cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
+             << "GraphExecutor::DataFlow::OutputOfAny to Node "
+             << ToNodeName << "(" << ToParameterName << ") from MacroNode " << aNodeName << endl ;
+      int sts ;
+      if ( aLinkedNode->IsLockedDataWait() ) {
+        cdebug << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
+               << " IsLockedDataWait --> UnLockDataWait" << endl ;
+      }
+      sts = aLinkedNode->SendSomeDataReady( (char * ) aNodeName ) ;
+      cdebug << pthread_self() << "/" << aLinkedNode->ThreadNo()
+             << "GraphExecutor::DataFlow::OutputOfAny " << aLinkedNode->Name()
+             << "->SendSomeDataReady( " << aNodeName << " ) sts " << sts << " " << aLinkedNode->State() << endl ;
+      if ( sts ) {
+        if ( aLinkedNode->State() == GraphExecutor::DataReadyState ) {
+          aLinkedNode->CreateNewThreadIf( true ) ;
+          aLinkedNode->UnLockDataWait() ;
+//          aLinkedNode->DataUndef_AllDataReadyAction() ;
+          aLinkedNode->SendEvent( GraphExecutor::ExecuteEvent ) ;
+        }
+      }
+    }
+    else if ( Graph()->GraphMacroLevel() != 0 ) {
+      cdebug << pthread_self() << "/" << Graph()->CoupledNode()->ThreadNo()
+             << "GraphExecutor::DataFlow::OutputOfAny to that graph "
+             << ToNodeName << "(" << ToParameterName << ") " << State() << " " << Graph()->CoupledNodeName ()
+             << " sended recursively to the MacroNode coupled to that graph" << endl ;
+      Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( Graph()->CoupledNodeName() ,
+                                                            ToParameterName ,
+//JR 30.03.2005                                                            *anOutPort->Value() ) ;
+                                                            anOutPort->Value() ) ;
+    }
+    else {
+      cdebug << "GraphExecutor::DataFlow::OutputOfAny to Graph " << ToNodeName
+             << "(" << ToParameterName << ") ignored" << endl ;
+    }
+  }
+  cdebug_out << pthread_self() << "/" << ThreadNo() << " GraphExecutor::DataFlow::OutputOfAny " << RetVal
+             << endl ;
+  return RetVal ;
+}
+
 bool GraphExecutor::DataFlow::Kill() {
   cdebug_in << "GraphExecutor::DataFlow::Kill()" << endl;
   bool RetVal = GraphExecutor::OutNode::Kill() ;
-  cdebug_out << "GraphExecutor::DataFlow::Kill()" << endl;
+  cdebug_out << "GraphExecutor::DataFlow::Kill() " << RetVal << endl;
   return RetVal ;
 }
 
 bool GraphExecutor::DataFlow::Kill( const char *aNodeName ) {
 //  cdebug_in << "GraphExecutor::DataFlow::Kill( " << aNodeName << " )"<< endl;
   bool RetVal = false ;
-  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode()) ;
+  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
   if ( aNode ) {
     RetVal = aNode->Kill() ;
   }
@@ -135,7 +252,7 @@ bool GraphExecutor::DataFlow::Kill( const char *aNodeName ) {
 bool GraphExecutor::DataFlow::KillDone( const char *aNodeName ) {
 //  cdebug_in << "GraphExecutor::DataFlow::KillDone( " << aNodeName << " )"<< endl;
   bool RetVal = false ;
-  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode()) ;
+  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
   if ( aNode ) {
     RetVal = aNode->KillDone() ;
   }
@@ -153,7 +270,7 @@ bool GraphExecutor::DataFlow::Suspend() {
 bool GraphExecutor::DataFlow::Suspend( const char *aNodeName ) {
 //  cdebug_in << "GraphExecutor::DataFlow::Suspend( " << aNodeName << " )"<< endl;
   bool RetVal = false ;
-  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode()) ;
+  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
   if ( aNode ) {
     RetVal = aNode->Suspend() ;
   }
@@ -172,7 +289,7 @@ bool GraphExecutor::DataFlow::SuspendDone() {
 bool GraphExecutor::DataFlow::SuspendDone( const char *aNodeName ) {
 //  cdebug_in << "GraphExecutor::DataFlow::SuspendDone( " << aNodeName << " )"<< endl;
   bool RetVal = false ;
-  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode()) ;
+  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
   if ( aNode ) {
     RetVal = aNode->SuspendDone() ;
   }
@@ -190,7 +307,7 @@ bool GraphExecutor::DataFlow::Resume() {
 bool GraphExecutor::DataFlow::Resume( const char *aNodeName ) {
 //  cdebug_in << "GraphExecutor::DataFlow::Resume( " << aNodeName << " )"<< endl;
   bool RetVal = false ;
-  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode()) ;
+  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
   if ( aNode ) {
     RetVal = aNode->Resume() ;
   }
@@ -208,7 +325,7 @@ bool GraphExecutor::DataFlow::Stop() {
 bool GraphExecutor::DataFlow::Stop( const char *aNodeName ) {
 //  cdebug_in << "GraphExecutor::DataFlow::Stop( " << aNodeName << " )"<< endl;
   bool RetVal = false ;
-  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode()) ;
+  GraphExecutor::InNode * aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode()) ;
   if ( aNode ) {
     RetVal = aNode->Stop() ;
   }