KiCad PCB EDA Suite
Loading...
Searching...
No Matches
reporter.cpp
Go to the documentation of this file.
1
4/*
5 * This program source code file is part of KiCad, a free EDA CAD application.
6 *
7 * Copyright (C) 2013 Wayne Stambaugh <[email protected]>
8 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#include <mutex>
29#include <macros.h>
30#include <reporter.h>
31#include <string_utils.h>
32#include <widgets/wx_infobar.h>
33#include <wx/crt.h>
34#include <wx/log.h>
35#include <wx/textctrl.h>
36#include <wx/statusbr.h>
37
38
44static const wxChar traceReporter[] = wxT( "KICAD_REPORTER" );
45
46static std::mutex g_logReporterMutex;
47
48
49REPORTER& REPORTER::Report( const char* aText, SEVERITY aSeverity )
50{
51 Report( From_UTF8( aText ) );
52 return *this;
53}
54
55
56REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
57{
58 REPORTER::Report( aText, aSeverity );
59
60 wxCHECK_MSG( m_textCtrl != nullptr, *this,
61 wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
62
63 m_textCtrl->AppendText( aText + wxS( "\n" ) );
64 return *this;
65}
66
67
68REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
69{
70 REPORTER::Report( aText, aSeverity );
71
72 m_string << aText << wxS( "\n" );
73 return *this;
74}
75
76
77const wxString& WX_STRING_REPORTER::GetMessages() const
78{
79 return m_string;
80}
81
82
84{
86 m_string.clear();
87}
88
89
90REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
91{
92 return REPORTER::Report( aText, aSeverity );
93}
94
95
97{
98 static REPORTER* s_nullReporter = nullptr;
99
100 if( !s_nullReporter )
101 s_nullReporter = new NULL_REPORTER();
102
103 return *s_nullReporter;
104}
105
106
107REPORTER& CLI_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
108{
109 REPORTER::Report( aMsg, aSeverity );
110
111 FILE* target = stdout;
112
113 if( aSeverity == RPT_SEVERITY_ERROR )
114 target = stderr;
115
116 if( aMsg.EndsWith( wxS( "\n" ) ) )
117 wxFprintf( target, aMsg );
118 else
119 wxFprintf( target, aMsg + wxS( "\n" ) );
120
121 // Needed after wxPrintf (or printf) to be sure the message is immediately printed
122 // (i.e. not stored in some i/o buffer)
123 fflush( target );
124
125 return *this;
126}
127
128
130{
131 static CLI_REPORTER s_cliReporter;
132
133 return s_cliReporter;
134}
135
136
137REPORTER& STDOUT_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
138{
139 REPORTER::Report( aMsg, aSeverity );
140
141 switch( aSeverity )
142 {
143 case RPT_SEVERITY_UNDEFINED: std::cout << "SEVERITY_UNDEFINED: "; break;
144 case RPT_SEVERITY_INFO: std::cout << "SEVERITY_INFO: "; break;
145 case RPT_SEVERITY_WARNING: std::cout << "SEVERITY_WARNING: "; break;
146 case RPT_SEVERITY_ERROR: std::cout << "SEVERITY_ERROR: "; break;
147 case RPT_SEVERITY_ACTION: std::cout << "SEVERITY_ACTION: "; break;
148 case RPT_SEVERITY_DEBUG: std::cout << "SEVERITY_DEBUG: "; break;
150 case RPT_SEVERITY_IGNORE: break;
151 }
152
153 std::cout << aMsg << std::endl;
154
155 return *this;
156}
157
158
160{
161 static REPORTER* s_stdoutReporter = nullptr;
162
163 if( !s_stdoutReporter )
164 s_stdoutReporter = new STDOUT_REPORTER();
165
166 return *s_stdoutReporter;
167}
168
169
170REPORTER& WXLOG_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
171{
172 REPORTER::Report( aMsg, aSeverity );
173
174 switch( aSeverity )
175 {
176 case RPT_SEVERITY_ERROR: wxLogError( aMsg ); break;
177 case RPT_SEVERITY_WARNING: wxLogWarning( aMsg ); break;
178 case RPT_SEVERITY_UNDEFINED: wxLogMessage( aMsg ); break;
179 case RPT_SEVERITY_INFO: wxLogInfo( aMsg ); break;
180 case RPT_SEVERITY_ACTION: wxLogInfo( aMsg ); break;
181 case RPT_SEVERITY_DEBUG: wxLogTrace( traceReporter, aMsg ); break;
182 case RPT_SEVERITY_EXCLUSION: break;
183 case RPT_SEVERITY_IGNORE: break;
184 }
185
186 return *this;
187}
188
189
191{
192 static REPORTER* s_wxLogReporter = nullptr;
193 std::lock_guard lock( g_logReporterMutex );
194
195 if( !s_wxLogReporter )
196 s_wxLogReporter = new WXLOG_REPORTER();
197
198 return *s_wxLogReporter;
199}
200
201
202REPORTER& REDIRECT_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
203{
204 REPORTER::Report( aText, aSeverity );
205
206 if( m_redirectTarget )
207 m_redirectTarget->Report( aText, aSeverity );
208
209 return *this;
210}
211
212
213REPORTER& STATUSBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
214{
215 REPORTER::Report( aText, aSeverity );
216
217 if( m_statusBar )
218 m_statusBar->SetStatusText( aText, m_position );
219
220 return *this;
221}
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:107
static REPORTER & GetInstance()
Definition reporter.cpp:129
static REPORTER & GetInstance()
Definition reporter.cpp:96
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:90
REPORTER * m_redirectTarget
Definition reporter.h:289
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:202
virtual void Clear()
Definition reporter.h:153
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
REPORTER()
Definition reporter.h:75
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:213
wxStatusBar * m_statusBar
Definition reporter.h:308
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:137
static REPORTER & GetInstance()
Definition reporter.cpp:159
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:170
static REPORTER & GetInstance()
Definition reporter.cpp:190
wxString m_string
Definition reporter.h:206
void Clear() override
Definition reporter.cpp:83
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:68
const wxString & GetMessages() const
Definition reporter.cpp:77
wxTextCtrl * m_textCtrl
Definition reporter.h:183
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:56
static const wxChar traceReporter[]
Flag to enable reporter debugging output.
Definition reporter.cpp:44
This file contains miscellaneous commonly used macros and functions.
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
@ RPT_SEVERITY_EXCLUSION
@ RPT_SEVERITY_IGNORE
@ RPT_SEVERITY_DEBUG
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
static std::mutex g_logReporterMutex
Definition reporter.cpp:46
wxString From_UTF8(const char *cstring)