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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 <<= (long ) 0 ;
76 else if ( !strcmp( Type , "char" ) ) {
77 cdebug << "char" << endl ;
78 InitialValue <<= (long ) 0 ;
80 else if ( !strcmp( Type , "short" ) ) {
81 cdebug << "short" << endl ;
82 InitialValue <<= (long ) 0 ;
84 else if ( !strcmp( Type , "int" ) ) {
85 cdebug << "long" << endl ;
86 InitialValue <<= (long ) 0 ;
88 else if ( !strcmp( Type , "long" ) ) {
89 cdebug << "long" << endl ;
90 InitialValue <<= (long ) 0 ;
92 else if ( !strcmp( Type , "float" ) ) {
93 cdebug << "float" << endl ;
95 InitialValue.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
96 //InitialValue <<= (double ) 0. ;
98 else if ( !strcmp( Type , "double" ) ) {
99 cdebug << "double" << endl ;
101 InitialValue.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
102 //InitialValue <<= (double ) 0. ;
105 cdebug << "objref" << endl ;
106 // InitialValue.replace(CORBA::_tc_Object, NULL);
107 InitialValue <<= CORBA::Object::_nil() ;
110 // cdebug << "InitialValues ERROR (other) " << Type << endl ;
111 // InitialValue <<= (long ) 0 ;
113 _InitialValue = new CORBA::Any( InitialValue ) ;
114 _Value = &_InitialValue ;
117 void GraphBase::DataPort::SetValue( const CORBA::Any & aDataValue ) {
118 CORBA::Any * aValue = new CORBA::Any( aDataValue ) ;
123 void GraphBase::DataPort::SetValue( const CORBA::Any * aDataValue ) {
124 // cdebug << pthread_self() << " SetValue(aDataValue) --> pthread_mutex_lock " << &_MutexWait
126 if ( pthread_mutex_lock( &_MutexWait ) ) {
127 perror( "lock DataValue" ) ;
130 // cdebug << pthread_self() << " SetValue(aDataValue) pthread_mutex_locked " << &_MutexWait
135 //JR 21.02.2005 Debug Memory leak : string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
136 // const char * Type = _Type.c_str() ;
137 const char * Type = GetServicesParameter().Parametertype ;
138 _Value = &_theValue ;
140 cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
141 << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
143 switch (aDataValue->type()->kind()) { // Input Value
144 case CORBA::tk_string: { // Input string Value
148 cdebug << t << " (string)" ;
150 if ( !strcmp( Type , "string" ) ) { // SuperVision Value
151 _theValue = aDataValue ;
154 cdebug << " == Value( " << t << ") (string)";
158 CORBA::Any * theValue = new CORBA::Any() ;
159 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
160 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
162 sscanf( t , "%ld" , &l ) ;
166 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
169 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
171 sscanf( t , "%lf" , &d ) ;
172 theValue->replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
176 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
180 CORBA::Object_ptr ObjRef ;
182 ObjRef = StringToObject( t ) ;
183 *theValue <<= ObjRef ;
186 *theValue <<= CORBA::Object::_nil() ;
188 #if OMNIORB_VERSION >= 4
189 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
191 *theValue >>= ObjRef ;
194 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
195 << theValue->type()->kind() ;
198 //_theValue = theValue ;
199 _theValue = new CORBA::Any( *theValue ) ;
201 //*_Value = theValue ;
202 _Value = &_theValue ;
204 //JR 21.02.2005 Debug Memory leak :
209 case CORBA::tk_long: { // Input long Value
213 cdebug << "Value( " << l << ") (long)";
215 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
216 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
217 _theValue = aDataValue ;
218 *_Value = aDataValue ;
221 cdebug << " == Value( " << l << ") (long)";
225 CORBA::Any * theValue = new CORBA::Any() ;
226 if ( !strcmp( Type , "string" ) ) {
228 sprintf( t , "%ld" , l ) ;
233 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
236 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
238 theValue->replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
243 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
247 CORBA::Object_ptr ObjRef ;
248 *theValue <<= CORBA::Object::_nil() ;
249 #if OMNIORB_VERSION >= 4
250 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
252 *theValue >>= ObjRef ;
255 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
256 << theValue->type()->kind() ;
260 //_theValue = theValue ;
261 _theValue = new CORBA::Any( *theValue ) ;
263 //*_Value = theValue ;
264 _Value = &_theValue ;
266 //JR 21.02.2005 Debug Memory leak :
271 case CORBA::tk_double: { // Input double Value
275 cdebug << "Value( " << d << ") (double)";
277 if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
278 //_theValue = aDataValue ;
279 _theValue = new CORBA::Any( *aDataValue ) ;
281 //*_Value = aDataValue ;
282 _Value = &_theValue ;
286 cdebug << " == Value( " << d << ") (double)";
290 CORBA::Any * theValue = new CORBA::Any() ;
291 if ( !strcmp( Type , "string" ) ) {
293 sprintf( t , "%lf" , d ) ;
298 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
301 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
302 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
307 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
311 CORBA::Object_ptr ObjRef ;
312 *theValue <<= CORBA::Object::_nil() ;
313 #if OMNIORB_VERSION >= 4
314 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
316 *theValue >>= ObjRef ;
319 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
320 << theValue->type()->kind() ;
323 //_theValue = theValue ;
324 _theValue = new CORBA::Any( *theValue ) ;
326 //*_Value = theValue ;
327 _Value = &_theValue ;
329 //JR 21.02.2005 Debug Memory leak :
334 case CORBA::tk_objref: { // Input objref Value
335 CORBA::Object_ptr obj ;
336 #if OMNIORB_VERSION >= 4
337 *aDataValue >>= (CORBA::Any::to_object ) obj;
342 cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
344 if ( strcmp( Type , "string" ) &&
345 strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
346 strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
347 strcmp( Type , "double" ) ) { // SuperVision Default Value
348 _theValue = aDataValue ;
349 *_Value = aDataValue ;
350 #if OMNIORB_VERSION >= 4
351 *_theValue >>= (CORBA::Any::to_object ) obj ;
356 cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
360 CORBA::Any * theValue = new CORBA::Any() ;
361 if ( !strcmp( Type , "string" ) ) {
362 *theValue <<= ObjectToString( obj ) ;
363 #if OMNIORB_VERSION >= 4
364 *theValue >>= (CORBA::Any::to_object ) obj ;
369 cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
372 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
373 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
374 long l = (long ) obj ;
378 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
381 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
382 double d = (double ) 0. ;
383 theValue->replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
387 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
390 //_theValue = theValue ;
391 _theValue = new CORBA::Any( *theValue ) ;
393 //*_Value = theValue ;
394 _Value = &_theValue ;
396 //JR 21.02.2005 Debug Memory leak :
402 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
403 << aDataValue->type()->kind() ;
410 if ( pthread_mutex_unlock( &_MutexWait ) ) {
411 perror( "unlock DataValue" ) ;
414 // cdebug << pthread_self() << " SetValue(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
420 //JR 30.03.2005 Memory Leak + Debug(crash) CORBA::Any const * GraphBase::DataPort::Value() const {
421 const CORBA::Any GraphBase::DataPort::Value() const {
422 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
423 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
424 if ( pthread_mutex_lock( aMutexWait ) ) {
425 perror( "lock DataValue" ) ;
428 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
429 const CORBA::Any *const Value = *_Value ;
430 //JR 30.03.2005 CORBA::Any * theValue ;
431 CORBA::Any theValue ;
432 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
433 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
434 // << Value->type() ;
435 if ( Value->type() ) {
436 // cdebug << " kind " << Value->type()->kind() << " :" << endl ;
439 // cdebug << " Null" << endl ;
442 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
443 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
445 //JR 30.03.2005 switch ( theValue->type()->kind() ) {
446 switch ( theValue.type()->kind() ) {
447 case CORBA::tk_string: {
449 //JR 30.03.2005 *theValue >>= t;
451 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
454 case CORBA::tk_double: {
456 //JR 30.03.2005 *theValue >>= d;
458 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
461 case CORBA::tk_long: {
463 //JR 30.03.2005 *theValue >>= l;
465 // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
468 case CORBA::tk_objref: {
469 CORBA::Object_ptr obj ;
472 //JR 30.03.2005 *theValue >>= obj ;
473 #if OMNIORB_VERSION >= 4
474 theValue >>= (CORBA::Any::to_object ) obj ;
478 retstr = ObjectToString( obj );
479 // cdebug << "GraphBase::DataPort::Value() : " << retstr
480 // << "(object reference) " << endl;
483 cdebug << "ToString( object ) Catched ERROR" << endl ;
488 cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
489 << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
495 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
496 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
497 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
500 if ( pthread_mutex_unlock( aMutexWait ) ) {
501 perror( "unlock DataValue" ) ;
504 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
509 bool GraphBase::DataPort::BoolValue() const {
510 bool RetVal = false ;
511 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
512 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
513 if ( pthread_mutex_lock( aMutexWait ) ) {
514 perror( "lock DataValue" ) ;
517 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
519 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
526 else if ( (*_Value)->type()->kind() == CORBA::tk_boolean ) {
533 if ( pthread_mutex_unlock( aMutexWait ) ) {
534 perror( "unlock DataValue" ) ;
537 // cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ;
541 void GraphBase::DataPort::StringValue(ostream & f ) const {
542 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
543 // cdebug_in << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
545 if ( pthread_mutex_lock( aMutexWait ) ) {
546 perror( "lock DataValue" ) ;
549 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
552 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
553 // << " _Value " << _Value << " *_Value "
554 // << *_Value << " " << endl ;
555 const CORBA::Any * theValue = *_Value ;
556 switch (theValue->type()->kind()) {
557 case CORBA::tk_string:
560 f << t << " (string)" ;
562 case CORBA::tk_double:
565 f << d << " (double)" ;
570 f << l << " (long)" ;
572 case CORBA::tk_objref:
573 CORBA::Object_ptr ObjRef ;
575 #if OMNIORB_VERSION >= 4
576 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
578 *theValue >>= ObjRef ;
580 f << "(object reference) " << ObjectToString( ObjRef ) ;
583 f << "(object reference) catched error" ;
587 f << "(other ERROR)" ;
592 f << " Default (undefined) DATAPORT NOT DONE" ;
594 if ( pthread_mutex_unlock( aMutexWait ) ) {
595 perror( "unlock DataValue" ) ;
598 // cdebug_out << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait