From 7f696da1b08a742d5b6ac5b9243672e2161ac54c Mon Sep 17 00:00:00 2001 From: prascle Date: Sun, 9 Jan 2005 18:44:30 +0000 Subject: [PATCH] PR: bugs 7433 (Splash) and 7435 (SALOMELocalTrace without CORBA), plus trace option in file: M bin/launchConfigureParser.py M bin/runSalome.py M bin/salome.launch M bin/salome/runIDLparser.in M src/Makefile.in M src/Container/Makefile.in M src/Container/SALOME_Container.cxx M src/DataTypeCatalog/Makefile.in M src/DataTypeCatalog/SALOME_DataTypeCatalog_Server.cxx M src/Loader/Makefile.in M src/Loader/SALOME_Session_Loader.cxx M src/ModuleCatalog/Makefile.in M src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx M src/Registry/Makefile.in M src/Registry/SALOME_Registry_Server.cxx M src/RessourcesCatalog/Makefile.in M src/RessourcesCatalog/SALOME_RessourcesCatalog_Server.cxx M src/SALOMELocalTrace/LocalTraceCollector.cxx M src/SALOMELocalTrace/LocalTraceCollector.hxx R src/SALOMELocalTrace/LocalTrace_WaitForServerReadiness.cxx R src/SALOMELocalTrace/LocalTrace_WaitForServerReadiness.hxx M src/SALOMELocalTrace/Makefile.in A src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx A src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.hxx A src/SALOMETraceCollector/Makefile.in A src/SALOMETraceCollector/SALOMETraceCollector.cxx A src/SALOMETraceCollector/SALOMETraceCollector.hxx M src/Session/Makefile.in M src/Session/SALOME_Session_Server.cxx M src/TestContainer/Makefile.in M src/TestContainer/TestContainer.cxx --- bin/launchConfigureParser.py | 12 +- bin/runSalome.py | 2 + bin/salome.launch | 1 + bin/salome/runIDLparser.in | 4 +- src/Container/Makefile.in | 2 +- src/Container/SALOME_Container.cxx | 4 +- src/DataTypeCatalog/Makefile.in | 2 +- .../SALOME_DataTypeCatalog_Server.cxx | 4 +- src/Loader/Makefile.in | 2 +- src/Loader/SALOME_Session_Loader.cxx | 4 +- src/Makefile.in | 2 +- src/ModuleCatalog/Makefile.in | 2 +- .../SALOME_ModuleCatalog_Server.cxx | 4 +- src/Registry/Makefile.in | 2 +- src/Registry/SALOME_Registry_Server.cxx | 4 +- src/RessourcesCatalog/Makefile.in | 2 +- .../SALOME_RessourcesCatalog_Server.cxx | 4 +- src/SALOMELocalTrace/LocalTraceCollector.cxx | 61 +--- src/SALOMELocalTrace/LocalTraceCollector.hxx | 4 +- src/SALOMELocalTrace/Makefile.in | 7 +- .../LocalTrace_WaitForServerReadiness.cxx | 0 .../LocalTrace_WaitForServerReadiness.hxx | 0 src/SALOMETraceCollector/Makefile.in | 52 ++++ .../SALOMETraceCollector.cxx | 279 ++++++++++++++++++ .../SALOMETraceCollector.hxx | 54 ++++ src/Session/Makefile.in | 2 +- src/Session/SALOME_Session_Server.cxx | 4 +- src/TestContainer/Makefile.in | 2 +- src/TestContainer/TestContainer.cxx | 4 +- 29 files changed, 435 insertions(+), 91 deletions(-) rename src/{SALOMELocalTrace => SALOMETraceCollector}/LocalTrace_WaitForServerReadiness.cxx (100%) rename src/{SALOMELocalTrace => SALOMETraceCollector}/LocalTrace_WaitForServerReadiness.hxx (100%) create mode 100644 src/SALOMETraceCollector/Makefile.in create mode 100644 src/SALOMETraceCollector/SALOMETraceCollector.cxx create mode 100644 src/SALOMETraceCollector/SALOMETraceCollector.hxx diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index b673049e9..717815401 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -159,9 +159,12 @@ else: for aKey in ("containers","embedded","key","modules","standalone"): if not args.has_key(aKey): args[aKey]=[] -for aKey in ("gui","logger","xterm","portkill","killall"): +for aKey in ("gui","logger","file","xterm","portkill","killall"): if not args.has_key(aKey): args[aKey]=0 +if args["file"]: + afile=args["file"] + args["file"]=[afile] args["appname"] = appname ### searching for my port @@ -237,7 +240,7 @@ except: opterror=0 for opt in opts: - if not opt in ("h","g","l","x","m","e","s","c","p","k","t"): + if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t"): print "command line error: -", opt opterror=1 @@ -250,7 +253,8 @@ if opts.has_key("h"): --help or -h : print this help --gui or -g : lancement du GUI --terminal -t : launching without gui (to deny --gui) - --logger or -l : redirection des messages dans un fichier + --logger or -l : redirection des messages via CORBA + --file=filename or -l=filename: redirection des messages dans un fichier --xterm or -x : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre --modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue or -m=module1,module2,... @@ -279,6 +283,8 @@ for opt in opts: args['gui'] = 1 elif opt == 'l': args['logger'] = 1 + elif opt == 'f': + args['file'] = opts['f'] elif opt == 'x': args['xterm'] = 1 elif opt == 'm': diff --git a/bin/runSalome.py b/bin/runSalome.py index 9cb2cfc67..d7ba78d8d 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -121,6 +121,8 @@ def set_env(args, modules_list, modules_root_dir): # special path for logger lib if needeed os.environ["SALOME_trace"]="local" + if args['file']: + os.environ["SALOME_trace"]=args['file'][0] if args['logger']: os.environ["SALOME_trace"]="with_logger" locdir=os.environ['PWD'] diff --git a/bin/salome.launch b/bin/salome.launch index 1b5bbdd1b..92c5eab6d 100644 --- a/bin/salome.launch +++ b/bin/salome.launch @@ -2,6 +2,7 @@ yes no + no yes no diff --git a/bin/salome/runIDLparser.in b/bin/salome/runIDLparser.in index 085ac77d8..79e309eb2 100644 --- a/bin/salome/runIDLparser.in +++ b/bin/salome/runIDLparser.in @@ -37,9 +37,9 @@ fi cd $DIR -PYTHONPATH=${PYTHONPATH}:${SALOME_HOME_DIR}/bin +#PYTHONPATH=${PYTHONPATH}:${SALOME_HOME_DIR}/bin #============================================================ # omiidl ==================================================== -omniidl -bIDLparser -I ${SALOME_SRC_DIR}/idl $@ +omniidl -bIDLparser -I ${KERNEL_ROOT_DIR}/idl $@ #============================================================ diff --git a/src/Container/Makefile.in b/src/Container/Makefile.in index 308814390..5cd3980a5 100644 --- a/src/Container/Makefile.in +++ b/src/Container/Makefile.in @@ -54,7 +54,7 @@ BIN_SERVER_IDL = SALOME_Component.idl CPPFLAGS+= $(PYTHON_INCLUDES) $(MPI_INCLUDE) $(OCC_INCLUDES) CXXFLAGS+=$(OCC_CXXFLAGS) -LDFLAGS+= -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace +LDFLAGS+= -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace -lSALOMETraceCollector LIBS += @LDEXPDYNFLAGS@ $(PYTHON_LIBS) $(MPI_LIBS) -lCASCatch diff --git a/src/Container/SALOME_Container.cxx b/src/Container/SALOME_Container.cxx index 02b2acce4..646480535 100644 --- a/src/Container/SALOME_Container.cxx +++ b/src/Container/SALOME_Container.cxx @@ -35,7 +35,7 @@ #include "SALOME_NamingService.hxx" #include "SALOME_Container_i.hxx" #include "utilities.h" -#include "LocalTraceCollector.hxx" +#include "SALOMETraceCollector.hxx" #ifdef CHECKTIME #include @@ -61,7 +61,7 @@ int main(int argc, char* argv[]) // Initialise the ORB. ORB_INIT &init = *SINGLETON_::Instance() ; CORBA::ORB_var &orb = init( argc , argv ) ; - LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); INFOS_COMPILATION; BEGIN_OF(argv[0]); diff --git a/src/DataTypeCatalog/Makefile.in b/src/DataTypeCatalog/Makefile.in index 5759b3b46..f5bd3bc35 100644 --- a/src/DataTypeCatalog/Makefile.in +++ b/src/DataTypeCatalog/Makefile.in @@ -54,6 +54,6 @@ BIN_SERVER_IDL = SALOME_DataTypeCatalog.idl CPPFLAGS+= $(QT_MT_INCLUDES) CXXFLAGS+= -LDFLAGS+= $(QT_MT_LIBS) $(OGL_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace +LDFLAGS+= $(QT_MT_LIBS) $(OGL_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector @CONCLUDE@ diff --git a/src/DataTypeCatalog/SALOME_DataTypeCatalog_Server.cxx b/src/DataTypeCatalog/SALOME_DataTypeCatalog_Server.cxx index 988cd8961..d79829163 100644 --- a/src/DataTypeCatalog/SALOME_DataTypeCatalog_Server.cxx +++ b/src/DataTypeCatalog/SALOME_DataTypeCatalog_Server.cxx @@ -30,7 +30,7 @@ #include "SALOME_NamingService.hxx" #include "SALOME_DataTypeCatalog_impl.hxx" #include "utilities.h" -#include "LocalTraceCollector.hxx" +#include "SALOMETraceCollector.hxx" #include "Utils_SINGLETON.hxx" using namespace std; @@ -38,7 +38,7 @@ int main(int argc,char **argv) { // initialize the ORB CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv); - LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); try { CosNaming::NamingContext_var _rootContext, catalogContext; diff --git a/src/Loader/Makefile.in b/src/Loader/Makefile.in index 972c503b6..99c98ab06 100644 --- a/src/Loader/Makefile.in +++ b/src/Loader/Makefile.in @@ -31,7 +31,7 @@ BIN_CLIENT_IDL = SALOME_Session.idl \ CPPFLAGS+=$(QT_MT_INCLUDES) CXXFLAGS+=$(OCC_CXXFLAGS) -LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace +LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector @CONCLUDE@ diff --git a/src/Loader/SALOME_Session_Loader.cxx b/src/Loader/SALOME_Session_Loader.cxx index 0db216d3c..4456b95ed 100644 --- a/src/Loader/SALOME_Session_Loader.cxx +++ b/src/Loader/SALOME_Session_Loader.cxx @@ -18,7 +18,7 @@ #include "Utils_SINGLETON.hxx" #include "SALOME_NamingService.hxx" #include "utilities.h" -#include "LocalTraceCollector.hxx" +#include "SALOMETraceCollector.hxx" //! CORBA client for SALOME Session server : launch GUI /*! @@ -32,7 +32,7 @@ using namespace std; int main(int argc, char **argv) { CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv) ; - LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); //VRV: T2.4 - Trace management improvement QApplication myQApp(argc, argv) ; InquireServersGUI myIS; diff --git a/src/Makefile.in b/src/Makefile.in index d97b5e791..8f779b462 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -33,7 +33,7 @@ VPATH=.:@srcdir@ @COMMENCE@ ifeq (@WITHIHM@,yes) -SUBDIRS = MSG2QM SALOMELocalTrace Logger Utils CASCatch PatchQt \ +SUBDIRS = MSG2QM SALOMELocalTrace SALOMETraceCollector Logger Utils CASCatch PatchQt \ GenericObj MEDWrapper NamingService Registry \ ModuleCatalog DataTypeCatalog RessourcesCatalog \ Notification NOTIFICATION_SWIG \ diff --git a/src/ModuleCatalog/Makefile.in b/src/ModuleCatalog/Makefile.in index 3d9a203c8..0ba61bbaa 100644 --- a/src/ModuleCatalog/Makefile.in +++ b/src/ModuleCatalog/Makefile.in @@ -62,6 +62,6 @@ LIB_CLIENT_IDL = SALOME_ModuleCatalog.idl BIN_SERVER_IDL = SALOME_ModuleCatalog.idl CPPFLAGS+= $(QT_MT_INCLUDES) -LDFLAGS+= $(QT_MT_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace +LDFLAGS+= $(QT_MT_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector @CONCLUDE@ diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx index 942c8f33d..9a5fb15ce 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx @@ -29,7 +29,7 @@ #include "SALOME_NamingService.hxx" #include "SALOME_ModuleCatalog_impl.hxx" #include "utilities.h" -#include "LocalTraceCollector.hxx" +#include "SALOMETraceCollector.hxx" #include "Utils_SINGLETON.hxx" #ifdef CHECKTIME @@ -41,7 +41,7 @@ int main(int argc,char **argv) { // initialize the ORB CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv); - LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); try { CosNaming::NamingContext_var _rootContext, catalogContext; diff --git a/src/Registry/Makefile.in b/src/Registry/Makefile.in index 2219e4235..cbcbf3931 100644 --- a/src/Registry/Makefile.in +++ b/src/Registry/Makefile.in @@ -53,6 +53,6 @@ BIN = SALOME_Registry_Server BIN_SRC = BIN_SERVER_IDL = SALOME_Registry.idl -LDFLAGS+= -lSalomeNS -lOpUtil -lSALOMELocalTrace +LDFLAGS+= -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector @CONCLUDE@ diff --git a/src/Registry/SALOME_Registry_Server.cxx b/src/Registry/SALOME_Registry_Server.cxx index 510366547..d47523a93 100644 --- a/src/Registry/SALOME_Registry_Server.cxx +++ b/src/Registry/SALOME_Registry_Server.cxx @@ -36,7 +36,7 @@ extern "C" } #include "utilities.h" -#include "LocalTraceCollector.hxx" +#include "SALOMETraceCollector.hxx" #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" #include "Utils_SALOME_Exception.hxx" @@ -54,7 +54,7 @@ int main( int argc , char **argv ) { ORB_INIT &init = *SINGLETON_::Instance() ; CORBA::ORB_var &orb = init( argc , argv ) ; - LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); BEGIN_OF( argv[0] ) INFOS_COMPILATION SCRUTE(argc) diff --git a/src/RessourcesCatalog/Makefile.in b/src/RessourcesCatalog/Makefile.in index c129dad04..b43546776 100644 --- a/src/RessourcesCatalog/Makefile.in +++ b/src/RessourcesCatalog/Makefile.in @@ -54,7 +54,7 @@ BIN_SERVER_IDL = SALOME_RessourcesCatalog.idl CPPFLAGS+= $(QT_MT_INCLUDES) CXXFLAGS+= -LDFLAGS+= $(QT_MT_LIBS) $(OGL_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace +LDFLAGS+= $(QT_MT_LIBS) $(OGL_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector @CONCLUDE@ diff --git a/src/RessourcesCatalog/SALOME_RessourcesCatalog_Server.cxx b/src/RessourcesCatalog/SALOME_RessourcesCatalog_Server.cxx index f8018d340..b52c63b67 100644 --- a/src/RessourcesCatalog/SALOME_RessourcesCatalog_Server.cxx +++ b/src/RessourcesCatalog/SALOME_RessourcesCatalog_Server.cxx @@ -30,7 +30,7 @@ #include "SALOME_NamingService.hxx" #include "SALOME_RessourcesCatalog_impl.hxx" #include "utilities.h" -#include "LocalTraceCollector.hxx" +#include "SALOMETraceCollector.hxx" #include "Utils_SINGLETON.hxx" using namespace std; @@ -38,7 +38,7 @@ int main(int argc,char **argv) { // initialize the ORB CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv); - LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); try { CosNaming::NamingContext_var _rootContext, catalogContext; diff --git a/src/SALOMELocalTrace/LocalTraceCollector.cxx b/src/SALOMELocalTrace/LocalTraceCollector.cxx index 0cb334b40..de347efd4 100644 --- a/src/SALOMELocalTrace/LocalTraceCollector.cxx +++ b/src/SALOMELocalTrace/LocalTraceCollector.cxx @@ -28,15 +28,12 @@ #include #include #include -#include using namespace std; #include "LocalTraceCollector.hxx" #include "LocalTrace_WaitForServerReadiness.hxx" //#include "SALOME_Log.hxx" -#include -#include CORBA_CLIENT_HEADER(Logger) // Class attributes initialisation, for class method LocalTraceCollector::run @@ -46,23 +43,20 @@ int LocalTraceCollector::_threadToClose = 0; pthread_t LocalTraceCollector::_threadId = 0; // used to control single run int LocalTraceCollector::_toFile = 0; std::string LocalTraceCollector::_fileName = ""; -CORBA::ORB_ptr LocalTraceCollector::_orb = 0; // ============================================================================ /*! * guarantees a unique object instance of the class (singleton thread safe) * a separate thread for loop to print traces is launched. - * \param typeTrace 0=standard out, 1=file(/tmp/tracetest.log), 2=CORBA log + * \param typeTrace 0=standard out, 1=file(/tmp/tracetest.log) * If typeTrace=0, checks environment for "SALOME_trace". Test values in * the following order: * - "local" standard out - * - "with_logger" CORBA log * - anything else is kept as a file name */ // ============================================================================ -LocalTraceCollector* LocalTraceCollector::instance(CORBA::ORB_ptr theOrb, - int typeTrace) +LocalTraceCollector* LocalTraceCollector::instance(int typeTrace) { if (_singleton == 0) // no need of lock when singleton already exists { @@ -74,7 +68,7 @@ LocalTraceCollector* LocalTraceCollector::instance(CORBA::ORB_ptr theOrb, _fileName = "/tmp/tracetest.log"; _toFile=0; - _orb = theOrb; + if (typeTrace) // caller sets a value different from default=0 _toFile = typeTrace; else // check environment @@ -84,7 +78,7 @@ LocalTraceCollector* LocalTraceCollector::instance(CORBA::ORB_ptr theOrb, if (traceKind) { if (strcmp(traceKind,"local")==0) _toFile=0; - else if (strcmp(traceKind,"with_logger")==0) _toFile=2; + else { _toFile=1; @@ -135,11 +129,9 @@ void* LocalTraceCollector::run(void *bid) // if trace in file requested, opens a file with append mode // so, several processes can share the same file - // if CORBA collection requested, wait for Logger server readiness + ofstream traceFile; - SALOME_Logger::Logger_var m_pInterfaceLogger; - CORBA::Object_var obj; switch (_toFile) { @@ -154,24 +146,7 @@ void* LocalTraceCollector::run(void *bid) } } break; - case 2 : // --- trace collection via CORBA - obj = LocalTrace_WaitForServerReadiness(_orb,"Logger"); - if (!CORBA::is_nil(obj)) - m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj); - if (CORBA::is_nil(m_pInterfaceLogger)) - { - cerr << "Logger server not found ! Abort" << endl; - cerr << flush ; - exit(1); - } - else - { - CORBA::String_var LogMsg = - CORBA::string_dup("\n---Init logger trace---\n"); - m_pInterfaceLogger->putMessage(LogMsg); - //cout << " Logger server found" << endl; - } - break; + case 0 : ; // --- trace to standard output default : // --- on standard output, too break; @@ -187,17 +162,6 @@ void* LocalTraceCollector::run(void *bid) { switch (_toFile) { - case 2 : // --- trace collection via CORBA - { - stringstream abortMessage(""); - abortMessage << "INTERRUPTION from thread " - << myTrace.threadId << " : " << myTrace.trace; - CORBA::String_var LogMsg = - CORBA::string_dup(abortMessage.str().c_str()); - m_pInterfaceLogger->putMessage(LogMsg); - exit(1); - } - break; case 1 : // --- trace to file traceFile << "INTERRUPTION from thread " << myTrace.threadId << " : " << myTrace.trace; @@ -217,16 +181,6 @@ void* LocalTraceCollector::run(void *bid) { switch (_toFile) { - case 2 : // --- trace collection via CORBA - { - stringstream aMessage(""); - aMessage << "th. " << myTrace.threadId - << " " << myTrace.trace; - CORBA::String_var LogMsg = - CORBA::string_dup(aMessage.str().c_str()); - m_pInterfaceLogger->putMessage(LogMsg); - } - break; case 1 : // --- trace to file traceFile << "th. " << myTrace.threadId << " " << myTrace.trace; @@ -252,14 +206,15 @@ void* LocalTraceCollector::run(void *bid) LocalTraceCollector:: ~LocalTraceCollector() { + LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance(); _threadToClose = 1; + myTraceBuffer->insert(NORMAL_MESS,"end of trace "); //needed to wake up thread if (_threadId) { int ret = pthread_join(_threadId, NULL); if (ret) cout << "error close LocalTraceCollector : "<< ret << endl; else cout << "LocalTraceCollector destruction OK" << endl; } - LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance(); delete myTraceBuffer; } diff --git a/src/SALOMELocalTrace/LocalTraceCollector.hxx b/src/SALOMELocalTrace/LocalTraceCollector.hxx index 90101efd3..bad917721 100644 --- a/src/SALOMELocalTrace/LocalTraceCollector.hxx +++ b/src/SALOMELocalTrace/LocalTraceCollector.hxx @@ -28,13 +28,12 @@ #define _LOCALTRACECOLLECTOR_HXX_ #include -#include #include "LocalTraceBufferPool.hxx" class LocalTraceCollector { public: - static LocalTraceCollector* instance(CORBA::ORB_ptr theOrb, int typeTrace=0); + static LocalTraceCollector* instance(int typeTrace=0); static void *run(void *bid); ~LocalTraceCollector(); @@ -48,7 +47,6 @@ class LocalTraceCollector static pthread_mutex_t _singletonMutex; static pthread_t _threadId; static std::string _fileName; - static CORBA::ORB_ptr _orb; }; #endif diff --git a/src/SALOMELocalTrace/Makefile.in b/src/SALOMELocalTrace/Makefile.in index 5928c6409..8d2beb1d5 100644 --- a/src/SALOMELocalTrace/Makefile.in +++ b/src/SALOMELocalTrace/Makefile.in @@ -37,8 +37,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl # header files EXPORT_HEADERS= utilities.h \ LocalTraceBufferPool.hxx \ - LocalTraceCollector.hxx \ - LocalTrace_WaitForServerReadiness.hxx + LocalTraceCollector.hxx EXPORT_PYSCRIPTS = @@ -46,10 +45,8 @@ EXPORT_PYSCRIPTS = LIB = libSALOMELocalTrace.la LIB_SRC = LocalTraceCollector.cxx \ - LocalTraceBufferPool.cxx \ - LocalTrace_WaitForServerReadiness.cxx + LocalTraceBufferPool.cxx -LIB_CLIENT_IDL = Logger.idl LDFLAGS+= @CONCLUDE@ diff --git a/src/SALOMELocalTrace/LocalTrace_WaitForServerReadiness.cxx b/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx similarity index 100% rename from src/SALOMELocalTrace/LocalTrace_WaitForServerReadiness.cxx rename to src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx diff --git a/src/SALOMELocalTrace/LocalTrace_WaitForServerReadiness.hxx b/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.hxx similarity index 100% rename from src/SALOMELocalTrace/LocalTrace_WaitForServerReadiness.hxx rename to src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.hxx diff --git a/src/SALOMETraceCollector/Makefile.in b/src/SALOMETraceCollector/Makefile.in new file mode 100644 index 000000000..394805883 --- /dev/null +++ b/src/SALOMETraceCollector/Makefile.in @@ -0,0 +1,52 @@ +# SALOMELocalTrace : log on local machine +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# 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. +# +# 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Paul RASCLE (EDF) +# Module : SALOME +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= SALOMETraceCollector.hxx \ + LocalTrace_WaitForServerReadiness.hxx + +EXPORT_PYSCRIPTS = + +# Libraries targets + +LIB = libSALOMETraceCollector.la +LIB_SRC = SALOMETraceCollector.cxx \ + LocalTrace_WaitForServerReadiness.cxx + +LIB_CLIENT_IDL = Logger.idl +LDFLAGS+= + +@CONCLUDE@ diff --git a/src/SALOMETraceCollector/SALOMETraceCollector.cxx b/src/SALOMETraceCollector/SALOMETraceCollector.cxx new file mode 100644 index 000000000..933670635 --- /dev/null +++ b/src/SALOMETraceCollector/SALOMETraceCollector.cxx @@ -0,0 +1,279 @@ +// Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : LocalTraceCollector.cxx +// Author : Paul RASCLE (EDF) +// Module : KERNEL +// $Header$ + +#include +#include +#include +#include +#include + +using namespace std; + +#include "SALOMETraceCollector.hxx" +#include "LocalTrace_WaitForServerReadiness.hxx" +//#include "SALOME_Log.hxx" +#include +#include CORBA_CLIENT_HEADER(Logger) + +// Class attributes initialisation, for class method SALOMETraceCollector::run + +SALOMETraceCollector* SALOMETraceCollector::_singleton = 0; +pthread_mutex_t SALOMETraceCollector::_singletonMutex; +int SALOMETraceCollector::_threadToClose = 0; +pthread_t SALOMETraceCollector::_threadId = 0; // used to control single run +int SALOMETraceCollector::_toFile = 0; +std::string SALOMETraceCollector::_fileName = ""; +CORBA::ORB_ptr SALOMETraceCollector::_orb = 0; + +// ============================================================================ +/*! + * guarantees a unique object instance of the class (singleton thread safe) + * a separate thread for loop to print traces is launched. + * \param typeTrace 0=standard out, 1=file(/tmp/tracetest.log), 2=CORBA log + * If typeTrace=0, checks environment for "SALOME_trace". Test values in + * the following order: + * - "local" standard out + * - "with_logger" CORBA log + * - anything else is kept as a file name + */ +// ============================================================================ + +SALOMETraceCollector* SALOMETraceCollector::instance(CORBA::ORB_ptr theOrb, + int typeTrace) +{ + if (_singleton == 0) // no need of lock when singleton already exists + { + int ret; + ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone + if (_singleton == 0) // another thread may have got + { // the lock after the first test + _singleton = new SALOMETraceCollector(); + + _fileName = "/tmp/tracetest.log"; + _toFile=0; + _orb = theOrb; + if (typeTrace) // caller sets a value different from default=0 + _toFile = typeTrace; + else // check environment + { + char* traceKind = getenv("SALOME_trace"); + //cout<<"SALOME_trace="<putMessage(LogMsg); + //cout << " Logger server found" << endl; + } + break; + case 0 : ; // --- trace to standard output + default : // --- on standard output, too + break; + } + + // Loop until there is no more buffer to print, + // and no ask for end from destructor. + + while ((!_threadToClose) || myTraceBuffer->toCollect() ) + { + int fullBuf = myTraceBuffer->retrieve(myTrace); + if (myTrace.traceType == ABORT_MESS) + { + switch (_toFile) + { + case 2 : // --- trace collection via CORBA + { + stringstream abortMessage(""); + abortMessage << "INTERRUPTION from thread " + << myTrace.threadId << " : " << myTrace.trace; + CORBA::String_var LogMsg = + CORBA::string_dup(abortMessage.str().c_str()); + m_pInterfaceLogger->putMessage(LogMsg); + exit(1); + } + break; + case 1 : // --- trace to file + traceFile << "INTERRUPTION from thread " << myTrace.threadId + << " : " << myTrace.trace; + traceFile.close(); + // no break here ! + case 0 : // --- trace to standard output + default : // --- on standard output, too + cout << flush ; + cerr << "INTERRUPTION from thread " << myTrace.threadId + << " : " << myTrace.trace; + cerr << flush ; + exit(1); + break; + } + } + else + { + switch (_toFile) + { + case 2 : // --- trace collection via CORBA + { + stringstream aMessage(""); + aMessage << "th. " << myTrace.threadId + << " " << myTrace.trace; + CORBA::String_var LogMsg = + CORBA::string_dup(aMessage.str().c_str()); + m_pInterfaceLogger->putMessage(LogMsg); + } + break; + case 1 : // --- trace to file + traceFile << "th. " << myTrace.threadId + << " " << myTrace.trace; + break; + case 0 : // --- trace to standard output + default : // --- on standard output, too + cout << "th. " << myTrace.threadId << " " << myTrace.trace; + break; + } + } + } + + if (_toFile==1) traceFile.close(); + } + pthread_exit(NULL); +} + +// ============================================================================ +/*! + * Destructor: wait until printing thread ends (SALOMETraceCollector::run) + */ +// ============================================================================ + +SALOMETraceCollector:: ~SALOMETraceCollector() +{ + LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance(); + _threadToClose = 1; + myTraceBuffer->insert(NORMAL_MESS,"end of trace "); //needed to wake up thread + if (_threadId) + { + int ret = pthread_join(_threadId, NULL); + if (ret) cout << "error close SALOMETraceCollector : "<< ret << endl; + else cout << "SALOMETraceCollector destruction OK" << endl; + } + delete myTraceBuffer; +} + +// ============================================================================ +/*! + * Constructor: no need of LocalTraceBufferPool object initialization here, + * thread safe singleton used in LocalTraceBufferPool::instance() + */ +// ============================================================================ + +SALOMETraceCollector::SALOMETraceCollector() +{ + _threadId=0; +} + + diff --git a/src/SALOMETraceCollector/SALOMETraceCollector.hxx b/src/SALOMETraceCollector/SALOMETraceCollector.hxx new file mode 100644 index 000000000..846c4adf2 --- /dev/null +++ b/src/SALOMETraceCollector/SALOMETraceCollector.hxx @@ -0,0 +1,54 @@ +// Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOMETraceCollector.hxx +// Author : Paul RASCLE (EDF) +// Module : KERNEL +// $Header$ + +#ifndef _SALOMETRACECOLLECTOR_HXX_ +#define _SALOMETRACECOLLECTOR_HXX_ + +#include +#include +#include "LocalTraceBufferPool.hxx" + +class SALOMETraceCollector +{ + public: + static SALOMETraceCollector* instance(CORBA::ORB_ptr theOrb, int typeTrace=0); + static void *run(void *bid); + ~SALOMETraceCollector(); + + protected: + SALOMETraceCollector(); + + private: + static int _threadToClose; + static int _toFile; + static SALOMETraceCollector* _singleton; + static pthread_mutex_t _singletonMutex; + static pthread_t _threadId; + static std::string _fileName; + static CORBA::ORB_ptr _orb; +}; + +#endif diff --git a/src/Session/Makefile.in b/src/Session/Makefile.in index 01c587221..45ce4c82b 100644 --- a/src/Session/Makefile.in +++ b/src/Session/Makefile.in @@ -53,7 +53,7 @@ BIN_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Component.idl SALOM CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) $(HDF5_INCLUDES) CXXFLAGS+=$(OCC_CXXFLAGS) -LDFLAGS+=$(QT_MT_LIBS) $(HDF5_LIBS) -lSalomeHDFPersist -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace -lSalomeContainer -lRegistry -lSalomeNotification -lSalomeDS -lTOOLSDS -lSalomeGenericObj -lSalomeCatalog -lEvent -lSalomePrs $(CAS_LDPATH) -lTKBO -lCASCatch +LDFLAGS+=$(QT_MT_LIBS) $(HDF5_LIBS) -lSalomeHDFPersist -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace -lSALOMETraceCollector -lSalomeContainer -lRegistry -lSalomeNotification -lSalomeDS -lTOOLSDS -lSalomeGenericObj -lSalomeCatalog -lEvent -lSalomePrs $(CAS_LDPATH) -lTKBO -lCASCatch @CONCLUDE@ diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 33d3440a3..17a971859 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -55,7 +55,7 @@ #include CORBA_SERVER_HEADER(SALOMEDS) #include "utilities.h" -#include "LocalTraceCollector.hxx" +#include "SALOMETraceCollector.hxx" #include "SALOME_Session_i.hxx" @@ -96,7 +96,7 @@ int main(int argc, char **argv) ORB_INIT &init = *SINGLETON_::Instance() ; int orbArgc = 1; CORBA::ORB_var &orb = init( orbArgc , argv ) ; - LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); try { CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); diff --git a/src/TestContainer/Makefile.in b/src/TestContainer/Makefile.in index 8ee409d99..b16797b1f 100644 --- a/src/TestContainer/Makefile.in +++ b/src/TestContainer/Makefile.in @@ -45,7 +45,7 @@ LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl BIN = TestContainer TestLogger BIN_SRC = -LDFLAGS+= -lSalomeNotification -lSalomeNS -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace +LDFLAGS+= -lSalomeNotification -lSalomeNS -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector @CONCLUDE@ diff --git a/src/TestContainer/TestContainer.cxx b/src/TestContainer/TestContainer.cxx index 7766bb46e..e8492fb6e 100644 --- a/src/TestContainer/TestContainer.cxx +++ b/src/TestContainer/TestContainer.cxx @@ -39,7 +39,7 @@ #include "Utils_SINGLETON.hxx" #include "Utils_SALOME_Exception.hxx" #include "Utils_CommException.hxx" -#include "LocalTraceCollector.hxx" +#include "SALOMETraceCollector.hxx" using namespace std; static ostream& operator<<(ostream& os, const CORBA::Exception& e) @@ -66,7 +66,7 @@ int main (int argc, char * argv[]) // Initializing omniORB ORB_INIT &init = *SINGLETON_::Instance() ; CORBA::ORB_var &orb = init( argc , argv ) ; - LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); try { -- 2.39.2