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 *theValue >>= ObjRef ;
185 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
186 << theValue->type()->kind() ;
189 _theValue = theValue ;
191 //JR 21.02.2005 Debug Memory leak :
196 case CORBA::tk_long: { // Input long Value
200 cdebug << "Value( " << l << ") (long)";
202 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
203 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
204 _theValue = aDataValue ;
205 *_Value = aDataValue ;
208 cdebug << " == Value( " << l << ") (long)";
212 CORBA::Any * theValue = new CORBA::Any() ;
213 if ( !strcmp( Type , "string" ) ) {
215 sprintf( t , "%ld" , l ) ;
220 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
223 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
228 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
232 CORBA::Object_ptr ObjRef ;
233 *theValue <<= CORBA::Object::_nil() ;
234 *theValue >>= ObjRef ;
236 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
237 << theValue->type()->kind() ;
240 _theValue = theValue ;
242 //JR 21.02.2005 Debug Memory leak :
247 case CORBA::tk_double: { // Input double Value
251 cdebug << "Value( " << d << ") (double)";
253 if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
254 _theValue = aDataValue ;
255 *_Value = aDataValue ;
258 cdebug << " == Value( " << d << ") (double)";
262 CORBA::Any * theValue = new CORBA::Any() ;
263 if ( !strcmp( Type , "string" ) ) {
265 sprintf( t , "%lf" , d ) ;
270 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
273 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
274 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
279 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
283 CORBA::Object_ptr ObjRef ;
284 *theValue <<= CORBA::Object::_nil() ;
285 *theValue >>= ObjRef ;
287 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
288 << theValue->type()->kind() ;
291 _theValue = theValue ;
293 //JR 21.02.2005 Debug Memory leak :
298 case CORBA::tk_objref: { // Input objref Value
299 CORBA::Object_ptr obj ;
302 cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
304 if ( strcmp( Type , "string" ) &&
305 strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
306 strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
307 strcmp( Type , "double" ) ) { // SuperVision Default Value
308 _theValue = aDataValue ;
309 *_Value = aDataValue ;
312 cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
316 CORBA::Any * theValue = new CORBA::Any() ;
317 if ( !strcmp( Type , "string" ) ) {
318 *theValue <<= ObjectToString( obj ) ;
321 cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
324 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
325 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
326 long l = (long ) obj ;
330 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
333 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
334 double d = (double ) 0. ;
338 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
341 _theValue = theValue ;
343 //JR 21.02.2005 Debug Memory leak :
349 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
350 << aDataValue->type()->kind() ;
357 if ( pthread_mutex_unlock( &_MutexWait ) ) {
358 perror( "unlock DataValue" ) ;
361 // cdebug << pthread_self() << " SetValue(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
367 //JR 30.03.2005 Memory Leak + Debug(crash) CORBA::Any const * GraphBase::DataPort::Value() const {
368 const CORBA::Any GraphBase::DataPort::Value() const {
369 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
370 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
371 if ( pthread_mutex_lock( aMutexWait ) ) {
372 perror( "lock DataValue" ) ;
375 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
376 const CORBA::Any *const Value = *_Value ;
377 //JR 30.03.2005 CORBA::Any * theValue ;
378 CORBA::Any theValue ;
379 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
380 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
381 // << Value->type() ;
382 if ( Value->type() ) {
383 // cdebug << " kind " << Value->type()->kind() << " :" << endl ;
386 // cdebug << " Null" << endl ;
389 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
390 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
392 //JR 30.03.2005 switch ( theValue->type()->kind() ) {
393 switch ( theValue.type()->kind() ) {
394 case CORBA::tk_string: {
396 //JR 30.03.2005 *theValue >>= t;
398 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
401 case CORBA::tk_double: {
403 //JR 30.03.2005 *theValue >>= d;
405 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
408 case CORBA::tk_long: {
410 //JR 30.03.2005 *theValue >>= l;
412 // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
415 case CORBA::tk_objref: {
416 CORBA::Object_ptr obj ;
419 //JR 30.03.2005 *theValue >>= obj ;
421 retstr = ObjectToString( obj );
422 // cdebug << "GraphBase::DataPort::Value() : " << retstr
423 // << "(object reference) " << endl;
426 cdebug << "ToString( object ) Catched ERROR" << endl ;
431 cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
432 << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
438 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
439 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
440 //JR 30.03.2005 theValue = (CORBA::Any * ) Value ;
443 if ( pthread_mutex_unlock( aMutexWait ) ) {
444 perror( "unlock DataValue" ) ;
447 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
452 bool GraphBase::DataPort::BoolValue() const {
453 bool RetVal = false ;
454 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
455 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
456 if ( pthread_mutex_lock( aMutexWait ) ) {
457 perror( "lock DataValue" ) ;
460 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
462 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
469 else if ( (*_Value)->type()->kind() == CORBA::tk_boolean ) {
476 if ( pthread_mutex_unlock( aMutexWait ) ) {
477 perror( "unlock DataValue" ) ;
480 // cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ;
484 void GraphBase::DataPort::StringValue(ostream & f ) const {
485 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
486 // cdebug_in << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
488 if ( pthread_mutex_lock( aMutexWait ) ) {
489 perror( "lock DataValue" ) ;
492 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
495 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
496 // << " _Value " << _Value << " *_Value "
497 // << *_Value << " " << endl ;
498 const CORBA::Any * theValue = *_Value ;
499 switch (theValue->type()->kind()) {
500 case CORBA::tk_string:
503 f << t << " (string)" ;
505 case CORBA::tk_double:
508 f << d << " (double)" ;
513 f << l << " (long)" ;
515 case CORBA::tk_objref:
516 CORBA::Object_ptr ObjRef ;
518 *theValue >>= ObjRef ;
519 f << "(object reference) " << ObjectToString( ObjRef ) ;
522 f << "(object reference) catched error" ;
526 f << "(other ERROR)" ;
531 f << " Default (undefined) DATAPORT NOT DONE" ;
533 if ( pthread_mutex_unlock( aMutexWait ) ) {
534 perror( "unlock DataValue" ) ;
537 // cdebug_out << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait