]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Make the EDF non reg test work in SSL mode : Bug14551_reloadStudy.py
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 17 Aug 2021 07:41:34 +0000 (09:41 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 17 Aug 2021 07:41:34 +0000 (09:41 +0200)
src/KERNEL_PY/__init__.py
src/KERNEL_PY/salome_study.py
src/SALOMEDS/KernelDS.cxx
src/SALOMEDS/KernelDS.hxx
src/SALOMEDS/KernelDS.i
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx

index 8a62c4a4226623f12ee4854d1be856fd5168a743..7b99a03e48498fa6999ea83e2b4205de950c0d64 100644 (file)
@@ -280,6 +280,8 @@ def salome_close():
     salome_iapp_close()
     salome_study_close()
     myStudy, myStudyName = None, None
+    import KernelDS
+    KernelDS.KillGlobalSessionInstance()
     pass
 
 def salome_NS():
index 57d2d71277c51e136002380b1b8d74556689d5fc..c8fab2542b9bcece546963276dd4be76e91c5c91 100644 (file)
@@ -302,6 +302,14 @@ def salome_study_init_without_session(theStudyPath=None):
         if verbose(): print("Study found")
         pass
 
+    import types
+    if theStudyPath and isinstance(theStudyPath, (str, bytes)):
+        if isinstance(theStudyPath, bytes):
+            theStudyPath = str(theStudyPath, 'UTF8')
+        openStudy(theStudyPath)
+    else:
+        myStudy.Init()
+
     myStudyName = myStudy._get_Name()
 
     return myStudy, myStudyName
index 82fe2aefb474588a575293592248e890ed640f7c..ef6ca4e244d92e2f4a451baad6e89c478c6a260d 100644 (file)
 
 std::string GetSessionInstance()
 {
-    SALOMEDS::Study_var study = KERNEL::getStudyServantSA();
-    CORBA::ORB_ptr orb = KERNEL::getORB();
-    CORBA::String_var ior = orb->object_to_string(study);
-    return std::string(ior.in());
+  SALOMEDS::Study_var study = KERNEL::getStudyServantSA();
+  CORBA::ORB_ptr orb = KERNEL::getORB();
+  CORBA::String_var ior = orb->object_to_string(study);
+  return std::string(ior.in());
 }
+
+std::string GetNewSessionInstance()
+{
+  SALOMEDS::Study_var study = KERNEL::retrieveNewStudyServantSA();
+  KERNEL::setStudyServantSA(study);
+  CORBA::ORB_ptr orb = KERNEL::getORB();
+  CORBA::String_var ior = orb->object_to_string(study);
+  return std::string(ior.in());
+}
+
+void KillGlobalSessionInstance()
+{
+  KERNEL::killStudyServantSA();
+}
\ No newline at end of file
index c60e72ee77e8e6cbac87d8f51a6a4215f83b25c8..53af1598dde5f739c893d0f883cf84e36c792c3c 100644 (file)
@@ -21,4 +21,7 @@
 #include <string>
 
 std::string GetSessionInstance();
+std::string GetNewSessionInstance();
+void KillGlobalSessionInstance();
+
 #endif
index 278870731f16afa56227b195a7d9092e345a73a0..663c32a363072a292f69972d62743a62ea1b921c 100644 (file)
@@ -27,7 +27,9 @@
 
 %inline
 {
-    std::string GetSessionInstance();
+  std::string GetSessionInstance();
+  std::string GetNewSessionInstance();
+  void KillGlobalSessionInstance();
 }
 
 %pythoncode %{
@@ -36,4 +38,10 @@ def myStudy():
   import CORBA
   orb=CORBA.ORB_init([''])
   return orb.string_to_object(GetSessionInstance())
+
+def myNewStudy():
+  import SALOMEDS
+  import CORBA
+  orb=CORBA.ORB_init([''])
+  return orb.string_to_object(GetNewSessionInstance())
 %}
index 96a37ba1d58e90d0d447a7b273bfe16805b542d1..42da7d8c66e2174805841699c7ecc3efe6755e59 100644 (file)
@@ -76,24 +76,28 @@ static SALOMEDS::Study_var _study;
  */
 SALOMEDS::Study_ptr KERNEL::getStudyServantSA()
 {
-
   if(CORBA::is_nil(_study))
   {
-    CORBA::ORB_ptr orb = KERNEL::getORB();
-    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
-    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
-    _poa = PortableServer::POA::_duplicate(poa);
-    SALOME_Fake_NamingService ns;
-    SALOMEDS_Study_i *servant = new SALOMEDS_Study_i(orb,&ns);
-    _study = servant->_this();
+    _study = retrieveNewStudyServantSA();
   }
   return SALOMEDS::Study::_duplicate(_study);
 }
 
-/**
- * If a study is already built and activated elsewhere (for example in GUI context)
- */
-void KERNEL::setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa)
+SALOMEDS::Study_var KERNEL::retrieveNewStudyServantSA()
+{
+  CORBA::ORB_ptr orb = KERNEL::getORB();
+  CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+  PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
+  if(CORBA::is_nil(_poa))
+    _poa = poa;
+  SALOME_Fake_NamingService *ns = new SALOME_Fake_NamingService;
+  SALOMEDS_Study_i *servant = new SALOMEDS_Study_i(orb,ns);
+  SALOMEDS::Study_var study = servant->_this();
+  servant->_remove_ref();
+  return study;
+}
+
+void KERNEL::killStudyServantSA()
 {
   if( ! CORBA::is_nil(_study) )
   {
@@ -101,12 +105,29 @@ void KERNEL::setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_va
     try
     {
       serv = _poa->reference_to_servant(_study);
+      PortableServer::ObjectId_var anObjectId = _poa->servant_to_id(serv);
+      _poa->deactivate_object(anObjectId);
     }
     catch(...) { }
     if(serv)
       serv->_remove_ref();
   }
-  _study = study; _poa = poa;
+  _study = SALOMEDS::Study::_nil();
+}
+
+/**
+ * If a study is already built and activated elsewhere (for example in GUI context)
+ */
+void KERNEL::setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa)
+{
+  _poa = poa;
+  setStudyServantSA(study);
+}
+
+void KERNEL::setStudyServantSA(SALOMEDS::Study_var study)
+{
+  killStudyServantSA();
+  _study = study;
 }
 
 namespace SALOMEDS
@@ -290,9 +311,8 @@ namespace SALOMEDS
    */
   //================================================================================
 
-  void sendMessageToGUI(const char* msg )
+  void sendMessageToGUI(SALOME_NamingService_Abstract *aNamingService, const char* msg)
   {
-    SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService();
     CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
     SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
     sendMessageToGUIGivenSession(aSession,msg);
@@ -302,12 +322,12 @@ namespace SALOMEDS
 
 SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME_NamingService_Abstract *ns)
 {
-  SALOME_NamingService_Abstract *aNamingService = ns==nullptr?KERNEL::getNamingService():ns;
+  _ns = ns==nullptr?KERNEL::getNamingService():ns;
   _orb     = CORBA::ORB::_duplicate(orb);
   _impl    = new SALOMEDSImpl_Study();
-  _factory = new SALOMEDS_DriverFactory_i(_orb,aNamingService);
+  _factory = new SALOMEDS_DriverFactory_i(_orb,_ns);
   _closed  = true;
-  CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
+  CORBA::Object_var obj = _ns->Resolve("/Kernel/Session");
   SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
   Init(aSession);
 }
@@ -319,6 +339,7 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME_NamingService_Abst
 //============================================================================
 SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME::Session_ptr session)
 {
+  _ns = KERNEL::getNamingService();
   _orb     = CORBA::ORB::_duplicate(orb);
   _impl    = new SALOMEDSImpl_Study();
   _factory = new SALOMEDS_DriverFactory_i(_orb,!CORBA::is_nil(session));
@@ -337,12 +358,15 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i()
   Clear();
   delete _factory;
   delete _impl;
+  //_ns is owned by SALOMEDS_Study_i only if IsTrueNS() returns false
+  if(_ns)
+    if(!_ns->IsTrueNS())
+      delete _ns;
 }
 
 void SALOMEDS_Study_i::Init()
 {
-  SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService();
-  CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
+  CORBA::Object_var obj = _ns->Resolve("/Kernel/Session");
   SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
   Init(aSession);
 }
@@ -432,7 +456,7 @@ void SALOMEDS_Study_i::Clear()
   }
 
   // Notify GUI that study is cleared
-  SALOMEDS::sendMessageToGUI( "studyCleared" );
+  SALOMEDS::sendMessageToGUI( _ns, "studyCleared" );
 
   _impl->Clear();
   _impl->setNotifier(0);
@@ -480,7 +504,7 @@ bool SALOMEDS_Study_i::Open(const wchar_t* aWUrl)
 
   // update desktop title with new study name
   //NameChanged();
-  SALOMEDS::sendMessageToGUI( "connect_to_study" );
+  SALOMEDS::sendMessageToGUI( _ns, "connect_to_study" );
 
   if ( !res )
     THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM)
@@ -1051,8 +1075,7 @@ void SALOMEDS_Study_i::URL(const wchar_t* wurl)
   _impl->URL(Kernel_Utils::encode_s(wurl));
 
   // update desktop title with new study name
-  SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService();
-  CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session");
+  CORBA::Object_var obj = _ns->Resolve("/Kernel/Session");
   SALOME::Session_var aSession = SALOME::Session::_narrow(obj);
   NameChanged(aSession);
 }
index 50a69af137924994c2fc50b3833ce40b1d404398..8de709f1747482e02ce2de97cd632803513c853b 100644 (file)
@@ -51,6 +51,9 @@ class SALOME_NamingService_Abstract;
 namespace KERNEL
 {
   Standard_EXPORT SALOMEDS::Study_ptr getStudyServantSA();
+  Standard_EXPORT SALOMEDS::Study_var retrieveNewStudyServantSA();
+  Standard_EXPORT void killStudyServantSA();
+  Standard_EXPORT void setStudyServantSA(SALOMEDS::Study_var study);
   Standard_EXPORT void setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa);
 }
 
@@ -66,6 +69,8 @@ private:
   SALOMEDSImpl_AbstractCallback* _genObjRegister;
   SALOMEDS_DriverFactory_i*      _factory;
   bool                           _closed;
+  //! naming service object to retrieve session. _ns is owned by SALOMEDS_Study_i only if IsTrueNS() returns false
+  SALOME_NamingService_Abstract *_ns = nullptr;
 
 public:
   //! standard constructor