]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
KERNEL Services to deal with embedded Study/ModulCatalog.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 13 Jan 2021 11:00:14 +0000 (12:00 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 1 Feb 2021 18:58:28 +0000 (19:58 +0100)
26 files changed:
src/Container/CMakeLists.txt
src/Container/SALOME_ComponentPy.py
src/Container/SALOME_ContainerPy.py
src/KERNEL_PY/__init__.py
src/KERNEL_PY/salome_kernel.py
src/KERNEL_PY/salome_study.py
src/KernelHelpers/CMakeLists.txt
src/KernelHelpers/KernelServices.cxx [new file with mode: 0644]
src/KernelHelpers/KernelServices.hxx [new file with mode: 0644]
src/KernelHelpers/KernelServices.i [new file with mode: 0644]
src/KernelHelpers/SALOME_KernelServices.cxx
src/KernelHelpers/SALOME_KernelServices.hxx
src/ModuleCatalog/CMakeLists.txt
src/ModuleCatalog/KernelModuleCatalog.cxx [new file with mode: 0644]
src/ModuleCatalog/KernelModuleCatalog.hxx [new file with mode: 0644]
src/ModuleCatalog/KernelModuleCatalog.i [new file with mode: 0644]
src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx
src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx
src/SALOMEDS/CMakeLists.txt
src/SALOMEDS/KernelDS.cxx [new file with mode: 0644]
src/SALOMEDS/KernelDS.hxx [new file with mode: 0644]
src/SALOMEDS/KernelDS.i [new file with mode: 0644]
src/SALOMEDS/SALOMEDS_Driver_i.cxx
src/SALOMEDS/SALOMEDS_Driver_i.hxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx

index 81de169b948d09f547548b5f8f59dca2160482aa..58c2c672fa9d0227e4ee8df47324c05569039732 100644 (file)
@@ -40,6 +40,7 @@ SET(SCRIPTS
   SALOME_ComponentPy.py
   SALOME_PyNode.py
   SALOME_Container.py
+  SALOME_ContainerPy.py
 )
 
 ADD_DEFINITIONS(${HDF5_DEFINITIONS} ${OMNIORB_DEFINITIONS})
index 81633b032ce1517b5b820f7826e0ffb877c63eb2..a10403cf0b74b4aa31b3d357d59278130835a1d1 100644 (file)
@@ -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
index 2bb32219f0ec0ae7e3efad0ac041f47b9d734928..ae86ed6db8db9e9c4f9fa7324bf3455148db772e 100755 (executable)
@@ -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)
index 4ee3b78c5f5aabdbad87fc82d6576cf8dac2199b..8577a7dd29391c5d7530fe345ba41fb97becdecb 100644 (file)
@@ -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
index 5edc7b3e0a6fc12b1b57e1bb40e6fc9d9ac4fc17..b89627e3d9f089cf10aeb7fab6b61df6b1005555 100644 (file)
@@ -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
index 613f802825de647e0c4735db5496da33021ba8f3..bf6a529869e45f042ee5cf32088b0197416fb30b 100644 (file)
@@ -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...")
index c5879fc716ac302951019ef7ad1e431ac8691ecc..1accd3a20c17b46bb9c7ce8d9f142b5885365d99 100644 (file)
 # 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 (file)
index 0000000..2a217d1
--- /dev/null
@@ -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 (file)
index 0000000..54bac04
--- /dev/null
@@ -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 <string>
+
+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 (file)
index 0000000..2d00ccd
--- /dev/null
@@ -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))
+%}
index 3bb6b144bd2107d86e01ca35066e677b4bd06542..4ca01ee7a315b2cedfc6193dd9952a122647f9d6 100644 (file)
 
 #include "SALOME_KernelServices.hxx"
 
+#include <map>
+
+std::map<std::string,CORBA::Object_var> _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 );
+    }
+  }
 }
index e03068d382bb6aba7dd6e3ee31516991a5824170..d232b1483ec706c2937964ecfe456568c404dd90 100644 (file)
@@ -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: "<<e) will log the data of the exception e
-
-#endif // KERNEL_SERVICES
index 3c8a47a224df2dbbe56a4f34f3dfb196196ccb80..4183628bfd3a9cb9c8c70ff4557ff17fb404cf26 100644 (file)
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+include(${SWIG_USE_FILE})
+
 INCLUDE_DIRECTORIES(
   ${PTHREAD_INCLUDE_DIR}
   ${OMNIORB_INCLUDE_DIR}
   ${LIBXML2_INCLUDE_DIR}
+  ${PYTHON_INCLUDE_DIRS}
   ${PROJECT_BINARY_DIR}/salome_adm
   ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
   ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace
   ${CMAKE_CURRENT_SOURCE_DIR}/../NamingService
   ${CMAKE_CURRENT_SOURCE_DIR}/../Utils
+  ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers
+  ${CMAKE_CURRENT_SOURCE_DIR}/../LifeCycleCORBA
+  ${CMAKE_CURRENT_SOURCE_DIR}
   ${PROJECT_BINARY_DIR}/idl
 )
 
@@ -36,6 +42,7 @@ SET(COMMON_LIBS
   SALOMELocalTrace
   SALOMEBasics
   SalomeIDLKernel
+  SalomeKernelHelpers
   ${LIBXML2_LIBRARIES}
   ${PTHREAD_LIBRARIES}
 )
@@ -58,6 +65,26 @@ TARGET_LINK_LIBRARIES(SALOME_ModuleCatalog_Server SalomeCatalog ${COMMON_LIBS} $
 ADD_EXECUTABLE(SALOME_ModuleCatalog_Client SALOME_ModuleCatalog_Client.cxx)
 TARGET_LINK_LIBRARIES(SALOME_ModuleCatalog_Client SalomeCatalog ${COMMON_LIBS} ${OMNIORB_LIBRARIES})
 
+#
+
+SET(KernelModuleCatalog_HEADERS KernelModuleCatalog.hxx KernelModuleCatalog.i)
+SET(KernelModuleCatalog_SOURCES KernelModuleCatalog.cxx ${KernelModuleCatalog_HEADERS})
+SET_SOURCE_FILES_PROPERTIES(KernelModuleCatalog.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(KernelModuleCatalog.i PROPERTIES SWIG_FLAGS "-py3")
+SET_SOURCE_FILES_PROPERTIES(KernelModuleCatalog_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H")
+SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelModuleCatalog.py )
+IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") 
+  SWIG_ADD_MODULE(KernelModuleCatalog python ${KernelModuleCatalog_SOURCES})
+ELSE()
+  SWIG_ADD_LIBRARY(KernelModuleCatalog LANGUAGE python SOURCES ${KernelModuleCatalog_SOURCES})
+ENDIF()
+SWIG_LINK_LIBRARIES(KernelModuleCatalog ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeCatalog SalomeKernelHelpers)
+install(TARGETS _KernelModuleCatalog DESTINATION ${SALOME_INSTALL_LIBS})
+install(FILES ${KernelModuleCatalog_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
+SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}"  ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelModuleCatalog_REAL_NAME}")
+
+#
+
 INSTALL(TARGETS SALOME_ModuleCatalog_Server SALOME_ModuleCatalog_Client 
         EXPORT ${PROJECT_NAME}TargetGroup
         DESTINATION ${SALOME_INSTALL_BINS})
diff --git a/src/ModuleCatalog/KernelModuleCatalog.cxx b/src/ModuleCatalog/KernelModuleCatalog.cxx
new file mode 100644 (file)
index 0000000..bc92373
--- /dev/null
@@ -0,0 +1,29 @@
+// 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_ModuleCatalog_impl.hxx"
+#include "SALOME_KernelServices.hxx"
+
+std::string GetModuleCatalogInstance(const std::string& listOfCatalogsGrouped)
+{
+    SALOME_ModuleCatalog::ModuleCatalog_var study = KERNEL::getModuleComponentServantSA(listOfCatalogsGrouped.c_str());
+    CORBA::ORB_ptr orb = KERNEL::getORB();
+    CORBA::String_var ior = orb->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 (file)
index 0000000..c70aef5
--- /dev/null
@@ -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 <string>
+
+std::string GetModuleCatalogInstance(const std::string& listOfCatalogsGrouped);
diff --git a/src/ModuleCatalog/KernelModuleCatalog.i b/src/ModuleCatalog/KernelModuleCatalog.i
new file mode 100644 (file)
index 0000000..d1905e9
--- /dev/null
@@ -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))
+%}
index 326dddc149563c369915f88389202849dc3c66b5..69f567a46fab7515e11109909dceef884be13bb7 100644 (file)
@@ -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<char*>(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<std::string> splitStringToList(const std::string& theString, const std::string& theSeparator)
 {
index 3936d778724d2a273d821b75cd0c27cfaf71c711..fbd260b29d82db7d6427b3c019054ad5b7de20a2 100644 (file)
 //  Module : SALOME
 //  $Header$
 //
-#ifndef MODULECATALOG_IMPL_H
-#define MODULECATALOG_IMPL_H
+#pragma once
 
 #include "SALOME_ModuleCatalog.hxx"
+#include "SALOME_KernelServices.hxx"
 
 #include <string>
 #include <map>
 #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
index 5423648ec385d9eb5b1bf9af2a543f8270b0f149..0ab1bd239af8eb2b0c12ecadd0a49a3a0074e224 100644 (file)
 # 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 (file)
index 0000000..82fe2ae
--- /dev/null
@@ -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 <cstring>
+
+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 (file)
index 0000000..f56aceb
--- /dev/null
@@ -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 <string>
+
+std::string GetSessionInstance();
diff --git a/src/SALOMEDS/KernelDS.i b/src/SALOMEDS/KernelDS.i
new file mode 100644 (file)
index 0000000..2788707
--- /dev/null
@@ -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())
+%}
index 04a85cb947a6767b7364ef0e8a5f6c717123a473..c82cc604efdda1094f9a6c4f6a59bbcbd80723d7 100644 (file)
@@ -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);
 }
 
 
index 28dc9e3dc76eeffa4b72465140bc81462601c613..3ec27fd16842c3bb5839303138c591f340c6bdfa 100644 (file)
@@ -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();
    
index f347a69e3f00c0225fe3b91a46aeee191b3edb24..31a2bef460e12c8d939c17b30cb6431b2bd2abc2 100644 (file)
@@ -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<CORBA::LongLong>(_impl);
 }
 
-void SALOMEDS_Study_i::NameChanged()
+void SALOMEDS_Study_i::NameChanged(SALOME::Session_ptr session)
 {
-  SALOMEDS::sendMessageToGUI( "studyNameChanged" );
+
+  SALOMEDS::sendMessageToGUIGivenSession(session,"studyNameChanged" );
 }
index 821414cc8a48c659832e1fe796434da5f4903f9c..36d0ef9623552deb37d265dd02ec72b9504ed16d 100644 (file)
@@ -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 <iostream>
@@ -34,7 +33,7 @@
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_GenericObj)
 #include CORBA_SERVER_HEADER(SALOMEDS)
-
+#include CORBA_CLIENT_HEADER(SALOME_Session)
 #include <stdio.h>
 
 //SALOMEDS headers
 #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