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 _State = 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 _State = 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 string _Type = CORBA::string_dup(GetServicesParameter().Parametertype) ;
58 const char * Type = _Type.c_str();
59 CORBA::Any InitialValue ;
60 cdebug << "InitialValues " << NodeName() << " " << PortName() << " " << PortType()
62 if ( !strcmp( Type , "" ) ) {
63 cdebug << "void" << endl ;
64 InitialValue <<= (void *) NULL ;
66 else if ( !strcmp( Type , "string" ) ) {
67 cdebug << "string" << endl ;
68 InitialValue <<= (char *) NULL ;
70 else if ( !strcmp( Type , "boolean" ) ) {
71 cdebug << "boolean" << endl ;
72 InitialValue <<= (long ) 0 ;
74 else if ( !strcmp( Type , "char" ) ) {
75 cdebug << "char" << endl ;
76 InitialValue <<= (long ) 0 ;
78 else if ( !strcmp( Type , "short" ) ) {
79 cdebug << "short" << endl ;
80 InitialValue <<= (long ) 0 ;
82 else if ( !strcmp( Type , "int" ) ) {
83 cdebug << "long" << endl ;
84 InitialValue <<= (long ) 0 ;
86 else if ( !strcmp( Type , "long" ) ) {
87 cdebug << "long" << endl ;
88 InitialValue <<= (long ) 0 ;
90 else if ( !strcmp( Type , "float" ) ) {
91 cdebug << "float" << endl ;
92 InitialValue <<= (double ) 0. ;
94 else if ( !strcmp( Type , "double" ) ) {
95 cdebug << "double" << endl ;
96 InitialValue <<= (double ) 0. ;
99 cdebug << "objref" << endl ;
100 // InitialValue.replace(CORBA::_tc_Object, NULL);
101 InitialValue <<= CORBA::Object::_nil() ;
104 // cdebug << "InitialValues ERROR (other) " << Type << endl ;
105 // InitialValue <<= (long ) 0 ;
107 _InitialValue = new CORBA::Any( InitialValue ) ;
108 _Value = &_InitialValue ;
111 void GraphBase::DataPort::Value( const CORBA::Any & aDataValue ) {
112 CORBA::Any * aValue = new CORBA::Any( aDataValue ) ;
116 void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
117 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_lock " << &_MutexWait
119 if ( pthread_mutex_lock( &_MutexWait ) ) {
120 perror( "lock DataValue" ) ;
123 // cdebug << pthread_self() << " Value(aDataValue) pthread_mutex_locked " << &_MutexWait
128 string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
129 const char * Type = _Type.c_str() ;
130 _Value = &_theValue ;
131 cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
132 << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
133 switch (aDataValue->type()->kind()) { // Input Value
134 case CORBA::tk_string: { // Input string Value
137 cdebug << t << " (string)" ;
138 if ( !strcmp( Type , "string" ) ) { // SuperVision Value
139 _theValue = aDataValue ;
141 cdebug << " == Value( " << t << ") (string)";
144 CORBA::Any * theValue = new CORBA::Any() ;
145 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
146 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
148 sscanf( t , "%ld" , &l ) ;
151 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
153 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
155 sscanf( t , "%lf" , &d ) ;
158 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
161 CORBA::Object_ptr ObjRef ;
163 ObjRef = StringToObject( t ) ;
164 *theValue <<= ObjRef ;
167 *theValue <<= CORBA::Object::_nil() ;
169 *theValue >>= ObjRef ;
170 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
171 << theValue->type()->kind() ;
173 _theValue = theValue ;
178 case CORBA::tk_long: { // Input long Value
181 cdebug << "Value( " << l << ") (long)";
182 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
183 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
184 _theValue = aDataValue ;
185 *_Value = aDataValue ;
187 cdebug << " == Value( " << l << ") (long)";
190 CORBA::Any * theValue = new CORBA::Any() ;
191 if ( !strcmp( Type , "string" ) ) {
193 sprintf( t , "%ld" , l ) ;
197 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
199 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
203 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
206 CORBA::Object_ptr ObjRef ;
207 *theValue <<= CORBA::Object::_nil() ;
208 *theValue >>= ObjRef ;
209 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
210 << theValue->type()->kind() ;
212 _theValue = theValue ;
217 case CORBA::tk_double: { // Input double Value
220 cdebug << "Value( " << d << ") (double)";
221 if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
222 _theValue = aDataValue ;
223 *_Value = aDataValue ;
225 cdebug << " == Value( " << d << ") (double)";
228 CORBA::Any * theValue = new CORBA::Any() ;
229 if ( !strcmp( Type , "string" ) ) {
231 sprintf( t , "%lf" , d ) ;
235 cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
237 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
238 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
242 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
245 CORBA::Object_ptr ObjRef ;
246 *theValue <<= CORBA::Object::_nil() ;
247 *theValue >>= ObjRef ;
248 cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
249 << theValue->type()->kind() ;
251 _theValue = theValue ;
256 case CORBA::tk_objref: { // Input objref Value
257 CORBA::Object_ptr obj ;
259 cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
260 if ( strcmp( Type , "string" ) &&
261 strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
262 strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
263 strcmp( Type , "double" ) ) { // SuperVision Default Value
264 _theValue = aDataValue ;
265 *_Value = aDataValue ;
267 cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
270 CORBA::Any * theValue = new CORBA::Any() ;
271 if ( !strcmp( Type , "string" ) ) {
272 *theValue <<= ObjectToString( obj ) ;
274 cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
276 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
277 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
278 long l = (long ) obj ;
281 cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
283 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
284 double d = (double ) 0. ;
287 cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
289 _theValue = theValue ;
295 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
296 << aDataValue->type()->kind() ;
301 if ( pthread_mutex_unlock( &_MutexWait ) ) {
302 perror( "unlock DataValue" ) ;
305 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
310 void GraphBase::DataPort::Value( const CORBA::Any ** aDataSharedValue ) {
312 _theValue = *aDataSharedValue ;
313 _Value = aDataSharedValue ;
317 MESSAGE( NodePortName() << " : " << hex << _Value << " " );
318 switch (_theValue->type()->kind()) {
319 case CORBA::tk_string:
322 MESSAGE( "Value( " << t << ") (string)");
324 case CORBA::tk_double:
327 MESSAGE( "Value( " << d << ") (double)");
332 MESSAGE( "Value( " << l << ") (long)");
334 case CORBA::tk_objref:
335 MESSAGE( "Value( " << ") (object reference)");
338 MESSAGE( "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR");
345 CORBA::Any const * GraphBase::DataPort::Value() const {
346 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
347 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
348 if ( pthread_mutex_lock( aMutexWait ) ) {
349 perror( "lock DataValue" ) ;
352 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
353 const CORBA::Any *const Value = *_Value ;
354 CORBA::Any * theValue ;
355 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
356 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
357 // << Value->type() ;
358 if ( Value->type() ) {
359 // cdebug << " kind " << Value->type()->kind() << " :" << endl ;
362 // cdebug << " Null" << endl ;
365 theValue = new CORBA::Any( *Value ) ;
366 switch ( theValue->type()->kind() ) {
367 case CORBA::tk_string: {
370 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
373 case CORBA::tk_double: {
376 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
379 case CORBA::tk_long: {
382 // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
385 case CORBA::tk_objref: {
386 CORBA::Object_ptr obj ;
390 retstr = ObjectToString( obj );
391 // cdebug << "GraphBase::DataPort::Value() : " << retstr
392 // << "(object reference) " << endl;
395 cdebug << "ToString( object ) Catched ERROR" << endl ;
400 cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
401 << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
407 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
408 theValue = new CORBA::Any( *Value ) ;
410 if ( pthread_mutex_unlock( aMutexWait ) ) {
411 perror( "unlock DataValue" ) ;
414 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
419 bool GraphBase::DataPort::BoolValue() const {
420 bool RetVal = false ;
422 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
423 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
424 if ( pthread_mutex_lock( aMutexWait ) ) {
425 perror( "lock DataValue" ) ;
428 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
430 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
436 if ( pthread_mutex_unlock( aMutexWait ) ) {
437 perror( "unlock DataValue" ) ;
440 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_unlocked " << aMutexWait
445 const CORBA::Any ** GraphBase::DataPort::ValuePtr() const {
449 void GraphBase::DataPort::StringValue(ostream & f ) const {
450 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
451 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
453 if ( pthread_mutex_lock( aMutexWait ) ) {
454 perror( "lock DataValue" ) ;
457 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
460 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
461 // << " _Value " << _Value << " *_Value "
462 // << *_Value << " " << endl ;
463 const CORBA::Any * theValue = *_Value ;
464 switch (theValue->type()->kind()) {
465 case CORBA::tk_string:
468 f << t << " (string)" ;
470 case CORBA::tk_double:
473 f << d << " (double)" ;
478 f << l << " (long)" ;
480 case CORBA::tk_objref:
481 CORBA::Object_ptr ObjRef ;
483 *theValue >>= ObjRef ;
484 f << "(object reference) " << ObjectToString( ObjRef ) ;
487 f << "(object reference) catched error" ;
491 f << "(other ERROR)" ;
496 f << " Default (undefined) NOT DONE" ;
498 if ( pthread_mutex_unlock( aMutexWait ) ) {
499 perror( "unlock DataValue" ) ;
502 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait