1 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : DataFlowBase_DataPort.cxx
25 // Author : Jean Rahuel, CEA
31 #include "DataFlowBase_DataPort.hxx"
33 GraphBase::DataPort::DataPort() :
35 pthread_mutex_init( &_MutexWait , NULL ) ;
36 _PortState = SUPERV::UndefinedState ;
38 InitialValues( CORBA::Any() ) ;
41 GraphBase::DataPort::DataPort( const char *const * NodeName ,
42 const SALOME_ModuleCatalog::ServicesParameter aserviceParameter ,
43 const SUPERV::KindOfPort aKind ,
44 const SALOME_ModuleCatalog::DataStreamDependency aDependency ) :
45 Port( NodeName , aserviceParameter , aKind , aDependency ) {
46 pthread_mutex_init( &_MutexWait , NULL ) ;
47 _PortState = SUPERV::UndefinedState ;
49 InitialValues( CORBA::Any() ) ;
52 GraphBase::DataPort::~DataPort() {
55 void GraphBase::DataPort::InitialValues(CORBA::Any aValue ) {
56 _theValue = new CORBA::Any( aValue ) ;
57 //JR 24.02.2005 Memory Leak string _Type = CORBA::string_dup(GetServicesParameter().Parametertype) ;
58 string _Type = string( GetServicesParameter().Parametertype ) ;
59 const char * Type = _Type.c_str();
60 CORBA::Any InitialValue ;
61 cdebug << "InitialValues " << NodeName() << " " << PortName() << " " << PortType()
63 if ( !strcmp( Type , "" ) ) {
64 cdebug << "void" << endl ;
65 InitialValue <<= (void *) NULL ;
67 else if ( !strcmp( Type , "string" ) ) {
68 cdebug << "string" << endl ;
69 // InitialValue <<= (char *) NULL ;
72 else if ( !strcmp( Type , "boolean" ) ) {
73 cdebug << "boolean" << endl ;
74 InitialValue <<= (CORBA::Long ) 0 ;
76 else if ( !strcmp( Type , "char" ) ) {
77 cdebug << "char" << endl ;
78 InitialValue <<= (CORBA::Long ) 0 ;
80 else if ( !strcmp( Type , "short" ) ) {
81 cdebug << "short" << endl ;
82 InitialValue <<= (CORBA::Long ) 0 ;
84 else if ( !strcmp( Type , "int" ) ) {
85 cdebug << "long" << endl ;
86 InitialValue <<= (CORBA::Long ) 0 ;
88 else if ( !strcmp( Type , "long" ) ) {
89 cdebug << "long" << endl ;
90 InitialValue <<= (CORBA::Long ) 0 ;
92 else if ( !strcmp( Type , "float" ) ) {
93 cdebug << "float" << endl ;
94 #ifdef REDHAT // mkr : debug for PAL12255
95 InitialValue <<= (float ) 0. ;
98 //JR InitialValue.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
99 InitialValue <<= (CORBA::Float) 0. ;
103 else if ( !strcmp( Type , "double" ) ) {
104 cdebug << "double" << endl ;
105 #ifdef REDHAT // mkr : debug for PAL12255
106 InitialValue <<= (double ) 0. ;
109 //JR InitialValue.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
110 InitialValue <<= (CORBA::Double) 0. ;
114 cdebug << "objref" << endl ;
115 // InitialValue.replace(CORBA::_tc_Object, NULL);
116 InitialValue <<= CORBA::Object::_nil() ;
119 // cdebug << "InitialValues ERROR (other) " << Type << endl ;
120 // InitialValue <<= (CORBA::Long ) 0 ;
122 _InitialValue = new CORBA::Any( InitialValue ) ;
123 _Value = &_InitialValue ;
126 void GraphBase::DataPort::SetValue( const CORBA::Any & aDataValue ) {
127 CORBA::Any * aValue = new CORBA::Any( aDataValue ) ;
132 void GraphBase::DataPort::SetValue( const CORBA::Any * aDataValue ) {
133 // cdebug << pthread_self() << " SetValue(aDataValue) --> pthread_mutex_lock " << &_MutexWait
135 if ( pthread_mutex_lock( &_MutexWait ) ) {
136 perror( "lock DataValue" ) ;
139 // cdebug << pthread_self() << " SetValue(aDataValue) pthread_mutex_locked " << &_MutexWait
144 //JR 21.02.2005 Debug Memory leak : string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
145 // const char * Type = _Type.c_str() ;
146 const char * Type = GetServicesParameter().Parametertype ;
147 _Value = &_theValue ;
149 cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
150 << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
152 switch (aDataValue->type()->kind()) { // Input Value
153 case CORBA::tk_string: { // Input string Value
157 cdebug << t << " (string)" ;
159 if ( !strcmp( Type , "string" ) ) { // SuperVision Value
160 _theValue = aDataValue ;
163 cdebug << " == Value( " << t << ") (string)";
167 CORBA::Any * theValue = new CORBA::Any() ;
168 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
169 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
171 sscanf( t , "%ld" , &ll ) ;
176 cdebug << " --> Value( " << l << ") (CORBA::Long) kind " << theValue->type()->kind() ;
179 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
181 sscanf( t , "%lf" , &d ) ;
182 #ifdef REDHAT // mkr : debug for PAL12255
185 //JR theValue->replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
186 *theValue <<= (CORBA::Double) d ;
190 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
194 CORBA::Object_ptr ObjRef ;
196 ObjRef = StringToObject( t ) ;
197 *theValue <<= ObjRef ;
200 *theValue <<= CORBA::Object::_nil() ;
202 #if OMNIORB_VERSION >= 4
203 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
205 *theValue >>= ObjRef ;
208 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
209 << theValue->type()->kind() ;
212 //_theValue = theValue ;
213 _theValue = new CORBA::Any( *theValue ) ;
215 //*_Value = theValue ;
216 _Value = &_theValue ;
218 //JR 21.02.2005 Debug Memory leak :
223 case CORBA::tk_long: { // Input CORBA::Long Value
227 cdebug << "Value( " << l << ") (CORBA::Long)";
229 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
230 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
231 _theValue = aDataValue ;
232 *_Value = aDataValue ;
235 cdebug << " == Value( " << l << ") (CORBA::Long)";
239 CORBA::Any * theValue = new CORBA::Any() ;
240 if ( !strcmp( Type , "string" ) ) {
243 sprintf( t , "%ld" , ll ) ;
248 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
251 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
253 #ifdef REDHAT // mkr : debug for PAL12255
256 //JR theValue->replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
257 *theValue <<= (CORBA::Double) d ;
262 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
266 CORBA::Object_ptr ObjRef ;
267 *theValue <<= CORBA::Object::_nil() ;
268 #if OMNIORB_VERSION >= 4
269 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
271 *theValue >>= ObjRef ;
274 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
275 << theValue->type()->kind() ;
279 //_theValue = theValue ;
280 _theValue = new CORBA::Any( *theValue ) ;
282 //*_Value = theValue ;
283 _Value = &_theValue ;
285 //JR 21.02.2005 Debug Memory leak :
290 case CORBA::tk_double: { // Input double Value
294 cdebug << "Value( " << d << ") (double)";
296 if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
297 //_theValue = aDataValue ;
298 _theValue = new CORBA::Any( *aDataValue ) ;
300 //*_Value = aDataValue ;
301 _Value = &_theValue ;
305 cdebug << " == Value( " << d << ") (double)";
309 CORBA::Any * theValue = new CORBA::Any() ;
310 if ( !strcmp( Type , "string" ) ) {
312 sprintf( t , "%lf" , d ) ;
317 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
320 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
321 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
322 CORBA::Long l = (CORBA::Long ) d ;
326 cdebug << " --> Value( " << l << ") (CORBA::Long) kind " << theValue->type()->kind() ;
330 CORBA::Object_ptr ObjRef ;
331 *theValue <<= CORBA::Object::_nil() ;
332 #if OMNIORB_VERSION >= 4
333 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
335 *theValue >>= ObjRef ;
338 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
339 << theValue->type()->kind() ;
342 //_theValue = theValue ;
343 _theValue = new CORBA::Any( *theValue ) ;
345 //*_Value = theValue ;
346 _Value = &_theValue ;
348 //JR 21.02.2005 Debug Memory leak :
353 case CORBA::tk_objref: { // Input objref Value
354 CORBA::Object_ptr obj ;
355 #if OMNIORB_VERSION >= 4
356 *aDataValue >>= (CORBA::Any::to_object ) obj;
361 cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
363 if ( strcmp( Type , "string" ) &&
364 strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
365 strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
366 strcmp( Type , "double" ) ) { // SuperVision Default Value
367 _theValue = aDataValue ;
368 *_Value = aDataValue ;
369 #if OMNIORB_VERSION >= 4
370 *_theValue >>= (CORBA::Any::to_object ) obj ;
375 cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
379 CORBA::Any * theValue = new CORBA::Any() ;
380 if ( !strcmp( Type , "string" ) ) {
381 *theValue <<= ObjectToString( obj ) ;
382 #if OMNIORB_VERSION >= 4
383 *theValue >>= (CORBA::Any::to_object ) obj ;
388 cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
391 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
392 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
393 #ifdef OMNI_LONG_IS_INT
394 long ll = (long ) obj ;
395 CORBA::Long l = (CORBA::Long ) ll ;
397 CORBA::Long l = (CORBA::Long ) obj ;
402 cdebug << " --> Value( " << l << ") (CORBA::Long) kind " << theValue->type()->kind() ;
405 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
406 double d = (double ) 0. ;
407 #ifdef REDHAT // mkr : debug for PAL12255
410 //JR theValue->replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
411 *theValue <<= (CORBA::Double) d ;
415 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
418 //_theValue = theValue ;
419 _theValue = new CORBA::Any( *theValue ) ;
421 //*_Value = theValue ;
422 _Value = &_theValue ;
424 //JR 21.02.2005 Debug Memory leak :
430 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
431 << aDataValue->type()->kind() ;
438 if ( pthread_mutex_unlock( &_MutexWait ) ) {
439 perror( "unlock DataValue" ) ;
442 // cdebug << pthread_self() << " SetValue(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
448 //JR 30.03.2005 Memory Leak + Debug(crash) CORBA::Any const * GraphBase::DataPort::Value() const {
449 const CORBA::Any GraphBase::DataPort::Value() const {
450 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
451 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
452 if ( pthread_mutex_lock( aMutexWait ) ) {
453 perror( "lock DataValue" ) ;
456 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
457 const CORBA::Any *const Value = *_Value ;
458 //JR 30.03.2005 CORBA::Any * theValue ;
459 CORBA::Any theValue ;
460 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
461 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
462 // << Value->type() ;
463 if ( Value->type() ) {
464 // cdebug << " kind " << Value->type()->kind() << " :" << endl ;
467 // cdebug << " Null" << endl ;
470 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
471 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
473 //JR 30.03.2005 switch ( theValue->type()->kind() ) {
474 switch ( theValue.type()->kind() ) {
475 case CORBA::tk_string: {
477 //JR 30.03.2005 *theValue >>= t;
479 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
482 case CORBA::tk_double: {
484 //JR 30.03.2005 *theValue >>= d;
486 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
489 case CORBA::tk_long: {
491 //JR 30.03.2005 *theValue >>= l;
493 // cdebug << "GraphBase::DataPort::Value() : " << l << " (CORBA::Long) " << endl ;
496 case CORBA::tk_objref: {
497 CORBA::Object_ptr obj ;
500 //JR 30.03.2005 *theValue >>= obj ;
501 #if OMNIORB_VERSION >= 4
502 theValue >>= (CORBA::Any::to_object ) obj ;
506 retstr = ObjectToString( obj );
507 // cdebug << "GraphBase::DataPort::Value() : " << retstr
508 // << "(object reference) " << endl;
511 cdebug << "ToString( object ) Catched ERROR" << endl ;
516 cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
517 << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
523 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
524 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
525 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
528 if ( pthread_mutex_unlock( aMutexWait ) ) {
529 perror( "unlock DataValue" ) ;
532 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
537 bool GraphBase::DataPort::BoolValue() const {
538 bool RetVal = false ;
539 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
540 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
541 if ( pthread_mutex_lock( aMutexWait ) ) {
542 perror( "lock DataValue" ) ;
545 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
547 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
554 else if ( (*_Value)->type()->kind() == CORBA::tk_boolean ) {
561 if ( pthread_mutex_unlock( aMutexWait ) ) {
562 perror( "unlock DataValue" ) ;
565 // cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ;
569 void GraphBase::DataPort::StringValue(ostream & f ) const {
570 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
571 // cdebug_in << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
573 if ( pthread_mutex_lock( aMutexWait ) ) {
574 perror( "lock DataValue" ) ;
577 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
580 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
581 // << " _Value " << _Value << " *_Value "
582 // << *_Value << " " << endl ;
583 const CORBA::Any * theValue = *_Value ;
584 switch (theValue->type()->kind()) {
585 case CORBA::tk_string:
588 f << t << " (string)" ;
590 case CORBA::tk_double:
593 f << d << " (double)" ;
598 f << l << " (CORBA::Long)" ;
600 case CORBA::tk_objref:
601 CORBA::Object_ptr ObjRef ;
603 #if OMNIORB_VERSION >= 4
604 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
606 *theValue >>= ObjRef ;
608 f << "(object reference) " << ObjectToString( ObjRef ) ;
611 f << "(object reference) catched error" ;
615 f << "(other ERROR)" ;
620 f << " Default (undefined) DATAPORT NOT DONE" ;
622 if ( pthread_mutex_unlock( aMutexWait ) ) {
623 perror( "unlock DataValue" ) ;
626 // cdebug_out << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait