SALOME_ComponentPy.py
SALOME_PyNode.py
SALOME_Container.py
+ SALOME_ContainerPy.py
)
ADD_DEFINITIONS(${HDF5_DEFINITIONS} ${OMNIORB_DEFINITIONS})
## 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 = []
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
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
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
#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
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):
#=============================================================================
+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)
# 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:
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
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
from SALOME_utilities import *
import Engines
import SALOME
+import SALOME_ModuleCatalog
orb = None
lcc = 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
#
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
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...")
# 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
${CMAKE_CURRENT_SOURCE_DIR}/../Container
${CMAKE_CURRENT_SOURCE_DIR}/../Notification
${CMAKE_CURRENT_SOURCE_DIR}/../GenericObj
+ ${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BINARY_DIR}/idl
)
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})
--- /dev/null
+// 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());
+}
--- /dev/null
+// 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);
--- /dev/null
+// 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))
+%}
#include "SALOME_KernelServices.hxx"
+#include <map>
+
+std::map<std::string,CORBA::Object_var> _compo_map;
+
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;
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 );
+ }
+ }
}
// Author: Guillaume Boulant (EDF/R&D)
-#ifndef __KERNEL_SERVICES_H__
-#define __KERNEL_SERVICES_H__
+#pragma once
#include "KernelHelpers.hxx"
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
#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
# 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
)
SALOMELocalTrace
SALOMEBasics
SalomeIDLKernel
+ SalomeKernelHelpers
${LIBXML2_LIBRARIES}
${PTHREAD_LIBRARIES}
)
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})
--- /dev/null
+// 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());
+}
--- /dev/null
+// 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);
--- /dev/null
+// 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))
+%}
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)
{
// 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;
CORBA::ORB_ptr _orb;
Private* myPrivate;
};
-
-#endif // MODULECATALOG_IMPL_H
# 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
${CMAKE_CURRENT_SOURCE_DIR}/../LifeCycleCORBA
${CMAKE_CURRENT_SOURCE_DIR}/../TOOLSDS
${CMAKE_CURRENT_SOURCE_DIR}/../Container
+ ${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BINARY_DIR}/idl
)
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})
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
--- /dev/null
+// 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());
+}
--- /dev/null
+// 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();
--- /dev/null
+// 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())
+%}
// 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);
}
{
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();
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
{
};
+ //================================================================================
+ /*!
+ * \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
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);
}
//============================================================================
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();
_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);
}
//============================================================================
_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)
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" );
}
// Author : Sergey RUIN
// Module : SALOME
//
-#ifndef __SALOMEDS_STUDY_I_H__
-#define __SALOMEDS_STUDY_I_H__
+#pragma once
// std C++ headers
#include <iostream>
#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;
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
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
virtual void attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify);
virtual void detach(SALOMEDS::Observer_ptr theObs);
};
-#endif