From: Anthony Geay Date: Sat, 23 Jan 2021 06:20:40 +0000 (+0100) Subject: For SHAPERSTUDY : Make the equivalent to NS Register X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=287a798ee50555105f0d7eac00c84b6c36fbdf3c;p=modules%2Fkernel.git For SHAPERSTUDY : Make the equivalent to NS Register --- diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 0c2ef0238..044be4842 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -202,6 +202,7 @@ class StandAloneLifecyle: 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() @@ -211,8 +212,10 @@ class StandAloneLifecyle: # pman.activate() # - servant = SHAPERSTUDY_No_Session(orb,poa,conId,"FactoryServer","SHAPERSTUDY_inst_1","SHAPERSTUDY") + compoName = "SHAPERSTUDY" + servant = SHAPERSTUDY_No_Session(orb,poa,conId,"FactoryServer","SHAPERSTUDY_inst_1",compoName) ret = servant.getCorbaRef() + KernelServices.RegisterCompo(compoName,ret) return ret raise RuntimeError("Undealed situation cont = {} module = {}".format(contName,moduleName)) 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)) +%}