aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJohannes Schickel2010-11-18 19:12:14 +0000
committerJohannes Schickel2010-11-18 19:12:14 +0000
commite1030e53a537677c234ad39de419fb97b88a37b7 (patch)
treeefa0f61d219a9de5299567c92f80662a7e5fb272 /common
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
Diffstat (limited to 'common')
-rw-r--r--common/debug.cpp38
-rw-r--r--common/system.cpp37
-rw-r--r--common/system.h31
-rw-r--r--common/textconsole.cpp84
4 files changed, 83 insertions, 107 deletions
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