+++ /dev/null
-// SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
-//
-// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
-//
-//
-//
-// File : DataFlowBase_DataPort.cxx
-// Author : Jean Rahuel, CEA
-// Module : SUPERV
-// $Header:
-
-using namespace std;
-#include <stdio.h>
-#include "DataFlowBase_DataPort.hxx"
-
-GraphBase::DataPort::DataPort() :
- Port() {
- pthread_mutex_init( &_MutexWait , NULL ) ;
- InitialValues( CORBA::Any() ) ;
-}
-
-GraphBase::DataPort::DataPort(
- const char *const * NodeName ,
- const SALOME_ModuleCatalog::ServicesParameter aserviceParameter ,
- const SUPERV::KindOfPort aKind ,
- const SALOME_ModuleCatalog::DataStreamDependency aDependency ) :
- Port( NodeName , aserviceParameter , aKind , aDependency ) {
- pthread_mutex_init( &_MutexWait , NULL ) ;
- InitialValues( CORBA::Any() ) ;
-}
-
-GraphBase::DataPort::~DataPort() {
-}
-
-void GraphBase::DataPort::InitialValues(CORBA::Any aValue ) {
- _theValue = new CORBA::Any( aValue ) ;
- string _Type = CORBA::string_dup(GetServicesParameter().Parametertype) ;
- const char * Type = _Type.c_str();
- CORBA::Any InitialValue ;
- cdebug << "InitialValues " << NodeName() << " " << PortName() << " " << PortType()
- << " : " ;
- if ( !strcmp( Type , "" ) ) {
- cdebug << "void" << endl ;
- InitialValue <<= (void *) NULL ;
- }
- else if ( !strcmp( Type , "string" ) ) {
- cdebug << "string" << endl ;
- InitialValue <<= (char *) NULL ;
- }
- else if ( !strcmp( Type , "boolean" ) ) {
- cdebug << "boolean" << endl ;
- InitialValue <<= (long ) 0 ;
- }
- else if ( !strcmp( Type , "char" ) ) {
- cdebug << "char" << endl ;
- InitialValue <<= (long ) 0 ;
- }
- else if ( !strcmp( Type , "short" ) ) {
- cdebug << "short" << endl ;
- InitialValue <<= (long ) 0 ;
- }
- else if ( !strcmp( Type , "int" ) ) {
- cdebug << "long" << endl ;
- InitialValue <<= (long ) 0 ;
- }
- else if ( !strcmp( Type , "long" ) ) {
- cdebug << "long" << endl ;
- InitialValue <<= (long ) 0 ;
- }
- else if ( !strcmp( Type , "float" ) ) {
- cdebug << "float" << endl ;
- InitialValue <<= (double ) 0. ;
- }
- else if ( !strcmp( Type , "double" ) ) {
- cdebug << "double" << endl ;
- InitialValue <<= (double ) 0. ;
- }
- else { // Default
- cdebug << "objref" << endl ;
-// InitialValue.replace(CORBA::_tc_Object, NULL);
- InitialValue <<= CORBA::Object::_nil() ;
- }
-// else {
-// cdebug << "InitialValues ERROR (other) " << Type << endl ;
-// InitialValue <<= (long ) 0 ;
-// }
- _InitialValue = new CORBA::Any( InitialValue ) ;
- _Value = &_InitialValue ;
-}
-
-void GraphBase::DataPort::Value( const CORBA::Any & aDataValue ) {
- CORBA::Any * aValue = new CORBA::Any( aDataValue ) ;
- Value( aValue ) ;
-}
-
-void GraphBase::DataPort::Value( const CORBA::Any * aDataValue ) {
-// cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_lock " << &_MutexWait
-// << endl ;
- if ( pthread_mutex_lock( &_MutexWait ) ) {
- perror( "lock DataValue" ) ;
- exit( 0 ) ;
- }
-// cdebug << pthread_self() << " Value(aDataValue) pthread_mutex_locked " << &_MutexWait
-// << endl ;
-
- delete _theValue ;
-
- string _Type = CORBA::string_dup( GetServicesParameter().Parametertype ) ;
- const char * Type = _Type.c_str() ;
- _Value = &_theValue ;
-// cdebug << "NewValue " << NodeName() << " " << PortName() << " " << PortType()
-// << " : " << aDataValue << " kind " << aDataValue->type()->kind() << " " ;
- switch (aDataValue->type()->kind()) { // Input Value
- case CORBA::tk_string: { // Input string Value
- char * t;
- *aDataValue >>= t;
- cdebug << t << " (string)" ;
- if ( !strcmp( Type , "string" ) ) { // SuperVision Value
- _theValue = aDataValue ;
- *_theValue >>= t;
-// cdebug << " == Value( " << t << ") (string)";
- }
- else {
- CORBA::Any * theValue = new CORBA::Any() ;
- if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
- !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
- long l ;
- sscanf( t , "%ld" , &l ) ;
- *theValue <<= l ;
- *theValue >>= l;
-// cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
- }
- else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
- double d ;
- sscanf( t , "%lf" , &d ) ;
- *theValue <<= d ;
- *theValue >>= d;
-// cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
- }
- else { // Default
- CORBA::Object_ptr ObjRef ;
- try {
- ObjRef = StringToObject( t ) ;
- *theValue <<= ObjRef ;
- }
- catch( ... ) {
- *theValue <<= CORBA::Object::_nil() ;
- }
- *theValue >>= ObjRef ;
-// cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
-// << theValue->type()->kind() ;
- }
- _theValue = theValue ;
- *_Value = theValue ;
- }
- break;
- }
- case CORBA::tk_long: { // Input long Value
- long l;
- *aDataValue >>= l;
-// cdebug << "Value( " << l << ") (long)";
- if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
- !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) { // SuperVision Value
- _theValue = aDataValue ;
- *_Value = aDataValue ;
- *_theValue >>= l;
-// cdebug << " == Value( " << l << ") (long)";
- }
- else {
- CORBA::Any * theValue = new CORBA::Any() ;
- if ( !strcmp( Type , "string" ) ) {
- char t[40] ;
- sprintf( t , "%ld" , l ) ;
- *theValue <<= t ;
- char *tt ;
- *theValue >>= tt ;
-// cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
- }
- else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
- double d = l ;
- *theValue <<= d ;
- *theValue >>= d ;
-// cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
- }
- else { // Default
- CORBA::Object_ptr ObjRef ;
- *theValue <<= CORBA::Object::_nil() ;
- *theValue >>= ObjRef ;
-// cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
-// << theValue->type()->kind() ;
- }
- _theValue = theValue ;
- *_Value = theValue ;
- }
- break;
- }
- case CORBA::tk_double: { // Input double Value
- double d;
- *aDataValue >>= d;
-// cdebug << "Value( " << d << ") (double)";
- if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) { // SuperVision Value
- _theValue = aDataValue ;
- *_Value = aDataValue ;
- *_theValue >>= d;
-// cdebug << " == Value( " << d << ") (double)";
- }
- else {
- CORBA::Any * theValue = new CORBA::Any() ;
- if ( !strcmp( Type , "string" ) ) {
- char t[40] ;
- sprintf( t , "%lf" , d ) ;
- *theValue <<= t ;
- char *tt ;
- *theValue >>= tt ;
-// cdebug << " --> Value( " << t << ") (string) kind " << theValue->type()->kind() ;
- }
- else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
- !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
- long l = (long ) d ;
- *theValue <<= l ;
- *theValue >>= l;
-// cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
- }
- else { // Default
- CORBA::Object_ptr ObjRef ;
- *theValue <<= CORBA::Object::_nil() ;
- *theValue >>= ObjRef ;
-// cdebug << " --> Value( " << ObjectToString( ObjRef ) << ") (object reference) kind "
-// << theValue->type()->kind() ;
- }
- _theValue = theValue ;
- *_Value = theValue ;
- }
- break;
- }
- case CORBA::tk_objref: { // Input objref Value
- CORBA::Object_ptr obj ;
- *aDataValue >>= obj;
-// cdebug << "Value( " << ObjectToString( obj ) << ") (object reference)";
- if ( strcmp( Type , "string" ) &&
- strcmp( Type , "boolean" ) && strcmp( Type , "char" ) &&
- strcmp( Type , "short" ) && strcmp( Type , "long" ) &&
- strcmp( Type , "double" ) ) { // SuperVision Default Value
- _theValue = aDataValue ;
- *_Value = aDataValue ;
- *_theValue >>= obj;
-// cdebug << " == Value( " << ObjectToString( obj ) << ") (object reference)";
- }
- else {
- CORBA::Any * theValue = new CORBA::Any() ;
- if ( !strcmp( Type , "string" ) ) {
- *theValue <<= ObjectToString( obj ) ;
- *theValue >>= obj ;
-// cdebug << " --> Value( " << ObjectToString( obj ) << ") (string) kind " << theValue->type()->kind() ;
- }
- else if ( !strcmp( Type , "boolean" ) || !strcmp( Type , "char" ) ||
- !strcmp( Type , "short" ) || !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
- long l = (long ) obj ;
- *theValue <<= l ;
- *theValue >>= l;
-// cdebug << " --> Value( " << l << ") (long) kind " << theValue->type()->kind() ;
- }
- else if ( !strcmp( Type , "float" ) || !strcmp( Type , "double" ) ) {
- double d = (double ) 0. ;
- *theValue <<= d ;
- *theValue >>= d;
-// cdebug << " --> Value( " << d << ") (double) kind " << theValue->type()->kind() ;
- }
- _theValue = theValue ;
- *_Value = theValue ;
- }
- break;
- }
- default: {
- cdebug << "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR kind "
- << aDataValue->type()->kind() ;
- break;
- }
- }
- cdebug << endl ;
- if ( pthread_mutex_unlock( &_MutexWait ) ) {
- perror( "unlock DataValue" ) ;
- exit( 0 ) ;
- }
-// cdebug << pthread_self() << " Value(aDataValue) --> pthread_mutex_unlocked " << &_MutexWait
-// << endl ;
-
-}
-
-void GraphBase::DataPort::Value( const CORBA::Any ** aDataSharedValue ) {
- delete _theValue ;
- _theValue = *aDataSharedValue ;
- _Value = aDataSharedValue ;
-// Done( true ) ;
-
-#if 0
- MESSAGE( NodePortName() << " : " << hex << _Value << " " );
- switch (_theValue->type()->kind()) {
- case CORBA::tk_string:
- char * t;
- *_theValue >>= t;
- MESSAGE( "Value( " << t << ") (string)");
- break;
- case CORBA::tk_double:
- double d;
- *_theValue >>= d;
- MESSAGE( "Value( " << d << ") (double)");
- break;
- case CORBA::tk_long:
- long l;
- *_theValue >>= l;
- MESSAGE( "Value( " << l << ") (long)");
- break;
- case CORBA::tk_objref:
- MESSAGE( "Value( " << ") (object reference)");
- break;
- default:
- MESSAGE( "Value" << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR");
- break;
- }
- MESSAGE();
-#endif
-}
-
-CORBA::Any const * GraphBase::DataPort::Value() const {
- pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
-// cdebug << pthread_self() << " Value() --> pthread_mutex_lock " << aMutexWait << endl ;
- if ( pthread_mutex_lock( aMutexWait ) ) {
- perror( "lock DataValue" ) ;
- exit( 0 ) ;
- }
-// cdebug << pthread_self() << " Value() --> pthread_mutex_locked " << aMutexWait << endl ;
- const CORBA::Any *const Value = *_Value ;
- CORBA::Any * theValue ;
-// cdebug << pthread_self() << " Value " << NodeName() << " " << PortName() << " "
-// << PortType() << " _Value " << _Value << " *_Value " << *_Value << " Value->type "
-// << Value->type() ;
- if ( Value->type() ) {
-// cdebug << " kind " << Value->type()->kind() << " :" << endl ;
- }
- else {
-// cdebug << " Null" << endl ;
- }
- if ( Done() ) {
- theValue = new CORBA::Any( *Value ) ;
- switch ( theValue->type()->kind() ) {
- case CORBA::tk_string: {
- char * t;
- *theValue >>= t;
-// cdebug << "GraphBase::DataPort::Value() : " << t << " (string) " << endl ;
- break;
- }
- case CORBA::tk_double: {
- double d;
- *theValue >>= d;
-// cdebug << "GraphBase::DataPort::Value() : " << d << " (double) " << endl ;
- break;
- }
- case CORBA::tk_long: {
- long l;
- *theValue >>= l;
-// cdebug << "GraphBase::DataPort::Value() : " << l << " (long) " << endl ;
- break;
- }
- case CORBA::tk_objref: {
- CORBA::Object_ptr obj ;
- char * retstr ;
- try {
- *theValue >>= obj ;
- retstr = ObjectToString( obj );
-// cdebug << "GraphBase::DataPort::Value() : " << retstr
-// << "(object reference) " << endl;
- }
- catch( ... ) {
- cdebug << "ToString( object ) Catched ERROR" << endl ;
- }
- break;
- }
- default: {
- cdebug << "GraphBase::DataPort::Value() : " << NodeName() << "( " << PortName() << " ) " << PortType()
- << " (other(tk_string,tk_double,tk_long,tk_objref)) ERROR" << endl ;
- break;
- }
- }
- }
- else {
-// cdebug << "GraphBase::DataPort::InitialValue() " << endl ;
- theValue = new CORBA::Any( *Value ) ;
- }
- if ( pthread_mutex_unlock( aMutexWait ) ) {
- perror( "unlock DataValue" ) ;
- exit( 0 ) ;
- }
-// cdebug << pthread_self() << " Value() --> pthread_mutex_unlocked " << aMutexWait << endl ;
-
- return theValue ;
-}
-
-bool GraphBase::DataPort::BoolValue() const {
- bool RetVal = false ;
- long val ;
- pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
-// cdebug << pthread_self() << " BoolValue() --> pthread_mutex_lock " << aMutexWait << endl ;
- if ( pthread_mutex_lock( aMutexWait ) ) {
- perror( "lock DataValue" ) ;
- exit( 0 ) ;
- }
-// cdebug << pthread_self() << " BoolValue() --> pthread_mutex_locked " << aMutexWait
-// << endl ;
- if ( (*_Value)->type()->kind() == CORBA::tk_long ) {
- **_Value >>= val ;
- if ( val ) {
- RetVal = true ;
- }
- }
- if ( pthread_mutex_unlock( aMutexWait ) ) {
- perror( "unlock DataValue" ) ;
- exit( 0 ) ;
- }
-// cdebug << pthread_self() << " BoolValue() --> pthread_mutex_unlocked " << aMutexWait
-// << endl ;
- return RetVal ;
-}
-
-const CORBA::Any ** GraphBase::DataPort::ValuePtr() const {
- return _Value ;
-}
-
-void GraphBase::DataPort::StringValue(ostream & f ) const {
- pthread_mutex_t * aMutexWait = (pthread_mutex_t *) &_MutexWait ;
-// cdebug << pthread_self() << " StringValue() --> pthread_mutex_lock " << aMutexWait
-// << endl ;
- if ( pthread_mutex_lock( aMutexWait ) ) {
- perror( "lock DataValue" ) ;
- exit( 0 ) ;
- }
-// cdebug << pthread_self() << " StringValue() --> pthread_mutex_locked " << aMutexWait
-// << endl ;
- if ( Done() ) {
-// cdebug << "StringValue " << NodeName() << " " << PortName() << " " << PortType()
-// << " _Value " << _Value << " *_Value "
-// << *_Value << " " << endl ;
- const CORBA::Any * theValue = *_Value ;
- switch (theValue->type()->kind()) {
- case CORBA::tk_string:
- char * t;
- *theValue >>= t;
- f << t << " (string)" ;
- break;
- case CORBA::tk_double:
- double d;
- *theValue >>= d;
- f << d << " (double)" ;
- break;
- case CORBA::tk_long:
- long l;
- *theValue >>= l;
- f << l << " (long)" ;
- break;
- case CORBA::tk_objref:
- CORBA::Object_ptr ObjRef ;
- try {
- *theValue >>= ObjRef ;
- f << "(object reference) " << ObjectToString( ObjRef ) ;
- }
- catch(...) {
- f << "(object reference) catched error" ;
- }
- break;
- default:
- f << "(other ERROR)" ;
- break;
- }
- }
- else {
- f << " Default (undefined) NOT DONE" ;
- }
- if ( pthread_mutex_unlock( aMutexWait ) ) {
- perror( "unlock DataValue" ) ;
- exit( 0 ) ;
- }
-// cdebug << pthread_self() << " StringValue() --> pthread_mutex_unlocked " << aMutexWait
-// << endl ;
-
-}
-
-