From 87b65d3a65a4ca2f90d85ef9bbe55f2c2b77826b Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 30 Jul 2021 10:19:56 +0200 Subject: [PATCH] Make HELLO component appear into "salome sesionless" --- resources/CMakeLists.txt | 1 + src/HELLO/CMakeLists.txt | 2 + src/HELLO/HELLO.cxx | 37 ++++++++++------ src/HELLO/HELLO.hxx | 33 ++++++++++++-- src/HELLO/HELLO_Component_Generator.cxx | 57 +++++++++++++++++++++++++ src/HELLO/HELLO_Component_Generator.hxx | 28 ++++++++++++ src/HELLOGUI/HELLOGUI.cxx | 20 +++++++-- 7 files changed, 159 insertions(+), 19 deletions(-) create mode 100644 src/HELLO/HELLO_Component_Generator.cxx create mode 100644 src/HELLO/HELLO_Component_Generator.hxx diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 2fb561f..69768ce 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -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}) +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 diff --git a/src/HELLO/CMakeLists.txt b/src/HELLO/CMakeLists.txt index 17a85db..91cb384 100644 --- a/src/HELLO/CMakeLists.txt +++ b/src/HELLO/CMakeLists.txt @@ -46,6 +46,7 @@ SET(_link_LIBRARIES # header files / no moc processing SET(HELLO_HEADERS HELLO.hxx + HELLO_Component_Generator.hxx ) # --- sources --- @@ -53,6 +54,7 @@ SET(HELLO_HEADERS # sources / static SET(HELLO_SOURCES HELLO.cxx + HELLO_Component_Generator.cxx ) # --- rules --- diff --git a/src/HELLO/HELLO.cxx b/src/HELLO/HELLO.cxx index edb0317..709f40f 100644 --- a/src/HELLO/HELLO.cxx +++ b/src/HELLO/HELLO.cxx @@ -51,12 +51,13 @@ namespace { \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, - 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 @@ -67,7 +68,7 @@ HELLO::HELLO( CORBA::ORB_ptr orb, Clean up allocated resources */ -HELLO::~HELLO() +HELLO_Abstract::~HELLO_Abstract() { // nothing to do } @@ -77,7 +78,7 @@ HELLO::~HELLO() \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); @@ -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; - 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 @@ -143,7 +144,7 @@ HELLO_ORB::status HELLO::hello( const char* name ) \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); @@ -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; - 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 @@ -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 */ -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::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 @@ -250,7 +251,7 @@ void HELLO::copyOrMove( const HELLO_ORB::object_list& what, } // Version information -char* HELLO::getVersion() +char* HELLO_Abstract::getVersion() { #if defined(HELLO_DEVELOPMENT) return CORBA::string_dup(HELLO_VERSION_STR"dev"); @@ -259,6 +260,18 @@ char* HELLO::getVersion() #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" { /*! @@ -276,7 +289,7 @@ extern "C" 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(); } } diff --git a/src/HELLO/HELLO.hxx b/src/HELLO/HELLO.hxx index 0790736..f551290 100644 --- a/src/HELLO/HELLO.hxx +++ b/src/HELLO/HELLO.hxx @@ -38,17 +38,18 @@ #include CORBA_SERVER_HEADER(HELLO_Gen) #include -class HELLOENGINE_EXPORT HELLO : +class HELLOENGINE_EXPORT HELLO_Abstract : 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, - 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 ); @@ -56,6 +57,30 @@ public: 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" diff --git a/src/HELLO/HELLO_Component_Generator.cxx b/src/HELLO/HELLO_Component_Generator.cxx new file mode 100644 index 0000000..3ab5256 --- /dev/null +++ b/src/HELLO/HELLO_Component_Generator.cxx @@ -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 + +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 index 0000000..3c6145f --- /dev/null +++ b/src/HELLO/HELLO_Component_Generator.hxx @@ -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(); diff --git a/src/HELLOGUI/HELLOGUI.cxx b/src/HELLOGUI/HELLOGUI.cxx index 91582eb..d9c8dc4 100644 --- a/src/HELLOGUI/HELLOGUI.cxx +++ b/src/HELLOGUI/HELLOGUI.cxx @@ -22,6 +22,7 @@ #include "HELLOGUI.h" #include "HELLO_version.h" +#include "HELLO_Component_Generator.hxx" #include #include @@ -40,6 +41,8 @@ #include #include #include +#include "SALOME_NamingService_Abstract.hxx" +#include "SALOME_KernelServices.hxx" #include @@ -881,9 +884,20 @@ void HELLOGUI::goodbye() 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 ); } } -- 2.30.2