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 ;
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 ) ;
117 void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
118 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_lock " << &_MutexWait
120 if ( pthread_mutex_lock( &_MutexWait ) ) {
121 perror( "lock DataValue" ) ;
124 // cdebug << pthread_self() << " Value(aDataValue) pthread_mutex_locked " << &_MutexWait
129 //JR 21.02.2005 Debug Memory leak : string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
130 // const char * Type = _Type.c_str() ;
131 const char * Type = GetServicesParameter().Parametertype ;
132 _Value = &_theValue ;
133 cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
134 << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
135 switch (aDataValue->type()->kind()) { // Input Value
136 case CORBA::tk_string: { // Input string Value
139 cdebug << t << " (string)" ;
140 if ( !strcmp( Type , "string" ) ) { // SuperVision Value
141 _theValue = aDataValue ;
143 cdebug << " == Value( " << t << ") (string)";
146 CORBA::Any * theValue = new CORBA::Any() ;
147 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
148 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
150 sscanf( t , "%ld" , &l ) ;
153 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
155 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
157 sscanf( t , "%lf" , &d ) ;
160 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
163 CORBA::Object_ptr ObjRef ;
165 ObjRef = StringToObject( t ) ;
166 *theValue <<= ObjRef ;
169 *theValue <<= CORBA::Object::_nil() ;
171 *theValue >>= ObjRef ;
172 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
173 << theValue->type()->kind() ;
175 _theValue = theValue ;
177 //JR 21.02.2005 Debug Memory leak :
182 case CORBA::tk_long: { // Input long Value
185 cdebug << "Value( " << l << ") (long)";
186 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
187 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
188 _theValue = aDataValue ;
189 *_Value = aDataValue ;
191 cdebug << " == Value( " << l << ") (long)";
194 CORBA::Any * theValue = new CORBA::Any() ;
195 if ( !strcmp( Type , "string" ) ) {
197 sprintf( t , "%ld" , l ) ;
201 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
203 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
207 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
210 CORBA::Object_ptr ObjRef ;
211 *theValue <<= CORBA::Object::_nil() ;
212 *theValue >>= ObjRef ;
213 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
214 << theValue->type()->kind() ;
216 _theValue = theValue ;
218 //JR 21.02.2005 Debug Memory leak :
223 case CORBA::tk_double: { // Input double Value
226 cdebug << "Value( " << d << ") (double)";
227 if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
228 _theValue = aDataValue ;
229 *_Value = aDataValue ;
231 cdebug << " == Value( " << d << ") (double)";
234 CORBA::Any * theValue = new CORBA::Any() ;
235 if ( !strcmp( Type , "string" ) ) {
237 sprintf( t , "%lf" , d ) ;
241 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
243 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
244 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
248 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
251 CORBA::Object_ptr ObjRef ;
252 *theValue <<= CORBA::Object::_nil() ;
253 *theValue >>= ObjRef ;
254 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
255 << theValue->type()->kind() ;
257 _theValue = theValue ;
259 //JR 21.02.2005 Debug Memory leak :
264 case CORBA::tk_objref: { // Input objref Value
265 CORBA::Object_ptr obj ;
267 cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
268 if ( strcmp( Type , "string" ) &&
269 strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
270 strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
271 strcmp( Type , "double" ) ) { // SuperVision Default Value
272 _theValue = aDataValue ;
273 *_Value = aDataValue ;
275 cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
278 CORBA::Any * theValue = new CORBA::Any() ;
279 if ( !strcmp( Type , "string" ) ) {
280 *theValue <<= ObjectToString( obj ) ;
282 cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
284 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
285 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
286 long l = (long ) obj ;
289 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
291 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
292 double d = (double ) 0. ;
295 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
297 _theValue = theValue ;
299 //JR 21.02.2005 Debug Memory leak :
305 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
306 << aDataValue->type()->kind() ;
311 if ( pthread_mutex_unlock( &_MutexWait ) ) {
312 perror( "unlock DataValue" ) ;
315 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
320 CORBA::Any const * GraphBase::DataPort::Value() const {
321 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
322 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
323 if ( pthread_mutex_lock( aMutexWait ) ) {
324 perror( "lock DataValue" ) ;
327 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
328 const CORBA::Any *const Value = *_Value ;
329 CORBA::Any * theValue ;
330 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
331 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
332 // << Value->type() ;
333 if ( Value->type() ) {
334 // cdebug << " kind " << Value->type()->kind() << " :" << endl ;
337 // cdebug << " Null" << endl ;
340 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
341 theValue = (CORBA::Any * ) Value ;
342 switch ( theValue->type()->kind() ) {
343 case CORBA::tk_string: {
346 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
349 case CORBA::tk_double: {
352 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
355 case CORBA::tk_long: {
358 // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
361 case CORBA::tk_objref: {
362 CORBA::Object_ptr obj ;
366 retstr = ObjectToString( obj );
367 // cdebug << "GraphBase::DataPort::Value() : " << retstr
368 // << "(object reference) " << endl;
371 cdebug << "ToString( object ) Catched ERROR" << endl ;
376 cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
377 << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
383 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
384 //JR 21.02.2005 Debug Memory leak : theValue = new CORBA::Any( *Value ) ;
385 theValue = (CORBA::Any * ) Value ;
387 if ( pthread_mutex_unlock( aMutexWait ) ) {
388 perror( "unlock DataValue" ) ;
391 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
396 bool GraphBase::DataPort::BoolValue() const {
397 bool RetVal = false ;
398 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
399 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
400 if ( pthread_mutex_lock( aMutexWait ) ) {
401 perror( "lock DataValue" ) ;
404 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
406 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
413 else if ( (*_Value)->type()->kind() == CORBA::tk_boolean ) {
420 if ( pthread_mutex_unlock( aMutexWait ) ) {
421 perror( "unlock DataValue" ) ;
424 cdebug << pthread_self() << " " << NodeName() << "( " << PortName() << " ) BoolValue " << RetVal << endl ;
428 void GraphBase::DataPort::StringValue(ostream & f ) const {
429 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
430 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
432 if ( pthread_mutex_lock( aMutexWait ) ) {
433 perror( "lock DataValue" ) ;
436 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
439 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
440 // << " _Value " << _Value << " *_Value "
441 // << *_Value << " " << endl ;
442 const CORBA::Any * theValue = *_Value ;
443 switch (theValue->type()->kind()) {
444 case CORBA::tk_string:
447 f << t << " (string)" ;
449 case CORBA::tk_double:
452 f << d << " (double)" ;
457 f << l << " (long)" ;
459 case CORBA::tk_objref:
460 CORBA::Object_ptr ObjRef ;
462 *theValue >>= ObjRef ;
463 f << "(object reference) " << ObjectToString( ObjRef ) ;
466 f << "(object reference) catched error" ;
470 f << "(other ERROR)" ;
475 f << " Default (undefined) DATAPORT NOT DONE" ;
477 if ( pthread_mutex_unlock( aMutexWait ) ) {
478 perror( "unlock DataValue" ) ;
481 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait