From 82762be51f5f474d90214277f61a0edc5ff9f665 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 13 Jan 2021 12:00:14 +0100 Subject: [PATCH] KERNEL Services to deal with embedded Study/ModulCatalog. --- src/Container/CMakeLists.txt | 1 + src/Container/SALOME_ComponentPy.py | 81 ++++++---- src/Container/SALOME_ContainerPy.py | 153 ++++++++++-------- src/KERNEL_PY/__init__.py | 78 ++++++++- src/KERNEL_PY/salome_kernel.py | 25 ++- src/KERNEL_PY/salome_study.py | 2 +- src/KernelHelpers/CMakeLists.txt | 24 +++ src/KernelHelpers/KernelServices.cxx | 35 ++++ src/KernelHelpers/KernelServices.hxx | 23 +++ src/KernelHelpers/KernelServices.i | 44 +++++ src/KernelHelpers/SALOME_KernelServices.cxx | 26 ++- src/KernelHelpers/SALOME_KernelServices.hxx | 8 +- src/ModuleCatalog/CMakeLists.txt | 27 ++++ src/ModuleCatalog/KernelModuleCatalog.cxx | 29 ++++ src/ModuleCatalog/KernelModuleCatalog.hxx | 22 +++ src/ModuleCatalog/KernelModuleCatalog.i | 40 +++++ .../SALOME_ModuleCatalog_impl.cxx | 15 ++ .../SALOME_ModuleCatalog_impl.hxx | 11 +- src/SALOMEDS/CMakeLists.txt | 23 +++ src/SALOMEDS/KernelDS.cxx | 33 ++++ src/SALOMEDS/KernelDS.hxx | 22 +++ src/SALOMEDS/KernelDS.i | 39 +++++ src/SALOMEDS/SALOMEDS_Driver_i.cxx | 5 +- src/SALOMEDS/SALOMEDS_Driver_i.hxx | 4 +- src/SALOMEDS/SALOMEDS_Study_i.cxx | 84 ++++++++-- src/SALOMEDS/SALOMEDS_Study_i.hxx | 19 ++- 26 files changed, 726 insertions(+), 147 deletions(-) create mode 100644 src/KernelHelpers/KernelServices.cxx create mode 100644 src/KernelHelpers/KernelServices.hxx create mode 100644 src/KernelHelpers/KernelServices.i create mode 100644 src/ModuleCatalog/KernelModuleCatalog.cxx create mode 100644 src/ModuleCatalog/KernelModuleCatalog.hxx create mode 100644 src/ModuleCatalog/KernelModuleCatalog.i create mode 100644 src/SALOMEDS/KernelDS.cxx create mode 100644 src/SALOMEDS/KernelDS.hxx create mode 100644 src/SALOMEDS/KernelDS.i diff --git a/src/Container/CMakeLists.txt b/src/Container/CMakeLists.txt index 81de169b9..58c2c672f 100644 --- a/src/Container/CMakeLists.txt +++ b/src/Container/CMakeLists.txt @@ -40,6 +40,7 @@ SET(SCRIPTS SALOME_ComponentPy.py SALOME_PyNode.py SALOME_Container.py + SALOME_ContainerPy.py ) ADD_DEFINITIONS(${HDF5_DEFINITIONS} ${OMNIORB_DEFINITIONS}) diff --git a/src/Container/SALOME_ComponentPy.py b/src/Container/SALOME_ComponentPy.py index 81633b032..a10403cf0 100644 --- a/src/Container/SALOME_ComponentPy.py +++ b/src/Container/SALOME_ComponentPy.py @@ -54,7 +54,10 @@ _Sleeping = 0 ## define an implementation of the component interface Engines::Component # # -class SALOME_ComponentPy_i (Engines__POA.EngineComponent): +class SALOME_ComponentPy_Gen_i (Engines__POA.EngineComponent): + """ + Implementation Without naming_service server + """ _orb = None _poa = None _fieldsDict = [] @@ -82,42 +85,13 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent): self._Executed = 0 self._contId = contID - naming_service = SALOME_NamingServicePy_i(self._orb) myMachine=getShortHostName() - Component_path = self._containerName + "/" + self._instanceName - MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) ) id_o = poa.activate_object(self) - compo_o = poa.id_to_reference(id_o) - naming_service.Register(compo_o, Component_path) + self._compo_o = poa.id_to_reference(id_o) + self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, self._notif) - # Add componentinstance to registry - obj = naming_service.Resolve('/Registry') - if obj is None: - MESSAGE( "Registry Reference is invalid" ) - else: - regist = obj._narrow(Registry.Components) - if regist is None: - MESSAGE( "Registry Reference is invalid" ) - else: - ior = orb.object_to_string(contID) - MESSAGE( ior ) - - lesInfos = Identity(self._instanceName) - infos = Registry.Infos(lesInfos._name, - lesInfos._pid, - lesInfos._machine, - lesInfos._adip, - lesInfos._uid, - lesInfos._pwname, - int(lesInfos._tc_start), - 0,0,0, - lesInfos._cdir, - -1, - ior) - - res = regist.add(infos) - - self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, notif) + def getCorbaRef(self): + return self._compo_o #------------------------------------------------------------------------- @@ -315,3 +289,42 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent): #------------------------------------------------------------------------- pass # end of SALOME_ComponentPy_i + +class SALOME_ComponentPy_i(SALOME_ComponentPy_Gen_i): + """ + Implementation with naming_service server + """ + def __init__ (self, orb, poa, contID, containerName, instanceName, interfaceName, notif=False): + SALOME_ComponentPy_Gen_i.__init__(self, orb, poa, contID, containerName, instanceName, interfaceName, notif) + naming_service = SALOME_NamingServicePy_i(self._orb) + Component_path = self._containerName + "/" + self._instanceName + MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) ) + naming_service.Register(self._compo_o, Component_path) + # Add componentinstance to registry + obj = naming_service.Resolve('/Registry') + if obj is None: + MESSAGE( "Registry Reference is invalid" ) + else: + regist = obj._narrow(Registry.Components) + if regist is None: + MESSAGE( "Registry Reference is invalid" ) + else: + ior = orb.object_to_string(contID) + MESSAGE( ior ) + + lesInfos = Identity(self._instanceName) + infos = Registry.Infos(lesInfos._name, + lesInfos._pid, + lesInfos._machine, + lesInfos._adip, + lesInfos._uid, + lesInfos._pwname, + int(lesInfos._tc_start), + 0,0,0, + lesInfos._cdir, + -1, + ior) + + res = regist.add(infos) + + pass diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index 2bb32219f..ae86ed6db 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -46,7 +46,10 @@ from launchConfigureParser import verbose #define an implementation of the container interface for the container implemented in Python -class SALOME_ContainerPy_i (Engines__POA.Container): +class SALOME_ContainerPy_Gen_i(Engines__POA.Container): + """ + Implementation without naming_service server + """ _orb = None _poa = None _numInstance = 0 @@ -63,76 +66,6 @@ class SALOME_ContainerPy_i (Engines__POA.Container): self._containerName = Container_path if verbose(): print("container name ",self._containerName) - naming_service = SALOME_NamingServicePy_i(self._orb) - self._naming_service = naming_service - MESSAGE( str(Container_path) ) - naming_service.Register(self._this(), Container_path) - - #------------------------------------------------------------------------- - - def start_impl(self, ContainerName): - MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) ) - myMachine=getShortHostName() - theContainer = "/Containers/" + myMachine + "/" + ContainerName - try: - obj = self._naming_service.Resolve(theContainer) - except : - obj = None - MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object not found in Naming Service" ) - if obj is None: - container = None - else: - container = obj._narrow(Engines.Container) - if container is None: - MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(containerName) + ".object exists but is not a Container" ) - else : - MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object found without new launch" ) - return container - #shstr = os.getenv( "PWD" ) + "/" - #shstr += "runSession ./SALOME_ContainerPy.py " - shstr = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/SALOME_ContainerPy.py "; - #shstr = "runSession SALOME_ContainerPy.py " - shstr += ContainerName - - # mpv: fix for SAL4731 - always create new file to write log of server - num = 1 - fileName = "" - while 1: - fileName = "/tmp/"+ContainerName+"_%i.log"%num - if not os.path.exists(fileName): - break - num += 1 - pass - - shstr += " > " - shstr += fileName - shstr += " 2>&1 &" - - #shstr += " > /tmp/" - #shstr += ContainerName - #shstr += ".log 2>&1 &" - - MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" ) - os.system( shstr ) - count = 21 - while container is None : - time.sleep(1) - count = count - 1 - MESSAGE( str(count) + ". Waiting for " + str(theContainer) ) - try : - obj = self._naming_service.Resolve(theContainer) - except : - obj = None - if obj is None: - container = None - else: - container = obj._narrow(Engines.Container) - if container is None: - MESSAGE( str(containerName) + ".object exists but is not a Container" ) - return container - if count == 0 : - return container - #------------------------------------------------------------------------- def instance(self, nameToRegister, componentName): @@ -306,6 +239,84 @@ class SALOME_ContainerPy_i (Engines__POA.Container): #============================================================================= +class SALOME_ContainerPy_i(SALOME_ContainerPy_Gen_i): + """ + Implementation with naming_service server + """ + def __init__(self, orb, poa, containerName): + SALOME_ContainerPy_Gen_i.__init__(self, orb, poa, containerName) + naming_service = SALOME_NamingServicePy_i(self._orb) + self._naming_service = naming_service + MESSAGE( str(Container_path) ) + naming_service.Register(self._this(), Container_path) + + #------------------------------------------------------------------------- + + def start_impl(self, ContainerName): + MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) ) + myMachine=getShortHostName() + theContainer = "/Containers/" + myMachine + "/" + ContainerName + try: + obj = self._naming_service.Resolve(theContainer) + except : + obj = None + MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object not found in Naming Service" ) + if obj is None: + container = None + else: + container = obj._narrow(Engines.Container) + if container is None: + MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(containerName) + ".object exists but is not a Container" ) + else : + MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object found without new launch" ) + return container + #shstr = os.getenv( "PWD" ) + "/" + #shstr += "runSession ./SALOME_ContainerPy.py " + shstr = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/SALOME_ContainerPy.py "; + #shstr = "runSession SALOME_ContainerPy.py " + shstr += ContainerName + + # mpv: fix for SAL4731 - always create new file to write log of server + num = 1 + fileName = "" + while 1: + fileName = "/tmp/"+ContainerName+"_%i.log"%num + if not os.path.exists(fileName): + break + num += 1 + pass + + shstr += " > " + shstr += fileName + shstr += " 2>&1 &" + + #shstr += " > /tmp/" + #shstr += ContainerName + #shstr += ".log 2>&1 &" + + MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" ) + os.system( shstr ) + count = 21 + while container is None : + time.sleep(1) + count = count - 1 + MESSAGE( str(count) + ". Waiting for " + str(theContainer) ) + try : + obj = self._naming_service.Resolve(theContainer) + except : + obj = None + if obj is None: + container = None + else: + container = obj._narrow(Engines.Container) + if container is None: + MESSAGE( str(containerName) + ".object exists but is not a Container" ) + return container + if count == 0 : + return container + + pass + if __name__ == "__main__": # change the stdout buffering to line buffering (same as C++ cout buffering) sys.stdout=os.fdopen(1,"w",1) diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 4ee3b78c5..8577a7dd2 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -161,11 +161,82 @@ if not flags: # sys.setdlopenflags(flags) # pass -orb, lcc, naming_service, cm, sg, esm, dsm = None,None,None,None,None,None,None +orb, lcc, naming_service, cm, sg, esm, dsm, modulcat = None,None,None,None,None,None,None,None myStudy, myStudyName = None,None salome_initial=True + +__EMB_SERVANT_ENV_VAR_NAME = "SALOME_EMB_SERVANT" + +def standalone(): + import os + os.environ[__EMB_SERVANT_ENV_VAR_NAME] = "1" + def salome_init(path=None, embedded=False): + import os + if __EMB_SERVANT_ENV_VAR_NAME in os.environ: + salome_init_without_session() + else: + salome_init_with_session(path, embedded) + +class StandAloneLifecyle: + def FindOrLoadComponent(self,contName,moduleName): + global orb + if contName == "FactoryServer" and moduleName == "GEOM": + import GeomHelper + geom_ior = GeomHelper.BuildGEOMInstance() + import GEOM + import CORBA + orb=CORBA.ORB_init(['']) + geom = orb.string_to_object(geom_ior) + return geom + if contName == "FactoryServer" and moduleName == "SMESH": + import SMeshHelper + smesh_ior = SMeshHelper.BuildSMESHInstance() + import SMESH + import CORBA + orb=CORBA.ORB_init(['']) + smeshInst = orb.string_to_object(smesh_ior) + return smeshInst + if contName == "FactoryServer" and moduleName == "SHAPERSTUDY": + from SHAPERSTUDY import SHAPERSTUDY_No_Session + from SALOME_ContainerPy import SALOME_ContainerPy_Gen_i + import PortableServer + import KernelServices + obj = orb.resolve_initial_references("RootPOA") + poa = obj._narrow(PortableServer.POA) + pman = poa._get_the_POAManager() + # + cont = SALOME_ContainerPy_Gen_i(orb,poa,"FactoryServer") + conId = poa.activate_object(cont) + conObj = poa.id_to_reference(conId) + # + pman.activate() + # + compoName = "SHAPERSTUDY" + servant = SHAPERSTUDY_No_Session(orb,poa,conObj,"FactoryServer","SHAPERSTUDY_inst_1",compoName) + ret = servant.getCorbaRef() + KernelServices.RegisterCompo(compoName,ret) + return ret + raise RuntimeError("Undealed situation cont = {} module = {}".format(contName,moduleName)) + +def salome_init_without_session(): + global lcc,myStudy,orb,modulcat + lcc = StandAloneLifecyle() + import KernelDS + myStudy = KernelDS.myStudy() + import CORBA + orb=CORBA.ORB_init(['']) + import KernelModuleCatalog + import SALOME_ModuleCatalog + from salome_kernel import list_of_catalogs_regarding_environement + modulcat = KernelModuleCatalog.myModuleCatalog( list_of_catalogs_regarding_environement() ) + # activate poaManager to accept co-localized CORBA calls. + poa = orb.resolve_initial_references("RootPOA") + poaManager = poa._get_the_POAManager() + poaManager.activate() + +def salome_init_with_session(path=None, embedded=False): """ Performs only once SALOME general purpose initialisation for scripts. Provides: @@ -175,12 +246,13 @@ def salome_init(path=None, embedded=False): cm reference to the container manager esm reference to external server manager dsm reference to shared dataserver manager + modulcat reference to modulecatalog instance sg access to SALOME GUI (when linked with IAPP GUI) myStudy active study itself (CORBA reference) myStudyName active study name """ global salome_initial - global orb, lcc, naming_service, cm, esm, dsm + global orb, lcc, naming_service, cm, esm, dsm, modulcat global sg global myStudy, myStudyName @@ -188,7 +260,7 @@ def salome_init(path=None, embedded=False): if salome_initial: salome_initial=False sg = salome_iapp_init(embedded) - orb, lcc, naming_service, cm, esm, dsm = salome_kernel_init() + orb, lcc, naming_service, cm, esm, dsm, modulcat = salome_kernel_init() myStudy, myStudyName = salome_study_init(path) pass pass diff --git a/src/KERNEL_PY/salome_kernel.py b/src/KERNEL_PY/salome_kernel.py index 5edc7b3e0..b89627e3d 100644 --- a/src/KERNEL_PY/salome_kernel.py +++ b/src/KERNEL_PY/salome_kernel.py @@ -32,6 +32,7 @@ from SALOME_NamingServicePy import * from SALOME_utilities import * import Engines import SALOME +import SALOME_ModuleCatalog orb = None lcc = None @@ -39,9 +40,26 @@ naming_service = None cm = None esm = None dsm = None +modulcat = None + +def list_of_catalogs_regarding_environement(): + """ + Method to detect XML module catalogs regarding environement variables + """ + import os + KEY_IN_ENV_VAR = "_ROOT_DIR" + modules_env_var = [elt for elt in os.environ.keys() if elt[-len(KEY_IN_ENV_VAR):]==KEY_IN_ENV_VAR] + list_catalogs = [] + for module_env_var in modules_env_var: + module_upper_case = module_env_var[:-len(KEY_IN_ENV_VAR)] + file_candidate = os.path.join(os.environ[module_env_var],"share","salome","resources",module_upper_case.lower(),"{}Catalog.xml".format(module_upper_case)) + if os.path.isfile(file_candidate): + list_catalogs.append(file_candidate) + pass + return list_catalogs def salome_kernel_init(): - global orb, lcc, naming_service, cm, esm, dsm + global orb, lcc, naming_service, cm, esm, dsm, modulcat if not orb: # initialise the ORB @@ -62,5 +80,8 @@ def salome_kernel_init(): # obj = naming_service.Resolve('/DataServerManager') dsm = obj._narrow(SALOME.DataServerManager) + # + obj = naming_service.Resolve('Kernel/ModulCatalog') + modulcat = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog) - return orb, lcc, naming_service, cm, esm, dsm + return orb, lcc, naming_service, cm, esm, dsm, modulcat diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py index 613f80282..bf6a52986 100644 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@ -292,7 +292,7 @@ def salome_study_init(theStudyPath=None): if verbose(): print("theStudyPath:", theStudyPath) if not myStudy: - orb, lcc, naming_service, cm, _, _ = salome_kernel.salome_kernel_init() + orb, lcc, naming_service, cm, _, _, _ = salome_kernel.salome_kernel_init() # get Study reference if verbose(): print("looking for study...") diff --git a/src/KernelHelpers/CMakeLists.txt b/src/KernelHelpers/CMakeLists.txt index c5879fc71..1accd3a20 100644 --- a/src/KernelHelpers/CMakeLists.txt +++ b/src/KernelHelpers/CMakeLists.txt @@ -17,9 +17,12 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +include(${SWIG_USE_FILE}) + INCLUDE_DIRECTORIES( ${PTHREAD_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/salome_adm ${CMAKE_CURRENT_SOURCE_DIR}/../NamingService ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace @@ -29,6 +32,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Container ${CMAKE_CURRENT_SOURCE_DIR}/../Notification ${CMAKE_CURRENT_SOURCE_DIR}/../GenericObj + ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR}/idl ) @@ -61,5 +65,25 @@ ADD_EXECUTABLE(KernelHelpersUseCases KernelHelpersUseCases.cxx) TARGET_LINK_LIBRARIES(KernelHelpersUseCases SalomeKernelHelpers ${SalomeKernelHelpers_LIBS}) INSTALL(TARGETS KernelHelpersUseCases DESTINATION ${SALOME_INSTALL_BINS}) +# + +SET(KernelServices_HEADERS KernelServices.hxx KernelServices.i) +SET(KernelServices_SOURCES KernelServices.cxx ${KernelServices_HEADERS}) +SET_SOURCE_FILES_PROPERTIES(KernelServices.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(KernelServices.i PROPERTIES SWIG_FLAGS "-py3") +SET_SOURCE_FILES_PROPERTIES(KernelServices_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H") +SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelServices.py ) +IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(KernelServices python ${KernelServices_SOURCES}) +ELSE() + SWIG_ADD_LIBRARY(KernelServices LANGUAGE python SOURCES ${KernelServices_SOURCES}) +ENDIF() +SWIG_LINK_LIBRARIES(KernelServices ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeKernelHelpers) +install(TARGETS _KernelServices DESTINATION ${SALOME_INSTALL_LIBS}) +install(FILES ${KernelServices_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) +SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}" ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelServices_REAL_NAME}") + +# + FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/KernelHelpers/KernelServices.cxx b/src/KernelHelpers/KernelServices.cxx new file mode 100644 index 000000000..2a217d1bd --- /dev/null +++ b/src/KernelHelpers/KernelServices.cxx @@ -0,0 +1,35 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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 "SALOME_KernelServices.hxx" + +void RegisterCompoInternal(const std::string& compoName, const std::string& compoIOR) +{ + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::Object_var obj = orb->string_to_object(compoIOR.c_str()); + KERNEL::RegisterCompo(compoName,obj); +} + +std::string RetrieveCompoInternal(const std::string& compoName) +{ + CORBA::Object_var obj = KERNEL::RetrieveCompo(compoName); + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::String_var ior = orb->object_to_string(obj); + return std::string(ior.in()); +} diff --git a/src/KernelHelpers/KernelServices.hxx b/src/KernelHelpers/KernelServices.hxx new file mode 100644 index 000000000..54bac046e --- /dev/null +++ b/src/KernelHelpers/KernelServices.hxx @@ -0,0 +1,23 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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 + +void RegisterCompoInternal(const std::string& compoName, const std::string& compoIOR); +std::string RetrieveCompoInternal(const std::string& compoName); diff --git a/src/KernelHelpers/KernelServices.i b/src/KernelHelpers/KernelServices.i new file mode 100644 index 000000000..2d00ccd2a --- /dev/null +++ b/src/KernelHelpers/KernelServices.i @@ -0,0 +1,44 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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 +// + +%module KernelServices + +%include "std_string.i" + +%{ +#include "KernelServices.hxx" +%} + +%inline +{ + void RegisterCompoInternal(const std::string& compoName, const std::string& compoIOR); + std::string RetrieveCompoInternal(const std::string& compoName); +} + +%pythoncode %{ +def RegisterCompo(compoName,compoRef): + import CORBA + orb=CORBA.ORB_init(['']) + RegisterCompoInternal(compoName,orb.object_to_string(compoRef)) + +def RetrieveCompo(compoName): + import CORBA + orb=CORBA.ORB_init(['']) + return orb.string_to_object(RetrieveCompoInternal(compoName)) +%} diff --git a/src/KernelHelpers/SALOME_KernelServices.cxx b/src/KernelHelpers/SALOME_KernelServices.cxx index 3bb6b144b..4ca01ee7a 100644 --- a/src/KernelHelpers/SALOME_KernelServices.cxx +++ b/src/KernelHelpers/SALOME_KernelServices.cxx @@ -21,6 +21,10 @@ #include "SALOME_KernelServices.hxx" +#include + +std::map _compo_map; + namespace KERNEL { /** @@ -64,6 +68,7 @@ namespace KERNEL { /** * This returns a static reference to the SALOME study. The * study can be used to get informations about it. + * \sa getStudyServantSA */ SALOMEDS::Study_ptr getStudyServant() { static SALOMEDS::Study_ptr aStudy; @@ -160,5 +165,24 @@ namespace KERNEL { es.text = CORBA::string_dup(text); return SALOME::SALOME_Exception(es); } - + + void RegisterCompo(const std::string& compoName, CORBA::Object_var compoPtr) + { + _compo_map[compoName] = compoPtr; + } + + CORBA::Object_var RetrieveCompo(const std::string& compoName) + { + auto it = _compo_map.find(compoName); + if( it != _compo_map.end() ) + { + return (*it).second; + } + else + { + SALOME::SALOME_Exception ex(createSalomeException("RetrieveCompo : not implemented yet !")); + throw ex; + //GetLCC()->FindOrLoad_Component( "FactoryServer", compoName ); + } + } } diff --git a/src/KernelHelpers/SALOME_KernelServices.hxx b/src/KernelHelpers/SALOME_KernelServices.hxx index e03068d38..d232b1483 100644 --- a/src/KernelHelpers/SALOME_KernelServices.hxx +++ b/src/KernelHelpers/SALOME_KernelServices.hxx @@ -19,8 +19,7 @@ // Author: Guillaume Boulant (EDF/R&D) -#ifndef __KERNEL_SERVICES_H__ -#define __KERNEL_SERVICES_H__ +#pragma once #include "KernelHelpers.hxx" @@ -54,7 +53,8 @@ namespace KERNEL { KERNELHELPERS_EXPORT CORBA::Object_ptr SObjectToObject(SALOMEDS::SObject_ptr); - + KERNELHELPERS_EXPORT void RegisterCompo(const std::string& compoName, CORBA::Object_var compoPtr); + KERNELHELPERS_EXPORT CORBA::Object_var RetrieveCompo(const std::string& compoName); /*! * This template function provides you with the servant (CORBA * object narrowed to its interface) corresponding to the specified @@ -101,5 +101,3 @@ namespace KERNEL { #include "Utils_CorbaException.hxx" // Tip: CORBA exceptions can be used with LOG (or more generally in streams) // Ex: LOG("An exception occurs: "<object_to_string(study); + return std::string(ior.in()); +} diff --git a/src/ModuleCatalog/KernelModuleCatalog.hxx b/src/ModuleCatalog/KernelModuleCatalog.hxx new file mode 100644 index 000000000..c70aef514 --- /dev/null +++ b/src/ModuleCatalog/KernelModuleCatalog.hxx @@ -0,0 +1,22 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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 + +std::string GetModuleCatalogInstance(const std::string& listOfCatalogsGrouped); diff --git a/src/ModuleCatalog/KernelModuleCatalog.i b/src/ModuleCatalog/KernelModuleCatalog.i new file mode 100644 index 000000000..d1905e930 --- /dev/null +++ b/src/ModuleCatalog/KernelModuleCatalog.i @@ -0,0 +1,40 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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 +// + +%module KernelModuleCatalog + +%include "std_string.i" + +%{ +#include "KernelModuleCatalog.hxx" +%} + +%inline +{ + std::string GetModuleCatalogInstance(const std::string& listOfCatalogsGrouped); +} + +%pythoncode %{ +def myModuleCatalog(listOfCatalogs): + import SALOMEDS + import CORBA + orb=CORBA.ORB_init(['']) + param = "::".join(["\"{}\"".format(elt) for elt in listOfCatalogs]) + return orb.string_to_object(GetModuleCatalogInstance(param)) +%} diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx index 326dddc14..69f567a46 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx @@ -60,6 +60,21 @@ static int MYDEBUG = 0; static const char* SEPARATOR = "::"; static const char* OLD_SEPARATOR = ":"; +SALOME_ModuleCatalog::ModuleCatalog_ptr KERNEL::getModuleComponentServantSA(const char *listOfCatalogs) +{ + static SALOME_ModuleCatalog::ModuleCatalog_var moduleCata; + if(CORBA::is_nil(moduleCata)) + { + CORBA::ORB_ptr orb = KERNEL::getORB(); + constexpr int NB_OF_ELT_IN_CMD = 3; + char *argv[NB_OF_ELT_IN_CMD] = {"SALOME_ModuleCatalog_Server","-common",nullptr}; + if(listOfCatalogs) + argv[2] = const_cast(listOfCatalogs); + SALOME_ModuleCatalogImpl *servant = new SALOME_ModuleCatalogImpl(NB_OF_ELT_IN_CMD,argv,orb); + moduleCata = servant->_this(); + } + return SALOME_ModuleCatalog::ModuleCatalog::_duplicate(moduleCata); +} std::list splitStringToList(const std::string& theString, const std::string& theSeparator) { diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx index 3936d7787..fbd260b29 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx @@ -26,10 +26,10 @@ // Module : SALOME // $Header$ // -#ifndef MODULECATALOG_IMPL_H -#define MODULECATALOG_IMPL_H +#pragma once #include "SALOME_ModuleCatalog.hxx" +#include "SALOME_KernelServices.hxx" #include #include @@ -42,6 +42,11 @@ #pragma warning(disable:4290) // Warning Exception ... #endif +namespace KERNEL +{ + MODULECATALOG_EXPORT SALOME_ModuleCatalog::ModuleCatalog_ptr getModuleComponentServantSA(const char *listOfCatalogs = nullptr); +} + class MODULECATALOG_EXPORT SALOME_ModuleCatalogImpl: public POA_SALOME_ModuleCatalog::ModuleCatalog { class Private; @@ -140,5 +145,3 @@ private: CORBA::ORB_ptr _orb; Private* myPrivate; }; - -#endif // MODULECATALOG_IMPL_H diff --git a/src/SALOMEDS/CMakeLists.txt b/src/SALOMEDS/CMakeLists.txt index 5423648ec..0ab1bd239 100644 --- a/src/SALOMEDS/CMakeLists.txt +++ b/src/SALOMEDS/CMakeLists.txt @@ -17,11 +17,14 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +include(${SWIG_USE_FILE}) + INCLUDE_DIRECTORIES( ${PTHREAD_INCLUDE_DIR} ${OMNIORB_INCLUDE_DIR} ${HDF5_INCLUDE_DIRS} ${Boost_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/salome_adm ${CMAKE_CURRENT_SOURCE_DIR}/../HDFPersist ${CMAKE_CURRENT_SOURCE_DIR}/../Basics @@ -36,6 +39,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../LifeCycleCORBA ${CMAKE_CURRENT_SOURCE_DIR}/../TOOLSDS ${CMAKE_CURRENT_SOURCE_DIR}/../Container + ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR}/idl ) @@ -157,6 +161,22 @@ TARGET_LINK_LIBRARIES(SALOMEDS_Server SalomeDS SALOMEBasics ${COMMON_LIBS} ${OMN ADD_EXECUTABLE(SALOMEDS_Client SALOMEDS_Client.cxx) TARGET_LINK_LIBRARIES(SALOMEDS_Client SalomeDS SALOMEBasics ${COMMON_LIBS} ${OMNIORB_LIBRARIES}) +SET(KernelDS_HEADERS KernelDS.hxx KernelDS.i) +SET(KernelDS_SOURCES KernelDS.cxx ${KernelDS_HEADERS}) +SET_SOURCE_FILES_PROPERTIES(KernelDS.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(KernelDS.i PROPERTIES SWIG_FLAGS "-py3") +SET_SOURCE_FILES_PROPERTIES(KernelDS_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H") +SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelDS.py ) +IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(KernelDS python ${KernelDS_SOURCES}) +ELSE() + SWIG_ADD_LIBRARY(KernelDS LANGUAGE python SOURCES ${KernelDS_SOURCES}) +ENDIF() +SWIG_LINK_LIBRARIES(KernelDS ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeDS SalomeKernelHelpers) +install(TARGETS _KernelDS DESTINATION ${SALOME_INSTALL_LIBS}) +install(FILES ${KernelDS_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) +SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}" ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelDS_REAL_NAME}") + INSTALL(TARGETS SALOMEDS_Server SALOMEDS_Client EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS}) @@ -165,6 +185,9 @@ INSTALL(TARGETS SALOMEDS_Server SALOMEDS_Client SALOME_INSTALL_SCRIPTS(SALOME_DriverPy.py ${SALOME_INSTALL_SCRIPT_PYTHON}) SET(COMMON_HEADERS_HXX + SALOMEDS_SComponentIterator_i.hxx + SALOMEDS_StudyBuilder_i.hxx + SALOMEDS_UseCaseBuilder_i.hxx SALOMEDS_Driver_i.hxx SALOMEDS_Study_i.hxx SALOMEDS_Study.hxx diff --git a/src/SALOMEDS/KernelDS.cxx b/src/SALOMEDS/KernelDS.cxx new file mode 100644 index 000000000..82fe2aefb --- /dev/null +++ b/src/SALOMEDS/KernelDS.cxx @@ -0,0 +1,33 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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 "KernelDS.hxx" + +#include "SALOME_KernelServices.hxx" +#include "SALOMEDS_Study_i.hxx" + +#include + +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()); +} diff --git a/src/SALOMEDS/KernelDS.hxx b/src/SALOMEDS/KernelDS.hxx new file mode 100644 index 000000000..f56aceb43 --- /dev/null +++ b/src/SALOMEDS/KernelDS.hxx @@ -0,0 +1,22 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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 + +std::string GetSessionInstance(); diff --git a/src/SALOMEDS/KernelDS.i b/src/SALOMEDS/KernelDS.i new file mode 100644 index 000000000..278870731 --- /dev/null +++ b/src/SALOMEDS/KernelDS.i @@ -0,0 +1,39 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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 +// + +%module KernelDS + +%include "std_string.i" + +%{ +#include "KernelDS.hxx" +%} + +%inline +{ + std::string GetSessionInstance(); +} + +%pythoncode %{ +def myStudy(): + import SALOMEDS + import CORBA + orb=CORBA.ORB_init(['']) + return orb.string_to_object(GetSessionInstance()) +%} diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.cxx b/src/SALOMEDS/SALOMEDS_Driver_i.cxx index 04a85cb94..c82cc604e 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.cxx @@ -348,10 +348,11 @@ SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(bool isPublished, // SALOMEDS_DriverFactory //############################################################################################################### -SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB) +SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool isNSAvail) { _orb = CORBA::ORB::_duplicate(theORB); - _name_service = new SALOME_NamingService(_orb); + if(isNSAvail) + _name_service = new SALOME_NamingService(_orb); } diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.hxx b/src/SALOMEDS/SALOMEDS_Driver_i.hxx index 28dc9e3dc..3ec27fd16 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.hxx @@ -111,11 +111,11 @@ class SALOMEDS_DriverFactory_i : public virtual SALOMEDSImpl_DriverFactory { protected: CORBA::ORB_var _orb; - SALOME_NamingService* _name_service; + SALOME_NamingService* _name_service = nullptr; public: - SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB); + SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB, bool isNSAvail = true); virtual ~SALOMEDS_DriverFactory_i(); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index f347a69e3..31a2bef46 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -64,7 +64,26 @@ UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection) static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb); -static PortableServer::POA_ptr _poa; +static PortableServer::POA_ptr _poa; + +/** + * Return a unique study obj but servant is embeded here. + * + */ +SALOMEDS::Study_ptr KERNEL::getStudyServantSA() +{ + static SALOMEDS::Study_ptr aStudy; + if(CORBA::is_nil(aStudy)) + { + 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); + SALOMEDS_Study_i *servant = new SALOMEDS_Study_i(orb,SALOME::Session::_nil()); + aStudy = servant->_this(); + } + return SALOMEDS::Study::_duplicate(aStudy); +} namespace SALOMEDS { @@ -226,6 +245,21 @@ namespace SALOMEDS }; + //================================================================================ + /*! + * \brief emitMessageOneWay to SALOME::Session + */ + //================================================================================ + + void sendMessageToGUIGivenSession(SALOME::Session_ptr session, const char* msg ) + { + if ( !CORBA::is_nil(session) ) { + SALOMEDS::unlock(); + session->emitMessageOneWay( msg ); + SALOMEDS::lock(); + } + } + //================================================================================ /*! * \brief emitMessageOneWay to SALOME::Session @@ -237,28 +271,36 @@ namespace SALOMEDS SALOME_NamingService *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); - if ( !CORBA::is_nil(aSession) ) { - SALOMEDS::unlock(); - aSession->emitMessageOneWay( msg ); - SALOMEDS::lock(); - } + sendMessageToGUIGivenSession(aSession,msg); } } // namespace SALOMEDS +SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb) +{ + _orb = CORBA::ORB::_duplicate(orb); + _impl = new SALOMEDSImpl_Study(); + _factory = new SALOMEDS_DriverFactory_i(_orb); + _closed = true; + SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); + SALOME::Session_var aSession = SALOME::Session::_narrow(obj); + Init(aSession); +} + //============================================================================ /*! Function : SALOMEDS_Study_i * Purpose : SALOMEDS_Study_i constructor */ //============================================================================ -SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb) +SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME::Session_ptr session) { _orb = CORBA::ORB::_duplicate(orb); _impl = new SALOMEDSImpl_Study(); - _factory = new SALOMEDS_DriverFactory_i(_orb); + _factory = new SALOMEDS_DriverFactory_i(_orb,!CORBA::is_nil(session)); _closed = true; - Init(); + Init(session); } //============================================================================ @@ -273,12 +315,20 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i() delete _impl; } +void SALOMEDS_Study_i::Init() +{ + SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); + SALOME::Session_var aSession = SALOME::Session::_narrow(obj); + Init(aSession); +} + //============================================================================ /*! Function : Init * Purpose : Initialize study components */ //============================================================================ -void SALOMEDS_Study_i::Init() +void SALOMEDS_Study_i::Init(SALOME::Session_ptr session) { if (!_closed) //throw SALOMEDS::Study::StudyInvalidReference(); @@ -298,10 +348,10 @@ void SALOMEDS_Study_i::Init() _impl->setGenObjRegister( _genObjRegister ); // Notify GUI that study was created - SALOMEDS::sendMessageToGUI( "studyCreated" ); + SALOMEDS::sendMessageToGUIGivenSession( session, "studyCreated" ); // update desktop title with new study name - NameChanged(); + NameChanged(session); } //============================================================================ @@ -977,7 +1027,10 @@ void SALOMEDS_Study_i::URL(const wchar_t* wurl) _impl->URL(Kernel_Utils::encode_s(wurl)); // update desktop title with new study name - NameChanged(); + SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); + SALOME::Session_var aSession = SALOME::Session::_narrow(obj); + NameChanged(aSession); } void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry) @@ -1681,7 +1734,8 @@ CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::L return reinterpret_cast(_impl); } -void SALOMEDS_Study_i::NameChanged() +void SALOMEDS_Study_i::NameChanged(SALOME::Session_ptr session) { - SALOMEDS::sendMessageToGUI( "studyNameChanged" ); + + SALOMEDS::sendMessageToGUIGivenSession(session,"studyNameChanged" ); } diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index 821414cc8..36d0ef962 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -24,8 +24,7 @@ // Author : Sergey RUIN // Module : SALOME // -#ifndef __SALOMEDS_STUDY_I_H__ -#define __SALOMEDS_STUDY_I_H__ +#pragma once // std C++ headers #include @@ -34,7 +33,7 @@ #include #include CORBA_SERVER_HEADER(SALOME_GenericObj) #include CORBA_SERVER_HEADER(SALOMEDS) - +#include CORBA_CLIENT_HEADER(SALOME_Session) #include //SALOMEDS headers @@ -47,11 +46,16 @@ #include "SALOMEDSImpl_Study.hxx" #include "SALOMEDSImpl_AttributeIOR.hxx" +namespace KERNEL +{ + Standard_EXPORT SALOMEDS::Study_ptr getStudyServantSA(); +} + class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study { private: - void NameChanged(); + void NameChanged(SALOME::Session_ptr session); CORBA::ORB_var _orb; SALOMEDSImpl_Study* _impl; SALOMEDS_StudyBuilder_i* _builder; @@ -61,9 +65,10 @@ private: bool _closed; public: - //! standard constructor SALOMEDS_Study_i(CORBA::ORB_ptr); + //! standard constructor + SALOMEDS_Study_i(CORBA::ORB_ptr, SALOME::Session_ptr session); //! standard destructor @@ -71,7 +76,8 @@ public: virtual PortableServer::POA_ptr _default_POA(); - virtual void Init(); + virtual void Init() override; + virtual void Init(SALOME::Session_ptr session); virtual void Clear(); //! method to open a Study @@ -358,4 +364,3 @@ public: virtual void attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify); virtual void detach(SALOMEDS::Observer_ptr theObs); }; -#endif -- 2.39.2