// ============================================================================
/*!
- * Destructor: wait until printing thread ends (BaseTraceCollector::run)
+ * Destructor: virtual, implemented in derived classes.
+ * Wait until printing thread ends (BaseTraceCollector::run)
*/
// ============================================================================
BaseTraceCollector:: ~BaseTraceCollector()
{
- LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance();
- _threadToClose = 1;
- cerr << "BaseTraceCollector:: ~BaseTraceCollector()" << endl << flush;
- myTraceBuffer->insert(NORMAL_MESS,"end of trace"); //needed to wake up thread
- if (_threadId)
- {
- int ret = pthread_join(*_threadId, NULL);
- if (ret) cerr << "error close BaseTraceCollector : "<< ret << endl;
- else cerr << "BaseTraceCollector destruction OK" << endl;
- _threadId = 0;
- }
}
// ============================================================================
/*!
* Constructor: no need of LocalTraceBufferPool object initialization here,
* thread safe singleton used in LocalTraceBufferPool::instance()
+ * See derived classes.
*/
// ============================================================================
BaseTraceCollector::BaseTraceCollector()
{
- _threadId=0;
}
class SALOMELOCALTRACE_EXPORT BaseTraceCollector
{
public:
- ~BaseTraceCollector();
+ virtual ~BaseTraceCollector();
protected:
BaseTraceCollector();
// ============================================================================
/*!
- * This class is for use without CORBA, outside SALOME.
+ * This class is for use without CORBA, inside or outside SALOME.
* SALOME uses SALOMETraceCollector, to allow trace collection via CORBA.
+ * Type of trace (and corresponding class) is choosen in LocalTraceBufferPool.
*
- * guarantees a unique object instance of the class (singleton thread safe)
+ * 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)
- * If typeTrace=0, checks environment for "SALOME_trace". Test values in
- * the following order:
- * - "local" standard out
- * - anything else is kept as a file name
*/
// ============================================================================
ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone
if (_singleton == 0) // another thread may have got
{ // the lock after the first test
+ //cerr << "FileTraceCollector:: instance()" << endl << flush;
_singleton = new FileTraceCollector();
_fileName = fileName;
- cout << " _fileName: " << _fileName << endl;
+ //cerr << " _fileName: " << _fileName << endl;
pthread_t traceThread;
int bid;
int re2 = pthread_create(&traceThread, NULL,
FileTraceCollector::run, (void *)bid);
+ //cerr << "FileTraceCollector:: instance()-end" << endl << flush;
}
ret = pthread_mutex_unlock(&_singletonMutex); // release lock
}
}
*_threadId = pthread_self();
}
- else cout << "----- Comment est-ce possible de passer la ? -------" <<endl;
+ else cerr << "--- FileTraceCollector::run-serious design problem..." <<endl;
ret = pthread_mutex_unlock(&_singletonMutex); // release lock
if (isOKtoRun)
{
-// if (_threadId == 0)
-// {
-// _threadId = new pthread_t;
-// }
if (_threadId == 0)
{
cerr << "FileTraceCollector::run error!" << endl << flush;
exit(1);
}
-// *_threadId = pthread_self();
LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance();
LocalTrace_TraceInfo myTrace;
while ((!_threadToClose) || myTraceBuffer->toCollect() )
{
+ //if (_threadToClose)
+ // cerr << "FileTraceCollector _threadToClose" << endl << flush;
+
int fullBuf = myTraceBuffer->retrieve(myTrace);
if (myTrace.traceType == ABORT_MESS)
{
FileTraceCollector:: ~FileTraceCollector()
{
- cerr << "FileTraceCollector:: ~FileTraceCollector()" << endl << flush;
+ int ret;
+ ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone
+ if (_singleton)
+ {
+ //cerr << "FileTraceCollector:: ~FileTraceCollector()" << endl << flush;
+ LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance();
+ _threadToClose = 1;
+ myTraceBuffer->insert(NORMAL_MESS,"end of trace\n"); // to wake up thread
+ if (_threadId)
+ {
+ int ret = pthread_join(*_threadId, NULL);
+ if (ret) cerr << "error close FileTraceCollector : "<< ret << endl;
+ //else cerr << "FileTraceCollector destruction OK" << endl;
+ _threadId = 0;
+ _threadToClose = 0;
+ }
+ _singleton = 0;
+ ret = pthread_mutex_unlock(&_singletonMutex); // release lock
+ }
}
// ============================================================================
FileTraceCollector::FileTraceCollector()
{
_threadId=0;
+ _threadToClose = 0;
}
char* traceKind = getenv("SALOME_trace");
assert(traceKind);
- cout<<"SALOME_trace="<<traceKind<<endl;
+ //cerr<<"SALOME_trace="<<traceKind<<endl;
if (strcmp(traceKind,"local")==0)
{
LocalTraceBufferPool::LocalTraceBufferPool()
{
- //cout << "LocalTraceBufferPool::LocalTraceBufferPool()" << endl;
+ //cerr << "LocalTraceBufferPool::LocalTraceBufferPool()" << endl;
_insertPos = ULONG_MAX; // first increment will give 0
_retrievePos = ULONG_MAX;
if (ret!=0) IMMEDIATE_ABORT(ret);
ret=pthread_mutex_init(&_incrementMutex,NULL); // default = fast mutex
if (ret!=0) IMMEDIATE_ABORT(ret);
+
+ //cerr << "LocalTraceBufferPool::LocalTraceBufferPool()-end" << endl;
}
// ============================================================================
LocalTraceBufferPool::~LocalTraceBufferPool()
{
- cerr << "LocalTraceBufferPool::~LocalTraceBufferPool()" << endl << flush;
- delete (_myThreadTrace);
- int ret;
- ret=sem_destroy(&_freeBufferSemaphore);
- ret=sem_destroy(&_fullBufferSemaphore);
- ret=pthread_mutex_destroy(&_incrementMutex);
- cerr << "LocalTraceBufferPool::~LocalTraceBufferPool()" << endl << flush;
+ int ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone
+ if (_singleton)
+ {
+ //cerr << "LocalTraceBufferPool::~LocalTraceBufferPool()" << endl<<flush;
+ delete (_myThreadTrace);
+ _myThreadTrace = 0;
+ int ret;
+ ret=sem_destroy(&_freeBufferSemaphore);
+ ret=sem_destroy(&_fullBufferSemaphore);
+ ret=pthread_mutex_destroy(&_incrementMutex);
+ //cerr<<"LocalTraceBufferPool::~LocalTraceBufferPool()-end"<<endl<<flush;
+ _singleton = 0;
+ ret = pthread_mutex_unlock(&_singletonMutex); // release lock
+ }
}
// ============================================================================
private:
static LocalTraceBufferPool* _singleton;
static pthread_mutex_t _singletonMutex;
+ static BaseTraceCollector *_myThreadTrace;
+
LocalTrace_TraceInfo _myBuffer[TRACE_BUFFER_SIZE];
sem_t _freeBufferSemaphore; // to wait until there is a free buffer
sem_t _fullBufferSemaphore; // to wait until there is a buffer to print
unsigned long _position;
unsigned long _insertPos;
unsigned long _retrievePos;
- pthread_t _threadId;
- static BaseTraceCollector *_myThreadTrace;
};
#endif
// ============================================================================
/*!
- * This class is for use without CORBA, outside SALOME.
+ * This class is for use without CORBA, inside or outside SALOME.
* SALOME uses SALOMETraceCollector, to allow trace collection via CORBA.
+ * Type of trace (and corresponding class) is choosen in LocalTraceBufferPool.
*
- * guarantees a unique object instance of the class (singleton thread safe)
+ * 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)
- * If typeTrace=0, checks environment for "SALOME_trace". Test values in
- * the following order:
- * - "local" standard out
- * - anything else is kept as a file name
*/
// ============================================================================
if (! _threadId) // only one run
{
isOKtoRun = 1;
- if(_threadId == 0) {
- _threadId = new pthread_t;
- }
+ if(_threadId == 0)
+ {
+ _threadId = new pthread_t;
+ }
*_threadId = pthread_self();
}
- else cout << "----- Comment est-ce possible de passer la ? -------" <<endl;
+ else cerr << "--- LocalTraceCollector::run-serious design problem..." <<endl;
ret = pthread_mutex_unlock(&_singletonMutex); // release lock
{
if(_threadId == 0)
{
- _threadId = new pthread_t;
+ cerr << "LocalTraceCollector::run error!" << endl << flush;
+ exit(1);
}
- *_threadId = pthread_self();
LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance();
LocalTrace_TraceInfo myTrace;
while ((!_threadToClose) || myTraceBuffer->toCollect() )
{
+ //if (_threadToClose)
+ // cerr << "FileTraceCollector _threadToClose" << endl << flush;
+
int fullBuf = myTraceBuffer->retrieve(myTrace);
if (myTrace.traceType == ABORT_MESS)
{
LocalTraceCollector:: ~LocalTraceCollector()
{
- cerr << "LocalTraceCollector:: ~LocalTraceCollector()" << endl << flush;
+ int ret;
+ ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone
+ if (_singleton)
+ {
+ //cerr << "LocalTraceCollector:: ~LocalTraceCollector()" << endl <<flush;
+ LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance();
+ _threadToClose = 1;
+ myTraceBuffer->insert(NORMAL_MESS,"end of trace\n"); // to wake up thread
+ if (_threadId)
+ {
+ int ret = pthread_join(*_threadId, NULL);
+ if (ret) cerr << "error close LocalTraceCollector : "<< ret << endl;
+ //else cerr << "LocalTraceCollector destruction OK" << endl;
+ _threadId = 0;
+ _threadToClose = 0;
+ }
+ _singleton = 0;
+ ret = pthread_mutex_unlock(&_singletonMutex); // release lock
+ }
}
// ============================================================================
LocalTraceCollector::LocalTraceCollector()
{
_threadId=0;
+ _threadToClose = 0;
}
#include "SALOMETraceCollector.hxx"
#include "TraceCollector_WaitForServerReadiness.hxx"
-//#include "SALOME_Log.hxx"
#include <SALOMEconfig.h>
#include CORBA_CLIENT_HEADER(Logger)
// ============================================================================
/*!
- * This class replaces LocalTraceCollector, which is to use outside SALOME,
- * without CORBA.
+ * This class is for use with CORBA, inside SALOME.
+ * Type of trace (and corresponding class) is choosen in LocalTraceBufferPool.
*
- * guarantees a unique object instance of the class (singleton thread safe)
+ * 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
*/
// ============================================================================
*_threadId = pthread_self();
}
- else cout << "----- Comment est-ce possible de passer la ? -------" <<endl;
+ else cerr << "-- SALOMETraceCollector::run-serious design problem..." <<endl;
+
ret = pthread_mutex_unlock(&_singletonMutex); // release lock
if (isOKtoRun)
{
if(_threadId == 0)
{
- _threadId = new pthread_t;
+ cerr << "SALOMETraceCollector::run error!" << endl << flush;
+ exit(1);
}
- *_threadId = pthread_self();
LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance();
LocalTrace_TraceInfo myTrace;
CORBA::String_var LogMsg =
CORBA::string_dup("\n---Init logger trace---\n");
m_pInterfaceLogger->putMessage(LogMsg);
- cout << " Logger server found" << endl;
+ //cerr << " Logger server found" << endl;
}
// --- Loop until there is no more buffer to print,
SALOMETraceCollector:: ~SALOMETraceCollector()
{
+ int ret;
+ ret = pthread_mutex_lock(&_singletonMutex); // acquire lock to be alone
+ if (_singleton)
+ {
+ //cerr << "SALOMETraceCollector:: ~SALOMETraceCollector()" <<endl<<flush;
+ LocalTraceBufferPool* myTraceBuffer = LocalTraceBufferPool::instance();
+ _threadToClose = 1;
+ myTraceBuffer->insert(NORMAL_MESS,"end of trace\n"); // to wake up thread
+ if (_threadId)
+ {
+ int ret = pthread_join(*_threadId, NULL);
+ if (ret) cerr << "error close SALOMETraceCollector : "<< ret << endl;
+ //else cerr << "SALOMETraceCollector destruction OK" << endl;
+ _threadId = 0;
+ _threadToClose = 0;
+ }
+ _singleton = 0;
+ ret = pthread_mutex_unlock(&_singletonMutex); // release lock
+ }
}
// ============================================================================
SALOMETraceCollector::SALOMETraceCollector()
{
_threadId=0;
+ _threadToClose = 0;
}
// ============================================================================
obj = inc->resolve(name);
if (!CORBA::is_nil(obj))
{
- cout << "TraceCollector_WaitForServerReadiness: "
- << serverName << " found in CORBA Name Service" << endl;
+ //cout << "TraceCollector_WaitForServerReadiness: "
+ // << serverName << " found in CORBA Name Service" << endl;
break;
}
}