From: Anthony Geay Date: Fri, 18 Feb 2022 16:04:44 +0000 (+0100) Subject: Fix runSalome.py --logger X-Git-Tag: V9_9_0a1~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a912b5982015ae2b0169be691b7c4915977132d9;p=modules%2Fkernel.git Fix runSalome.py --logger Fix runSalome.py --forground=1 [dft] --- diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index 59a6c2b93..5375452df 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -302,6 +302,38 @@ def __guessPiDictFilename(port): 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. diff --git a/bin/runSalome.py b/bin/runSalome.py index bd0a5bcaf..20f3da436 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -70,6 +70,8 @@ def startSalome(args, modules_list, modules_root_dir): logger.debug("startSalome : {} ".format(args)) + ior_fakens_filename = None + # Launch Session Server (to show splash ASAP) # @@ -77,6 +79,7 @@ def startSalome(args, modules_list, modules_root_dir): 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() @@ -96,14 +99,13 @@ def startSalome(args, modules_list, modules_root_dir): 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() @@ -115,7 +117,7 @@ def startSalome(args, modules_list, modules_root_dir): except ImportError: pass - return + return ior_fakens_filename # ----------------------------------------------------------------------------- @@ -126,15 +128,13 @@ def useSalome(args, modules_list, modules_root_dir): 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) @@ -160,7 +160,7 @@ def useSalome(args, modules_list, modules_root_dir): the processes resulting from the previous execution. """%filedict) - return + return ior_fakens_filename def execScript(script_path): print('executing', script_path) @@ -186,35 +186,66 @@ def main(exeName=None): 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: @@ -248,14 +279,14 @@ def foreGround(args): 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'] @@ -279,7 +310,7 @@ def runSalome(): if test: from time import sleep sleep(3.0) - foreGround(args) + foreGround(args, ior_fakens_filename) pass pass # diff --git a/bin/runSalomeCommon.py b/bin/runSalomeCommon.py index 1e3295a7e..354017404 100755 --- a/bin/runSalomeCommon.py +++ b/bin/runSalomeCommon.py @@ -242,6 +242,7 @@ class LoggerServer(Server): # --- import abc +import tempfile class CommonSessionServer(Server): def __init__(self,args,modules_list,modules_root_dir): self.args = args.copy() @@ -321,6 +322,11 @@ class CommonSessionServer(Server): 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 diff --git a/bin/server.py b/bin/server.py index 2d30b82ba..8bbe12051 100644 --- a/bin/server.py +++ b/bin/server.py @@ -24,6 +24,7 @@ import os, sys, string from salome_utils import getHostName process_id = {} +import logging # ----------------------------------------------------------------------------- # @@ -70,6 +71,11 @@ class Server: + 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 @@ -86,6 +92,7 @@ class Server: #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): diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 175a86c30..d2be57dfc 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -173,11 +173,14 @@ def withServers(): 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: @@ -220,7 +223,7 @@ def salome_init_without_session_common(path=None, embedded=False): 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 @@ -241,6 +244,14 @@ def salome_init_without_session(path=None, embedded=False): # 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): """ diff --git a/src/Logger/CMakeLists.txt b/src/Logger/CMakeLists.txt index 5a32c47ad..5b74e794c 100644 --- a/src/Logger/CMakeLists.txt +++ b/src/Logger/CMakeLists.txt @@ -17,20 +17,27 @@ # 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 @@ -43,6 +50,7 @@ SET(SALOME_Logger_Server_LIBS SalomeLoggerServer SalomeIDLKernel OpUtil + SalomeKernelHelpers ${OMNIORB_LIBRARIES} ) @@ -50,6 +58,25 @@ ADD_EXECUTABLE(SALOME_Logger_Server ${SALOME_Logger_Server_SOURCES}) 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}) diff --git a/src/Logger/KernelLogger.cxx b/src/Logger/KernelLogger.cxx new file mode 100644 index 000000000..fdc4b9ae8 --- /dev/null +++ b/src/Logger/KernelLogger.cxx @@ -0,0 +1,30 @@ +// 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()); +} diff --git a/src/Logger/KernelLogger.hxx b/src/Logger/KernelLogger.hxx new file mode 100644 index 000000000..acc216b14 --- /dev/null +++ b/src/Logger/KernelLogger.hxx @@ -0,0 +1,24 @@ +// Copyright (C) 2022 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once + +#include + +std::string GetLoggerInstance(); diff --git a/src/Logger/KernelLogger.i b/src/Logger/KernelLogger.i new file mode 100644 index 000000000..068a7f825 --- /dev/null +++ b/src/Logger/KernelLogger.i @@ -0,0 +1,39 @@ +// Copyright (C) 2022 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%module 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()) +%} diff --git a/src/Logger/SALOME_Logger_Server.cxx b/src/Logger/SALOME_Logger_Server.cxx index 05751ac97..3fda42741 100644 --- a/src/Logger/SALOME_Logger_Server.cxx +++ b/src/Logger/SALOME_Logger_Server.cxx @@ -27,6 +27,7 @@ // #include #include "SALOME_Logger_Server.hxx" +#include "SALOME_KernelServices.hxx" #include #include #ifndef WIN32 @@ -39,6 +40,17 @@ 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 ////////////////////////////////////////////////////////////////////// diff --git a/src/Logger/SALOME_Logger_Server.hxx b/src/Logger/SALOME_Logger_Server.hxx index 07615ccb7..7377d7696 100644 --- a/src/Logger/SALOME_Logger_Server.hxx +++ b/src/Logger/SALOME_Logger_Server.hxx @@ -51,6 +51,11 @@ #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 { diff --git a/src/SALOMETraceCollector/CMakeLists.txt b/src/SALOMETraceCollector/CMakeLists.txt index ba6acb9b7..4ce179f9a 100644 --- a/src/SALOMETraceCollector/CMakeLists.txt +++ b/src/SALOMETraceCollector/CMakeLists.txt @@ -25,6 +25,8 @@ INCLUDE_DIRECTORIES( ${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 ) diff --git a/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx index 3320bdfb9..ce2ccd4e9 100644 --- a/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx +++ b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx @@ -26,9 +26,12 @@ // $Header$ // #include "TraceCollector_WaitForServerReadiness.hxx" +#include "KernelBasis.hxx" +#include "SALOME_Fake_NamingService.hxx" #include "OpUtil.hxx" #include #include +#include #if defined(WIN32) && defined(_MSC_VER) && _MSC_VER < 1900 @@ -68,60 +71,78 @@ CORBA::Object_ptr TraceCollector_WaitForServerReadiness(const std::string& serve // 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 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&) {