From: Anthony Geay Date: Wed, 29 Oct 2014 09:51:31 +0000 (+0100) Subject: ScopeServer are correctly created and destroyed. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a16c9b6631ec467c6708eb46cb4dbe10ce462d89;p=modules%2Fkernel.git ScopeServer are correctly created and destroyed. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ef93d381..4fdf9c560 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,7 +218,7 @@ ELSE() LIST(APPEND _${PROJECT_NAME}_exposed_targets DF SalomeLoggerServer with_loggerTraceCollector SalomeNS SalomeGenericObj Registry SalomeCatalog ResourcesManager SalomeResourcesManager - SalomeNotification SalomeContainer Launcher SalomeLauncher + SalomeNotification SalomeContainer SalomeSDS Launcher SalomeLauncher SalomeLifeCycleCORBA SalomeDSClient TOOLSDS SalomeKernelHelpers SalomeDSImpl SalomeDS SalomeCommunication SalomeDSCContainer) # Temporary solution for package src\DSC on windows diff --git a/SalomeKERNELConfig.cmake.in b/SalomeKERNELConfig.cmake.in index f3fc6bd48..02f080dfb 100644 --- a/SalomeKERNELConfig.cmake.in +++ b/SalomeKERNELConfig.cmake.in @@ -168,6 +168,7 @@ SET(KERNEL_SALOMEBasics SALOMEBasics) SET(KERNEL_SalomeCatalog SalomeCatalog) SET(KERNEL_SalomeCommunication SalomeCommunication) SET(KERNEL_SalomeContainer SalomeContainer) +SET(KERNEL_SalomeSDS SalomeSDS) SET(KERNEL_SalomeDatastream SalomeDatastream) SET(KERNEL_SalomeDSCContainer SalomeDSCContainer) SET(KERNEL_SalomeDSClient SalomeDSClient) diff --git a/idl/SALOME_SDS.idl b/idl/SALOME_SDS.idl index 51a36bf10..ecb53c7e7 100644 --- a/idl/SALOME_SDS.idl +++ b/idl/SALOME_SDS.idl @@ -41,6 +41,8 @@ module SALOME any getValueOf(); }; + interface DataServerManager; + interface DataScopeServer { string getScopeName(); @@ -48,6 +50,7 @@ module SALOME BasicDataServer retrieveVar(in string varName); StringDataServer createGlobalStringVar(in string varName); AnyDataServer createGlobalAnyVar(in string varName); + void shutdownIfNotHostedByDSM(); }; interface DataServerManager @@ -57,5 +60,6 @@ module SALOME DataScopeServer createDataScope(in string scopeName); DataScopeServer retriveDataScope(in string scopeName); void removeDataScope(in string scopeName); + void shutdownScopes(); }; }; diff --git a/src/LifeCycleCORBA/CMakeLists.txt b/src/LifeCycleCORBA/CMakeLists.txt index abc89bbcd..2ae2bf280 100755 --- a/src/LifeCycleCORBA/CMakeLists.txt +++ b/src/LifeCycleCORBA/CMakeLists.txt @@ -33,6 +33,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Batch ${CMAKE_CURRENT_SOURCE_DIR}/../Notification ${CMAKE_CURRENT_SOURCE_DIR}/../Registry + ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMESDS ${PROJECT_BINARY_DIR}/idl ) @@ -40,6 +41,7 @@ SET(COMMON_LIBS SalomeContainer SalomeResourcesManager SalomeNS + SalomeSDS OpUtil SALOMELocalTrace SALOMEBasics diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index a63385a43..e35f4953e 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -43,12 +43,14 @@ #include "SALOME_LifeCycleCORBA.hxx" #include "SALOME_ResourcesManager.hxx" +#include "SALOMESDS_DataServerManager.hxx" #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog) #include CORBA_CLIENT_HEADER(SALOME_Session) #include CORBA_CLIENT_HEADER(DSC_Engines) #include CORBA_CLIENT_HEADER(SALOME_Registry) #include CORBA_CLIENT_HEADER(SALOMEDS) +#include CORBA_CLIENT_HEADER(SALOME_SDS) #include CORBA_CLIENT_HEADER(Logger) #include CORBA_CLIENT_HEADER(SALOME_Launcher) @@ -504,8 +506,20 @@ void SALOME_LifeCycleCORBA::shutdownServers() #ifndef WIN32 nanosleep(&ts_req,0); #endif + // 4 ) Remote ScopeServer (the DataServer is hosted by SalomeLauncher shutdown right after) + try + { + CORBA::Object_var objDSM(_NS->Resolve(SALOMESDS::DataServerManager::NAME_IN_NS)); + SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM)); + if ( !CORBA::is_nil(dsm) ) + dsm->shutdownScopes(); + } + catch(const CORBA::Exception& e) + { + // ignore and continue + } - // 4) SalomeLauncher + // 5) SalomeLauncher try { CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher"); @@ -523,7 +537,7 @@ void SALOME_LifeCycleCORBA::shutdownServers() nanosleep(&ts_req,0); #endif - // 5) Registry + // 6) Registry try { CORBA::Object_var objR = _NS->Resolve("/Registry"); @@ -536,20 +550,6 @@ void SALOME_LifeCycleCORBA::shutdownServers() // ignore and continue } - /* - // 6) Session - if ( !CORBA::is_nil( session ) ) { - try - { - session->Shutdown(); - } - catch(const CORBA::Exception& e) - { - // ignore and continue - } - } - */ - // 7) Logger int argc = 0; char *xargv = (char*)""; diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index eed86acd9..79292d867 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -19,8 +19,10 @@ // Author : Anthony GEAY (EDF R&D) #include "SALOMESDS_DataScopeServer.hxx" +#include "SALOMESDS_DataServerManager.hxx" #include "SALOMESDS_StringDataServer.hxx" #include "SALOMESDS_AnyDataServer.hxx" +#include "SALOME_NamingService.hxx" #include "SALOMESDS_Exception.hxx" #include @@ -33,7 +35,7 @@ DataScopeServer::DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeNam { } -DataScopeServer::DataScopeServer(const DataScopeServer& other):RefCountServ(other),_name(other._name),_vars(other._vars) +DataScopeServer::DataScopeServer(const DataScopeServer& other):_name(other._name),_vars(other._vars) { } @@ -123,6 +125,41 @@ SALOME::AnyDataServer_ptr DataScopeServer::createGlobalAnyVar(const char *varNam return SALOME::AnyDataServer::_narrow(ret); } +void DataScopeServer::shutdownIfNotHostedByDSM() +{ + SALOME_NamingService ns(_orb); + CORBA::Object_var obj(ns.Resolve(DataServerManager::NAME_IN_NS)); + SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(obj)); + if(CORBA::is_nil(dsm)) + return ; + // destroy ref in the naming service + std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name)); + ns.Destroy_Name(fullScopeName.c_str()); + // establish if dsm and this shared the same POA. If yes dsm and this are collocated ! + PortableServer::ServantBase *ret(0); + try + { + ret=_poa->reference_to_servant(dsm); + } + catch(...) { ret=0; } + // + if(!ret) + _orb->shutdown(0); + else + ret->_remove_ref(); +} + +/*! + * \a ptr has been activated by the POA \a poa. + */ +void DataScopeServer::setPOAAndRegister(PortableServer::POA_var poa, SALOME::DataScopeServer_ptr ptr) +{ + _poa=poa; + std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name)); + SALOME_NamingService ns(_orb); + ns.Register(ptr,fullScopeName.c_str()); +} + std::vector< std::string > DataScopeServer::getAllVarNames() const { std::size_t sz(_vars.size()); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index 25409bf92..87bcf4c2c 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -24,8 +24,8 @@ #include "SALOMEconfig.h" #include CORBA_SERVER_HEADER(SALOME_SDS) -#include "SALOMESDS_AutoRefCountPtr.hxx" #include "SALOMESDS_RefCountServ.hxx" +#include "SALOMESDS_AutoRefCountPtr.hxx" #include "SALOMESDS_BasicDataServer.hxx" #include @@ -34,7 +34,7 @@ namespace SALOMESDS { - class DataScopeServer : public RefCountServ, public virtual POA_SALOME::DataScopeServer + class DataScopeServer : public virtual POA_SALOME::DataScopeServer { public: DataScopeServer(CORBA::ORB_ptr orb, const std::string& scopeName); @@ -44,10 +44,14 @@ namespace SALOMESDS SALOME::BasicDataServer_ptr retrieveVar(const char *varName); SALOME::StringDataServer_ptr createGlobalStringVar(const char *varName); SALOME::AnyDataServer_ptr createGlobalAnyVar(const char *varName); + void shutdownIfNotHostedByDSM(); + public: + void setPOAAndRegister(PortableServer::POA_var poa, SALOME::DataScopeServer_ptr ptr); private: std::vector< std::string> getAllVarNames() const; CORBA::Object_var activateWithDedicatedPOA(BasicDataServer *ds); private: + PortableServer::POA_var _poa; CORBA::ORB_var _orb; std::string _name; std::list< std::pair< SALOME::BasicDataServer_var, AutoRefCountPtr > > _vars; diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index ef946e2ef..f09e94641 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -25,6 +25,7 @@ #include "SALOME_NamingService.hxx" #include +#include using namespace SALOMESDS; @@ -32,8 +33,9 @@ const char DataServerManager::NAME_IN_NS[]="/DataServerManager"; const char DataServerManager::DFT_SCOPE_NAME_IN_NS[]="Default"; -DataServerManager::DataServerManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa):_dft_scope(new DataScopeServer(orb,DFT_SCOPE_NAME_IN_NS)),_orb(CORBA::ORB::_duplicate(orb)) +DataServerManager::DataServerManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa):_orb(CORBA::ORB::_duplicate(orb)) { + DataScopeServer *dftScope(new DataScopeServer(orb,DFT_SCOPE_NAME_IN_NS));//_remove_ref will be call by DataScopeServer::shutdownIfNotHostedByDSM PortableServer::POAManager_var pman(poa->the_POAManager()); CORBA::PolicyList policies; policies.length(1); @@ -49,49 +51,36 @@ DataServerManager::DataServerManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr SALOME_NamingService ns(orb); ns.Register(obj2,NAME_IN_NS); // the default DataScopeServer object is the only one hosted by the current process - id=_poa->activate_object(_dft_scope); + id=_poa->activate_object(dftScope); obj=_poa->id_to_reference(id); - _ptr_dft_scope=SALOME::DataScopeServer::_narrow(obj); - _scopes.push_back(_ptr_dft_scope); - // - std::string fullNameInNS(CreateAbsNameInNSFromScopeName(DFT_SCOPE_NAME_IN_NS)); - ns.Register(_ptr_dft_scope,fullNameInNS.c_str()); + SALOME::DataScopeServer_var dftScopePtr(SALOME::DataScopeServer::_narrow(obj)); + dftScope->setPOAAndRegister(_poa,dftScopePtr); } SALOME::StringVec *DataServerManager::listScopes() { + std::vector scopes(listOfScopesCpp()); SALOME::StringVec *ret(new SALOME::StringVec); - std::size_t sz(_scopes.size()); + std::size_t sz(scopes.size()); ret->length(sz); - std::list< SALOME::DataScopeServer_var >::iterator it(_scopes.begin()); - for(std::size_t i=0;igetScopeName()); - (*ret)[i]=CORBA::string_dup(name); - CORBA::string_free(name); - } + for(std::size_t i=0;i::iterator it(_scopes.begin()); - for(std::size_t i=0;i scopes(listOfScopesCpp()); + if(std::find(scopes.begin(),scopes.end(),scopeNameCpp)!=scopes.end()) { - CORBA::String_var zeName((*it)->getScopeName()); - if(scopeNameCpp==(const char *)zeName) - { - std::ostringstream oss; oss << "DataServerManager::createDataScope : scope name \"" << scopeName << "\" already exists !"; - throw Exception(oss.str()); - } + std::ostringstream oss; oss << "DataServerManager::createDataScope : scope name \"" << scopeName << "\" already exists !"; + throw Exception(oss.str()); } // SALOME_NamingService ns(_orb); @@ -110,22 +99,26 @@ SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scope CORBA::Object_var obj(ns.Resolve(fullScopeName.c_str())); ret=SALOME::DataScopeServer::_narrow(obj); } - if(!CORBA::is_nil(ret)) - { - _scopes.push_back(ret); - } return SALOME::DataScopeServer::_duplicate(ret); } SALOME::DataScopeServer_ptr DataServerManager::retriveDataScope(const char *scopeName) { - std::list< SALOME::DataScopeServer_var >::iterator it(getScopePtrGivenName(scopeName)); - return SALOME::DataScopeServer::_duplicate(*it); + SALOME::DataScopeServer_var ret(getScopePtrGivenName(scopeName)); + return SALOME::DataScopeServer::_duplicate(ret); } void DataServerManager::removeDataScope(const char *scopeName) { - std::list< SALOME::DataScopeServer_var >::iterator it(getScopePtrGivenName(scopeName)); + SALOME::DataScopeServer_var scs(getScopePtrGivenName(scopeName)); + scs->shutdownIfNotHostedByDSM(); +} + +void DataServerManager::shutdownScopes() +{ + std::vector scopeNames(listOfScopesCpp()); + for(std::vector::const_iterator it=scopeNames.begin();it!=scopeNames.end();it++) + getScopePtrGivenName(*it)->shutdownIfNotHostedByDSM(); } std::string DataServerManager::CreateAbsNameInNSFromScopeName(const std::string& scopeName) @@ -134,22 +127,26 @@ std::string DataServerManager::CreateAbsNameInNSFromScopeName(const std::string& return oss.str(); } -std::list< SALOME::DataScopeServer_var >::iterator DataServerManager::getScopePtrGivenName(const std::string& scopeName) +std::vector DataServerManager::listOfScopesCpp() { - std::size_t sz(_scopes.size()); - std::list< SALOME::DataScopeServer_var >::iterator it(_scopes.begin()); - bool found(false); - for(std::size_t i=0;igetScopeName()); - found=(scopeName==(const char *)zeName); - if(found) - break; - } - if(!found) + SALOME_NamingService ns(_orb); + ns.Change_Directory(NAME_IN_NS); + std::vector ret(ns.list_directory()); + return ret; +} + +SALOME::DataScopeServer_var DataServerManager::getScopePtrGivenName(const std::string& scopeName) +{ + std::vector scopes(listOfScopesCpp()); + std::size_t sz(scopes.size()); + if(std::find(scopes.begin(),scopes.end(),scopeName)==scopes.end()) { std::ostringstream oss; oss << "DataServerManager::getScopePtrGivenName : scope name \"" << scopeName << "\" does not exist !"; throw Exception(oss.str()); } - return it; + SALOME_NamingService ns(_orb); + std::string fullScopeName(CreateAbsNameInNSFromScopeName(scopeName)); + CORBA::Object_var obj(ns.Resolve(fullScopeName.c_str())); + SALOME::DataScopeServer_var ret(SALOME::DataScopeServer::_narrow(obj)); + return ret; } diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx index 55fcd62e3..8f0447b86 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.hxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.hxx @@ -27,7 +27,6 @@ #include "SALOMESDS_AutoRefCountPtr.hxx" #include "SALOMESDS_DataScopeServer.hxx" -#include #include namespace SALOMESDS @@ -43,16 +42,15 @@ namespace SALOMESDS SALOME::DataScopeServer_ptr createDataScope(const char *scopeName); SALOME::DataScopeServer_ptr retriveDataScope(const char *scopeName); void removeDataScope(const char *scopeName); + void shutdownScopes(); static std::string CreateAbsNameInNSFromScopeName(const std::string& scopeName); public: static const char NAME_IN_NS[]; static const char DFT_SCOPE_NAME_IN_NS[]; private: - std::list< SALOME::DataScopeServer_var >::iterator getScopePtrGivenName(const std::string& scopeName); + std::vector listOfScopesCpp(); + SALOME::DataScopeServer_var getScopePtrGivenName(const std::string& scopeName); private: - AutoRefCountPtr _dft_scope; - SALOME::DataScopeServer_var _ptr_dft_scope; - std::list< SALOME::DataScopeServer_var > _scopes; CORBA::ORB_var _orb; //! single thread poa PortableServer::POA_var _poa; diff --git a/src/SALOMESDS/SALOME_DataScopeServer.cxx b/src/SALOMESDS/SALOME_DataScopeServer.cxx index 6dac94637..e68715586 100644 --- a/src/SALOMESDS/SALOME_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOME_DataScopeServer.cxx @@ -49,13 +49,10 @@ int main(int argc, char* argv[]) PortableServer::ObjectId_var id(poa2->activate_object(server)); obj=poa2->id_to_reference(id); SALOME::DataScopeServer_var serverPtr(SALOME::DataScopeServer::_narrow(obj)); - // - std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(scopeName)); - SALOME_NamingService ns(orb); - ns.Register(serverPtr,fullScopeName.c_str()); + server->setPOAAndRegister(poa2,serverPtr); // orb->run(); - server->decrRef(); + server->_remove_ref(); return 0; }