X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGraphBase%2FDataFlowBase_DataPort.cxx;h=4e7c3e1ed5b8fb6202fee03a792fc6dc89f32e80;hb=21f42338a5a328977269d6e4ee57b9a672cd3bf5;hp=a4c366393db7adcb45b85430f0721668d5d0ea6a;hpb=bae06cd3bdae2ac2acb878e96689b2ea283aad23;p=modules%2Fsuperv.git diff --git a/src/GraphBase/DataFlowBase_DataPort.cxx b/src/GraphBase/DataFlowBase_DataPort.cxx index a4c3663..4e7c3e1 100644 --- a/src/GraphBase/DataFlowBase_DataPort.cxx +++ b/src/GraphBase/DataFlowBase_DataPort.cxx @@ -33,16 +33,19 @@ using namespace std; GraphBase::DataPort::DataPort() : Port() { pthread_mutex_init( &_MutexWait , NULL ) ; + _PortState = SUPERV::UndefinedState ; + _Done = false ; InitialValues( CORBA::Any() ) ; } -GraphBase::DataPort::DataPort( - const char *const * NodeName , - const SALOME_ModuleCatalog::ServicesParameter aserviceParameter , - const SUPERV::KindOfPort aKind , - const SALOME_ModuleCatalog::DataStreamDependency aDependency ) : - Port( NodeName , aserviceParameter , aKind , aDependency ) { +GraphBase::DataPort::DataPort( const char *const * NodeName , + const SALOME_ModuleCatalog::ServicesParameter aserviceParameter , + const SUPERV::KindOfPort aKind , + const SALOME_ModuleCatalog::DataStreamDependency aDependency ) : + Port( NodeName , aserviceParameter , aKind , aDependency ) { pthread_mutex_init( &_MutexWait , NULL ) ; + _PortState = SUPERV::UndefinedState ; + _Done = false ; InitialValues( CORBA::Any() ) ; } @@ -51,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() @@ -62,7 +66,7 @@ void GraphBase::DataPort::InitialValues(CORBA::Any aValue ) { } else if ( !strcmp( Type , "string" ) ) { cdebug << "string" << endl ; - InitialValue <<= (char *) NULL ; + InitialValue <<= (char *) ""; } else if ( !strcmp( Type , "boolean" ) ) { cdebug << "boolean" << endl ; @@ -110,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 ; @@ -122,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 ; -// cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType() -// << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ; +#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; -// cdebug << " == Value( " << t << ") (string)"; +#if ValueTrace + cdebug << " == Value( " << t << ") (string)"; +#endif } else { CORBA::Any * theValue = new CORBA::Any() ; @@ -145,14 +157,18 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { sscanf( t , "%ld" , &l ) ; *theValue <<= l ; *theValue >>= l; -// cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ; +#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; -// cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ; +#if ValueTrace + cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ; +#endif } else { // Default CORBA::Object_ptr ObjRef ; @@ -164,24 +180,32 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { *theValue <<= CORBA::Object::_nil() ; } *theValue >>= ObjRef ; -// cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind " -// << theValue->type()->kind() ; +#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; -// cdebug << "Value( " << l << ") (long)"; +#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; -// cdebug << " == Value( " << l << ") (long)"; +#if ValueTrace + cdebug << " == Value( " << l << ") (long)"; +#endif } else { CORBA::Any * theValue = new CORBA::Any() ; @@ -191,35 +215,47 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { *theValue <<= t ; char *tt ; *theValue >>= tt ; -// cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ; +#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 ; -// cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ; +#if ValueTrace + cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ; +#endif } else { // Default CORBA::Object_ptr ObjRef ; *theValue <<= CORBA::Object::_nil() ; *theValue >>= ObjRef ; -// cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind " -// << theValue->type()->kind() ; +#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; -// cdebug << "Value( " << d << ") (double)"; +#if ValueTrace + cdebug << "Value( " << d << ") (double)"; +#endif if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value _theValue = aDataValue ; *_Value = aDataValue ; *_theValue >>= d; -// cdebug << " == Value( " << d << ") (double)"; +#if ValueTrace + cdebug << " == Value( " << d << ") (double)"; +#endif } else { CORBA::Any * theValue = new CORBA::Any() ; @@ -229,31 +265,41 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { *theValue <<= t ; char *tt ; *theValue >>= tt ; -// cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ; +#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; -// cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ; +#if ValueTrace + cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ; +#endif } else { // Default CORBA::Object_ptr ObjRef ; *theValue <<= CORBA::Object::_nil() ; *theValue >>= ObjRef ; -// cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind " -// << theValue->type()->kind() ; +#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; -// cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)"; +#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" ) && @@ -261,30 +307,40 @@ void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) { _theValue = aDataValue ; *_Value = aDataValue ; *_theValue >>= obj; -// cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)"; +#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 ; -// cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ; +#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; -// cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ; +#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; -// cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ; +#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; } @@ -294,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 ) ; @@ -304,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 ) ) { @@ -348,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() ; @@ -358,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; } @@ -383,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; @@ -402,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" ) ; @@ -415,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 ) ) { @@ -425,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 ; @@ -434,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 ; @@ -490,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 ; }