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(
34 const char *const * NodeName ,
35 const SALOME_ModuleCatalog::ServicesParameter aserviceParameter ) :
36 Port( NodeName , aserviceParameter ) {
37 pthread_mutex_init( &_MutexWait , NULL ) ;
38 InitialValues( CORBA::Any() ) ;
41 GraphBase::DataPort::~DataPort() {
44 void GraphBase::DataPort::InitialValues(CORBA::Any aValue ) {
45 _theValue = new CORBA::Any( aValue ) ;
46 string _Type = CORBA::string_dup(GetServicesParameter().Parametertype) ;
47 const char * Type = _Type.c_str();
48 CORBA::Any InitialValue ;
49 cdebug << "InitialValues " << NodeName() << " " << PortName() << " " << PortType()
51 if ( !strcmp( Type , "" ) ) {
52 cdebug << "void" << endl ;
53 InitialValue <<= (void *) NULL ;
55 else if ( !strcmp( Type , "string" ) ) {
56 cdebug << "string" << endl ;
57 InitialValue <<= (char *) NULL ;
59 else if ( !strcmp( Type , "boolean" ) ) {
60 cdebug << "boolean" << endl ;
61 InitialValue <<= (long ) 0 ;
63 else if ( !strcmp( Type , "char" ) ) {
64 cdebug << "char" << endl ;
65 InitialValue <<= (long ) 0 ;
67 else if ( !strcmp( Type , "short" ) ) {
68 cdebug << "short" << endl ;
69 InitialValue <<= (long ) 0 ;
71 else if ( !strcmp( Type , "int" ) ) {
72 cdebug << "long" << endl ;
73 InitialValue <<= (long ) 0 ;
75 else if ( !strcmp( Type , "long" ) ) {
76 cdebug << "long" << endl ;
77 InitialValue <<= (long ) 0 ;
79 else if ( !strcmp( Type , "float" ) ) {
80 cdebug << "float" << endl ;
81 InitialValue <<= (double ) 0. ;
83 else if ( !strcmp( Type , "double" ) ) {
84 cdebug << "double" << endl ;
85 InitialValue <<= (double ) 0. ;
88 cdebug << "objref" << endl ;
89 // InitialValue.replace(CORBA::_tc_Object, NULL);
90 InitialValue <<= CORBA::Object::_nil() ;
93 // cdebug << "InitialValues ERROR (other) " << Type << endl ;
94 // InitialValue <<= (long ) 0 ;
96 _InitialValue = new CORBA::Any( InitialValue ) ;
97 _Value = &_InitialValue ;
100 void GraphBase::DataPort::Value( const CORBA::Any & aDataValue ) {
101 Value( new CORBA::Any( aDataValue ) ) ;
104 void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
105 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_lock " << &_MutexWait
107 if ( pthread_mutex_lock( &_MutexWait ) ) {
108 perror( "lock DataValue" ) ;
111 // cdebug << pthread_self() << " Value(aDataValue) pthread_mutex_locked " << &_MutexWait
116 string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
117 const char * Type = _Type.c_str() ;
118 _Value = &_theValue ;
119 // cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
120 // << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
121 switch (aDataValue->type()->kind()) { // Input Value
122 case CORBA::tk_string: { // Input string Value
125 cdebug << t << " (string)" ;
126 if ( !strcmp( Type , "string" ) ) { // SuperVision Value
127 _theValue = aDataValue ;
129 // cdebug << " == Value( " << t << ") (string)";
132 CORBA::Any * theValue = new CORBA::Any() ;
133 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
134 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
136 sscanf( t , "%ld" , &l ) ;
139 // cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
141 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
143 sscanf( t , "%lf" , &d ) ;
146 // cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
149 CORBA::Object_ptr ObjRef ;
151 ObjRef = StringToObject( t ) ;
152 *theValue <<= ObjRef ;
155 *theValue <<= CORBA::Object::_nil() ;
157 *theValue >>= ObjRef ;
158 // cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
159 // << theValue->type()->kind() ;
161 _theValue = theValue ;
166 case CORBA::tk_long: { // Input long Value
169 // cdebug << "Value( " << l << ") (long)";
170 if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
171 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
172 _theValue = aDataValue ;
173 *_Value = aDataValue ;
175 // cdebug << " == Value( " << l << ") (long)";
178 CORBA::Any * theValue = new CORBA::Any() ;
179 if ( !strcmp( Type , "string" ) ) {
181 sprintf( t , "%ld" , l ) ;
185 // cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
187 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
191 // cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
194 CORBA::Object_ptr ObjRef ;
195 *theValue <<= CORBA::Object::_nil() ;
196 *theValue >>= ObjRef ;
197 // cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
198 // << theValue->type()->kind() ;
200 _theValue = theValue ;
205 case CORBA::tk_double: { // Input double Value
208 // cdebug << "Value( " << d << ") (double)";
209 if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
210 _theValue = aDataValue ;
211 *_Value = aDataValue ;
213 // cdebug << " == Value( " << d << ") (double)";
216 CORBA::Any * theValue = new CORBA::Any() ;
217 if ( !strcmp( Type , "string" ) ) {
219 sprintf( t , "%lf" , d ) ;
223 // cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
225 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
226 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
230 // cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
233 CORBA::Object_ptr ObjRef ;
234 *theValue <<= CORBA::Object::_nil() ;
235 *theValue >>= ObjRef ;
236 // cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
237 // << theValue->type()->kind() ;
239 _theValue = theValue ;
244 case CORBA::tk_objref: { // Input objref Value
245 CORBA::Object_ptr obj ;
247 // cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
248 if ( strcmp( Type , "string" ) &&
249 strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
250 strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
251 strcmp( Type , "double" ) ) { // SuperVision Default Value
252 _theValue = aDataValue ;
253 *_Value = aDataValue ;
255 // cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
258 CORBA::Any * theValue = new CORBA::Any() ;
259 if ( !strcmp( Type , "string" ) ) {
260 *theValue <<= ObjectToString( obj ) ;
262 // cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
264 else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
265 !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
266 long l = (long ) obj ;
269 // cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
271 else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
272 double d = (double ) 0. ;
275 // cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
277 _theValue = theValue ;
283 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
284 << aDataValue->type()->kind() ;
289 if ( pthread_mutex_unlock( &_MutexWait ) ) {
290 perror( "unlock DataValue" ) ;
293 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
298 void GraphBase::DataPort::Value( const CORBA::Any ** aDataSharedValue ) {
300 _theValue = *aDataSharedValue ;
301 _Value = aDataSharedValue ;
305 MESSAGE( NodePortName() << " : " << hex << _Value << " " );
306 switch (_theValue->type()->kind()) {
307 case CORBA::tk_string:
310 MESSAGE( "Value( " << t << ") (string)");
312 case CORBA::tk_double:
315 MESSAGE( "Value( " << d << ") (double)");
320 MESSAGE( "Value( " << l << ") (long)");
322 case CORBA::tk_objref:
323 MESSAGE( "Value( " << ") (object reference)");
326 MESSAGE( "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR");
333 CORBA::Any const * GraphBase::DataPort::Value() const {
334 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
335 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
336 if ( pthread_mutex_lock( aMutexWait ) ) {
337 perror( "lock DataValue" ) ;
340 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
341 const CORBA::Any *const Value = *_Value ;
342 CORBA::Any * theValue ;
343 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
344 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
345 // << Value->type() ;
346 if ( Value->type() ) {
347 // cdebug << " kind " << Value->type()->kind() << " :" << endl ;
350 // cdebug << " Null" << endl ;
353 theValue = new CORBA::Any( *Value ) ;
354 switch ( theValue->type()->kind() ) {
355 case CORBA::tk_string: {
358 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
361 case CORBA::tk_double: {
364 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
367 case CORBA::tk_long: {
370 // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
373 case CORBA::tk_objref: {
374 CORBA::Object_ptr obj ;
378 retstr = ObjectToString( obj );
379 // cdebug << "GraphBase::DataPort::Value() : " << retstr
380 // << "(object reference) " << endl;
383 cdebug << "ToString( object ) Catched ERROR" << endl ;
388 cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
389 << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
395 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
396 theValue = new CORBA::Any( *Value ) ;
398 if ( pthread_mutex_unlock( aMutexWait ) ) {
399 perror( "unlock DataValue" ) ;
402 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
407 bool GraphBase::DataPort::BoolValue() const {
408 bool RetVal = false ;
410 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
411 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
412 if ( pthread_mutex_lock( aMutexWait ) ) {
413 perror( "lock DataValue" ) ;
416 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
418 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
424 if ( pthread_mutex_unlock( aMutexWait ) ) {
425 perror( "unlock DataValue" ) ;
428 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_unlocked " << aMutexWait
433 const CORBA::Any ** GraphBase::DataPort::ValuePtr() const {
437 void GraphBase::DataPort::StringValue(ostream & f ) const {
438 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
439 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
441 if ( pthread_mutex_lock( aMutexWait ) ) {
442 perror( "lock DataValue" ) ;
445 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
448 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
449 // << " _Value " << _Value << " *_Value "
450 // << *_Value << " " << endl ;
451 const CORBA::Any * theValue = *_Value ;
452 switch (theValue->type()->kind()) {
453 case CORBA::tk_string:
456 f << t << " (string)" ;
458 case CORBA::tk_double:
461 f << d << " (double)" ;
466 f << l << " (long)" ;
468 case CORBA::tk_objref:
469 CORBA::Object_ptr ObjRef ;
471 *theValue >>= ObjRef ;
472 f << "(object reference) " << ObjectToString( ObjRef ) ;
475 f << "(object reference) catched error" ;
479 f << "(other ERROR)" ;
484 f << " Default (undefined) NOT DONE" ;
486 if ( pthread_mutex_unlock( aMutexWait ) ) {
487 perror( "unlock DataValue" ) ;
490 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait