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 ;
94 InitialValue <<= (double ) 0. ;
96 else if ( !strcmp( Type , "double" ) ) {
97 cdebug << "double" << endl ;
98 InitialValue <<= (double ) 0. ;
101 cdebug << "objref" << endl ;
102 // InitialValue.replace(CORBA::_tc_Object, NULL);
103 InitialValue <<= CORBA::Object::_nil() ;
106 // cdebug << "InitialValues ERROR (other) " << Type << endl ;
107 // InitialValue <<= (long ) 0 ;
109 _InitialValue = new CORBA::Any( InitialValue ) ;
110 _Value = &_InitialValue ;
113 void GraphBase::DataPort::SetValue( const CORBA::Any & aDataValue ) {
114 CORBA::Any * aValue = new CORBA::Any( aDataValue ) ;
119 void GraphBase::DataPort::SetValue( const CORBA::Any * aDataValue ) {
120 // cdebug << pthread_self() << " SetValue(aDataValue) --> pthread_mutex_lock " << &_MutexWait
122 if ( pthread_mutex_lock( &_MutexWait ) ) {
123 perror( "lock DataValue" ) ;
126 // cdebug << pthread_self() << " SetValue(aDataValue) pthread_mutex_locked " << &_MutexWait
131 //JR 21.02.2005 Debug Memory leak : string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
132 // const char * Type = _Type.c_str() ;
133 const char * Type = GetServicesParameter().Parametertype ;
134 _Value = &_theValue ;
136 cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
137 << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
139 switch (aDataValue->type()->kind()) { // Input Value
140 case CORBA::tk_string: { // Input string Value
144 cdebug << t << " (string)" ;
146 if ( !strcmp( Type , "string" ) ) { // SuperVision Value
147 _theValue = aDataValue ;
150 cdebug << " == Value( " << t << ") (string)";
154 CORBA::Any * theValue = new CORBA::Any() ;
155 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
156 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
158 sscanf( t , "%ld" , &l ) ;
162 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
165 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
167 sscanf( t , "%lf" , &d ) ;
171 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
175 CORBA::Object_ptr ObjRef ;
177 ObjRef = StringToObject( t ) ;
178 *theValue <<= ObjRef ;
181 *theValue <<= CORBA::Object::_nil() ;
183 #if OMNIORB_VERSION >= 4
184 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
186 *theValue >>= ObjRef ;
189 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
190 << theValue->type()->kind() ;
193 _theValue = theValue ;
195 //JR 21.02.2005 Debug Memory leak :
200 case CORBA::tk_long: { // Input long Value
204 cdebug << "Value( " << l << ") (long)";
206 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
207 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
208 _theValue = aDataValue ;
209 *_Value = aDataValue ;
212 cdebug << " == Value( " << l << ") (long)";
216 CORBA::Any * theValue = new CORBA::Any() ;
217 if ( !strcmp( Type , "string" ) ) {
219 sprintf( t , "%ld" , l ) ;
224 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
227 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
232 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
236 CORBA::Object_ptr ObjRef ;
237 *theValue <<= CORBA::Object::_nil() ;
238 #if OMNIORB_VERSION >= 4
239 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
241 *theValue >>= ObjRef ;
244 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
245 << theValue->type()->kind() ;
248 _theValue = theValue ;
250 //JR 21.02.2005 Debug Memory leak :
255 case CORBA::tk_double: { // Input double Value
259 cdebug << "Value( " << d << ") (double)";
261 if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
262 _theValue = aDataValue ;
263 *_Value = aDataValue ;
266 cdebug << " == Value( " << d << ") (double)";
270 CORBA::Any * theValue = new CORBA::Any() ;
271 if ( !strcmp( Type , "string" ) ) {
273 sprintf( t , "%lf" , d ) ;
278 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
281 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
282 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
287 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
291 CORBA::Object_ptr ObjRef ;
292 *theValue <<= CORBA::Object::_nil() ;
293 #if OMNIORB_VERSION >= 4
294 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
296 *theValue >>= ObjRef ;
299 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
300 << theValue->type()->kind() ;
303 _theValue = theValue ;
305 //JR 21.02.2005 Debug Memory leak :
310 case CORBA::tk_objref: { // Input objref Value
311 CORBA::Object_ptr obj ;
312 #if OMNIORB_VERSION >= 4
313 *aDataValue >>= (CORBA::Any::to_object ) obj;
318 cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
320 if ( strcmp( Type , "string" ) &&
321 strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
322 strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
323 strcmp( Type , "double" ) ) { // SuperVision Default Value
324 _theValue = aDataValue ;
325 *_Value = aDataValue ;
326 #if OMNIORB_VERSION >= 4
327 *_theValue >>= (CORBA::Any::to_object ) obj ;
332 cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
336 CORBA::Any * theValue = new CORBA::Any() ;
337 if ( !strcmp( Type , "string" ) ) {
338 *theValue <<= ObjectToString( obj ) ;
339 #if OMNIORB_VERSION >= 4
340 *theValue >>= (CORBA::Any::to_object ) obj ;
345 cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
348 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
349 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
350 long l = (long ) obj ;
354 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
357 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
358 double d = (double ) 0. ;
362 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
365 _theValue = theValue ;
367 //JR 21.02.2005 Debug Memory leak :
373 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
374 << aDataValue->type()->kind() ;
381 if ( pthread_mutex_unlock( &_MutexWait ) ) {
382 perror( "unlock DataValue" ) ;
385 // cdebug << pthread_self() << " SetValue(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
391 //JR 30.03.2005 Memory Leak + Debug(crash) CORBA::Any const * GraphBase::DataPort::Value() const {
392 const CORBA::Any GraphBase::DataPort::Value() const {
393 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
394 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
395 if ( pthread_mutex_lock( aMutexWait ) ) {
396 perror( "lock DataValue" ) ;
399 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
400 const CORBA::Any *const Value = *_Value ;
401 //JR 30.03.2005 CORBA::Any * theValue ;
402 CORBA::Any theValue ;
403 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
404 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
405 // << Value->type() ;
406 if ( Value->type() ) {
407 // cdebug << " kind " << Value->type()->kind() << " :" << endl ;
410 // cdebug << " Null" << endl ;
413 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
414 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
416 //JR 30.03.2005 switch ( theValue->type()->kind() ) {
417 switch ( theValue.type()->kind() ) {
418 case CORBA::tk_string: {
420 //JR 30.03.2005 *theValue >>= t;
422 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
425 case CORBA::tk_double: {
427 //JR 30.03.2005 *theValue >>= d;
429 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
432 case CORBA::tk_long: {
434 //JR 30.03.2005 *theValue >>= l;
436 // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
439 case CORBA::tk_objref: {
440 CORBA::Object_ptr obj ;
443 //JR 30.03.2005 *theValue >>= obj ;
444 #if OMNIORB_VERSION >= 4
445 theValue >>= (CORBA::Any::to_object ) obj ;
449 retstr = ObjectToString( obj );
450 // cdebug << "GraphBase::DataPort::Value() : " << retstr
451 // << "(object reference) " << endl;
454 cdebug << "ToString( object ) Catched ERROR" << endl ;
459 cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
460 << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
466 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
467 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
468 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
471 if ( pthread_mutex_unlock( aMutexWait ) ) {
472 perror( "unlock DataValue" ) ;
475 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
480 bool GraphBase::DataPort::BoolValue() const {
481 bool RetVal = false ;
482 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
483 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
484 if ( pthread_mutex_lock( aMutexWait ) ) {
485 perror( "lock DataValue" ) ;
488 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
490 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
497 else if ( (*_Value)->type()->kind() == CORBA::tk_boolean ) {
504 if ( pthread_mutex_unlock( aMutexWait ) ) {
505 perror( "unlock DataValue" ) ;
508 // cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ;
512 void GraphBase::DataPort::StringValue(ostream & f ) const {
513 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
514 // cdebug_in << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
516 if ( pthread_mutex_lock( aMutexWait ) ) {
517 perror( "lock DataValue" ) ;
520 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
523 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
524 // << " _Value " << _Value << " *_Value "
525 // << *_Value << " " << endl ;
526 const CORBA::Any * theValue = *_Value ;
527 switch (theValue->type()->kind()) {
528 case CORBA::tk_string:
531 f << t << " (string)" ;
533 case CORBA::tk_double:
536 f << d << " (double)" ;
541 f << l << " (long)" ;
543 case CORBA::tk_objref:
544 CORBA::Object_ptr ObjRef ;
546 #if OMNIORB_VERSION >= 4
547 *theValue >>= (CORBA::Any::to_object ) ObjRef ;
549 *theValue >>= ObjRef ;
551 f << "(object reference) " << ObjectToString( ObjRef ) ;
554 f << "(object reference) catched error" ;
558 f << "(other ERROR)" ;
563 f << " Default (undefined) DATAPORT NOT DONE" ;
565 if ( pthread_mutex_unlock( aMutexWait ) ) {
566 perror( "unlock DataValue" ) ;
569 // cdebug_out << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait