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 *) "";
71 else if ( !strcmp( Type , "boolean" ) ) {
72 cdebug << "boolean" << endl ;
73 InitialValue <<= (long ) 0 ;
75 else if ( !strcmp( Type , "char" ) ) {
76 cdebug << "char" << endl ;
77 InitialValue <<= (long ) 0 ;
79 else if ( !strcmp( Type , "short" ) ) {
80 cdebug << "short" << endl ;
81 InitialValue <<= (long ) 0 ;
83 else if ( !strcmp( Type , "int" ) ) {
84 cdebug << "long" << endl ;
85 InitialValue <<= (long ) 0 ;
87 else if ( !strcmp( Type , "long" ) ) {
88 cdebug << "long" << endl ;
89 InitialValue <<= (long ) 0 ;
91 else if ( !strcmp( Type , "float" ) ) {
92 cdebug << "float" << endl ;
93 InitialValue <<= (double ) 0. ;
95 else if ( !strcmp( Type , "double" ) ) {
96 cdebug << "double" << endl ;
97 InitialValue <<= (double ) 0. ;
100 cdebug << "objref" << endl ;
101 // InitialValue.replace(CORBA::_tc_Object, NULL);
102 InitialValue <<= CORBA::Object::_nil() ;
105 // cdebug << "InitialValues ERROR (other) " << Type << endl ;
106 // InitialValue <<= (long ) 0 ;
108 _InitialValue = new CORBA::Any( InitialValue ) ;
109 _Value = &_InitialValue ;
112 void GraphBase::DataPort::Value( const CORBA::Any & aDataValue ) {
113 CORBA::Any * aValue = new CORBA::Any( aDataValue ) ;
118 void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
119 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_lock " << &_MutexWait
121 if ( pthread_mutex_lock( &_MutexWait ) ) {
122 perror( "lock DataValue" ) ;
125 // cdebug << pthread_self() << " Value(aDataValue) pthread_mutex_locked " << &_MutexWait
130 //JR 21.02.2005 Debug Memory leak : string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
131 // const char * Type = _Type.c_str() ;
132 const char * Type = GetServicesParameter().Parametertype ;
133 _Value = &_theValue ;
135 cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
136 << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
138 switch (aDataValue->type()->kind()) { // Input Value
139 case CORBA::tk_string: { // Input string Value
143 cdebug << t << " (string)" ;
145 if ( !strcmp( Type , "string" ) ) { // SuperVision Value
146 _theValue = aDataValue ;
149 cdebug << " == Value( " << t << ") (string)";
153 CORBA::Any * theValue = new CORBA::Any() ;
154 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
155 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
157 sscanf( t , "%ld" , &l ) ;
161 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
164 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
166 sscanf( t , "%lf" , &d ) ;
170 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
174 CORBA::Object_ptr ObjRef ;
176 ObjRef = StringToObject( t ) ;
177 *theValue <<= ObjRef ;
180 *theValue <<= CORBA::Object::_nil() ;
182 *theValue >>= ObjRef ;
184 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
185 << theValue->type()->kind() ;
188 _theValue = theValue ;
190 //JR 21.02.2005 Debug Memory leak :
195 case CORBA::tk_long: { // Input long Value
199 cdebug << "Value( " << l << ") (long)";
201 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
202 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
203 _theValue = aDataValue ;
204 *_Value = aDataValue ;
207 cdebug << " == Value( " << l << ") (long)";
211 CORBA::Any * theValue = new CORBA::Any() ;
212 if ( !strcmp( Type , "string" ) ) {
214 sprintf( t , "%ld" , l ) ;
219 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
222 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
227 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
231 CORBA::Object_ptr ObjRef ;
232 *theValue <<= CORBA::Object::_nil() ;
233 *theValue >>= ObjRef ;
235 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
236 << theValue->type()->kind() ;
239 _theValue = theValue ;
241 //JR 21.02.2005 Debug Memory leak :
246 case CORBA::tk_double: { // Input double Value
250 cdebug << "Value( " << d << ") (double)";
252 if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
253 _theValue = aDataValue ;
254 *_Value = aDataValue ;
257 cdebug << " == Value( " << d << ") (double)";
261 CORBA::Any * theValue = new CORBA::Any() ;
262 if ( !strcmp( Type , "string" ) ) {
264 sprintf( t , "%lf" , d ) ;
269 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
272 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
273 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
278 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
282 CORBA::Object_ptr ObjRef ;
283 *theValue <<= CORBA::Object::_nil() ;
284 *theValue >>= ObjRef ;
286 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
287 << theValue->type()->kind() ;
290 _theValue = theValue ;
292 //JR 21.02.2005 Debug Memory leak :
297 case CORBA::tk_objref: { // Input objref Value
298 CORBA::Object_ptr obj ;
301 cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
303 if ( strcmp( Type , "string" ) &&
304 strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
305 strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
306 strcmp( Type , "double" ) ) { // SuperVision Default Value
307 _theValue = aDataValue ;
308 *_Value = aDataValue ;
311 cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
315 CORBA::Any * theValue = new CORBA::Any() ;
316 if ( !strcmp( Type , "string" ) ) {
317 *theValue <<= ObjectToString( obj ) ;
320 cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
323 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
324 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
325 long l = (long ) obj ;
329 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
332 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
333 double d = (double ) 0. ;
337 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
340 _theValue = theValue ;
342 //JR 21.02.2005 Debug Memory leak :
348 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
349 << aDataValue->type()->kind() ;
356 if ( pthread_mutex_unlock( &_MutexWait ) ) {
357 perror( "unlock DataValue" ) ;
360 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
366 //JR 30.03.2005 Memory Leak + Debug(crash) CORBA::Any const * GraphBase::DataPort::Value() const {
367 const CORBA::Any GraphBase::DataPort::Value() const {
368 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
369 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
370 if ( pthread_mutex_lock( aMutexWait ) ) {
371 perror( "lock DataValue" ) ;
374 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
375 const CORBA::Any *const Value = *_Value ;
376 //JR 30.03.2005 CORBA::Any * theValue ;
377 CORBA::Any theValue ;
378 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
379 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
380 // << Value->type() ;
381 if ( Value->type() ) {
382 // cdebug << " kind " << Value->type()->kind() << " :" << endl ;
385 // cdebug << " Null" << endl ;
388 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
389 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
391 //JR 30.03.2005 switch ( theValue->type()->kind() ) {
392 switch ( theValue.type()->kind() ) {
393 case CORBA::tk_string: {
395 //JR 30.03.2005 *theValue >>= t;
397 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
400 case CORBA::tk_double: {
402 //JR 30.03.2005 *theValue >>= d;
404 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
407 case CORBA::tk_long: {
409 //JR 30.03.2005 *theValue >>= l;
411 // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
414 case CORBA::tk_objref: {
415 CORBA::Object_ptr obj ;
418 //JR 30.03.2005 *theValue >>= obj ;
420 retstr = ObjectToString( obj );
421 // cdebug << "GraphBase::DataPort::Value() : " << retstr
422 // << "(object reference) " << endl;
425 cdebug << "ToString( object ) Catched ERROR" << endl ;
430 cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
431 << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
437 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
438 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
439 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
442 if ( pthread_mutex_unlock( aMutexWait ) ) {
443 perror( "unlock DataValue" ) ;
446 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
451 bool GraphBase::DataPort::BoolValue() const {
452 bool RetVal = false ;
453 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
454 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
455 if ( pthread_mutex_lock( aMutexWait ) ) {
456 perror( "lock DataValue" ) ;
459 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
461 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
468 else if ( (*_Value)->type()->kind() == CORBA::tk_boolean ) {
475 if ( pthread_mutex_unlock( aMutexWait ) ) {
476 perror( "unlock DataValue" ) ;
479 // cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ;
483 void GraphBase::DataPort::StringValue(ostream & f ) const {
484 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
485 // cdebug_in << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
487 if ( pthread_mutex_lock( aMutexWait ) ) {
488 perror( "lock DataValue" ) ;
491 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
494 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
495 // << " _Value " << _Value << " *_Value "
496 // << *_Value << " " << endl ;
497 const CORBA::Any * theValue = *_Value ;
498 switch (theValue->type()->kind()) {
499 case CORBA::tk_string:
502 f << t << " (string)" ;
504 case CORBA::tk_double:
507 f << d << " (double)" ;
512 f << l << " (long)" ;
514 case CORBA::tk_objref:
515 CORBA::Object_ptr ObjRef ;
517 *theValue >>= ObjRef ;
518 f << "(object reference) " << ObjectToString( ObjRef ) ;
521 f << "(object reference) catched error" ;
525 f << "(other ERROR)" ;
530 f << " Default (undefined) DATAPORT NOT DONE" ;
532 if ( pthread_mutex_unlock( aMutexWait ) ) {
533 perror( "unlock DataValue" ) ;
536 // cdebug_out << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait