-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathFasterCapGlobal.cpp
164 lines (123 loc) · 5.11 KB
/
FasterCapGlobal.cpp
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
/***************************************************************************
* *
* Copyright (c) 2017 *
* FastFieldSolvers S.R.L. http://www.fastfieldsolvers.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License (LGPL) *
* as published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* for detail see the LICENCE text file. *
* *
* This program 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 Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* USA *
* *
***************************************************************************/
#include "FasterCapGlobal.h"
#ifndef FCG_HEADLESS
#include <wx/msgdlg.h>
#endif // !FCG_HEADLESS
// signals FasterCap to abort simulation and start waiting again for commands
volatile bool g_bFCContinue = true;
#ifdef DEBUG_LOG_ENABLE
int DebugMsg(const char *fmt,...)
{
int ret = 0;
wxString msg;
va_list arg_ptr;
wxDateTime currtime;
va_start(arg_ptr, fmt);
ret = msg.PrintfV(fmt, arg_ptr);
va_end(arg_ptr);
// if PrintfV() returns error
if(ret < 0) {
msg = wxT("Error: DebugMsg() is not able to print the message\n");
}
// add timestamp
currtime.SetToCurrent();
msg = currtime.FormatISODate() + wxT("@") + currtime.FormatISOTime() + wxT(" ") + msg;
std::cout << msg;
std::cout.flush();
return ret;
}
#else //not DEBUG_LOG_ENABLE
int DebugMsg(const char *,...)
{
return 0;
}
#endif //DEBUG_LOG_ENABLE
#ifndef FCG_HEADLESS
// Static data members must be initialized at file scope, even if private.
FasterCapApp *Globals::m_pApp = NULL;
// remark: cannot be used before initializing 'g_bIsConsole'
// also, in console mode 'style' is ignored
void SysMsg(wxString message, wxString caption, long style)
{
if(g_bIsConsole == true) {
std::cout << caption << " : " << message << std::endl;
}
else {
wxMessageBox(message, caption, style);
}
}
// in case of GUI, the LogMsg(), ErrMsg() functions etc. are implemented in FasterCapApp.cpp
#else // if FCG_HEADLESS
// ----------------------------------------------------------------------------
// global functions for printing messages to the console window
// ----------------------------------------------------------------------------
int LogMsg(const char *fmt,...)
{
wxString msg;
int ret;
va_list arg_ptr;
char buf[FCM_LOG_BUF_SIZE];
// The reason for using vsnprintf() instead of wxString::Format() or
// wxString::PrintfV() is that, since we passed variable args,
// then the proper casting is 'gone' beecause it's too late to do anything about
// the arguments when they're already in va_list form
// so wxString::PrintfV() expects strings in Unicode in a Unicode build,
// or in UTF-8 in a non-unicode build, i.e. build-depending.
// Since our LogMsg / ErrMsg is used with UTF-8 parameters in many cases
// (i.e. passing a buffer of char), this does not work (interprets
// the content of the buffer as Unicode). So we use vsnprintf()
// that is always UTF-8 (viceversa, vswprintf() is always Unicode).
// Note: the wx vararg functions (in this case wxString::Format)
// accept any kind of strings. But this works only because they're not vararg
// functions any longer, in fact, but rather pseudo-variadic templates.
// (as per wxWidgets explanation in a forum thread)
va_start(arg_ptr, fmt);
ret = vsnprintf(buf, FCM_LOG_BUF_SIZE, fmt, arg_ptr);
va_end(arg_ptr);
msg = buf;
// if PrintfV() returns error
if(ret < 0) {
msg = wxT("Error: LogMsg() is not able to print the message\n");
}
std::cout << msg;
return ret;
}
int ErrMsg(const char *fmt,...)
{
wxString msg;
int ret;
va_list arg_ptr;
char buf[FCM_LOG_BUF_SIZE];
va_start(arg_ptr, fmt);
ret = vsnprintf(buf, FCM_LOG_BUF_SIZE, fmt, arg_ptr);
va_end(arg_ptr);
msg = buf;
// if PrintfV() returns error
if(ret < 0) {
msg = wxT("Error: ErrMsg() is not able to print the message\n");
}
std::cout << msg;
return ret;
}
#endif // !FCG_HEADLESS