From 69f3f815e0d9d91f1392a4c2c4a568e9a733dc0e Mon Sep 17 00:00:00 2001 From: prascle Date: Wed, 20 Apr 2005 12:27:48 +0000 Subject: [PATCH] PR: Documentation --- src/Container/Component_i.cxx | 508 ++++++++++++++++++---------------- 1 file changed, 275 insertions(+), 233 deletions(-) diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index e0622fec3..fb2dc2b68 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -26,7 +26,7 @@ // Module : SALOME // $Header$ -#define private protected +//#define private protected // for pd_refCount trace #include "SALOME_Component_i.hxx" #include "SALOME_Container_i.hxx" #include "RegistryConnexion.hxx" @@ -50,18 +50,25 @@ bool Engines_Component_i::_isMultiInstance = false; //============================================================================= /*! - * + * Default constructor, not for use */ //============================================================================= Engines_Component_i::Engines_Component_i() { -// MESSAGE("Component constructor"); + ASSERT(0); } //============================================================================= /*! - * + * Standard Constructor for generic Component, used in derived class + * Connection to Registry and Notification + * \param orb Object Request broker given by Container + * \parap poa Portable Object Adapter from Container (normally root_poa) + * \param contId container CORBA id inside the server + * \param instanceName unique instance name for this object (see Container_i) + * \param interfaceName component class name + * \param notif use of notification */ //============================================================================= @@ -82,7 +89,7 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _studyId(-1) { MESSAGE("Component constructor with instanceName "<< _instanceName); - SCRUTE(pd_refCount); + //SCRUTE(pd_refCount); _orb = CORBA::ORB::_duplicate(orb); _poa = PortableServer::POA::_duplicate(poa); _contId = contId ; @@ -92,16 +99,23 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _instanceName.c_str()); _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif); - SCRUTE(pd_refCount); + //SCRUTE(pd_refCount); } //============================================================================= /*! - * + * Standard constructor for parallel component + * Connection Notification (no connection to Registry !) + * \param orb Object Request broker given by Container + * \parap poa Portable Object Adapter from Container (normally root_poa) + * \param contId container CORBA id inside the server + * \param instanceName unique instance name for this object (see Container_i) + * \param interfaceName component class name + * \param flag not used... + * \param notif use of notification */ //============================================================================= -// Constructeur pour composant parallele: ne pas faire appel au registry!! Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId * contId, @@ -119,7 +133,6 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _nodeName(""), _studyId(-1) { - // MESSAGE("Component constructor with instanceName "<< _instanceName); _orb = CORBA::ORB::_duplicate(orb); _poa = PortableServer::POA::_duplicate(poa); _contId = contId ; @@ -129,7 +142,9 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, //============================================================================= /*! - * + * Destructor: call Container for decrement of instances count. + * When instances count falls to 0, the container tries to remove the + * component library (dlclose) */ //============================================================================= @@ -141,7 +156,7 @@ Engines_Component_i::~Engines_Component_i() //============================================================================= /*! - * + * CORBA method: return name of the instance, unique in this Container */ //============================================================================= @@ -152,7 +167,7 @@ char* Engines_Component_i::instanceName() //============================================================================= /*! - * + * CORBA method: return name of the component class */ //============================================================================= @@ -163,27 +178,10 @@ char* Engines_Component_i::interfaceName() //============================================================================= /*! - * - */ -//============================================================================= - -CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId) -{ - ASSERT( studyId >= 0); - CORBA::Boolean ret = false; - if (_studyId < 0) - { - _studyId = studyId; - ret = true; - } - else - if ( _studyId == studyId) ret = true; - return ret; -} - -//============================================================================= -/*! - * + * CORBA method: Get study Id + * \return -1: not initialised (Internal Error) + * 0: multistudy component instance + * >0: study id associated to this instance */ //============================================================================= @@ -194,7 +192,7 @@ CORBA::Long Engines_Component_i::getStudyId() //============================================================================= /*! - * + * CORBA method: Test if instance is alive and responds */ //============================================================================= @@ -206,14 +204,19 @@ void Engines_Component_i::ping() //============================================================================= /*! - * + * CORBA method: Deactivate this instance. CORBA object is deactivated (do not + * respond any more to CORBA calls), the connection to Regsitry is removed + * (Registry informed of deactivation), internal server reference counter on + * the derived servant class is decremented, to allow destruction of the class + * (delete) by POA, when there are no more references. + * -- TO BE USED BY CONTAINER ONLY (Container housekeeping) -- */ //============================================================================= void Engines_Component_i::destroy() { MESSAGE("Engines_Component_i::destroy()"); - SCRUTE(pd_refCount); + //SCRUTE(pd_refCount); delete _notifSupplier; _notifSupplier = 0; @@ -223,14 +226,15 @@ void Engines_Component_i::destroy() _poa->deactivate_object(*_id) ; CORBA::release(_poa) ; delete(_id) ; - SCRUTE(pd_refCount); + //SCRUTE(pd_refCount); _thisObj->_remove_ref(); - SCRUTE(pd_refCount); + //SCRUTE(pd_refCount); MESSAGE("Engines_Component_i::destroyed") ; } //============================================================================= /*! + * CORBA method: return CORBA reference of the Container * */ //============================================================================= @@ -244,19 +248,12 @@ Engines::Container_ptr Engines_Component_i::GetContainerRef() //============================================================================= /*! - * - */ -//============================================================================= - -PortableServer::ObjectId * Engines_Component_i::getId() -{ -// MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()"); - return _id ; -} - -//============================================================================= -/*! - * + * CORBA method: + * Gives a sequence of (key=string,value=any) to the component. + * Base class component stores the sequence in a map. + * The map is cleared before. + * This map is for use by derived classes. + * \param dico sequence of (key=string,value=any) */ //============================================================================= @@ -272,7 +269,9 @@ void Engines_Component_i::setProperties(const Engines::FieldsDict& dico) //============================================================================= /*! - * + * CORBA method: + * returns a previously stored map (key=string,value=any) as a sequence. + * (see setProperties) */ //============================================================================= @@ -293,7 +292,214 @@ Engines::FieldsDict* Engines_Component_i::getProperties() //============================================================================= /*! - * + * CORBA method: used by Supervision to give names to this instance + */ +//============================================================================= + +void Engines_Component_i::Names( const char * graphName , + const char * nodeName ) +{ + _graphName = graphName ; + _nodeName = nodeName ; + // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '" + // << _nodeName << "' )"); +} + +//============================================================================= +/*! + * CORBA method: used in Supervision + */ +//============================================================================= + +bool Engines_Component_i::Kill_impl() +{ +// MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self() +// << " pid " << getpid() << " instanceName " +// << _instanceName.c_str() << " interface " << _interfaceName.c_str() +// << " machineName " << GetHostname().c_str()<< " _id " << hex << _id +// << dec << " _ThreadId " << _ThreadId << " this " << hex << this +// << dec ) ; + + bool RetVal = false ; + if ( _ThreadId > 0 && pthread_self() != _ThreadId ) + { + RetVal = Killer( _ThreadId , 0 ) ; + _ThreadId = (pthread_t ) -1 ; + } + return RetVal ; +} + +//============================================================================= +/*! + * CORBA method: used in Supervision + */ +//============================================================================= + +bool Engines_Component_i::Stop_impl() +{ + MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self() + << " pid " << getpid() << " instanceName " + << _instanceName.c_str() << " interface " << _interfaceName.c_str() + << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << dec << " _ThreadId " << _ThreadId ); + + + bool RetVal = false ; + if ( _ThreadId > 0 && pthread_self() != _ThreadId ) + { + RetVal = Killer( _ThreadId , 0 ) ; + _ThreadId = (pthread_t ) -1 ; + } + return RetVal ; +} + +//============================================================================= +/*! + * CORBA method: used in Supervision + */ +//============================================================================= + +bool Engines_Component_i::Suspend_impl() +{ + MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self() + << " pid " << getpid() << " instanceName " + << _instanceName.c_str() << " interface " << _interfaceName.c_str() + << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << dec << " _ThreadId " << _ThreadId ); + + bool RetVal = false ; + if ( _ThreadId > 0 && pthread_self() != _ThreadId ) + { + if ( _Sleeping ) + { + return false ; + } + else + { + RetVal = Killer( _ThreadId ,SIGINT ) ; + } + } + return RetVal ; +} + +//============================================================================= +/*! + * CORBA method: used in Supervision + */ +//============================================================================= + +bool Engines_Component_i::Resume_impl() +{ + MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self() + << " pid " << getpid() << " instanceName " + << _instanceName.c_str() << " interface " << _interfaceName.c_str() + << " machineName " << GetHostname().c_str()<< " _id " << hex << _id + << dec << " _ThreadId " << _ThreadId ); + bool RetVal = false ; + if ( _ThreadId > 0 && pthread_self() != _ThreadId ) + { + if ( _Sleeping ) + { + _Sleeping = false ; + RetVal = true ; + } + else + { + RetVal = false ; + } + } + return RetVal ; +} + +//============================================================================= +/*! + * CORBA method: + */ +//============================================================================= + +CORBA::Long Engines_Component_i::CpuUsed_impl() +{ + long cpu = 0 ; + if ( _ThreadId || _Executed ) + { + if ( _ThreadId > 0 ) + { + if ( pthread_self() != _ThreadId ) + { + if ( _Sleeping ) + { + } + else + { + // Get Cpu in the appropriate thread with that object !... + theEngines_Component = this ; + Killer( _ThreadId ,SIGUSR1 ) ; + } + cpu = _ThreadCpuUsed ; + } + else + { + _ThreadCpuUsed = CpuUsed() ; + cpu = _ThreadCpuUsed ; + // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl " + // << _serviceName << " " << cpu << endl ; + } + } + else + { + cpu = _ThreadCpuUsed ; + // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl " + // << _serviceName << " " << cpu<< endl ; + } + } + else + { + // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId " + // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<0 otherwise (== study id) + * \return true if the set of study Id is OK + * must be set once by Container, and cannot be changed after. + */ +//============================================================================= + +CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId) +{ + ASSERT( studyId >= 0); + CORBA::Boolean ret = false; + if (_studyId < 0) + { + _studyId = studyId; + ret = true; + } + else + if ( _studyId == studyId) ret = true; + return ret; +} + +//============================================================================= +/*! + * C++ method: return CORBA instance id, the id is set in derived class + * constructor, when instance is activated. + */ +//============================================================================= + +PortableServer::ObjectId * Engines_Component_i::getId() +{ +// MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()"); + return _id ; +} + +//============================================================================= +/*! + * C++ method: used by derived classes for supervision */ //============================================================================= @@ -332,7 +538,7 @@ void Engines_Component_i::beginService(const char *serviceName) { const char* value; (*it).second >>= value; - // --- todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC. + // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC. #if defined __GNUC__ int ret = setenv(cle.c_str(), value, overwrite); #else @@ -340,7 +546,8 @@ void Engines_Component_i::beginService(const char *serviceName) std::string s(cle); s+='='; s+=value; - //char* cast because 1st arg of linux putenv function is not a const char* ! + // char* cast because 1st arg of linux putenv function + // is not a const char* ! int ret=putenv((char *)s.c_str()); //End of CCRT porting #endif @@ -351,7 +558,7 @@ void Engines_Component_i::beginService(const char *serviceName) //============================================================================= /*! - * + * C++ method: used by derived classes for supervision */ //============================================================================= @@ -366,22 +573,7 @@ void Engines_Component_i::endService(const char *serviceName) //============================================================================= /*! - * - */ -//============================================================================= - -void Engines_Component_i::Names( const char * graphName , - const char * nodeName ) -{ - _graphName = graphName ; - _nodeName = nodeName ; - // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '" - // << _nodeName << "' )"); -} - -//============================================================================= -/*! - * + * C++ method: -- CHECK IF USED -- */ //============================================================================= @@ -392,7 +584,7 @@ char* Engines_Component_i::graphName() //============================================================================= /*! - * + * C++ method: -- CHECK IF USED -- */ //============================================================================= @@ -403,7 +595,7 @@ char* Engines_Component_i::nodeName() //============================================================================= /*! - * + * C++ method: used in Supervision (see kill_impl) */ //============================================================================= @@ -443,110 +635,8 @@ bool Engines_Component_i::Killer( pthread_t ThreadId , int signum ) //============================================================================= /*! - * - */ -//============================================================================= - -bool Engines_Component_i::Kill_impl() { -// MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self() -// << " pid " << getpid() << " instanceName " -// << _instanceName.c_str() << " interface " << _interfaceName.c_str() -// << " machineName " << GetHostname().c_str()<< " _id " << hex << _id -// << dec << " _ThreadId " << _ThreadId << " this " << hex << this -// << dec ) ; - bool RetVal = false ; - if ( _ThreadId > 0 && pthread_self() != _ThreadId ) { - RetVal = Killer( _ThreadId , 0 ) ; - _ThreadId = (pthread_t ) -1 ; - } - return RetVal ; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -bool Engines_Component_i::Stop_impl() -{ - MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self() - << " pid " << getpid() << " instanceName " - << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id - << dec << " _ThreadId " << _ThreadId ); - - bool RetVal = false ; - if ( _ThreadId > 0 && pthread_self() != _ThreadId ) - { - RetVal = Killer( _ThreadId , 0 ) ; - _ThreadId = (pthread_t ) -1 ; - } - return RetVal ; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -bool Engines_Component_i::Suspend_impl() -{ - MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self() - << " pid " << getpid() << " instanceName " - << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id - << dec << " _ThreadId " << _ThreadId ); - bool RetVal = false ; - if ( _ThreadId > 0 && pthread_self() != _ThreadId ) - { - if ( _Sleeping ) - { - return false ; - } - else - { - RetVal = Killer( _ThreadId ,SIGINT ) ; - } - } - return RetVal ; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -bool Engines_Component_i::Resume_impl() -{ - MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self() - << " pid " << getpid() << " instanceName " - << _instanceName.c_str() << " interface " << _interfaceName.c_str() - << " machineName " << GetHostname().c_str()<< " _id " << hex << _id - << dec << " _ThreadId " << _ThreadId ); - bool RetVal = false ; - if ( _ThreadId > 0 && pthread_self() != _ThreadId ) - { - if ( _Sleeping ) - { - _Sleeping = false ; - RetVal = true ; - } - else - { - RetVal = false ; - } - } - return RetVal ; - -} - -//============================================================================= -/*! - * - */ + * C++ method: + */ //============================================================================= void SetCpuUsed() @@ -556,7 +646,7 @@ void SetCpuUsed() //============================================================================= /*! - * + * C++ method: */ //============================================================================= @@ -569,7 +659,7 @@ void Engines_Component_i::SetCurCpu() //============================================================================= /*! - * + * C++ method: */ //============================================================================= @@ -600,56 +690,7 @@ long Engines_Component_i::CpuUsed() //============================================================================= /*! - * - */ -//============================================================================= - -CORBA::Long Engines_Component_i::CpuUsed_impl() -{ - long cpu = 0 ; - if ( _ThreadId || _Executed ) - { - if ( _ThreadId > 0 ) - { - if ( pthread_self() != _ThreadId ) - { - if ( _Sleeping ) - { - } - else - { - // Get Cpu in the appropriate thread with that object !... - theEngines_Component = this ; - Killer( _ThreadId ,SIGUSR1 ) ; - } - cpu = _ThreadCpuUsed ; - } - else - { - _ThreadCpuUsed = CpuUsed() ; - cpu = _ThreadCpuUsed ; - // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl " - // << _serviceName << " " << cpu << endl ; - } - } - else - { - cpu = _ThreadCpuUsed ; - // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl " - // << _serviceName << " " << cpu<< endl ; - } - } - else - { - // cout << pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId " - // <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<