X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FContainer%2FComponent_i.cxx;h=04eff5a0d25599213588980d420968f58e6da52a;hb=a6e69d107ff10ff9de9475a9c381b535d5baea5c;hp=ff343a2cc5065e9a6c22413bd13dc2dfca994d59;hpb=ab41913b136c189f3aab5e4ce3f3da7f62395f23;p=modules%2Fkernel.git diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index ff343a2cc..04eff5a0d 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -26,6 +26,7 @@ // Module : SALOME // $Header$ +#define private protected #include "SALOME_Component_i.hxx" #include "SALOME_Container_i.hxx" #include "RegistryConnexion.hxx" @@ -34,16 +35,36 @@ #include #include #include "utilities.h" + +#include +#include +#include + using namespace std; extern bool _Sleeping ; static Engines_Component_i * theEngines_Component ; +bool Engines_Component_i::_isMultiStudy = true; +bool Engines_Component_i::_isMultiInstance = false; + +//============================================================================= +/*! + * + */ +//============================================================================= + Engines_Component_i::Engines_Component_i() { // MESSAGE("Component constructor"); } +//============================================================================= +/*! + * + */ +//============================================================================= + Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId * contId, @@ -53,18 +74,33 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _instanceName(instanceName), _interfaceName(interfaceName), _myConnexionToRegistry(0), - _ThreadId(0) , _ThreadCpuUsed(0) , _Executed(false) , _graphName("") , _nodeName("") { + _ThreadId(0) , + _ThreadCpuUsed(0) , + _Executed(false) , + _graphName("") , + _nodeName(""), + _studyId(-1) +{ MESSAGE("Component constructor with instanceName "<< _instanceName); + SCRUTE(pd_refCount); _orb = CORBA::ORB::_duplicate(orb); _poa = PortableServer::POA::_duplicate(poa); _contId = contId ; CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior... const CORBA::String_var ior = _orb->object_to_string(o); - _myConnexionToRegistry = new RegistryConnexion(0, 0, ior, "theSession", _instanceName.c_str()); + _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession", + _instanceName.c_str()); _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif); + SCRUTE(pd_refCount); } +//============================================================================= +/*! + * + */ +//============================================================================= + // Constructeur pour composant parallele: ne pas faire appel au registry!! Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, @@ -72,44 +108,111 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, const char *instanceName, const char *interfaceName, int flag, - bool notif ) - : _instanceName(instanceName), - _interfaceName(interfaceName), - _myConnexionToRegistry(0), - _ThreadId(0) , _ThreadCpuUsed(0) , _Executed(false) , _graphName("") , _nodeName("") { -// MESSAGE("Component constructor with instanceName "<< _instanceName); + bool notif ) : + _instanceName(instanceName), + _interfaceName(interfaceName), + _myConnexionToRegistry(0), + _ThreadId(0) , + _ThreadCpuUsed(0) , + _Executed(false) , + _graphName("") , + _nodeName(""), + _studyId(-1) +{ + // MESSAGE("Component constructor with instanceName "<< _instanceName); _orb = CORBA::ORB::_duplicate(orb); _poa = PortableServer::POA::_duplicate(poa); _contId = contId ; - // CORBA::Object_var myself = this->_this(); //appel a _this = increment reference _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif); } +//============================================================================= +/*! + * + */ +//============================================================================= + Engines_Component_i::~Engines_Component_i() { MESSAGE("Component destructor"); -// delete _myConnexionToRegistry; -// _myConnexionToRegistry = 0 ; } -char* Engines_Component_i::instanceName() { +//============================================================================= +/*! + * + */ +//============================================================================= + +char* Engines_Component_i::instanceName() +{ return CORBA::string_dup(_instanceName.c_str()) ; } -char* Engines_Component_i::interfaceName() { - return CORBA::string_dup(_interfaceName.c_str()) ; +//============================================================================= +/*! + * + */ +//============================================================================= + +char* Engines_Component_i::interfaceName() +{ + return CORBA::string_dup(_interfaceName.c_str()) ; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +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::Long Engines_Component_i::getStudyId() +{ + return _studyId; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + void Engines_Component_i::ping() { MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid " << pthread_self()); } +//============================================================================= +/*! + * + */ +//============================================================================= + void Engines_Component_i::destroy() { MESSAGE("Engines_Component_i::destroy()"); + SCRUTE(pd_refCount); delete _notifSupplier; _notifSupplier = 0; @@ -119,10 +222,18 @@ void Engines_Component_i::destroy() _poa->deactivate_object(*_id) ; CORBA::release(_poa) ; delete(_id) ; + SCRUTE(pd_refCount); _thisObj->_remove_ref(); + SCRUTE(pd_refCount); MESSAGE("Engines_Component_i::destroyed") ; } +//============================================================================= +/*! + * + */ +//============================================================================= + Engines::Container_ptr Engines_Component_i::GetContainerRef() { MESSAGE("Engines_Component_i::GetContainerRef"); @@ -130,12 +241,24 @@ Engines::Container_ptr Engines_Component_i::GetContainerRef() return Engines::Container::_narrow(o); } +//============================================================================= +/*! + * + */ +//============================================================================= + PortableServer::ObjectId * Engines_Component_i::getId() { // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()"); return _id ; } +//============================================================================= +/*! + * + */ +//============================================================================= + void Engines_Component_i::setProperties(const Engines::FieldsDict& dico) { _fieldsDict.clear(); @@ -146,6 +269,12 @@ void Engines_Component_i::setProperties(const Engines::FieldsDict& dico) } } +//============================================================================= +/*! + * + */ +//============================================================================= + Engines::FieldsDict* Engines_Component_i::getProperties() { Engines::FieldsDict_var copie = new Engines::FieldsDict; @@ -161,24 +290,32 @@ Engines::FieldsDict* Engines_Component_i::getProperties() return copie._retn(); } +//============================================================================= +/*! + * + */ +//============================================================================= + void Engines_Component_i::beginService(const char *serviceName) { - MESSAGE(pthread_self() << "Send BeginService notification for " << serviceName << endl - << "Component instance : " << _instanceName << endl << endl); + MESSAGE(pthread_self() << "Send BeginService notification for " <>= 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 @@ -202,7 +339,7 @@ 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 @@ -211,56 +348,104 @@ void Engines_Component_i::beginService(const char *serviceName) } } +//============================================================================= +/*! + * + */ +//============================================================================= + void Engines_Component_i::endService(const char *serviceName) { _ThreadCpuUsed = CpuUsed_impl() ; - MESSAGE(pthread_self() << " Send EndService notification for " << serviceName << endl - << " Component instance : " << _instanceName << " StartUsed " << _StartUsed << " _ThreadCpuUsed " - << _ThreadCpuUsed << endl << endl); + MESSAGE(pthread_self() << " Send EndService notification for " << serviceName + << endl << " Component instance : " << _instanceName << " StartUsed " + << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl < 0 && pthread_self() != _ThreadId ) { - RetVal = Killer( _ThreadId , 0 ) ; - _ThreadId = (pthread_t ) -1 ; - } + if ( _ThreadId > 0 && pthread_self() != _ThreadId ) + { + RetVal = Killer( _ThreadId , 0 ) ; + _ThreadId = (pthread_t ) -1 ; + } return RetVal ; } -bool Engines_Component_i::Suspend_impl() { +//============================================================================= +/*! + * + */ +//============================================================================= + +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 ) ; + if ( _ThreadId > 0 && pthread_self() != _ThreadId ) + { + if ( _Sleeping ) + { + return false ; + } + else + { + RetVal = Killer( _ThreadId ,SIGINT ) ; + } } - } return RetVal ; } -bool Engines_Component_i::Resume_impl() { +//============================================================================= +/*! + * + */ +//============================================================================= + +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 ; + if ( _ThreadId > 0 && pthread_self() != _ThreadId ) + { + if ( _Sleeping ) + { + _Sleeping = false ; + RetVal = true ; + } + else + { + RetVal = false ; + } } - } return RetVal ; } -void SetCpuUsed() { +//============================================================================= +/*! + * + */ +//============================================================================= + +void SetCpuUsed() +{ theEngines_Component->SetCurCpu() ; } -void Engines_Component_i::SetCurCpu() { + +//============================================================================= +/*! + * + */ +//============================================================================= + +void Engines_Component_i::SetCurCpu() +{ _ThreadCpuUsed = CpuUsed() ; -// MESSAGE(pthread_self() << " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ; + // MESSAGE(pthread_self() << + // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ; } -#include -#include -#include +//============================================================================= +/*! + * + */ +//============================================================================= -long Engines_Component_i::CpuUsed() { +long Engines_Component_i::CpuUsed() +{ long cpu = 0 ; struct rusage usage ; - if ( _ThreadId || _Executed ) { - if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) { - perror("Engines_Component_i::CpuUsed") ; - return 0 ; + if ( _ThreadId || _Executed ) + { + if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) + { + perror("Engines_Component_i::CpuUsed") ; + return 0 ; + } + cpu = usage.ru_utime.tv_sec - _StartUsed ; + // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " " + // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed + // << " = " << cpu << endl ; + } + else + { + // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId " + // << _ThreadId << " " << _serviceName<< " _StartUsed " + // << _StartUsed << endl ; } - cpu = usage.ru_utime.tv_sec - _StartUsed ; -// cout << pthread_self() << " Engines_Component_i::CpuUsed " << " " << _serviceName -// << usage.ru_utime.tv_sec << " - " << _StartUsed << " = " << cpu << endl ; - } - else { -// cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId " << _ThreadId << " " << _serviceName -// << " _StartUsed " << _StartUsed << endl ; - } return cpu ; } -CORBA::Long Engines_Component_i::CpuUsed_impl() { +//============================================================================= +/*! + * + */ +//============================================================================= + +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 ) ; - } + 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 { - _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 { - 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<Send(graphName(), nodeName(), event_type, message); } +//============================================================================= +/*! + * + */ +//============================================================================= + string Engines_Component_i::GetDynLibraryName(const char *componentName) { string ret="lib"; @@ -407,7 +672,15 @@ string Engines_Component_i::GetDynLibraryName(const char *componentName) return ret; } -string Engines_Component_i::BuildComponentNameForNS(const char *ComponentName, const char *ContainerName, const char *hostname) +//============================================================================= +/*! + * + */ +//============================================================================= + +string Engines_Component_i::BuildComponentNameForNS(const char *ComponentName, + const char *ContainerName, + const char *hostname) { string ret=Engines_Container_i::BuildContainerNameForNS(ContainerName,hostname); ret+="/";