]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
ScopeServer are correctly created and destroyed.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 29 Oct 2014 09:51:31 +0000 (10:51 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 29 Oct 2014 09:51:31 +0000 (10:51 +0100)
CMakeLists.txt
SalomeKERNELConfig.cmake.in
idl/SALOME_SDS.idl
src/LifeCycleCORBA/CMakeLists.txt
src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_DataServerManager.cxx
src/SALOMESDS/SALOMESDS_DataServerManager.hxx
src/SALOMESDS/SALOME_DataScopeServer.cxx

index 9ef93d381a4ef84a63846aed497516a9c072382d..4fdf9c5608d1efc01a9c52af475468d77185d765 100755 (executable)
@@ -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
index f3fc6bd4812ff03da744d85fdb91759ab80e3a3b..02f080dfbfcf70a3eaee4deadd7adbd92f67626d 100644 (file)
@@ -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)
index 51a36bf1014994c098a88ad615f505371d88af36..ecb53c7e73dffdfac7da94cd8234a256115cff91 100644 (file)
@@ -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();
   };
 };
index abc89bbcd84d57445ea983252649a7a5d3cfa136..2ae2bf280a9cabbfae44a2346b7e86dca87507c0 100755 (executable)
@@ -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
index a63385a43b083915e71edc1bbe8fd998c3db2225..e35f4953e86781f130ee3aabfe2e11f1e8fb0197 100644 (file)
 
 #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*)"";
index eed86acd90cc8252534c64b7db8eaa17644b20a7..79292d86761fe36702f33d43a76d4409ad7b3026 100644 (file)
 // 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 <sstream>
@@ -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());
index 25409bf925519fb17d5aba5eaa24c356b595f2cd..87bcf4c2c6354f750154d5f445514c5443c855a3 100644 (file)
@@ -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 <string>
@@ -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<BasicDataServer> > > _vars;
index ef946e2efa68b1da97cec030e43552ebf76ec84d..f09e94641a9c12456dfb6381568dd624fbec1c8a 100644 (file)
@@ -25,6 +25,7 @@
 #include "SALOME_NamingService.hxx"
 
 #include <sstream>
+#include <algorithm>
 
 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<std::string> 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;i<sz;it++,i++)
-    {
-      SALOME::DataScopeServer_var obj(*it);
-      char *name(obj->getScopeName());
-      (*ret)[i]=CORBA::string_dup(name);
-      CORBA::string_free(name);
-    }
+  for(std::size_t i=0;i<sz;i++)
+    (*ret)[i]=CORBA::string_dup(scopes[i].c_str());
   return ret;
 }
 
 SALOME::DataScopeServer_ptr DataServerManager::getDefaultScope()
 {
-  return SALOME::DataScopeServer::_duplicate(_ptr_dft_scope);
+  return retriveDataScope(DFT_SCOPE_NAME_IN_NS);
 }
 
 SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName)
 {
   std::string scopeNameCpp(scopeName);
-  std::size_t sz(_scopes.size());
-  std::list< SALOME::DataScopeServer_var >::iterator it(_scopes.begin());
-  for(std::size_t i=0;i<sz;it++,i++)
+  std::vector<std::string> 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<std::string> scopeNames(listOfScopesCpp());
+  for(std::vector<std::string>::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<std::string> 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;i<sz;it++,i++)
-    {
-      CORBA::String_var zeName((*it)->getScopeName());
-      found=(scopeName==(const char *)zeName);
-      if(found)
-        break;
-    }
-  if(!found)
+  SALOME_NamingService ns(_orb);
+  ns.Change_Directory(NAME_IN_NS);
+  std::vector<std::string> ret(ns.list_directory());
+  return ret;
+}
+
+SALOME::DataScopeServer_var DataServerManager::getScopePtrGivenName(const std::string& scopeName)
+{
+  std::vector<std::string> 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;
 }
index 55fcd62e39b5ae0d9bbbcb3981505fe0cc242a4b..8f0447b86557312f1c39f6073f0efd785dbd9748 100644 (file)
@@ -27,7 +27,6 @@
 #include "SALOMESDS_AutoRefCountPtr.hxx"
 #include "SALOMESDS_DataScopeServer.hxx"
 
-#include <list>
 #include <string>
 
 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<std::string> listOfScopesCpp();
+    SALOME::DataScopeServer_var getScopePtrGivenName(const std::string& scopeName);
   private:
-    AutoRefCountPtr<DataScopeServer> _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;
index 6dac946379a932cd78ae31654d6713eab6527eaa..e68715586fe1e82e2913f750ec773ee73eb622e9 100644 (file)
@@ -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;
 }