]> SALOME platform Git repositories - samples/hello.git/commitdiff
Salome HOME
Make HELLO component appear into "salome sesionless"
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 30 Jul 2021 08:19:56 +0000 (10:19 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 30 Jul 2021 11:52:31 +0000 (13:52 +0200)
resources/CMakeLists.txt
src/HELLO/CMakeLists.txt
src/HELLO/HELLO.cxx
src/HELLO/HELLO.hxx
src/HELLO/HELLO_Component_Generator.cxx [new file with mode: 0644]
src/HELLO/HELLO_Component_Generator.hxx [new file with mode: 0644]
src/HELLOGUI/HELLOGUI.cxx

index 2fb561f56e95510621289afe687c215bd160573b..69768ce09ef96cc5d3508f2f75a68452f582da50 100644 (file)
@@ -30,4 +30,5 @@ SET(HELLO_RESOURCES_FILES
 INSTALL(FILES ${HELLO_RESOURCES_FILES} DESTINATION ${SALOME_HELLO_INSTALL_RES_DATA})
 
 SALOME_CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/SalomeApp.xml.in ${CMAKE_CURRENT_BINARY_DIR}/SalomeApp.xml INSTALL ${SALOME_HELLO_INSTALL_RES_DATA})
 INSTALL(FILES ${HELLO_RESOURCES_FILES} DESTINATION ${SALOME_HELLO_INSTALL_RES_DATA})
 
 SALOME_CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/SalomeApp.xml.in ${CMAKE_CURRENT_BINARY_DIR}/SalomeApp.xml INSTALL ${SALOME_HELLO_INSTALL_RES_DATA})
+SALOME_CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/SalomeApp.xml.in ${CMAKE_CURRENT_BINARY_DIR}/SalomeAppSL.xml INSTALL ${SALOME_HELLO_INSTALL_RES_DATA})
 SALOME_CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/HELLOCatalog.xml.in ${CMAKE_CURRENT_BINARY_DIR}/HELLOCatalog.xml INSTALL ${SALOME_HELLO_INSTALL_RES_DATA})
\ No newline at end of file
 SALOME_CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/HELLOCatalog.xml.in ${CMAKE_CURRENT_BINARY_DIR}/HELLOCatalog.xml INSTALL ${SALOME_HELLO_INSTALL_RES_DATA})
\ No newline at end of file
index 17a85db16e0ec01acef0132ad488df88e36fb14b..91cb3842c38822b073f74cf319176a2f67b5d995 100644 (file)
@@ -46,6 +46,7 @@ SET(_link_LIBRARIES
 # header files / no moc processing
 SET(HELLO_HEADERS
   HELLO.hxx
 # header files / no moc processing
 SET(HELLO_HEADERS
   HELLO.hxx
+  HELLO_Component_Generator.hxx
 )
 
 # --- sources ---
 )
 
 # --- sources ---
@@ -53,6 +54,7 @@ SET(HELLO_HEADERS
 # sources / static
 SET(HELLO_SOURCES
   HELLO.cxx
 # sources / static
 SET(HELLO_SOURCES
   HELLO.cxx
+  HELLO_Component_Generator.cxx
 )
 
 # --- rules ---
 )
 
 # --- rules ---
index edb03173e3e4a81272d5c4a899769c3e0e39d2b2..709f40f8e9f981f762c8aa637d253ea2550a25c1 100644 (file)
@@ -51,12 +51,13 @@ namespace {
   \param instanceName SALOME component instance name
   \param interfaceName SALOME component interface name
 */
   \param instanceName SALOME component instance name
   \param interfaceName SALOME component interface name
 */
-HELLO::HELLO( CORBA::ORB_ptr orb,
+HELLO_Abstract::HELLO_Abstract( CORBA::ORB_ptr orb,
              PortableServer::POA_ptr poa,
              PortableServer::ObjectId* contId, 
              const char* instanceName, 
              PortableServer::POA_ptr poa,
              PortableServer::ObjectId* contId, 
              const char* instanceName, 
-             const char* interfaceName )
-  : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
+             const char* interfaceName,
+        bool withRegistry)
+  : Engines_Component_i( orb, poa, contId, instanceName, interfaceName, false, withRegistry)
 {
   _thisObj = this;
   _id = _poa->activate_object( _thisObj ); // register and activate this servant object
 {
   _thisObj = this;
   _id = _poa->activate_object( _thisObj ); // register and activate this servant object
@@ -67,7 +68,7 @@ HELLO::HELLO( CORBA::ORB_ptr orb,
 
   Clean up allocated resources
 */
 
   Clean up allocated resources
 */
-HELLO::~HELLO()
+HELLO_Abstract::~HELLO_Abstract()
 {
   // nothing to do
 }
 {
   // nothing to do
 }
@@ -77,7 +78,7 @@ HELLO::~HELLO()
   \param name person's name
   \return operation status
 */
   \param name person's name
   \return operation status
 */
-HELLO_ORB::status HELLO::hello( const char* name )
+HELLO_ORB::status HELLO_Abstract::hello( const char* name )
 {
   // set exception handler to catch unexpected CORBA exceptions
   Unexpect aCatch(SALOME_SalomeException);
 {
   // set exception handler to catch unexpected CORBA exceptions
   Unexpect aCatch(SALOME_SalomeException);
@@ -85,7 +86,7 @@ HELLO_ORB::status HELLO::hello( const char* name )
   // set result status to error initially
   HELLO_ORB::status result = HELLO_ORB::OP_ERR_UNKNOWN;
 
   // set result status to error initially
   HELLO_ORB::status result = HELLO_ORB::OP_ERR_UNKNOWN;
 
-  SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
+  SALOMEDS::Study_var aStudy = this->getStudyServant();
   // check if reference to study is valid
   if ( !CORBA::is_nil( aStudy ) ) {
     // get full object path
   // check if reference to study is valid
   if ( !CORBA::is_nil( aStudy ) ) {
     // get full object path
@@ -143,7 +144,7 @@ HELLO_ORB::status HELLO::hello( const char* name )
   \param name person's name
   \return operation status
 */
   \param name person's name
   \return operation status
 */
-HELLO_ORB::status HELLO::goodbye( const char* name )
+HELLO_ORB::status HELLO_Abstract::goodbye( const char* name )
 {
   // set exception handler to catch unexpected CORBA exceptions
   Unexpect aCatch(SALOME_SalomeException);
 {
   // set exception handler to catch unexpected CORBA exceptions
   Unexpect aCatch(SALOME_SalomeException);
@@ -151,7 +152,7 @@ HELLO_ORB::status HELLO::goodbye( const char* name )
   // set result status to error initially
   HELLO_ORB::status result = HELLO_ORB::OP_ERR_UNKNOWN;
 
   // set result status to error initially
   HELLO_ORB::status result = HELLO_ORB::OP_ERR_UNKNOWN;
 
-  SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
+  SALOMEDS::Study_var aStudy = this->getStudyServant();
   // check if reference to study is valid
   if ( !CORBA::is_nil( aStudy ) ) {
     // get full object path
   // check if reference to study is valid
   if ( !CORBA::is_nil( aStudy ) ) {
     // get full object path
@@ -205,13 +206,13 @@ HELLO_ORB::status HELLO::goodbye( const char* name )
   \param row position in the parent object's children list at which objects are copied/moved
   \param isCopy \c true if object are copied or \c false otherwise
 */
   \param row position in the parent object's children list at which objects are copied/moved
   \param isCopy \c true if object are copied or \c false otherwise
 */
-void HELLO::copyOrMove( const HELLO_ORB::object_list& what,
+void HELLO_Abstract::copyOrMove( const HELLO_ORB::object_list& what,
                        SALOMEDS::SObject_ptr where,
                        CORBA::Long row, CORBA::Boolean isCopy )
 {
   if ( CORBA::is_nil( where ) ) return; // bad parent
 
                        SALOMEDS::SObject_ptr where,
                        CORBA::Long row, CORBA::Boolean isCopy )
 {
   if ( CORBA::is_nil( where ) ) return; // bad parent
 
-  SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
+  SALOMEDS::Study_var aStudy = this->getStudyServant();
   SALOMEDS::StudyBuilder_var studyBuilder = aStudy->NewBuilder();               // study builder
   SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();    // use case builder
   SALOMEDS::SComponent_var father = where->GetFatherComponent();               // father component
   SALOMEDS::StudyBuilder_var studyBuilder = aStudy->NewBuilder();               // study builder
   SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();    // use case builder
   SALOMEDS::SComponent_var father = where->GetFatherComponent();               // father component
@@ -250,7 +251,7 @@ void HELLO::copyOrMove( const HELLO_ORB::object_list& what,
 }
 
 // Version information
 }
 
 // Version information
-char* HELLO::getVersion()
+char* HELLO_Abstract::getVersion()
 {
 #if defined(HELLO_DEVELOPMENT)
   return CORBA::string_dup(HELLO_VERSION_STR"dev");
 {
 #if defined(HELLO_DEVELOPMENT)
   return CORBA::string_dup(HELLO_VERSION_STR"dev");
@@ -259,6 +260,18 @@ char* HELLO::getVersion()
 #endif
 }
 
 #endif
 }
 
+SALOMEDS::Study_var HELLO_Session::getStudyServant()
+{
+  return KERNEL::getStudyServant();
+}
+
+#include "SALOMEDS_Study_i.hxx"
+
+SALOMEDS::Study_var HELLO_No_Session::getStudyServant()
+{
+  return SALOMEDS::Study::_duplicate(KERNEL::getStudyServantSA());
+}
+
 extern "C"
 {
   /*!
 extern "C"
 {
   /*!
@@ -276,7 +289,7 @@ extern "C"
                                                 const char* instanceName, 
                                                 const char* interfaceName )
   {
                                                 const char* instanceName, 
                                                 const char* interfaceName )
   {
-    HELLO* component = new HELLO( orb, poa, contId, instanceName, interfaceName );
+    HELLO_Session* component = new HELLO_Session( orb, poa, contId, instanceName, interfaceName );
     return component->getId();
   }
 }
     return component->getId();
   }
 }
index 0790736af522561d9829f7e05a76b9f14a290005..f55129051b66e8620186d4e9f9631bc11eaf3e57 100644 (file)
 #include CORBA_SERVER_HEADER(HELLO_Gen)
 #include <SALOME_Component_i.hxx>
 
 #include CORBA_SERVER_HEADER(HELLO_Gen)
 #include <SALOME_Component_i.hxx>
 
-class HELLOENGINE_EXPORT HELLO :
+class HELLOENGINE_EXPORT HELLO_Abstract :
   public POA_HELLO_ORB::HELLO_Gen,
   public Engines_Component_i 
 {
 public:
   public POA_HELLO_ORB::HELLO_Gen,
   public Engines_Component_i 
 {
 public:
-  HELLO( CORBA::ORB_ptr orb,
+  HELLO_Abstract( CORBA::ORB_ptr orb,
         PortableServer::POA_ptr poa,
         PortableServer::ObjectId* contId, 
         const char* instanceName, 
         PortableServer::POA_ptr poa,
         PortableServer::ObjectId* contId, 
         const char* instanceName, 
-        const char* interfaceName );
-  virtual ~HELLO();
+        const char* interfaceName ,
+        bool withRegistry = true);
+  virtual ~HELLO_Abstract();
 
   HELLO_ORB::status hello  ( const char* name );
   HELLO_ORB::status goodbye( const char* name );
 
   HELLO_ORB::status hello  ( const char* name );
   HELLO_ORB::status goodbye( const char* name );
@@ -56,6 +57,30 @@ public:
                                SALOMEDS::SObject_ptr where,
                                CORBA::Long row, CORBA::Boolean isCopy );
   virtual char*     getVersion();
                                SALOMEDS::SObject_ptr where,
                                CORBA::Long row, CORBA::Boolean isCopy );
   virtual char*     getVersion();
+  // Get Study
+  virtual SALOMEDS::Study_var getStudyServant() = 0;
+};
+
+class HELLOENGINE_EXPORT HELLO_Session : public HELLO_Abstract
+{
+public:
+  HELLO_Session( CORBA::ORB_ptr orb,
+        PortableServer::POA_ptr poa,
+        PortableServer::ObjectId* contId, 
+        const char* instanceName, 
+        const char* interfaceName):HELLO_Abstract(orb,poa,contId,instanceName,interfaceName,true) { }
+   SALOMEDS::Study_var getStudyServant() override;
+};
+
+class HELLOENGINE_EXPORT HELLO_No_Session : public HELLO_Abstract
+{
+public:
+  HELLO_No_Session( CORBA::ORB_ptr orb,
+        PortableServer::POA_ptr poa,
+        PortableServer::ObjectId* contId, 
+        const char* instanceName, 
+        const char* interfaceName):HELLO_Abstract(orb,poa,contId,instanceName,interfaceName,false) { }
+  SALOMEDS::Study_var getStudyServant() override;
 };
 
 extern "C"
 };
 
 extern "C"
diff --git a/src/HELLO/HELLO_Component_Generator.cxx b/src/HELLO/HELLO_Component_Generator.cxx
new file mode 100644 (file)
index 0000000..3ab5256
--- /dev/null
@@ -0,0 +1,57 @@
+// 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 "HELLO_Component_Generator.hxx"
+
+#include "HELLO.hxx"
+#include "SALOME_Container_i.hxx"
+#include "SALOME_KernelServices.hxx"
+
+#include <cstring>
+
+static Engines::EngineComponent_var _unique_compo;
+
+Engines::EngineComponent_var RetrieveHELLOInstance()
+{
+  constexpr char COMPO_NAME[]="HELLO";
+  if (CORBA::is_nil(_unique_compo))
+  {
+    CORBA::ORB_var orb;
+    {
+      int argc(0);
+      orb = CORBA::ORB_init(argc, nullptr);
+    }
+    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
+    PortableServer::POAManager_var pman = poa->the_POAManager();
+    CORBA::PolicyList policies;
+    policies.length(0);
+    auto *cont(KERNEL::getContainerSA());
+    PortableServer::ObjectId *conId(cont->getCORBAId());
+    //
+    pman->activate();
+    //
+    HELLO_No_Session *servant = new HELLO_No_Session(orb, poa, conId, "HELLO_inst_2", COMPO_NAME);
+    PortableServer::ObjectId *zeId = servant->getId();
+    CORBA::Object_var zeRef = poa->id_to_reference(*zeId);
+    KERNEL::RegisterCompo(COMPO_NAME,zeRef);
+    _unique_compo = Engines::EngineComponent::_narrow(zeRef);
+  }
+  return _unique_compo;
+}
diff --git a/src/HELLO/HELLO_Component_Generator.hxx b/src/HELLO/HELLO_Component_Generator.hxx
new file mode 100644 (file)
index 0000000..3c6145f
--- /dev/null
@@ -0,0 +1,28 @@
+// 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 "HELLO.hxx"
+
+#include "SALOMEconfig.h"
+
+#include CORBA_SERVER_HEADER(HELLO_Gen)
+
+HELLOENGINE_EXPORT Engines::EngineComponent_var RetrieveHELLOInstance();
index 91582ebb7ade2a1292f02cfc81c697db071eebfd..d9c8dc4362fe91c34fd94268605b6db961d97bb8 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "HELLOGUI.h"
 #include "HELLO_version.h"
 
 #include "HELLOGUI.h"
 #include "HELLO_version.h"
+#include "HELLO_Component_Generator.hxx"
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
@@ -40,6 +41,8 @@
 #include <SALOME_LifeCycleCORBA.hxx>
 #include <SALOMEDS_SObject.hxx>
 #include <SALOMEDS_Study.hxx>
 #include <SALOME_LifeCycleCORBA.hxx>
 #include <SALOMEDS_SObject.hxx>
 #include <SALOMEDS_Study.hxx>
+#include "SALOME_NamingService_Abstract.hxx"
+#include "SALOME_KernelServices.hxx"
 
 #include <QInputDialog>
 
 
 #include <QInputDialog>
 
@@ -881,9 +884,20 @@ void HELLOGUI::goodbye()
 void HELLOGUI::init()
 {
   // initialize HELLO module engine (load, if necessary)
 void HELLOGUI::init()
 {
   // initialize HELLO module engine (load, if necessary)
-  if ( CORBA::is_nil( myEngine ) ) {
-    Engines::EngineComponent_var comp =
-    SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "HELLO" );
+  if ( CORBA::is_nil( myEngine ) )
+  {
+    SALOME_NamingService_Abstract *ns = SalomeApp_Application::namingService();
+    Engines::EngineComponent_var comp;
+    if(ns->IsTrueNS())
+    {
+      comp = SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "HELLO" );
+    }
+    else
+    {
+      comp = RetrieveHELLOInstance();
+      CORBA::Object_var comp2 = CORBA::Object::_narrow(comp);
+      KERNEL::RegisterCompo("HELLO",comp2);
+    }
     myEngine = HELLO_ORB::HELLO_Gen::_narrow( comp );
   }
 }
     myEngine = HELLO_ORB::HELLO_Gen::_narrow( comp );
   }
 }