[Scummvm-cvs-logs] SF.net SVN: scummvm:[54339] scummvm/trunk
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Thu Nov 18 20:12:14 CET 2010
Revision: 54339
http://scummvm.svn.sourceforge.net/scummvm/?rev=54339&view=rev
Author: lordhoto
Date: 2010-11-18 19:12:14 +0000 (Thu, 18 Nov 2010)
Log Message:
-----------
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).
Modified Paths:
--------------
scummvm/trunk/backends/platform/android/android.cpp
scummvm/trunk/backends/platform/psp/osys_psp.cpp
scummvm/trunk/backends/platform/psp/osys_psp.h
scummvm/trunk/backends/platform/samsungtv/samsungtv.cpp
scummvm/trunk/backends/platform/samsungtv/samsungtv.h
scummvm/trunk/backends/platform/sdl/sdl.cpp
scummvm/trunk/backends/platform/sdl/sdl.h
scummvm/trunk/common/debug.cpp
scummvm/trunk/common/system.cpp
scummvm/trunk/common/system.h
scummvm/trunk/common/textconsole.cpp
Modified: scummvm/trunk/backends/platform/android/android.cpp
===================================================================
--- scummvm/trunk/backends/platform/android/android.cpp 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/backends/platform/android/android.cpp 2010-11-18 19:12:14 UTC (rev 54339)
@@ -299,6 +299,7 @@
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,7 +1267,24 @@
}
}
+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);
Modified: scummvm/trunk/backends/platform/psp/osys_psp.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/osys_psp.cpp 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/backends/platform/psp/osys_psp.cpp 2010-11-18 19:12:14 UTC (rev 54339)
@@ -408,6 +408,13 @@
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);
Modified: scummvm/trunk/backends/platform/psp/osys_psp.h
===================================================================
--- scummvm/trunk/backends/platform/psp/osys_psp.h 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/backends/platform/psp/osys_psp.h 2010-11-18 19:12:14 UTC (rev 54339)
@@ -153,6 +153,8 @@
void quit();
+ void logMessage(LogMessageType::Type type, const char *message);
+
Common::SeekableReadStream *createConfigReadStream();
Common::WriteStream *createConfigWriteStream();
Modified: scummvm/trunk/backends/platform/samsungtv/samsungtv.cpp
===================================================================
--- scummvm/trunk/backends/platform/samsungtv/samsungtv.cpp 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/backends/platform/samsungtv/samsungtv.cpp 2010-11-18 19:12:14 UTC (rev 54339)
@@ -54,4 +54,9 @@
}
}
+void OSystem_SDL_SamsungTV::fatalError() {
+ // FIXME
+ for (;;) {}
+}
+
#endif
Modified: scummvm/trunk/backends/platform/samsungtv/samsungtv.h
===================================================================
--- scummvm/trunk/backends/platform/samsungtv/samsungtv.h 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/backends/platform/samsungtv/samsungtv.h 2010-11-18 19:12:14 UTC (rev 54339)
@@ -43,6 +43,7 @@
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);
Modified: scummvm/trunk/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.cpp 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/backends/platform/sdl/sdl.cpp 2010-11-18 19:12:14 UTC (rev 54339)
@@ -562,6 +562,30 @@
#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];
Modified: scummvm/trunk/backends/platform/sdl/sdl.h
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.h 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/backends/platform/sdl/sdl.h 2010-11-18 19:12:14 UTC (rev 54339)
@@ -191,6 +191,9 @@
// 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;
Modified: scummvm/trunk/common/debug.cpp
===================================================================
--- scummvm/trunk/common/debug.cpp 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/common/debug.cpp 2010-11-18 19:12:14 UTC (rev 54339)
@@ -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 @@
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, ...) {
Modified: scummvm/trunk/common/system.cpp
===================================================================
--- scummvm/trunk/common/system.cpp 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/common/system.cpp 2010-11-18 19:12:14 UTC (rev 54339)
@@ -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 @@
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);
+}
+
Modified: scummvm/trunk/common/system.h
===================================================================
--- scummvm/trunk/common/system.h 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/common/system.h 2010-11-18 19:12:14 UTC (rev 54339)
@@ -73,6 +73,16 @@
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 @@
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 @@
*/
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);
+
//@}
};
Modified: scummvm/trunk/common/textconsole.cpp
===================================================================
--- scummvm/trunk/common/textconsole.cpp 2010-11-18 19:06:38 UTC (rev 54338)
+++ scummvm/trunk/common/textconsole.cpp 2010-11-18 19:12:14 UTC (rev 54339)
@@ -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 @@
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 @@
buf_output[STRINGBUFLEN-1] = '\0';
strcat(buf_output, "!\n");
+ 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.
- // Print the error message to stderr
- fputs(buf_output, stderr);
-
// 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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list