-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.cpp
More file actions
290 lines (208 loc) · 8.11 KB
/
Debug.cpp
File metadata and controls
290 lines (208 loc) · 8.11 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/* -----------------------------------------------------------------
Debug.cpp
This class is for displaying error, warning, and debugging
messages to the user and the error log.
Michael T. Duffy
----------------------------------------------------------------- */
// Debug.cpp
// Copyright 2002, 2008 Michael T. Duffy. All Rights Reserved
// contact: mduffor@gmail.com
// This file is part of TEdit.
//
// TEdit is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3 as
// published by the Free Software Foundation.
//
// TEdit 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TEdit. If not, see <http://www.gnu.org/licenses/>.
// ***********************************************************************
// Compile Directives
// ***********************************************************************
// #pragma pack (1);
// ***********************************************************************
// Header Files
// ***********************************************************************
#include <stdio.h>
#include <stdlib.h>
#include "RStr.hpp"
#include "Types.hpp"
#include "Debug.hpp"
ASSERTFILE (__FILE__)
#ifdef ANDROID_NDK
#include <jni.h>
#include <android/log.h>
#endif // ANDROID_NDK
// ***********************************************************************
// Module Variables
// ***********************************************************************
// Define the singleton
PDebugMessages pdbgMessages = NULL;
RStr strDbgBuffer;
// ***********************************************************************
// DebugMessages
// ***********************************************************************
//------------------------------------------------------------------------
DebugMessages::DebugMessages ()
{
};
//------------------------------------------------------------------------
DebugMessages::~DebugMessages ()
{
};
//------------------------------------------------------------------------
void DebugMessages::Assert (UINT32 uStatusIn,
const RStr & strFileIn,
UINT32 uLineIn)
{
if (uStatusIn)
{
// the status checks out. Do nothing.
}
else
{
// failed status check. Display a message.
RStr strMsgOut;
strMsgOut.Format ("ASSERT ERROR in file %s at line %d.", strFileIn.AsChar (), uLineIn);
RawWriteLog (strMsgOut.AsChar ());
RawUserDisp ("Assert", strMsgOut.AsChar ());
};
};
//------------------------------------------------------------------------
void DebugMessages::RunMark (const char * pszTextIn,
const RStr & strFileIn,
UINT32 uLineIn)
{
RStr strMsgOut;
strMsgOut.Format ("RUN MARK in file %s at line %d: %s", strFileIn.AsChar (), uLineIn, pszTextIn);
RawWriteLog (strMsgOut.AsChar ());
};
//------------------------------------------------------------------------
void DebugMessages::Info (const char * pszTextIn,
const RStr & strFileIn,
UINT32 uLineIn)
{
RStr strMsgOut;
// For info messages, we will only display the file name, not the entire path.
strMsgOut.Format ("INFO (%s:%d): %s",
strFileIn.AsChar (strFileIn.ReverseFindChar ('/') + 1),
uLineIn,
pszTextIn);
RawWriteLog (strMsgOut.AsChar ());
};
//------------------------------------------------------------------------
void DebugMessages::Warning (const char * pszTextIn,
const RStr & strFileIn,
UINT32 uLineIn)
{
RStr strMsgOut;
strMsgOut.Format ("WARNING (%s:%d): %s", strFileIn.AsChar (strFileIn.ReverseFindChar ('/') + 1), uLineIn, pszTextIn);
RawWriteLog (strMsgOut.AsChar ());
};
//------------------------------------------------------------------------
void DebugMessages::Error (const char * pszTextIn,
const RStr & strFileIn,
UINT32 uLineIn)
{
RStr strMsgOut;
strMsgOut.Format ("***** ERROR!!! (%s:%d): %s *****", strFileIn.AsChar (strFileIn.ReverseFindChar ('/') + 1), uLineIn, pszTextIn);
RawWriteLog (strMsgOut.AsChar ());
RawUserDisp ("Error!!!", strMsgOut.AsChar ());
};
//------------------------------------------------------------------------
void DebugMessages::RawError (const char * pszTextIn)
{
RStr strMsgOut (pszTextIn);
RawWriteLog (strMsgOut.AsChar ());
RawUserDisp ("Error!!!", strMsgOut.AsChar ());
};
//------------------------------------------------------------------------
void DebugMessages::RunMark (const RStr & strTextIn,
const RStr & strFileIn,
UINT32 uLineIn)
{
RunMark (strTextIn.AsChar (), strFileIn, uLineIn);
};
//------------------------------------------------------------------------
void DebugMessages::Warning (const RStr & strTextIn,
const RStr & strFileIn,
UINT32 uLineIn)
{
Warning (strTextIn.AsChar (), strFileIn, uLineIn);
};
//------------------------------------------------------------------------
void DebugMessages::Error (const RStr & strTextIn,
const RStr & strFileIn,
UINT32 uLineIn)
{
Error (strTextIn.AsChar (), strFileIn, uLineIn);
};
//------------------------------------------------------------------------
void DebugMessages::RawError (const RStr & strTextIn)
{
RawError (strTextIn.AsChar ());
};
//------------------------------------------------------------------------
void DebugMessages::RawUserDisp (const char * pszDialogTitleIn,
const char * pszTextIn)
{
// There is no default behavior for displaying user messages. Generally anything
// that will display a user message will also write out a log message.
printf ("%s\n", pszTextIn);
};
//------------------------------------------------------------------------
void DebugMessages::RawWriteLog (const char * pszTextIn)
{
FILE * fp;
// The default behavior for RawWriteLog is to display a message to a
// file called "debug.err".
// we open and close the file each time in order to assure that the
// message is written, even if we crash.
#ifdef ANDROID_NDK
__android_log_print(ANDROID_LOG_INFO, "RavenDebug", "%s", pszTextIn);
#else
printf ("%s\n", pszTextIn);
fp = fopen ("debug.err", "at");
if (fp != NULL)
{
fprintf (fp, "%s\n", pszTextIn);
fclose (fp);
};
#endif
};
// ***********************************************************************
// DebugMessagesFactory
// ***********************************************************************
//------------------------------------------------------------------------
DebugMessagesFactory::DebugMessagesFactory ()
{
};
//------------------------------------------------------------------------
DebugMessagesFactory::~DebugMessagesFactory ()
{
};
//------------------------------------------------------------------------
PDebugMessages DebugMessagesFactory::Initialize (VOID)
{
#ifdef ANDROID_NDK
#else
remove ("debug.err");
#endif
SetSingleton (new DebugMessages);
return (pdbgMessages);
};
//------------------------------------------------------------------------
void DebugMessagesFactory::Uninitialize (VOID)
{
delete pdbgMessages;
SetSingleton (NULL);
};
//------------------------------------------------------------------------
void DebugMessagesFactory::SetSingleton (PDebugMessages pdbgMessagesIn)
{
pdbgMessages = pdbgMessagesIn;
};