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 , "string" ) ) {
52 cdebug << "string" << endl ;
53 InitialValue <<= (char *) NULL ;
55 else if ( !strcmp( Type , "double" ) ) {
56 cdebug << "double" << endl ;
59 else if ( !strcmp( Type , "long" ) ) {
60 cdebug << "long" << endl ;
61 InitialValue <<= (long ) 0 ;
63 else if ( !strcmp( Type , "objref" ) ) {
64 cdebug << "objref" << endl ;
65 // InitialValue.replace(CORBA::_tc_Object, NULL);
66 InitialValue <<= CORBA::Object::_nil() ;
69 cdebug << "InitialValues ERROR (other) " << Type << endl ;
70 InitialValue <<= (long ) 0 ;
72 _InitialValue = new CORBA::Any( InitialValue ) ;
73 _Value = &_InitialValue ;
76 void GraphBase::DataPort::Value( const CORBA::Any & aDataValue ) {
77 Value( new CORBA::Any( aDataValue ) ) ;
80 void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
81 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_lock " << &_MutexWait
83 if ( pthread_mutex_lock( &_MutexWait ) ) {
84 perror( "lock DataValue" ) ;
87 // cdebug << pthread_self() << " Value(aDataValue) pthread_mutex_locked " << &_MutexWait
91 _theValue = aDataValue ;
92 *_Value = aDataValue ;
96 cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
97 << " : " << _Value << " *_Value " << *_Value << " " ;
98 switch (_theValue->type()->kind()) {
99 case CORBA::tk_string: {
102 cdebug << "Value( " << t << ") (string)";
105 case CORBA::tk_double: {
108 cdebug << "Value( " << d << ") (double)";
111 case CORBA::tk_long: {
114 cdebug << "Value( " << l << ") (long)";
117 case CORBA::tk_objref: {
118 cdebug << "Value( " << ") (object reference)";
122 cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR";
128 if ( pthread_mutex_unlock( &_MutexWait ) ) {
129 perror( "unlock DataValue" ) ;
132 // cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
137 void GraphBase::DataPort::Value( const CORBA::Any ** aDataSharedValue ) {
139 _theValue = *aDataSharedValue ;
140 _Value = aDataSharedValue ;
144 MESSAGE( NodePortName() << " : " << hex << _Value << " " );
145 switch (_theValue->type()->kind()) {
146 case CORBA::tk_string:
149 MESSAGE( "Value( " << t << ") (string)");
151 case CORBA::tk_double:
154 MESSAGE( "Value( " << d << ") (double)");
159 MESSAGE( "Value( " << l << ") (long)");
161 case CORBA::tk_objref:
162 MESSAGE( "Value( " << ") (object reference)");
165 MESSAGE( "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR");
172 CORBA::Any const * GraphBase::DataPort::Value() const {
173 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
174 // cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
175 if ( pthread_mutex_lock( aMutexWait ) ) {
176 perror( "lock DataValue" ) ;
179 // cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
180 const CORBA::Any *const Value = *_Value ;
181 CORBA::Any * theValue ;
182 // cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
183 // << PortType() << " _Value " << _Value << " *_Value " << *_Value << " kind "
184 // << Value->type()->kind() << " :" << endl ;
186 theValue = new CORBA::Any( *Value ) ;
187 switch ( theValue->type()->kind() ) {
188 case CORBA::tk_string: {
191 // cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
194 case CORBA::tk_double: {
197 // cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
200 case CORBA::tk_long: {
203 // cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
206 case CORBA::tk_objref: {
207 CORBA::Object_ptr obj ;
211 retstr = ObjectToString( obj );
212 // cdebug << "GraphBase::DataPort::Value() : " << retstr
213 // << "(object reference) " << endl;
216 cdebug << "ToString( object ) Catched ERROR" << endl ;
221 cdebug << "GraphBase::DataPort::Value() : "
222 << "(other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
228 // cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
229 theValue = new CORBA::Any( *Value ) ;
231 if ( pthread_mutex_unlock( aMutexWait ) ) {
232 perror( "unlock DataValue" ) ;
235 // cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
240 bool GraphBase::DataPort::BoolValue() const {
241 bool RetVal = false ;
243 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
244 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
245 if ( pthread_mutex_lock( aMutexWait ) ) {
246 perror( "lock DataValue" ) ;
249 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
251 if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
257 if ( pthread_mutex_unlock( aMutexWait ) ) {
258 perror( "unlock DataValue" ) ;
261 // cdebug << pthread_self() << " BoolValue() --> pthread_mutex_unlocked " << aMutexWait
266 const CORBA::Any ** GraphBase::DataPort::ValuePtr() const {
270 void GraphBase::DataPort::StringValue(ostream & f ) const {
271 pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
272 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
274 if ( pthread_mutex_lock( aMutexWait ) ) {
275 perror( "lock DataValue" ) ;
278 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
281 // cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
282 // << " _Value " << _Value << " *_Value "
283 // << *_Value << " " << endl ;
284 const CORBA::Any * theValue = *_Value ;
285 switch (theValue->type()->kind()) {
286 case CORBA::tk_string:
289 f << t << " (string)" ;
291 case CORBA::tk_double:
294 f << d << " (double)" ;
299 f << l << " (long)" ;
301 case CORBA::tk_objref:
302 CORBA::Object_ptr ObjRef ;
304 *theValue >>= ObjRef ;
305 f << "(object reference) " << ObjectToString( ObjRef ) ;
308 f << "(object reference) catched error" ;
312 f << "(other ERROR)" ;
317 f << " Default (undefined) NOT DONE" ;
319 if ( pthread_mutex_unlock( aMutexWait ) ) {
320 perror( "unlock DataValue" ) ;
323 // cdebug << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait