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
This commit is contained in:
parent
411866ee18
commit
e1030e53a5
11 changed files with 143 additions and 107 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -153,6 +153,8 @@ public:
|
|||
|
||||
void quit();
|
||||
|
||||
void logMessage(LogMessageType::Type type, const char *message);
|
||||
|
||||
Common::SeekableReadStream *createConfigReadStream();
|
||||
Common::WriteStream *createConfigWriteStream();
|
||||
|
||||
|
|
|
@ -54,4 +54,9 @@ bool OSystem_SDL_SamsungTV::getFeatureState(Feature f) {
|
|||
}
|
||||
}
|
||||
|
||||
void OSystem_SDL_SamsungTV::fatalError() {
|
||||
// FIXME
|
||||
for (;;) {}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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, ...) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -952,6 +962,13 @@ public:
|
|||
/** Quit (exit) the application. */
|
||||
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
|
||||
|
@ -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);
|
||||
|
||||
//@}
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue