diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 38f387b..0fed2bf 100644
a
|
b
|
public:
|
299 | 299 | virtual void getTimeAndDate(TimeDate &t) const; |
300 | 300 | virtual Common::TimerManager *getTimerManager(); |
301 | 301 | virtual FilesystemFactory *getFilesystemFactory(); |
| 302 | |
302 | 303 | virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); |
303 | 304 | }; |
304 | 305 | |
… |
… |
void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s,
|
1266 | 1267 | } |
1267 | 1268 | } |
1268 | 1269 | |
| 1270 | void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) { |
| 1271 | switch (type) { |
| 1272 | case LogMessageType::kDebug: |
| 1273 | BaseBackend::logMessage(type, message); |
| 1274 | break; |
| 1275 | |
| 1276 | case LogMessageType::kWarning: |
| 1277 | __android_log_write(ANDROID_LOG_WARN, "ScummVM", message); |
| 1278 | break; |
| 1279 | |
| 1280 | case LogMessageType::kError: |
| 1281 | // FIXME: From the name it looks like this will also quit the program. |
| 1282 | // This shouldn't do that though. |
| 1283 | __android_log_assert("Fatal error", "ScummVM", "%s", message); |
| 1284 | break; |
| 1285 | } |
| 1286 | } |
1269 | 1287 | |
1270 | 1288 | static jint ScummVM_scummVMMain(JNIEnv* env, jobject self, jobjectArray args) { |
1271 | 1289 | OSystem_Android* cpp_obj = OSystem_Android::fromJavaObject(env, self); |
diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp
index 40c074a..0f60d54 100644
a
|
b
|
void OSystem_PSP::quit() {
|
408 | 408 | sceKernelExitGame(); |
409 | 409 | } |
410 | 410 | |
| 411 | void OSystem_PSP::logMessage(LogMessageType::Type type, const char *message) { |
| 412 | BaseBackend::logMessage(type, message); |
| 413 | |
| 414 | if (type == LogMessageType::kError) |
| 415 | PspDebugTrace(false, "%s", buf_output); // write to file |
| 416 | } |
| 417 | |
411 | 418 | void OSystem_PSP::getTimeAndDate(TimeDate &td) const { |
412 | 419 | time_t curTime = time(0); |
413 | 420 | struct tm t = *localtime(&curTime); |
diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h
index 52b8f4e..d21c7e7 100644
a
|
b
|
public:
|
153 | 153 | |
154 | 154 | void quit(); |
155 | 155 | |
| 156 | void logMessage(LogMessageType::Type type, const char *message); |
| 157 | |
156 | 158 | Common::SeekableReadStream *createConfigReadStream(); |
157 | 159 | Common::WriteStream *createConfigWriteStream(); |
158 | 160 | |
diff --git a/backends/platform/samsungtv/samsungtv.cpp b/backends/platform/samsungtv/samsungtv.cpp
index aa79b92..909734d 100644
a
|
b
|
bool OSystem_SDL_SamsungTV::getFeatureState(Feature f) {
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
| 57 | void OSystem_SDL_SamsungTV::fatalError() { |
| 58 | // FIXME |
| 59 | for (;;) {} |
| 60 | } |
| 61 | |
57 | 62 | #endif |
diff --git a/backends/platform/samsungtv/samsungtv.h b/backends/platform/samsungtv/samsungtv.h
index b334438..59d1c24 100644
a
|
b
|
public:
|
43 | 43 | virtual void setFeatureState(Feature f, bool enable); |
44 | 44 | virtual bool getFeatureState(Feature f); |
45 | 45 | |
| 46 | virtual void fatalError(); |
46 | 47 | protected: |
47 | 48 | |
48 | 49 | virtual bool remapKey(SDL_Event &ev, Common::Event &event); |
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 8725a7d..324e714 100644
a
|
b
|
void OSystem_SDL::quit() {
|
561 | 561 | #endif |
562 | 562 | } |
563 | 563 | |
| 564 | void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) { |
| 565 | BaseBackend::logMessage(type, message); |
| 566 | |
| 567 | #if defined( USE_WINDBG ) |
| 568 | #if defined( _WIN32_WCE ) |
| 569 | TCHAR buf_unicode[1024]; |
| 570 | MultiByteToWideChar(CP_ACP, 0, message, strlen(message) + 1, buf_unicode, sizeof(buf_unicode)); |
| 571 | OutputDebugString(buf_unicode); |
| 572 | |
| 573 | if (type == LogMessageType::kError) { |
| 574 | #ifndef DEBUG |
| 575 | drawError(buf_output); |
| 576 | #else |
| 577 | int cmon_break_into_the_debugger_if_you_please = *(int *)(buf_output + 1); // bus error |
| 578 | printf("%d", cmon_break_into_the_debugger_if_you_please); // don't optimize the int out |
| 579 | #endif |
| 580 | } |
| 581 | |
| 582 | #else |
| 583 | OutputDebugString(message); |
| 584 | #endif |
| 585 | #endif |
| 586 | } |
| 587 | |
564 | 588 | void OSystem_SDL::setupIcon() { |
565 | 589 | int x, y, w, h, ncols, nbytes, i; |
566 | 590 | unsigned int rgba[256]; |
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index e7f9a06..1e27feb 100644
a
|
b
|
public:
|
202 | 202 | // Quit |
203 | 203 | virtual void quit(); // overloaded by CE backend |
204 | 204 | |
| 205 | // Logging |
| 206 | virtual void logMessage(LogMessageType::Type type, const char *message); |
| 207 | |
205 | 208 | void deinit(); |
206 | 209 | |
207 | 210 | virtual void getTimeAndDate(TimeDate &t) const; |
diff --git a/common/debug.cpp b/common/debug.cpp
index 46f8e8b..23bdb6d 100644
a
|
b
|
|
22 | 22 | * $Id$ |
23 | 23 | */ |
24 | 24 | |
25 | | // Disable symbol overrides so that we can use system headers. |
26 | | // FIXME: Necessary for the PS2 port, should get rid of this eventually. |
27 | | #define FORBIDDEN_SYMBOL_ALLOW_ALL |
28 | | |
29 | 25 | #include "common/debug.h" |
30 | 26 | #include "common/debug-channels.h" |
31 | 27 | #include "common/util.h" |
| 28 | #include "common/system.h" |
32 | 29 | |
33 | 30 | #include <stdarg.h> // For va_list etc. |
34 | 31 | |
35 | | |
36 | | #ifdef __PLAYSTATION2__ |
37 | | // for those replaced fopen/fread/etc functions |
38 | | #include "backends/platform/ps2/fileio.h" |
39 | | |
40 | | #define fputs(str, file) ps2_fputs(str, file) |
41 | | #define fflush(a) ps2_fflush(a) |
42 | | #endif |
43 | | |
44 | | #ifdef __DS__ |
45 | | #include "backends/fs/ds/ds-fs.h" |
46 | | |
47 | | #define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file) |
48 | | #define fflush(file) DS::std_fflush(file) |
49 | | #endif |
50 | | |
51 | 32 | // TODO: Move gDebugLevel into namespace Common. |
52 | 33 | int gDebugLevel = -1; |
53 | 34 | |
… |
… |
static void debugHelper(const char *s, va_list va, bool caret = true) {
|
139 | 120 | strcat(buf, "\n"); |
140 | 121 | } |
141 | 122 | |
142 | | fputs(buf, stdout); |
143 | | |
144 | | #if defined( USE_WINDBG ) |
145 | | #if defined( _WIN32_WCE ) |
146 | | TCHAR buf_unicode[1024]; |
147 | | MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode)); |
148 | | OutputDebugString(buf_unicode); |
149 | | #else |
150 | | OutputDebugString(buf); |
151 | | #endif |
152 | | #endif |
153 | | |
154 | | fflush(stdout); |
| 123 | if (g_system) |
| 124 | g_system->logMessage(LogMessageType::kDebug, buf); |
| 125 | // TODO: Think of a good fallback in case we do not have |
| 126 | // any OSystem yet. |
155 | 127 | } |
156 | 128 | |
157 | 129 | void debug(const char *s, ...) { |
diff --git a/common/system.cpp b/common/system.cpp
index 387e0df..a05690a 100644
a
|
b
|
|
23 | 23 | * |
24 | 24 | */ |
25 | 25 | |
| 26 | // Disable symbol overrides so that we can use system headers. |
| 27 | // FIXME: Necessary for the PS2 port, should get rid of this eventually. |
| 28 | #define FORBIDDEN_SYMBOL_ALLOW_ALL |
| 29 | |
26 | 30 | #include "common/system.h" |
27 | 31 | |
| 32 | #ifdef __PLAYSTATION2__ |
| 33 | // for those replaced fopen/fread/etc functions |
| 34 | #include "backends/platform/ps2/fileio.h" |
| 35 | |
| 36 | #define fputs(str, file) ps2_fputs(str, file) |
| 37 | #define fflush(a) ps2_fflush(a) |
| 38 | #endif |
| 39 | |
| 40 | #ifdef __DS__ |
| 41 | #include "backends/fs/ds/ds-fs.h" |
| 42 | |
| 43 | #define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file) |
| 44 | #define fflush(file) DS::std_fflush(file) |
| 45 | #endif |
| 46 | |
28 | 47 | OSystem *g_system = 0; |
29 | 48 | |
30 | 49 | OSystem::OSystem() { |
… |
… |
bool OSystem::openCD(int drive) {
|
61 | 80 | bool OSystem::pollCD() { |
62 | 81 | return false; |
63 | 82 | } |
| 83 | |
| 84 | void OSystem::fatalError() { |
| 85 | quit(); |
| 86 | exit(1); |
| 87 | } |
| 88 | |
| 89 | void OSystem::logMessage(LogMessageType::Type type, const char *message) { |
| 90 | FILE *output = 0; |
| 91 | |
| 92 | if (type == LogMessageType::kDebug) |
| 93 | output = stdout; |
| 94 | else |
| 95 | output = stderr; |
| 96 | |
| 97 | fputs(message, output); |
| 98 | fflush(output); |
| 99 | } |
| 100 | |
diff --git a/common/system.h b/common/system.h
index 0ff841e..58de7bc 100644
a
|
b
|
struct TimeDate {
|
72 | 72 | int tm_year; ///< year - 1900 |
73 | 73 | }; |
74 | 74 | |
| 75 | namespace LogMessageType { |
| 76 | |
| 77 | enum Type { |
| 78 | kError, |
| 79 | kWarning, |
| 80 | kDebug |
| 81 | }; |
| 82 | |
| 83 | } // End of namespace LogMessageType |
| 84 | |
75 | 85 | /** |
76 | 86 | * Interface for ScummVM backends. If you want to port ScummVM to a system |
77 | 87 | * which is not currently covered by any of our backends, this is the place |
… |
… |
public:
|
977 | 987 | virtual void quit() = 0; |
978 | 988 | |
979 | 989 | /** |
| 990 | * Signals that a fatal error inside the client code has happened. |
| 991 | * |
| 992 | * This should quit the application. |
| 993 | */ |
| 994 | virtual void fatalError(); |
| 995 | |
| 996 | /** |
980 | 997 | * Set a window caption or any other comparable status display to the |
981 | 998 | * given value. The caption must be a pure ISO LATIN 1 string. Passing a |
982 | 999 | * string with a different encoding may lead to unexpected behavior, |
… |
… |
public:
|
1043 | 1060 | */ |
1044 | 1061 | virtual Common::WriteStream *createConfigWriteStream() = 0; |
1045 | 1062 | |
| 1063 | /** |
| 1064 | * Logs a given message. |
| 1065 | * |
| 1066 | * It is up to the backend where to log the different messages. |
| 1067 | * The backend should aim at using a non-buffered output for it |
| 1068 | * so that no log data is lost in case of a crash. |
| 1069 | * |
| 1070 | * The default implementation outputs them on stdout/stderr. |
| 1071 | * |
| 1072 | * @param type the type of the message |
| 1073 | * @param message the message itself |
| 1074 | */ |
| 1075 | virtual void logMessage(LogMessageType::Type type, const char *message); |
| 1076 | |
1046 | 1077 | //@} |
1047 | 1078 | }; |
1048 | 1079 | |
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index 246a9a1..866128e 100644
a
|
b
|
|
22 | 22 | * $Id$ |
23 | 23 | */ |
24 | 24 | |
25 | | // Disable symbol overrides so that we can use system headers. |
26 | | // FIXME: Necessary for the PS2 port, should get rid of this eventually. |
27 | | #define FORBIDDEN_SYMBOL_ALLOW_ALL |
28 | | |
29 | 25 | #include "common/textconsole.h" |
30 | 26 | #include "common/system.h" |
31 | 27 | |
32 | | #ifdef __PLAYSTATION2__ |
33 | | // for those replaced fopen/fread/etc functions |
34 | | #include "backends/platform/ps2/fileio.h" |
35 | | |
36 | | #define fputs(str, file) ps2_fputs(str, file) |
37 | | #endif |
38 | | |
39 | | #ifdef __DS__ |
40 | | #include "backends/fs/ds/ds-fs.h" |
41 | | |
42 | | #define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file) |
43 | | #endif |
44 | | |
45 | | #ifdef ANDROID |
46 | | #include <android/log.h> |
47 | | #endif |
48 | | |
49 | | #ifdef __PSP__ |
50 | | #include "backends/platform/psp/trace.h" |
51 | | #endif |
52 | | |
53 | 28 | namespace Common { |
54 | 29 | |
55 | 30 | static OutputFormatter s_errorOutputFormatter = 0; |
… |
… |
void warning(const char *s, ...) {
|
78 | 53 | vsnprintf(buf, STRINGBUFLEN, s, va); |
79 | 54 | va_end(va); |
80 | 55 | |
81 | | #if defined( ANDROID ) |
82 | | __android_log_write(ANDROID_LOG_WARN, "ScummVM", buf); |
83 | | #elif !defined (__SYMBIAN32__) |
84 | | fputs("WARNING: ", stderr); |
85 | | fputs(buf, stderr); |
86 | | fputs("!\n", stderr); |
87 | | #endif |
| 56 | Common::String output = Common::String::format("WARNING: %s!\n", buf); |
88 | 57 | |
89 | | #if defined( USE_WINDBG ) |
90 | | strcat(buf, "\n"); |
91 | | #if defined( _WIN32_WCE ) |
92 | | TCHAR buf_unicode[1024]; |
93 | | MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode)); |
94 | | OutputDebugString(buf_unicode); |
95 | | #else |
96 | | OutputDebugString(buf); |
97 | | #endif |
98 | | #endif |
| 58 | if (g_system) |
| 59 | g_system->logMessage(LogMessageType::kWarning, output.c_str()); |
| 60 | // TODO: Think of a good fallback in case we do not have |
| 61 | // any OSystem yet. |
99 | 62 | } |
100 | 63 | |
101 | 64 | #endif |
… |
… |
void NORETURN_PRE error(const char *s, ...) {
|
123 | 86 | buf_output[STRINGBUFLEN-1] = '\0'; |
124 | 87 | strcat(buf_output, "!\n"); |
125 | 88 | |
126 | | |
127 | | // Print the error message to stderr |
128 | | fputs(buf_output, stderr); |
| 89 | if (g_system) |
| 90 | g_system->logMessage(LogMessageType::kError, buf_output); |
| 91 | // TODO: Think of a good fallback in case we do not have |
| 92 | // any OSystem yet. |
129 | 93 | |
130 | 94 | // If there is an error handler, invoke it now |
131 | 95 | if (Common::s_errorHandler) |
132 | 96 | (*Common::s_errorHandler)(buf_output); |
133 | 97 | |
134 | | // TODO: Add a OSystem::fatalError() method and invoke it here. |
135 | | // The default implementation would just call OSystem::quit(). |
136 | | |
137 | | #if defined( USE_WINDBG ) |
138 | | #if defined( _WIN32_WCE ) |
139 | | TCHAR buf_output_unicode[1024]; |
140 | | MultiByteToWideChar(CP_ACP, 0, buf_output, strlen(buf_output) + 1, buf_output_unicode, sizeof(buf_output_unicode)); |
141 | | OutputDebugString(buf_output_unicode); |
142 | | #ifndef DEBUG |
143 | | drawError(buf_output); |
144 | | #else |
145 | | int cmon_break_into_the_debugger_if_you_please = *(int *)(buf_output + 1); // bus error |
146 | | printf("%d", cmon_break_into_the_debugger_if_you_please); // don't optimize the int out |
147 | | #endif |
148 | | #else |
149 | | OutputDebugString(buf_output); |
150 | | #endif |
151 | | #endif |
152 | | |
153 | | #ifdef ANDROID |
154 | | __android_log_assert("Fatal error", "ScummVM", "%s", buf_output); |
155 | | #endif |
156 | | |
157 | 98 | #ifdef __SYMBIAN32__ |
158 | 99 | Symbian::FatalError(buf_output); |
159 | 100 | #endif |
160 | 101 | |
161 | | #ifdef __PSP__ |
162 | | PspDebugTrace(false, "%s", buf_output); // write to file |
163 | | #endif |
164 | | |
165 | | // Finally exit. quit() will terminate the program if g_system is present |
166 | 102 | if (g_system) |
167 | | g_system->quit(); |
| 103 | g_system->fatalError(); |
168 | 104 | |
169 | 105 | #if defined(SAMSUNGTV) |
170 | 106 | // FIXME |