]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
OK for container_i servant
authorAnthony GEAY <anthony.geay@edf.fr>
Fri, 19 Feb 2021 13:46:40 +0000 (14:46 +0100)
committerAnthony GEAY <anthony.geay@edf.fr>
Fri, 19 Feb 2021 13:46:40 +0000 (14:46 +0100)
src/Session/CMakeLists.txt
src/Session/SALOME_Session_Server.cxx
src/Session/Session_NS_wrapper.cxx [new file with mode: 0644]
src/Session/Session_NS_wrapper.hxx [new file with mode: 0644]
src/Session/Session_ServerLauncher.cxx
src/Session/Session_ServerThread.cxx
src/Session/Session_ServerThread.hxx

index 77038452fa8b8df0c429594bb092cfa75b92a3e1..5a783b5080990e6076ebd86cb6d150248e1744f1 100644 (file)
@@ -82,6 +82,7 @@ SET(SalomeSession_HEADERS
   Session_ServerThread.hxx
   Session_Session_i.hxx
   Session_Promises.hxx
+  Session_NS_wrapper.hxx
 )
 
 # --- resources ---
@@ -100,6 +101,7 @@ SET(SalomeSession_SOURCES
   Session_ServerThread.cxx
   Session_Session_i.cxx
   Session_Promises.cxx
+  Session_NS_wrapper.cxx
 )
 
 # --- rules ---
index 464f68e1f4f05e10a79ad2adf07b82183d8552af..4b7d802d041c5bb786c2b3b5f54f7fb001b1f44d 100644 (file)
@@ -38,7 +38,7 @@
 #include "Session_ServerCheck.hxx"
 #include "Session_ServerLauncher.hxx"
 #include "Session_Promises.hxx"
-#include "SALOME_Fake_NamingService.hxx"
+#include "Session_NS_wrapper.hxx"
 
 #include "GUI_version.h"
 #include "Qtx.h"
@@ -459,7 +459,7 @@ SALOME::Session_var GUIAppNewStyle::getSession()
 // ---------------------------- MAIN -----------------------
 int AbstractGUIApp::main(int argc, char **argv)
 {
-  using NamingServiceImplementation = SALOME_Fake_NamingService;
+  using NamingServiceImplementation = NewStyleNS;
   // Set-up application settings configuration (as for QSettings)
   // Note: these are default settings which can be customized (see below)
   QApplication::setOrganizationName("salome");
diff --git a/src/Session/Session_NS_wrapper.cxx b/src/Session/Session_NS_wrapper.cxx
new file mode 100644 (file)
index 0000000..b65708d
--- /dev/null
@@ -0,0 +1,109 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "Session_NS_wrapper.hxx"
+
+#include "SALOME_Container_i.hxx"
+#include "utilities.h"
+
+Engines_Container_i *OldStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
+{
+  Engines_Container_i *_container = nullptr;
+  try
+  {
+    MESSAGE("Container thread started");
+
+    // get or create the child POA
+
+    PortableServer::POA_var factory_poa;
+    try
+    {
+      factory_poa = poa->find_POA("factory_poa", 0);
+      // 0 = no activation (already done if exists)
+    }
+    catch (PortableServer::POA::AdapterNonExistent &)
+    {
+      MESSAGE("factory_poa does not exists, create...");
+      // define policy objects
+      PortableServer::ImplicitActivationPolicy_var implicitActivation =
+          poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
+      // default = NO_IMPLICIT_ACTIVATION
+      PortableServer::ThreadPolicy_var threadPolicy =
+          poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
+      // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
+
+      // create policy list
+      CORBA::PolicyList policyList;
+      policyList.length(2);
+      policyList[0] = PortableServer::ImplicitActivationPolicy::
+          _duplicate(implicitActivation);
+      policyList[1] = PortableServer::ThreadPolicy::
+          _duplicate(threadPolicy);
+
+      PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil();
+      factory_poa = poa->create_POA("factory_poa",
+                                    nil_mgr,
+                                    policyList);
+      //with nil_mgr instead of pman,
+      //a new POA manager is created with the new POA
+
+      // destroy policy objects
+      implicitActivation->destroy();
+      threadPolicy->destroy();
+
+      // obtain the factory poa manager
+      PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
+      pmanfac->activate();
+      MESSAGE("pmanfac->activate()");
+    }
+
+    char *containerName = (char *)"";
+    if (argc > 1)
+    {
+      containerName = argv[1];
+    }
+    _container = new Engines_Container_i(orb, poa, containerName, argc, argv, true, false);
+  }
+  catch (CORBA::SystemException &)
+  {
+    INFOS("Caught CORBA::SystemException.");
+  }
+  catch (PortableServer::POA::WrongPolicy &)
+  {
+    INFOS("Caught CORBA::WrongPolicyException.");
+  }
+  catch (PortableServer::POA::ServantAlreadyActive &)
+  {
+    INFOS("Caught CORBA::ServantAlreadyActiveException");
+  }
+  catch (CORBA::Exception &)
+  {
+    INFOS("Caught CORBA::Exception.");
+  }
+  catch (...)
+  {
+    INFOS("Caught unknown exception.");
+  }
+  return _container;
+}
+
+Engines_Container_i *NewStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
+{
+  return KERNEL::getContainerSA();
+}
diff --git a/src/Session/Session_NS_wrapper.hxx b/src/Session/Session_NS_wrapper.hxx
new file mode 100644 (file)
index 0000000..44fccdf
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "SALOME_NamingService.hxx"
+
+#include "omniORB4/CORBA.h"
+
+class Engines_Container_i;
+
+class OldStyleNS
+{
+public:
+  using RealNS = SALOME_NamingService;
+public:
+  OldStyleNS(CORBA::ORB_ptr orb):_NS(orb) {}
+  void Register(CORBA::Object_ptr ObjRef, const char* Path) { _NS.Register(ObjRef,Path); }
+  CORBA::Object_ptr Resolve(const char* Path) { return _NS.Resolve(Path); }
+  RealNS *getNS() { return &_NS; }
+  Engines_Container_i *activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char** argv);
+private:
+  RealNS _NS;
+};
+
+#include "SALOME_Fake_NamingService.hxx"
+
+class NewStyleNS
+{
+public:
+  using RealNS = SALOME_Fake_NamingService;
+public:
+  NewStyleNS(CORBA::ORB_ptr orb):_NS(orb) {}
+  void Register(CORBA::Object_ptr ObjRef, const char* Path) { _NS.Register(ObjRef,Path); }
+  CORBA::Object_ptr Resolve(const char* Path) { return _NS.Resolve(Path); }
+  RealNS *getNS() { return &_NS; }
+  Engines_Container_i *activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char** argv);
+private:
+  RealNS _NS;
+};
index 730e7f0897c3da7bb2af2e90de34f1b49b5cab7c..73ed5b1186583e53346036d9d5f566698bbca17c 100644 (file)
@@ -262,8 +262,8 @@ void Session_ServerLauncher<MY_NS>::KillAll()
   }
 }
 
-template class Session_ServerLauncher<SALOME_NamingService>;
+#include "Session_NS_wrapper.hxx" 
 
-#include "SALOME_Fake_NamingService.hxx"
+template class Session_ServerLauncher<OldStyleNS>;
 
-template class Session_ServerLauncher<SALOME_Fake_NamingService>;
+template class Session_ServerLauncher<NewStyleNS>;
index fc1d2ac91f1e13c5b27751bc7d356c85cd8991a4..e1effb791e9accedd73d45837bac594f3bb477fe 100644 (file)
@@ -123,42 +123,42 @@ void Session_ServerThread<MY_NS>::Init()
       switch (_servType) {
       case 0:  // Container
         {
-          NamingService_WaitForServerReadiness(_NS.get(),"/Registry");
-          NamingService_WaitForServerReadiness(_NS.get(),"/ContainerManager");
+          NamingService_WaitForServerReadiness(this->getNS(),"/Registry");
+          NamingService_WaitForServerReadiness(this->getNS(),"/ContainerManager");
           ActivateContainer(_argc, _argv);
           break;
         }
       case 1:  // ModuleCatalog
         {
-          NamingService_WaitForServerReadiness(_NS.get(),"/Registry");
+          NamingService_WaitForServerReadiness(this->getNS(),"/Registry");
           ActivateModuleCatalog(_argc, _argv);
           break;
         }
       case 2:  // Registry
         {
-          NamingService_WaitForServerReadiness(_NS.get(),"");
+          NamingService_WaitForServerReadiness(this->getNS(),"");
           ActivateRegistry(_argc, _argv);
           break;
         }
       case 3:  // SALOMEDS
         {
-          NamingService_WaitForServerReadiness(_NS.get(),"/Kernel/ModulCatalog");
+          NamingService_WaitForServerReadiness(this->getNS(),"/Kernel/ModulCatalog");
           ActivateSALOMEDS(_argc, _argv);
           break;
         }
       case 4:  // Session
         {
-          NamingService_WaitForServerReadiness(_NS.get(),"/Study");
+          NamingService_WaitForServerReadiness(this->getNS(),"/Study");
           std::string containerName = "/Containers/";
           containerName = containerName + Kernel_Utils::GetHostname();
           containerName = containerName + "/FactoryServer";
-          NamingService_WaitForServerReadiness(_NS.get(),containerName);
+          NamingService_WaitForServerReadiness(this->getNS(),containerName);
           ActivateSession(_argc, _argv);
           break;
         }
       case 5: // Container Manager
         {
-          NamingService_WaitForServerReadiness(_NS.get(),"");
+          NamingService_WaitForServerReadiness(this->getNS(),"");
           ActivateContainerManager(_argc, _argv);
           break;
         }
@@ -325,77 +325,19 @@ void Session_ServerThread<MY_NS>::ActivateContainerManager(int /*argc*/, char**
   }
 }
 
+template<class MY_NS>
+typename MY_NS::RealNS *Session_ServerThread<MY_NS>::getNS()
+{
+  MY_NS *pt(_NS.get());
+  if(!pt)
+     THROW_SALOME_EXCEPTION("Session_ServerThread<MY_NS>::getNS : null pointer !");
+  return pt->getNS();
+}
+
 template<class MY_NS>
 void Session_ServerThread<MY_NS>::ActivateContainer(int argc, char** argv)
 {
-  try {
-    MESSAGE("Container thread started");
-    
-    // get or create the child POA
-    
-    PortableServer::POA_var factory_poa;
-    try {
-      factory_poa = _root_poa->find_POA("factory_poa",0);
-      // 0 = no activation (already done if exists)
-    }
-    catch (PortableServer::POA::AdapterNonExistent&) {
-      MESSAGE("factory_poa does not exists, create...");
-      // define policy objects     
-      PortableServer::ImplicitActivationPolicy_var implicitActivation =
-        _root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
-      // default = NO_IMPLICIT_ACTIVATION
-      PortableServer::ThreadPolicy_var threadPolicy =
-        _root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
-      // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
-      
-      // create policy list
-      CORBA::PolicyList policyList;
-      policyList.length(2);
-      policyList[0] = PortableServer::ImplicitActivationPolicy::
-        _duplicate(implicitActivation);
-      policyList[1] = PortableServer::ThreadPolicy::
-        _duplicate(threadPolicy);
-      
-      PortableServer::POAManager_var nil_mgr
-        = PortableServer::POAManager::_nil();
-      factory_poa = _root_poa->create_POA("factory_poa",
-                                          nil_mgr,
-                                          policyList);
-      //with nil_mgr instead of pman,
-      //a new POA manager is created with the new POA
-      
-      // destroy policy objects
-      implicitActivation->destroy();
-      threadPolicy->destroy();
-      
-      // obtain the factory poa manager
-      PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
-      pmanfac->activate();
-      MESSAGE("pmanfac->activate()");
-    }
-    
-    char *containerName = (char*)"";
-    if (argc >1) {
-      containerName = argv[1];
-    }
-    
-    _container = new Engines_Container_i(_orb, _root_poa, containerName, argc, argv, true, false);
-  }
-  catch(CORBA::SystemException&) {
-    INFOS("Caught CORBA::SystemException.");
-  }
-  catch(PortableServer::POA::WrongPolicy&) {
-    INFOS("Caught CORBA::WrongPolicyException.");
-  }
-  catch(PortableServer::POA::ServantAlreadyActive&) {
-    INFOS("Caught CORBA::ServantAlreadyActiveException");
-  }
-  catch(CORBA::Exception&) {
-    INFOS("Caught CORBA::Exception.");
-  }
-  catch(...) {
-    INFOS("Caught unknown exception.");
-  }
+  _container = this->_NS->activateContainer(this->_orb,this->_root_poa,argc,argv);
 }
 
 template<class MY_NS>
@@ -452,10 +394,8 @@ void Session_SessionThread<MY_NS>::ActivateSession(int argc, char ** argv)
   }
 }
 
-template class Session_ServerThread<SALOME_NamingService>;
-template class Session_SessionThread<SALOME_NamingService>;
-
-#include "SALOME_Fake_NamingService.hxx"
+template class Session_ServerThread<OldStyleNS>;
+template class Session_SessionThread<OldStyleNS>;
 
-template class Session_ServerThread<SALOME_Fake_NamingService>;
-template class Session_SessionThread<SALOME_Fake_NamingService>;
+template class Session_ServerThread<NewStyleNS>;
+template class Session_SessionThread<NewStyleNS>;
index 1df729038ba6e5cd2931cb4e6e56cb84fc9c5079..a10aca6dc54dbf3ca47a3fa57a8dce7b975ef70e 100644 (file)
@@ -27,6 +27,7 @@
 #ifndef _SESSION_SERVERTHREAD_HXX_
 #define _SESSION_SERVERTHREAD_HXX_
 
+#include "Session_NS_wrapper.hxx"
 #include "SALOME_Session.hxx"
 
 #include <omniORB4/CORBA.h> 
@@ -41,6 +42,8 @@ class Engines_Container_i;
 template<class MY_NS>
 class SESSION_EXPORT Session_ServerThread
 {
+public:
+  using RealNS = typename MY_NS::RealNS;
 public:
   static const int NB_SRV_TYP;
   static const char* _serverTypes[];
@@ -61,13 +64,14 @@ protected:
   virtual void ActivateSession         ( int argc, char ** argv );
   void         ActivateEngine          ( int argc, char ** argv );
   void         ActivateContainerManager( int argc, char ** argv );
+  RealNS *getNS();
 protected:
   int                     _argc;
   char **                 _argv;
   int                     _servType;
   CORBA::ORB_var          _orb;
   PortableServer::POA_var _root_poa;
-  std::unique_ptr<MY_NS> _NS;
+  std::unique_ptr<MY_NS>  _NS;
   Engines_Container_i*    _container;
 };