~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/codesnippets/Search/ThreadSearchTrace.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

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