Salome HOME
SMH: 3.0.0 preparation = merged version (POLYWORK + RTVDEBUG01) + adopation for new GUI
[modules/superv.git] / src / GraphBase / DataFlowBase_DataPort.cxx
index 1f6d837551b06e1e09581cd2a8044cec0938543c..c2f9e8f261e82747d4aeac6351e759b5b3365eb7 100644 (file)
@@ -33,7 +33,7 @@ using namespace std;
 GraphBase::DataPort::DataPort() :
               Port() {
   pthread_mutex_init( &_MutexWait , NULL ) ;
-  _State = SUPERV::UndefinedState ;
+  _PortState = SUPERV::UndefinedState ;
   _Done = false ;
   InitialValues( CORBA::Any() ) ;
 }
@@ -44,7 +44,7 @@ GraphBase::DataPort::DataPort( const char *const * NodeName  ,
                                const SALOME_ModuleCatalog::DataStreamDependency aDependency ) :
            Port( NodeName , aserviceParameter , aKind , aDependency ) {
   pthread_mutex_init( &_MutexWait , NULL ) ;
-  _State = SUPERV::UndefinedState ;
+  _PortState = SUPERV::UndefinedState ;
   _Done = false ;
   InitialValues( CORBA::Any() ) ;
 }
@@ -54,7 +54,8 @@ GraphBase::DataPort::~DataPort() {
 
 void GraphBase::DataPort::InitialValues(CORBA::Any aValue ) {
   _theValue = new CORBA::Any( aValue ) ;
-  string _Type = CORBA::string_dup(GetServicesParameter().Parametertype) ;
+//JR 24.02.2005 Memory Leak  string _Type = CORBA::string_dup(GetServicesParameter().Parametertype) ;
+  string _Type = string( GetServicesParameter().Parametertype ) ;
   const char * Type = _Type.c_str();
   CORBA::Any InitialValue ;
   cdebug << "InitialValues " << NodeName() << " " << PortName() << " " << PortType()
@@ -113,6 +114,7 @@ void GraphBase::DataPort::Value( const CORBA::Any & aDataValue ) {
   Value( aValue ) ;
 }
 
+#define ValueTrace 0
 void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
 //  cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_lock " << &_MutexWait
 //         << endl ;
@@ -125,20 +127,27 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
 
   delete _theValue ;
 
-  string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
-  const char * Type = _Type.c_str() ;
+//JR 21.02.2005 Debug Memory leak :  string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
+//  const char * Type = _Type.c_str() ;
+  const char * Type = GetServicesParameter().Parametertype ;
   _Value = &_theValue ;
+#if ValueTrace
   cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
          << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
+#endif
   switch (aDataValue->type()->kind()) { // Input Value
   case CORBA::tk_string: { // Input string Value
     char * t;
     *aDataValue >>= t;
+#if ValueTrace
     cdebug << t << " (string)" ;
+#endif
     if ( !strcmp( Type , "string" ) ) { // SuperVision Value
       _theValue = aDataValue ;
       *_theValue >>= t;
+#if ValueTrace
       cdebug << " == Value( " << t << ") (string)";
+#endif
     }
     else {
       CORBA::Any * theValue = new CORBA::Any() ;
@@ -148,14 +157,18 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
         sscanf( t , "%ld" , &l ) ;
         *theValue <<= l ;
         *theValue >>= l;
+#if ValueTrace
         cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
+#endif
       }
       else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
         double d ;
         sscanf( t , "%lf" , &d ) ;
         *theValue <<= d ;
         *theValue >>= d;
+#if ValueTrace
         cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
+#endif
       }
       else { // Default
         CORBA::Object_ptr ObjRef ;
@@ -167,24 +180,32 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
           *theValue <<= CORBA::Object::_nil() ;
         }
         *theValue >>= ObjRef ;
+#if ValueTrace
         cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
                << theValue->type()->kind() ;
+#endif
       }
       _theValue = theValue ;
       *_Value = theValue ;
+//JR 21.02.2005 Debug Memory leak : 
+      delete aDataValue ;
     }
     break;
   }
   case CORBA::tk_long: { // Input long Value
     long l;
     *aDataValue >>= l;
+#if ValueTrace
     cdebug << "Value( " << l << ") (long)";
+#endif
     if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
          !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
       _theValue = aDataValue ;
       *_Value = aDataValue ;
       *_theValue >>= l;
+#if ValueTrace
       cdebug << " == Value( " << l << ") (long)";
+#endif
     }
     else {
       CORBA::Any * theValue = new CORBA::Any() ;
@@ -194,35 +215,47 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
         *theValue <<=  t ;
         char *tt ;
         *theValue >>= tt ;
+#if ValueTrace
         cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
+#endif
       }
       else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
         double d = l ;
         *theValue <<= d ;
         *theValue >>= d ;
+#if ValueTrace
         cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
+#endif
       }
       else { // Default
         CORBA::Object_ptr ObjRef ;
         *theValue <<= CORBA::Object::_nil() ;
         *theValue >>= ObjRef ;
+#if ValueTrace
         cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
                << theValue->type()->kind() ;
+#endif
       }
       _theValue = theValue ;
       *_Value = theValue ;
+//JR 21.02.2005 Debug Memory leak : 
+      delete aDataValue ;
     }
     break;
   }
   case CORBA::tk_double: { // Input double Value
     double d;
     *aDataValue >>= d;
+#if ValueTrace
     cdebug << "Value( " << d << ") (double)";
+#endif
     if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
       _theValue = aDataValue ;
       *_Value = aDataValue ;
       *_theValue >>= d;
+#if ValueTrace
       cdebug << " == Value( " << d << ") (double)";
+#endif
     }
     else {
       CORBA::Any * theValue = new CORBA::Any() ;
@@ -232,31 +265,41 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
         *theValue <<=  t ;
         char *tt ;
         *theValue >>= tt ;
+#if ValueTrace
         cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
+#endif
       }
       else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
                 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
         long l = (long ) d ;
         *theValue <<= l ;
         *theValue >>= l;
+#if ValueTrace
         cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
+#endif
       }
       else { // Default
         CORBA::Object_ptr ObjRef ;
         *theValue <<= CORBA::Object::_nil() ;
         *theValue >>= ObjRef ;
+#if ValueTrace
         cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
                << theValue->type()->kind() ;
+#endif
       }
       _theValue = theValue ;
       *_Value = theValue ;
+//JR 21.02.2005 Debug Memory leak : 
+      delete aDataValue ;
     }
     break;
   }
   case CORBA::tk_objref: { // Input objref Value
     CORBA::Object_ptr obj ;
     *aDataValue >>= obj;
+#if ValueTrace
     cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
+#endif
     if ( strcmp( Type , "string" ) &&
          strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
          strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
@@ -264,30 +307,40 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
       _theValue = aDataValue ;
       *_Value = aDataValue ;
       *_theValue >>= obj;
+#if ValueTrace
       cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
+#endif
     }
     else {
       CORBA::Any * theValue = new CORBA::Any() ;
       if ( !strcmp( Type , "string" ) ) {
         *theValue <<=  ObjectToString( obj ) ;
         *theValue >>= obj ;
+#if ValueTrace
         cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
+#endif
       }
       else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
                 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
         long l = (long ) obj ;
         *theValue <<= l ;
         *theValue >>= l;
+#if ValueTrace
         cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
+#endif
       }
       else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
         double d = (double ) 0. ;
         *theValue <<= d ;
         *theValue >>= d;
+#if ValueTrace
         cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
+#endif
       }
       _theValue = theValue ;
       *_Value = theValue ;
+//JR 21.02.2005 Debug Memory leak : 
+      delete aDataValue ;
     }
     break;
   }
@@ -297,7 +350,9 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
     break;
   }
   }
+#if ValueTrace
   cdebug << endl ;
+#endif
   if ( pthread_mutex_unlock( &_MutexWait ) ) {
     perror( "unlock DataValue" ) ;
     exit( 0 ) ;
@@ -307,42 +362,9 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
 
 }
 
-void GraphBase::DataPort::Value( const CORBA::Any ** aDataSharedValue ) {
-  delete _theValue ;
-  _theValue = *aDataSharedValue ;
-  _Value = aDataSharedValue ;
-//  Done( true ) ;
-
-#if 0
-  MESSAGE( NodePortName() << " : " << hex << _Value << " " );
-  switch (_theValue->type()->kind()) {
-  case CORBA::tk_string:
-    char * t;
-    *_theValue >>= t;
-    MESSAGE( "Value( " << t << ") (string)");
-    break;
-  case CORBA::tk_double:
-    double d;
-    *_theValue >>= d;
-    MESSAGE( "Value( " << d << ") (double)");
-    break;
-  case CORBA::tk_long:
-    long l;
-    *_theValue >>= l;
-    MESSAGE( "Value( " << l << ") (long)");
-    break;
-  case CORBA::tk_objref:
-    MESSAGE( "Value( " << ") (object reference)");
-    break;
-  default:
-    MESSAGE( "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR");
-    break;
-  }
-  MESSAGE();
-#endif
-}
-
-CORBA::Any const * GraphBase::DataPort::Value() const {
+// PAL8506
+//JR 30.03.2005 Memory Leak + Debug(crash) CORBA::Any const * GraphBase::DataPort::Value() const {
+const CORBA::Any GraphBase::DataPort::Value() const {
   pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
 //  cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
   if ( pthread_mutex_lock( aMutexWait ) ) {
@@ -351,7 +373,8 @@ CORBA::Any const * GraphBase::DataPort::Value() const {
   }
 //  cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
   const CORBA::Any *const Value = *_Value ;
-  CORBA::Any * theValue ;
+//JR 30.03.2005  CORBA::Any * theValue ;
+  CORBA::Any theValue ;
 //  cdebug  << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
 //          << PortType() << " _Value " << _Value << " *_Value " << *_Value  << " Value->type "
 //          << Value->type() ;
@@ -361,24 +384,30 @@ CORBA::Any const * GraphBase::DataPort::Value() const {
   else {
 //    cdebug << " Null" << endl ;
   }
-  if ( Done() ) {
-    theValue = new CORBA::Any( *Value ) ;
-    switch ( theValue->type()->kind() ) {
+  if ( PortDone() ) {
+//JR 21.02.2005 Debug Memory leak :     theValue = new CORBA::Any( *Value ) ;
+//JR 30.03.2005     theValue = (CORBA::Any * ) Value ;
+    theValue = *Value ;
+//JR 30.03.2005    switch ( theValue->type()->kind() ) {
+    switch ( theValue.type()->kind() ) {
     case CORBA::tk_string: {
       char * t;
-      *theValue >>= t;
+//JR 30.03.2005      *theValue >>= t;
+      theValue >>= t;
 //      cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
       break;
     }
     case CORBA::tk_double: {
       double d;
-      *theValue >>= d;
+//JR 30.03.2005      *theValue >>= d;
+      theValue >>= d;
 //      cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
       break;
     }
     case CORBA::tk_long: {
       long l;
-      *theValue >>= l;
+//JR 30.03.2005      *theValue >>= l;
+      theValue >>= l;
 //      cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
       break;
     }
@@ -386,7 +415,8 @@ CORBA::Any const * GraphBase::DataPort::Value() const {
       CORBA::Object_ptr obj ;
       char * retstr ;
       try {
-        *theValue >>= obj ;
+//JR 30.03.2005        *theValue >>= obj ;
+        theValue >>= obj ;
         retstr = ObjectToString( obj );
 //        cdebug << "GraphBase::DataPort::Value() : " << retstr
 //               << "(object reference) " << endl;
@@ -405,7 +435,9 @@ CORBA::Any const * GraphBase::DataPort::Value() const {
   }
   else {
 //    cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
-    theValue = new CORBA::Any( *Value ) ;
+//JR 21.02.2005 Debug Memory leak :    theValue = new CORBA::Any( *Value ) ;
+//JR 30.03.2005    theValue = (CORBA::Any * ) Value ;
+    theValue = *Value ;
   }
   if ( pthread_mutex_unlock( aMutexWait ) ) {
     perror( "unlock DataValue" ) ;
@@ -418,7 +450,6 @@ CORBA::Any const * GraphBase::DataPort::Value() const {
 
 bool GraphBase::DataPort::BoolValue() const {
   bool RetVal = false ;
-  long val ;
   pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
 //  cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
   if ( pthread_mutex_lock( aMutexWait ) ) {
@@ -428,6 +459,14 @@ bool GraphBase::DataPort::BoolValue() const {
 //  cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
 //         << endl ;
   if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
+    long val ;
+    **_Value >>= val ;
+    if ( val ) {
+      RetVal = true ;
+    }
+  }
+  else if ( (*_Value)->type()->kind() == CORBA::tk_boolean ) {
+    bool val ;
     **_Value >>= val ;
     if ( val ) {
       RetVal = true ;
@@ -437,26 +476,21 @@ bool GraphBase::DataPort::BoolValue() const {
     perror( "unlock DataValue" ) ;
     exit( 0 ) ;
   }
-//  cdebug << pthread_self() << " BoolValue() --> pthread_mutex_unlocked " << aMutexWait
-//         << endl ;
+//  cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ;
   return RetVal ;
 }
 
-const CORBA::Any ** GraphBase::DataPort::ValuePtr() const {
-  return _Value ;
-}
-
 void GraphBase::DataPort::StringValue(ostream & f ) const {
   pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
-//  cdebug << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
-//         << endl ;
+//  cdebug_in << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
+//            << endl ;
   if ( pthread_mutex_lock( aMutexWait ) ) {
     perror( "lock DataValue" ) ;
     exit( 0 ) ;
   }
 //  cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
 //         << endl ;
-  if ( Done() ) {
+  if ( PortDone() ) {
 //    cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
 //           << " _Value "  << _Value << " *_Value "
 //           << *_Value  << " " << endl ;
@@ -493,14 +527,14 @@ void GraphBase::DataPort::StringValue(ostream & f ) const {
     }
   }
   else {
-    f << " Default (undefined) NOT DONE"  ;
+    f << " Default (undefined) DATAPORT NOT DONE"  ;
   }
   if ( pthread_mutex_unlock( aMutexWait ) ) {
     perror( "unlock DataValue" ) ;
     exit( 0 ) ;
   }
-//  cdebug << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait
-//         << endl ;
+//  cdebug_out << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait
+//             << endl ;
     
 }