Salome HOME
Create FactoryServer Container servant into the current process
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 24 Jan 2022 14:34:46 +0000 (15:34 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 24 Jan 2022 14:34:46 +0000 (15:34 +0100)
src/Container/CMakeLists.txt
src/Container/KernelContainer.cxx [new file with mode: 0644]
src/Container/KernelContainer.hxx [new file with mode: 0644]
src/Container/KernelContainer.i [new file with mode: 0644]
src/KERNEL_PY/__init__.py

index 0c497e0f9a5f3a8ebb82ff629ccf5523819eb61d..5f1810df2825bfd1679e549c908cc6279f51237a 100644 (file)
@@ -17,6 +17,8 @@
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+include(${SWIG_USE_FILE})
+
 INCLUDE_DIRECTORIES(
   ${OMNIORB_INCLUDE_DIR}
   ${PTHREAD_INCLUDE_DIR}
@@ -36,6 +38,7 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMETraceCollector/Test
   ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers
   ${PROJECT_BINARY_DIR}/idl
+  ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
 SET(SCRIPTS
@@ -123,3 +126,22 @@ INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS})
 IF(SALOME_BUILD_TESTS)
   ADD_SUBDIRECTORY(Test)
 ENDIF(SALOME_BUILD_TESTS)
+
+SET(KernelContainer_HEADERS KernelContainer.hxx KernelContainer.i)
+SET(KernelContainer_SOURCES KernelContainer.cxx ${KernelContainer_HEADERS})
+SET_SOURCE_FILES_PROPERTIES(KernelContainer.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(KernelContainer.i PROPERTIES SWIG_FLAGS "-py3")
+SET_SOURCE_FILES_PROPERTIES(KernelContainer_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H")
+SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelContainer.py )
+IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") 
+  SWIG_ADD_MODULE(KernelContainer python ${KernelContainer_SOURCES})
+ELSE()
+  SWIG_ADD_LIBRARY(KernelContainer LANGUAGE python SOURCES ${KernelContainer_SOURCES})
+ENDIF()
+IF(${MACHINE} STREQUAL WINDOWS)
+  SET_TARGET_PROPERTIES(_KernelContainer PROPERTIES DEBUG_OUTPUT_NAME _KernelContainer_d)
+ENDIF(${MACHINE} STREQUAL WINDOWS)
+SWIG_LINK_LIBRARIES(KernelContainer ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeContainer SalomeKernelHelpers)
+install(TARGETS _KernelContainer DESTINATION ${SALOME_INSTALL_LIBS})
+install(FILES ${KernelContainer_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
+SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}"  ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelContainer_REAL_NAME}")
diff --git a/src/Container/KernelContainer.cxx b/src/Container/KernelContainer.cxx
new file mode 100644 (file)
index 0000000..4e29f5b
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (C) 2022  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 "KernelContainer.hxx"
+
+#include "SALOME_Container_i.hxx" 
+#include "SALOME_KernelORB.hxx"
+
+std::string GetContainerInstance()
+{
+  Engines::Container_var cont = KERNEL::getContainerRefSA();
+  CORBA::ORB_ptr orb = KERNEL::getORB();
+  CORBA::String_var ior = orb->object_to_string(cont);
+  return std::string(ior.in());
+}
diff --git a/src/Container/KernelContainer.hxx b/src/Container/KernelContainer.hxx
new file mode 100644 (file)
index 0000000..c2b86df
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright (C) 2022  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
+//
+
+#pragma once
+
+#include <string>
+
+std::string GetContainerInstance();
diff --git a/src/Container/KernelContainer.i b/src/Container/KernelContainer.i
new file mode 100644 (file)
index 0000000..ecc7b41
--- /dev/null
@@ -0,0 +1,39 @@
+// Copyright (C) 2022  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 KernelContainer
+
+%include "std_string.i"
+
+%{
+#include "KernelContainer.hxx"
+%}
+
+%inline
+{
+  std::string GetContainerInstance();
+}
+
+%pythoncode %{
+def myContainer():
+  import Engines
+  import CORBA
+  orb=CORBA.ORB_init([''])
+  return orb.string_to_object(GetContainerInstance())
+%}
index 2aa01975bdc5ba6dd057e731dc61fe403a3f316e..b82ee7dfe322631253b9cd987a3416a64fc93923 100644 (file)
@@ -251,6 +251,9 @@ def salome_init_without_session(path=None, embedded=False):
     import KernelLauncher
     cm = KernelLauncher.myContainerManager()
     lcc = StandAloneLifecyle(cm, KernelLauncher.myResourcesManager())
+    # create a FactoryServer Container servant
+    import KernelContainer
+    KernelContainer.myContainer()
     # activate poaManager to accept co-localized CORBA calls.
     from KernelSDS import GetDSMInstance
     import sys