1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/***************************************************************
* Name: ThreadSearchTrace
*
* Purpose: This class implements the events sent by the
* worker search thread (ThreadSearchThread) to the
* ThreadSearchView to update the file/line/line
* list control.
* wxCommandEvent m_commandString contains file path.
* m_LineTextArray contains Line/FoundText series of items
*
* Author: Jerome ANTOINE
* Created: 2007-10-08
* Copyright: Jerome ANTOINE
* License: GPL
**************************************************************/
#include <wx/datetime.h>
#include <wx/intl.h>
#include "ThreadSearchTrace.h"
ThreadSearchTrace* ThreadSearchTrace::ms_Tracer = NULL;
bool ThreadSearchTrace::Trace(const wxString& str)
{
wxASSERT(ms_Tracer != NULL);
wxMutexLocker mutexLocker(*ms_Tracer);
if ( mutexLocker.IsOk() )
{
if ( (ms_Tracer != NULL) && (ms_Tracer->IsOpened() == true) )
{
wxDateTime now = wxDateTime::Now();
//ms_Tracer->Write(_T(" ") + now.FormatISOTime() + _T(" "));
ms_Tracer->Write(_T(" ") + wxString::Format(wxT("%d:%d:%d:%d %s\n"), now.GetHour(), now.GetMinute(), now.GetSecond(), now.GetMillisecond(), str.c_str()));
// ms_Tracer->Write(str);
// ms_Tracer->Write(_T("\n"));
}
}
return mutexLocker.IsOk();
}
bool ThreadSearchTrace::Init(const wxString& path)
{
wxASSERT(ms_Tracer == NULL);
ms_Tracer = new ThreadSearchTrace();
if ( wxFile::Exists(path) )
{
wxRemoveFile(path);
}
return ms_Tracer->Open(path.c_str(), wxFile::write_excl);
}
void ThreadSearchTrace::Uninit()
{
wxASSERT(ms_Tracer != NULL);
wxMutexLocker mutexLocker(*ms_Tracer);
if ( mutexLocker.IsOk() )
{
if ( ms_Tracer != NULL )
{
if ( ms_Tracer->IsOpened() == true )
{
ms_Tracer->Close();
}
delete ms_Tracer;
ms_Tracer = NULL;
}
}
}
TraceBeginEndOfMethod::TraceBeginEndOfMethod(const wxString& method)
:m_Method(method)
{
wxString begin(_("Begin of "));
begin += m_Method;
ThreadSearchTrace::Trace(begin);
}
TraceBeginEndOfMethod::~TraceBeginEndOfMethod()
{
wxString end(_("End of "));
end += m_Method;
ThreadSearchTrace::Trace(end);
}
|