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
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
--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,...
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':
# 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']
<launchoptions>
<gui>yes</gui>
<logger>no</logger>
+ <!-- <file>atrace.log</file> -->
<xterm>no</xterm>
<portkill>yes</portkill>
<killall>no</killall>
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 $@
#============================================================
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
#include "SALOME_NamingService.hxx"
#include "SALOME_Container_i.hxx"
#include "utilities.h"
-#include "LocalTraceCollector.hxx"
+#include "SALOMETraceCollector.hxx"
#ifdef CHECKTIME
#include <Utils_Timer.hxx>
// Initialise the ORB.
ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
CORBA::ORB_var &orb = init( argc , argv ) ;
- LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb);
+ SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
INFOS_COMPILATION;
BEGIN_OF(argv[0]);
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@
#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;
{
// 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;
CPPFLAGS+=$(QT_MT_INCLUDES)
CXXFLAGS+=$(OCC_CXXFLAGS)
-LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace
+LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector
@CONCLUDE@
#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
/*!
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;
@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 \
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@
#include "SALOME_NamingService.hxx"
#include "SALOME_ModuleCatalog_impl.hxx"
#include "utilities.h"
-#include "LocalTraceCollector.hxx"
+#include "SALOMETraceCollector.hxx"
#include "Utils_SINGLETON.hxx"
#ifdef CHECKTIME
{
// 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;
BIN_SRC =
BIN_SERVER_IDL = SALOME_Registry.idl
-LDFLAGS+= -lSalomeNS -lOpUtil -lSALOMELocalTrace
+LDFLAGS+= -lSalomeNS -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector
@CONCLUDE@
}
#include "utilities.h"
-#include "LocalTraceCollector.hxx"
+#include "SALOMETraceCollector.hxx"
#include "Utils_ORB_INIT.hxx"
#include "Utils_SINGLETON.hxx"
#include "Utils_SALOME_Exception.hxx"
{
ORB_INIT &init = *SINGLETON_<ORB_INIT>::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)
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@
#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;
{
// 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;
#include <sstream>
#include <fstream>
#include <cstdlib>
-#include <CORBA.h>
using namespace std;
#include "LocalTraceCollector.hxx"
#include "LocalTrace_WaitForServerReadiness.hxx"
//#include "SALOME_Log.hxx"
-#include <SALOMEconfig.h>
-#include CORBA_CLIENT_HEADER(Logger)
// Class attributes initialisation, for class method LocalTraceCollector::run
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
{
_fileName = "/tmp/tracetest.log";
_toFile=0;
- _orb = theOrb;
+
if (typeTrace) // caller sets a value different from default=0
_toFile = typeTrace;
else // check environment
if (traceKind)
{
if (strcmp(traceKind,"local")==0) _toFile=0;
- else if (strcmp(traceKind,"with_logger")==0) _toFile=2;
+
else
{
_toFile=1;
// 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)
{
}
}
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;
{
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;
{
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;
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;
}
#define _LOCALTRACECOLLECTOR_HXX_
#include <string>
-#include <CORBA.h>
#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();
static pthread_mutex_t _singletonMutex;
static pthread_t _threadId;
static std::string _fileName;
- static CORBA::ORB_ptr _orb;
};
#endif
+++ /dev/null
-// 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 : LocalTrace_WaitForServerReadiness.cxx
-// Author : Paul RASCLE (EDF)
-// Module : KERNEL
-// $Header$
-
-#include "LocalTrace_WaitForServerReadiness.hxx"
-#include <iostream>
-#include <ctime>
-
-using namespace std;
-
-// ============================================================================
-/*!
- * Wait until a server is registered in naming service.
- * \param serverName name of the server to find.
- * When SALOME_NamingService is available,
- * use NamingService_WaitForServerReadiness instead.
- * This function is needed when macro MESSAGE used by SALOME_NamingService
- * is not available (inside LocalTrace methods, for instance !).
- * Direct access to CORBA Name Service. Look for serverName at Name service
- * Root without extensions.
- */
-// ============================================================================
-
-CORBA::Object_ptr LocalTrace_WaitForServerReadiness(CORBA::ORB_ptr orb,
- string serverName)
-{
- long TIMESleep = 250000000;
- int NumberOfTries = 40;
-
- timespec ts_req;
- ts_req.tv_nsec=TIMESleep;
- ts_req.tv_sec=0;
- timespec ts_rem;
- ts_rem.tv_nsec=0;
- ts_rem.tv_sec=0;
-
- CORBA::Object_var obj;
-
- try
- {
- // 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;
-
- 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::COMM_FAILURE& )
- {
- cout << "LocalTrace_WaitForServerReadiness: "
- << "CORBA::COMM_FAILURE: "
- << "Unable to contact the Naming Service" << endl;
- }
- catch(...)
- {
- cout << "LocalTrace_WaitForServerReadiness: "
- << "Unknown exception dealing with Naming Service" << endl;
- }
-
- if(!CORBA::is_nil(inc))
- {
- obj = inc->resolve(name);
- if (!CORBA::is_nil(obj))
- {
- cout << "LocalTrace_WaitForServerReadiness: "
- << serverName << " found in CORBA Name Service" << endl;
- break;
- }
- }
- int a = nanosleep(&ts_req,&ts_rem);
- cout << "LocalTrace_WaitForServerReadiness: retry look for"
- << serverName << endl;
- }
- }
- catch (const CosNaming::NamingContext::NotFound&)
- {
- cout << "Caught exception: Naming Service can't found Logger";
- }
- catch (CORBA::COMM_FAILURE&)
- {
- cout << "Caught CORBA::SystemException CommFailure.";
- }
- catch (CORBA::SystemException&)
- {
- cout << "Caught CORBA::SystemException.";
- }
- catch (CORBA::Exception&)
- {
- cout << "Caught CORBA::Exception.";
- }
- catch (...)
- {
- cout << "Caught unknown exception.";
- }
- return obj._retn();
-}
-
+++ /dev/null
-// 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 : LocalTrace_WaitForServerReadiness.hxx
-// Author : Paul RASCLE (EDF)
-// Module : KERNEL
-// $Header$
-
-#ifndef _LOCALTRACE_WAITFORSERVERREADINESS_HXX_
-#define _LOCALTRACE_WAITFORSERVERREADINESS_HXX_
-
-#include <CORBA.h>
-#include <string>
-
-CORBA::Object_ptr LocalTrace_WaitForServerReadiness(CORBA::ORB_ptr theOrb,
- std::string serverName);
-
-#endif
# header files
EXPORT_HEADERS= utilities.h \
LocalTraceBufferPool.hxx \
- LocalTraceCollector.hxx \
- LocalTrace_WaitForServerReadiness.hxx
+ LocalTraceCollector.hxx
EXPORT_PYSCRIPTS =
LIB = libSALOMELocalTrace.la
LIB_SRC = LocalTraceCollector.cxx \
- LocalTraceBufferPool.cxx \
- LocalTrace_WaitForServerReadiness.cxx
+ LocalTraceBufferPool.cxx
-LIB_CLIENT_IDL = Logger.idl
LDFLAGS+=
@CONCLUDE@
--- /dev/null
+// 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 : LocalTrace_WaitForServerReadiness.cxx
+// Author : Paul RASCLE (EDF)
+// Module : KERNEL
+// $Header$
+
+#include "LocalTrace_WaitForServerReadiness.hxx"
+#include <iostream>
+#include <ctime>
+
+using namespace std;
+
+// ============================================================================
+/*!
+ * Wait until a server is registered in naming service.
+ * \param serverName name of the server to find.
+ * When SALOME_NamingService is available,
+ * use NamingService_WaitForServerReadiness instead.
+ * This function is needed when macro MESSAGE used by SALOME_NamingService
+ * is not available (inside LocalTrace methods, for instance !).
+ * Direct access to CORBA Name Service. Look for serverName at Name service
+ * Root without extensions.
+ */
+// ============================================================================
+
+CORBA::Object_ptr LocalTrace_WaitForServerReadiness(CORBA::ORB_ptr orb,
+ string serverName)
+{
+ long TIMESleep = 250000000;
+ int NumberOfTries = 40;
+
+ timespec ts_req;
+ ts_req.tv_nsec=TIMESleep;
+ ts_req.tv_sec=0;
+ timespec ts_rem;
+ ts_rem.tv_nsec=0;
+ ts_rem.tv_sec=0;
+
+ CORBA::Object_var obj;
+
+ try
+ {
+ // 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;
+
+ 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::COMM_FAILURE& )
+ {
+ cout << "LocalTrace_WaitForServerReadiness: "
+ << "CORBA::COMM_FAILURE: "
+ << "Unable to contact the Naming Service" << endl;
+ }
+ catch(...)
+ {
+ cout << "LocalTrace_WaitForServerReadiness: "
+ << "Unknown exception dealing with Naming Service" << endl;
+ }
+
+ if(!CORBA::is_nil(inc))
+ {
+ obj = inc->resolve(name);
+ if (!CORBA::is_nil(obj))
+ {
+ cout << "LocalTrace_WaitForServerReadiness: "
+ << serverName << " found in CORBA Name Service" << endl;
+ break;
+ }
+ }
+ int a = nanosleep(&ts_req,&ts_rem);
+ cout << "LocalTrace_WaitForServerReadiness: retry look for"
+ << serverName << endl;
+ }
+ }
+ catch (const CosNaming::NamingContext::NotFound&)
+ {
+ cout << "Caught exception: Naming Service can't found Logger";
+ }
+ catch (CORBA::COMM_FAILURE&)
+ {
+ cout << "Caught CORBA::SystemException CommFailure.";
+ }
+ catch (CORBA::SystemException&)
+ {
+ cout << "Caught CORBA::SystemException.";
+ }
+ catch (CORBA::Exception&)
+ {
+ cout << "Caught CORBA::Exception.";
+ }
+ catch (...)
+ {
+ cout << "Caught unknown exception.";
+ }
+ return obj._retn();
+}
+
--- /dev/null
+// 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 : LocalTrace_WaitForServerReadiness.hxx
+// Author : Paul RASCLE (EDF)
+// Module : KERNEL
+// $Header$
+
+#ifndef _LOCALTRACE_WAITFORSERVERREADINESS_HXX_
+#define _LOCALTRACE_WAITFORSERVERREADINESS_HXX_
+
+#include <CORBA.h>
+#include <string>
+
+CORBA::Object_ptr LocalTrace_WaitForServerReadiness(CORBA::ORB_ptr theOrb,
+ std::string serverName);
+
+#endif
--- /dev/null
+# 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@
--- /dev/null
+// 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 <iostream>
+#include <sstream>
+#include <fstream>
+#include <cstdlib>
+#include <CORBA.h>
+
+using namespace std;
+
+#include "SALOMETraceCollector.hxx"
+#include "LocalTrace_WaitForServerReadiness.hxx"
+//#include "SALOME_Log.hxx"
+#include <SALOMEconfig.h>
+#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="<<traceKind<<endl;
+ if (traceKind)
+ {
+ if (strcmp(traceKind,"local")==0) _toFile=0;
+ else if (strcmp(traceKind,"with_logger")==0) _toFile=2;
+ else
+ {
+ _toFile=1;
+ _fileName = traceKind;
+ }
+ }
+ }
+ //cout <<"_toFile: "<<_toFile<<" _fileName: "<<_fileName<<endl;
+
+ pthread_t traceThread;
+ int bid;
+ int re2 = pthread_create(&traceThread, NULL,
+ SALOMETraceCollector::run, (void *)bid);
+ }
+ ret = pthread_mutex_unlock(&_singletonMutex); // release lock
+ }
+ return _singleton;
+}
+
+// ============================================================================
+/*!
+ * In a separate thread, loop to print traces.
+ * Mutex garantees intialisation on instance method is done and only one run
+ * allowed (double check ...)
+ * Loop until there is no more buffer to print,
+ * and no ask for end from destructor.
+ * Get a buffer. If type = ABORT then exit application with message.
+ */
+// ============================================================================
+
+void* SALOMETraceCollector::run(void *bid)
+{
+ int isOKtoRun = 0;
+ int ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone
+ if (! _threadId) // only one run
+ {
+ isOKtoRun = 1;
+ _threadId = pthread_self();
+ }
+ else cout << "----- Comment est-ce possible de passer la ? -------" <<endl;
+ ret = pthread_mutex_unlock(&_singletonMutex); // release lock
+
+ if (isOKtoRun)
+ {
+ _threadId = pthread_self();
+ LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance();
+ LocalTrace_TraceInfo myTrace;
+
+ // 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)
+ {
+ case 1 : // --- trace to file
+ {
+ const char *fileName = _fileName.c_str();
+ traceFile.open(fileName, ios::out | ios::app);
+ if (!traceFile)
+ {
+ cerr << "impossible to open trace file "<< fileName << endl;
+ exit (1);
+ }
+ }
+ 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;
+ }
+
+ // 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;
+}
+
+
--- /dev/null
+// 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 <string>
+#include <CORBA.h>
+#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
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@
#include CORBA_SERVER_HEADER(SALOMEDS)
#include "utilities.h"
-#include "LocalTraceCollector.hxx"
+#include "SALOMETraceCollector.hxx"
#include "SALOME_Session_i.hxx"
ORB_INIT &init = *SINGLETON_<ORB_INIT>::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");
BIN = TestContainer TestLogger
BIN_SRC =
-LDFLAGS+= -lSalomeNotification -lSalomeNS -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace
+LDFLAGS+= -lSalomeNotification -lSalomeNS -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace -lSALOMETraceCollector
@CONCLUDE@
#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)
// Initializing omniORB
ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
CORBA::ORB_var &orb = init( argc , argv ) ;
- LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb);
+ SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
try
{