aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2010-11-18 19:12:14 +0000
committerJohannes Schickel2010-11-18 19:12:14 +0000
commite1030e53a537677c234ad39de419fb97b88a37b7 (patch)
treeefa0f61d219a9de5299567c92f80662a7e5fb272
parent411866ee1881d248400da25f1889ad872ed54ee3 (diff)
downloadscummvm-rg350-e1030e53a537677c234ad39de419fb97b88a37b7.tar.gz
scummvm-rg350-e1030e53a537677c234ad39de419fb97b88a37b7.tar.bz2
scummvm-rg350-e1030e53a537677c234ad39de419fb97b88a37b7.zip
BACKENDS: Implement logging API proposed by Max on -devel.
This commits a slightly modified patch from my patch tracker item #3104630 "OSYSTEM: Add logging API as proposed by Max on -devel". I was not able to test compilation on Android and SamsungTV, since there is no toolchain for those on buildbot (or I was too blind to find them). svn-id: r54339
-rw-r--r--backends/platform/android/android.cpp18
-rw-r--r--backends/platform/psp/osys_psp.cpp7
-rw-r--r--backends/platform/psp/osys_psp.h2
-rw-r--r--backends/platform/samsungtv/samsungtv.cpp5
-rw-r--r--backends/platform/samsungtv/samsungtv.h1
-rw-r--r--backends/platform/sdl/sdl.cpp24
-rw-r--r--backends/platform/sdl/sdl.h3
-rw-r--r--common/debug.cpp38
-rw-r--r--common/system.cpp37
-rw-r--r--common/system.h31
-rw-r--r--common/textconsole.cpp84
11 files changed, 143 insertions, 107 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 38f387b201..7a4ae24e6b 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -299,6 +299,7 @@ public:
virtual void getTimeAndDate(TimeDate &t) const;
virtual Common::TimerManager *getTimerManager();
virtual FilesystemFactory *getFilesystemFactory();
+ virtual void logMessage(LogMessageType::Type type, const char *message);
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
};
@@ -1266,6 +1267,23 @@ void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s,
}
}
+void OSystem_Android::logMessage(LogMessageType::Type type, const char *message) {
+ switch (type) {
+ case LogMessageType::kDebug:
+ BaseBackend::logMessage(type, message);
+ break;
+
+ case LogMessageType::kWarning:
+ __android_log_write(ANDROID_LOG_WARN, "ScummVM", message);
+ break;
+
+ case LogMessageType::kError:
+ // FIXME: From the name it looks like this will also quit the program.
+ // This shouldn't do that though.
+ __android_log_assert("Fatal error", "ScummVM", "%s", message);
+ break;
+ }
+}
static jint ScummVM_scummVMMain(JNIEnv* env, jobject self, jobjectArray args) {
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 40c074ae00..df330b0b00 100644
--- a/backends/platform/psp/osys_psp.cpp
+++ b/backends/platform/psp/osys_psp.cpp
@@ -408,6 +408,13 @@ void OSystem_PSP::quit() {
sceKernelExitGame();
}
+void OSystem_PSP::logMessage(LogMessageType::Type type, const char *message) {
+ BaseBackend::logMessage(type, message);
+
+ if (type == LogMessageType::kError)
+ PspDebugTrace(false, "%s", message); // write to file
+}
+
void OSystem_PSP::getTimeAndDate(TimeDate &td) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h
index 52b8f4e887..d21c7e78ef 100644
--- a/backends/platform/psp/osys_psp.h
+++ b/backends/platform/psp/osys_psp.h
@@ -153,6 +153,8 @@ public:
void quit();
+ void logMessage(LogMessageType::Type type, const char *message);
+
Common::SeekableReadStream *createConfigReadStream();
Common::WriteStream *createConfigWriteStream();
diff --git a/backends/platform/samsungtv/samsungtv.cpp b/backends/platform/samsungtv/samsungtv.cpp
index aa79b92558..909734d719 100644
--- a/backends/platform/samsungtv/samsungtv.cpp
+++ b/backends/platform/samsungtv/samsungtv.cpp
@@ -54,4 +54,9 @@ bool OSystem_SDL_SamsungTV::getFeatureState(Feature f) {
}
}
+void OSystem_SDL_SamsungTV::fatalError() {
+ // FIXME
+ for (;;) {}
+}
+
#endif
diff --git a/backends/platform/samsungtv/samsungtv.h b/backends/platform/samsungtv/samsungtv.h
index b3344385aa..59d1c24cbe 100644
--- a/backends/platform/samsungtv/samsungtv.h
+++ b/backends/platform/samsungtv/samsungtv.h
@@ -43,6 +43,7 @@ public:
virtual void setFeatureState(Feature f, bool enable);
virtual bool getFeatureState(Feature f);
+ virtual void fatalError();
protected:
virtual bool remapKey(SDL_Event &ev, Common::Event &event);
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 2e3819f6f5..8a139e5c1b 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -562,6 +562,30 @@ void OSystem_SDL::quit() {
#endif
}
+void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) {
+ BaseBackend::logMessage(type, message);
+
+#if defined( USE_WINDBG )
+#if defined( _WIN32_WCE )
+ TCHAR buf_unicode[1024];
+ MultiByteToWideChar(CP_ACP, 0, message, strlen(message) + 1, buf_unicode, sizeof(buf_unicode));
+ OutputDebugString(buf_unicode);
+
+ if (type == LogMessageType::kError) {
+#ifndef DEBUG
+ drawError(message);
+#else
+ int cmon_break_into_the_debugger_if_you_please = *(int *)(message + 1); // bus error
+ printf("%d", cmon_break_into_the_debugger_if_you_please); // don't optimize the int out
+#endif
+ }
+
+#else
+ OutputDebugString(message);
+#endif
+#endif
+}
+
void OSystem_SDL::setupIcon() {
int x, y, w, h, ncols, nbytes, i;
unsigned int rgba[256];
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index b701824517..328bb03426 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -191,6 +191,9 @@ public:
// Quit
virtual void quit(); // overloaded by CE backend
+ // Logging
+ virtual void logMessage(LogMessageType::Type type, const char *message);
+
void deinit();
virtual void getTimeAndDate(TimeDate &t) const;
diff --git a/common/debug.cpp b/common/debug.cpp
index 890648d4ec..c87d195b76 100644
--- a/common/debug.cpp
+++ b/common/debug.cpp
@@ -22,32 +22,13 @@
* $Id$
*/
-// Disable symbol overrides so that we can use system headers.
-// FIXME: Necessary for the PS2 port, should get rid of this eventually.
-#define FORBIDDEN_SYMBOL_ALLOW_ALL
-
#include "common/debug.h"
#include "common/debug-channels.h"
#include "common/util.h"
+#include "common/system.h"
#include <stdarg.h> // For va_list etc.
-
-#ifdef __PLAYSTATION2__
- // for those replaced fopen/fread/etc functions
- #include "backends/platform/ps2/fileio.h"
-
- #define fputs(str, file) ps2_fputs(str, file)
- #define fflush(a) ps2_fflush(a)
-#endif
-
-#ifdef __DS__
- #include "backends/fs/ds/ds-fs.h"
-
- #define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file)
- #define fflush(file) DS::std_fflush(file)
-#endif
-
// TODO: Move gDebugLevel into namespace Common.
int gDebugLevel = -1;
@@ -139,19 +120,10 @@ static void debugHelper(const char *s, va_list va, bool caret = true) {
strcat(buf, "\n");
}
- fputs(buf, stdout);
-
-#if defined( USE_WINDBG )
-#if defined( _WIN32_WCE )
- TCHAR buf_unicode[1024];
- MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
- OutputDebugString(buf_unicode);
-#else
- OutputDebugString(buf);
-#endif
-#endif
-
- fflush(stdout);
+ if (g_system)
+ g_system->logMessage(LogMessageType::kDebug, buf);
+ // TODO: Think of a good fallback in case we do not have
+ // any OSystem yet.
}
void debug(const char *s, ...) {
diff --git a/common/system.cpp b/common/system.cpp
index 816d444c89..e14e5ea7d3 100644
--- a/common/system.cpp
+++ b/common/system.cpp
@@ -23,8 +23,27 @@
*
*/
+// Disable symbol overrides so that we can use system headers.
+// FIXME: Necessary for the PS2 port, should get rid of this eventually.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
#include "common/system.h"
+#ifdef __PLAYSTATION2__
+ // for those replaced fopen/fread/etc functions
+ #include "backends/platform/ps2/fileio.h"
+
+ #define fputs(str, file) ps2_fputs(str, file)
+ #define fflush(a) ps2_fflush(a)
+#endif
+
+#ifdef __DS__
+ #include "backends/fs/ds/ds-fs.h"
+
+ #define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file)
+ #define fflush(file) DS::std_fflush(file)
+#endif
+
OSystem *g_system = 0;
OSystem::OSystem() {
@@ -53,3 +72,21 @@ bool OSystem::setGraphicsMode(const char *name) {
return false;
}
+
+void OSystem::fatalError() {
+ quit();
+ exit(1);
+}
+
+void OSystem::logMessage(LogMessageType::Type type, const char *message) {
+ FILE *output = 0;
+
+ if (type == LogMessageType::kDebug)
+ output = stdout;
+ else
+ output = stderr;
+
+ fputs(message, output);
+ fflush(output);
+}
+
diff --git a/common/system.h b/common/system.h
index e84801562d..83d11998a4 100644
--- a/common/system.h
+++ b/common/system.h
@@ -73,6 +73,16 @@ struct TimeDate {
int tm_year; ///< year - 1900
};
+namespace LogMessageType {
+
+enum Type {
+ kError,
+ kWarning,
+ kDebug
+};
+
+} // End of namespace LogMessageType
+
/**
* Interface for ScummVM backends. If you want to port ScummVM to a system
* which is not currently covered by any of our backends, this is the place
@@ -953,6 +963,13 @@ public:
virtual void quit() = 0;
/**
+ * Signals that a fatal error inside the client code has happened.
+ *
+ * This should quit the application.
+ */
+ virtual void fatalError();
+
+ /**
* Set a window caption or any other comparable status display to the
* given value. The caption must be a pure ISO LATIN 1 string. Passing a
* string with a different encoding may lead to unexpected behavior,
@@ -1019,6 +1036,20 @@ public:
*/
virtual Common::WriteStream *createConfigWriteStream() = 0;
+ /**
+ * Logs a given message.
+ *
+ * It is up to the backend where to log the different messages.
+ * The backend should aim at using a non-buffered output for it
+ * so that no log data is lost in case of a crash.
+ *
+ * The default implementation outputs them on stdout/stderr.
+ *
+ * @param type the type of the message
+ * @param message the message itself
+ */
+ virtual void logMessage(LogMessageType::Type type, const char *message);
+
//@}
};
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index 246a9a1fe1..866128e2e2 100644
--- a/common/textconsole.cpp
+++ b/common/textconsole.cpp
@@ -22,34 +22,9 @@
* $Id$
*/
-// Disable symbol overrides so that we can use system headers.
-// FIXME: Necessary for the PS2 port, should get rid of this eventually.
-#define FORBIDDEN_SYMBOL_ALLOW_ALL
-
#include "common/textconsole.h"
#include "common/system.h"
-#ifdef __PLAYSTATION2__
- // for those replaced fopen/fread/etc functions
- #include "backends/platform/ps2/fileio.h"
-
- #define fputs(str, file) ps2_fputs(str, file)
-#endif
-
-#ifdef __DS__
- #include "backends/fs/ds/ds-fs.h"
-
- #define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file)
-#endif
-
-#ifdef ANDROID
- #include <android/log.h>
-#endif
-
-#ifdef __PSP__
- #include "backends/platform/psp/trace.h"
-#endif
-
namespace Common {
static OutputFormatter s_errorOutputFormatter = 0;
@@ -78,24 +53,12 @@ void warning(const char *s, ...) {
vsnprintf(buf, STRINGBUFLEN, s, va);
va_end(va);
-#if defined( ANDROID )
- __android_log_write(ANDROID_LOG_WARN, "ScummVM", buf);
-#elif !defined (__SYMBIAN32__)
- fputs("WARNING: ", stderr);
- fputs(buf, stderr);
- fputs("!\n", stderr);
-#endif
+ Common::String output = Common::String::format("WARNING: %s!\n", buf);
-#if defined( USE_WINDBG )
- strcat(buf, "\n");
-#if defined( _WIN32_WCE )
- TCHAR buf_unicode[1024];
- MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
- OutputDebugString(buf_unicode);
-#else
- OutputDebugString(buf);
-#endif
-#endif
+ if (g_system)
+ g_system->logMessage(LogMessageType::kWarning, output.c_str());
+ // TODO: Think of a good fallback in case we do not have
+ // any OSystem yet.
}
#endif
@@ -123,48 +86,21 @@ void NORETURN_PRE error(const char *s, ...) {
buf_output[STRINGBUFLEN-1] = '\0';
strcat(buf_output, "!\n");
-
- // Print the error message to stderr
- fputs(buf_output, stderr);
+ if (g_system)
+ g_system->logMessage(LogMessageType::kError, buf_output);
+ // TODO: Think of a good fallback in case we do not have
+ // any OSystem yet.
// If there is an error handler, invoke it now
if (Common::s_errorHandler)
(*Common::s_errorHandler)(buf_output);
- // TODO: Add a OSystem::fatalError() method and invoke it here.
- // The default implementation would just call OSystem::quit().
-
-#if defined( USE_WINDBG )
-#if defined( _WIN32_WCE )
- TCHAR buf_output_unicode[1024];
- MultiByteToWideChar(CP_ACP, 0, buf_output, strlen(buf_output) + 1, buf_output_unicode, sizeof(buf_output_unicode));
- OutputDebugString(buf_output_unicode);
-#ifndef DEBUG
- drawError(buf_output);
-#else
- int cmon_break_into_the_debugger_if_you_please = *(int *)(buf_output + 1); // bus error
- printf("%d", cmon_break_into_the_debugger_if_you_please); // don't optimize the int out
-#endif
-#else
- OutputDebugString(buf_output);
-#endif
-#endif
-
-#ifdef ANDROID
- __android_log_assert("Fatal error", "ScummVM", "%s", buf_output);
-#endif
-
#ifdef __SYMBIAN32__
Symbian::FatalError(buf_output);
#endif
-#ifdef __PSP__
- PspDebugTrace(false, "%s", buf_output); // write to file
-#endif
-
- // Finally exit. quit() will terminate the program if g_system is present
if (g_system)
- g_system->quit();
+ g_system->fatalError();
#if defined(SAMSUNGTV)
// FIXME