return None
+def killMyPortSSL(*ports):
+ """ Called by runSalome.py after CTRL-C"""
+ for port in ports:
+ # ensure port is an integer
+ with suppress(ValueError):
+ port = int(port)
+
+ with suppress(Exception):
+ # DO NOT REMOVE NEXT LINE: it tests PortManager availability!
+ from PortManager import releasePort
+ # get pidict file
+ filedict = getPiDict(port)
+ if not osp.isfile(filedict): # removed by previous call, see (1) above
+ if verbose():
+ print("SALOME session on port {} is already stopped".format(port))
+ # remove port from PortManager config file
+ with suppress(ImportError):
+ if verbose():
+ print("Removing port from PortManager configuration file")
+ releasePort(port)
+ return
+ try:
+ # DO NOT REMOVE NEXT LINE: it tests PortManager availability!
+ import PortManager # pragma pylint: disable=unused-import
+ for file_path in glob('{}*'.format(getPiDict(port))):
+ __killMyPort(port, file_path)
+ except ImportError:
+ __killMyPort(port, __guessPiDictFilename(port))
+
+ # clear-up omniOrb config files
+ appliCleanOmniOrbConfig(port)
+
def killMyPort(*ports):
"""
Kill SALOME session running on the specified port.
logger.debug("startSalome : {} ".format(args))
+ ior_fakens_filename = None
+
# Launch Session Server (to show splash ASAP)
#
mySessionServ = runSalomeNoServer.NoSessionServer(args,args['modules'],modules_root_dir)
mySessionServ.setpath(modules_list,modules_root_dir)
mySessionServ.run()
+ ior_fakens_filename = mySessionServ.iorfakens
end_time = os.times()
except Exception:
import traceback
traceback.print_exc()
- print("-------------------------------------------------------------")
- print("-- to get an external python interpreter:runSalome --interp=1")
- print("-------------------------------------------------------------")
+ logger.error("-------------------------------------------------------------")
+ logger.error("-- to get an external python interpreter:runSalome --interp=1")
+ logger.error("-------------------------------------------------------------")
logger.debug("additional external python interpreters: {}".format(nbaddi))
if nbaddi:
for i in range(nbaddi):
- print("i=",i)
anInterp=InterpServer(args)
anInterp.run()
except ImportError:
pass
- return
+ return ior_fakens_filename
# -----------------------------------------------------------------------------
show registered objects in Naming Service.
"""
global process_id
-
+ ior_fakens_filename = None
try:
- startSalome(args, modules_list, modules_root_dir)
+ ior_fakens_filename = startSalome(args, modules_list, modules_root_dir)
except Exception:
import traceback
traceback.print_exc()
- print()
- print()
- print("--- Error during Salome launch ---")
+ logger.error("--- Error during Salome launch ---")
# print(process_id)
the processes resulting from the previous execution.
"""%filedict)
- return
+ return ior_fakens_filename
def execScript(script_path):
print('executing', script_path)
kill_salome(args)
# --
setenv.set_env(args, modules_list, modules_root_dir, keepEnvironment=keep_env)
- useSalome(args, modules_list, modules_root_dir)
- return args
+ ior_fakens_filename = useSalome(args, modules_list, modules_root_dir)
+ return args, ior_fakens_filename
# -----------------------------------------------------------------------------
-def foreGround(args):
+def foreGround(args, ior_fakens_filename):
# --
- if "session_object" not in args:
+ import os
+ gui_detected = False
+ dt = 0.1
+ nbtot = 100
+ nb = 0
+ if ior_fakens_filename is None:
+ logger.warn("No file set to host IOR of the fake naming server")
+ return
+ if not os.path.exists(ior_fakens_filename):
+ logger.warn("No file {} set to host IOR of the fake naming server does not exit !")
return
- session = args["session_object"]
+ import CORBA
+ import Engines
+ import SALOME
+ from time import sleep
+ orb = CORBA.ORB_init([''], CORBA.ORB_ID)
+ ior_fakens = None
+ session = None
+ while True:
+ try:
+ ior_fakens = orb.string_to_object(open(ior_fakens_filename).read())
+ session = orb.string_to_object(ior_fakens.Resolve("/Kernel/Session").decode())
+ except Exception:
+ pass
+ if ( session is not None ) and (not CORBA.is_nil(session)):
+ try:
+ os.remove(ior_fakens_filename)
+ logger.debug("File {} has been removed".format(ior_fakens_filename))
+ except:
+ pass
+ logger.debug("Session in child process has been found ! yeah ! {}".format(str(session)))
+ break
+ sleep(dt)
+ nb += 1
+ logger.debug("Unfortunately Session not found into {} : Sleep and retry. {}/{}".format(ior_fakens_filename,nb,nbtot))
+ if nb == nbtot:
+ break
+ nb = 0
# --
# Wait until gui is arrived
# tmax = nbtot * dt
# --
- gui_detected = False
- dt = 0.1
- nbtot = 100
- nb = 0
session_pid = None
while 1:
try:
status = session.GetStatSession()
gui_detected = status.activeGUI
session_pid = session.getPID()
+ logger.debug("Process of the session under monitoring {}".format(session_pid))
except Exception:
pass
if gui_detected:
break
- from time import sleep
sleep(dt)
nb += 1
if nb == nbtot:
pass
pass
except KeyboardInterrupt:
- from killSalomeWithPort import killMyPort
- killMyPort(port)
+ from killSalomeWithPort import killMyPortSSL
+ killMyPortSSL(port)
pass
return
#
def runSalome():
- args = main()
+ args, ior_fakens_filename = main()
# --
test = args['gui'] and args['session_gui']
test = test or args['wake_up_session']
if test:
from time import sleep
sleep(3.0)
- foreGround(args)
+ foreGround(args, ior_fakens_filename)
pass
pass
#
# ---
import abc
+import tempfile
class CommonSessionServer(Server):
def __init__(self,args,modules_list,modules_root_dir):
self.args = args.copy()
pass
if 'language' in self.args:
self.SCMD2+=['--language=%s' % self.args['language']]
+ tempfile.mkstemp()
+ os_handle, iorfakens = tempfile.mkstemp()
+ self.iorfakens = iorfakens
+ os.close(os_handle)
+ self.SCMD2+=["--iorfakens={}".format(iorfakens)]
pass
@abc.abstractmethod
import os, sys, string
from salome_utils import getHostName
process_id = {}
+import logging
# -----------------------------------------------------------------------------
#
+ os.getenv("LD_LIBRARY_PATH")]
myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
command = myargs + self.CMD
+ for sapcfg in ["SalomeAppSLConfig","SalomeAppConfig"]:
+ if sapcfg in os.environ:
+ logging.getLogger().debug("{}={}".format(sapcfg,os.environ[sapcfg]))
+ command1 = (" ".join(command)).replace("(","\\\(") ; command1 = command1.replace(")","\\\)")
+ logging.getLogger().debug("Command to be launched : {}".format(command1))
# print("command = ", command)
if sys.platform == "win32":
import subprocess
#store process pid if it really exists
process_id[pid]=self.CMD
self.PID = pid
+ logging.getLogger().debug("PID of launched command : {}".format(pid))
return pid
def daemonize(self,args):
import KernelBasis
KernelBasis.setSSLMode(False)
-def salome_init(path=None, embedded=False):
+def salome_init(path=None, embedded=False, iorfakensfile=None):
+ """
+ :param iorfakensfile: filename inside which IOR of fake NS will be written
+ """
import KernelBasis
if KernelBasis.getSSLMode():
if KernelBasis.getIOROfEmbeddedNS() == "":
- salome_init_without_session(path, embedded)
+ salome_init_without_session(path, embedded, iorfakensfile)
else:
salome_init_without_session_attached(path, embedded)
else:
from NamingService import NamingService
naming_service = NamingService()
-def salome_init_without_session(path=None, embedded=False):
+def salome_init_without_session(path=None, embedded=False, iorfakensfile=None):
salome_init_without_session_common(path,embedded)
global lcc,cm,dsm,esm
import KernelLauncher
# esm inherits from SALOME_CPythonHelper singleton already initialized by GetDSMInstance
# esm inherits also from SALOME_ResourcesManager creation/initialization (concerning SingleThreadPOA POA) when KernelLauncher.GetContainerManager() has been called
esm = KernelLauncher.GetExternalServer()
+ #
+ import KernelLogger
+ naming_service.Register(KernelLogger.myLogger(),"/Logger")
+ #
+ from NamingService import NamingService
+ if iorfakensfile is not None:
+ with open(iorfakensfile,"w") as iorfakensf:
+ iorfakensf.write(NamingService.IOROfNS())
def salome_init_without_session_attached(path=None, embedded=False):
"""
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
+include(${SWIG_USE_FILE})
+
INCLUDE_DIRECTORIES(
${OMNIORB_INCLUDE_DIR}
${PTHREAD_INCLUDE_DIR}
+ ${PYTHON_INCLUDE_DIRS}
${PROJECT_BINARY_DIR}/salome_adm
${CMAKE_CURRENT_SOURCE_DIR}/../ArgvKeeper
${CMAKE_CURRENT_SOURCE_DIR}/../Basics
${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace
${CMAKE_CURRENT_SOURCE_DIR}/../Utils
+ ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers
+ ${CMAKE_CURRENT_SOURCE_DIR}/../NamingService
+ ${CMAKE_CURRENT_SOURCE_DIR}/../LifeCycleCORBA
+ ${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BINARY_DIR}/idl
)
ADD_DEFINITIONS(${OMNIORB_DEFINITIONS})
ADD_LIBRARY(SalomeLoggerServer SALOME_Trace.cxx SALOME_Logger_Server.cxx)
-TARGET_LINK_LIBRARIES(SalomeLoggerServer SalomeIDLKernel ${OMNIORB_LIBRARIES} ${PLATFORM_LIBS})
+TARGET_LINK_LIBRARIES(SalomeLoggerServer SalomeKernelHelpers SalomeIDLKernel ${OMNIORB_LIBRARIES} ${PLATFORM_LIBS})
INSTALL(TARGETS SalomeLoggerServer EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
SET(SALOME_Logger_Server_SOURCES
SalomeLoggerServer
SalomeIDLKernel
OpUtil
+ SalomeKernelHelpers
${OMNIORB_LIBRARIES}
)
TARGET_LINK_LIBRARIES(SALOME_Logger_Server ${SALOME_Logger_Server_LIBS})
INSTALL(TARGETS SALOME_Logger_Server EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS})
+SET(KernelLogger_HEADERS KernelLogger.hxx KernelLogger.i)
+SET(KernelLogger_SOURCES KernelLogger.cxx ${KernelLogger_HEADERS})
+SET_SOURCE_FILES_PROPERTIES(KernelLogger.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(KernelLogger.i PROPERTIES SWIG_FLAGS "-py3")
+SET_SOURCE_FILES_PROPERTIES(KernelLogger_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H")
+SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelLogger.py )
+IF(${CMAKE_VERSION} VERSION_LESS "3.8.0")
+ SWIG_ADD_MODULE(KernelLogger python ${KernelLogger_SOURCES})
+ELSE()
+ SWIG_ADD_LIBRARY(KernelLogger LANGUAGE python SOURCES ${KernelLogger_SOURCES})
+ENDIF()
+IF(${MACHINE} STREQUAL WINDOWS)
+ SET_TARGET_PROPERTIES(_KernelLogger PROPERTIES DEBUG_OUTPUT_NAME _KernelLogger_d)
+ENDIF(${MACHINE} STREQUAL WINDOWS)
+SWIG_LINK_LIBRARIES(KernelLogger ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeLoggerServer)
+install(TARGETS _KernelLogger DESTINATION ${SALOME_INSTALL_LIBS})
+install(FILES ${KernelLogger_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
+SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}" ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelLogger_REAL_NAME}")
+
# Executable scripts to be installed
SALOME_INSTALL_SCRIPTS(SALOME_Trace.py ${SALOME_INSTALL_SCRIPT_PYTHON})
--- /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 "KernelLogger.hxx"
+#include "SALOME_Logger_Server.hxx"
+#include "SALOME_KernelServices.hxx"
+
+std::string GetLoggerInstance()
+{
+ SALOME_Logger::Logger_var study = KERNEL::getLoggerServantSA();
+ CORBA::ORB_ptr orb = KERNEL::getORB();
+ CORBA::String_var ior = orb->object_to_string(study);
+ return std::string(ior.in());
+}
--- /dev/null
+// 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 GetLoggerInstance();
--- /dev/null
+// 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 KernelLogger
+
+%include "std_string.i"
+
+%{
+#include "KernelLogger.hxx"
+%}
+
+%inline
+{
+ std::string GetLoggerInstance();
+}
+
+%pythoncode %{
+def myLogger():
+ import SALOME_Logger
+ import CORBA
+ orb=CORBA.ORB_init([''])
+ return orb.string_to_object(GetLoggerInstance())
+%}
//
#include <iostream>
#include "SALOME_Logger_Server.hxx"
+#include "SALOME_KernelServices.hxx"
#include <SALOMEconfig.h>
#include <sys/types.h>
#ifndef WIN32
omni_mutex Logger::myLock;
+SALOME_Logger::Logger_ptr KERNEL::getLoggerServantSA()
+{
+ CORBA::ORB_ptr orb = KERNEL::getORB();
+ CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+ PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
+ Logger *servant = new Logger;
+ SALOME_Logger::Logger_ptr logger = servant->_this();
+ servant->_remove_ref();
+ return logger;
+}
+
/////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#pragma warning(disable:4275) // Disable warning interface non dll
#endif
+namespace KERNEL
+{
+ SALOME_Logger::Logger_ptr getLoggerServantSA();
+}
+
class LOGGER_EXPORT Logger :
public POA_SALOME_Logger::Logger
{
${CMAKE_CURRENT_SOURCE_DIR}/../Basics
${CMAKE_CURRENT_SOURCE_DIR}/../Utils
${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace
+ ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
+ ${CMAKE_CURRENT_SOURCE_DIR}/../NamingService
${PROJECT_BINARY_DIR}/idl
)
// $Header$
//
#include "TraceCollector_WaitForServerReadiness.hxx"
+#include "KernelBasis.hxx"
+#include "SALOME_Fake_NamingService.hxx"
#include "OpUtil.hxx"
#include <iostream>
#include <ctime>
+#include <memory>
#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER < 1900
// NB. You can't use SALOME_NamingService class because
// it uses MESSAGE macro
// Otherwise, you will get segmentation fault.
-
- CosNaming::NamingContext_var inc;
- CosNaming::Name name;
- name.length(1);
- name[0].id = CORBA::string_dup(serverName.c_str());
- CORBA::Object_var theObj=CORBA::Object::_nil();
-
- for (int itry=0; itry < NumberOfTries; itry++)
+ if(getSSLMode())
+ {
+ std::string regName(std::string("/")+serverName);
+ std::unique_ptr<SALOME_Fake_NamingService> ns(new SALOME_Fake_NamingService);
+ for (int itry=0; itry < NumberOfTries; itry++)
{
- try
- {
- if(!CORBA::is_nil(orb))
- theObj = orb->resolve_initial_references("NameService");
- if (!CORBA::is_nil(theObj))
- inc = CosNaming::NamingContext::_narrow(theObj);
- }
- catch( CORBA::SystemException& )
- {
- std::cout << "TraceCollector_WaitForServerReadiness: "
- << "CORBA::SystemException: "
- << "Unable to contact the Naming Service" << std::endl;
- }
- catch(...)
- {
- std::cout << "TraceCollector_WaitForServerReadiness: "
- << "Unknown exception dealing with Naming Service" << std::endl;
- }
-
- obj=CORBA::Object::_nil();
- if(!CORBA::is_nil(inc))
- {
- try
- {
- obj = inc->resolve(name);
- if (!CORBA::is_nil(obj))
- {
- //cout << "TraceCollector_WaitForServerReadiness: "
- // << serverName << " found in CORBA Name Service" << endl;
- break;
- }
- }
- catch (const CosNaming::NamingContext::NotFound&)
- {
- std::cout << "Caught exception: Naming Service can't found Logger";
- }
- }
-#ifndef WIN32
- nanosleep(&ts_req,&ts_rem);
-#else
- Sleep(TIMESleep / 1000000);
-#endif
- std::cout << "TraceCollector_WaitForServerReadiness: retry look for"
- << serverName << std::endl;
- }
+ obj = ns->Resolve(regName.c_str());
+ if(!CORBA::is_nil(obj))
+ break;
+ #ifndef WIN32
+ nanosleep(&ts_req,&ts_rem);
+ #else
+ Sleep(TIMESleep / 1000000);
+ #endif
+ }
+ }
+ else
+ {
+ CosNaming::NamingContext_var inc;
+ CosNaming::Name name;
+ name.length(1);
+ name[0].id = CORBA::string_dup(serverName.c_str());
+ CORBA::Object_var theObj=CORBA::Object::_nil();
+
+ for (int itry=0; itry < NumberOfTries; itry++)
+ {
+ try
+ {
+ if(!CORBA::is_nil(orb))
+ theObj = orb->resolve_initial_references("NameService");
+ if (!CORBA::is_nil(theObj))
+ inc = CosNaming::NamingContext::_narrow(theObj);
+ }
+ catch( CORBA::SystemException& )
+ {
+ std::cout << "TraceCollector_WaitForServerReadiness: "
+ << "CORBA::SystemException: "
+ << "Unable to contact the Naming Service" << std::endl;
+ }
+ catch(...)
+ {
+ std::cout << "TraceCollector_WaitForServerReadiness: "
+ << "Unknown exception dealing with Naming Service" << std::endl;
+ }
+
+ obj=CORBA::Object::_nil();
+ if(!CORBA::is_nil(inc))
+ {
+ try
+ {
+ obj = inc->resolve(name);
+ if (!CORBA::is_nil(obj))
+ {
+ //cout << "TraceCollector_WaitForServerReadiness: "
+ // << serverName << " found in CORBA Name Service" << endl;
+ break;
+ }
+ }
+ catch (const CosNaming::NamingContext::NotFound&)
+ {
+ std::cout << "Caught exception: Naming Service can't found Logger";
+ }
+ }
+ #ifndef WIN32
+ nanosleep(&ts_req,&ts_rem);
+ #else
+ Sleep(TIMESleep / 1000000);
+ #endif
+ std::cout << "TraceCollector_WaitForServerReadiness: retry look for"
+ << serverName << std::endl;
+ }
+ }
}
catch (const CosNaming::NamingContext::NotFound&)
{