Ticket #9250: osystem_log.patch

File osystem_log.patch, 11.9 KB (added by lordhoto, 13 years ago)

Patch against r54114

  • backends/platform/android/android.cpp

    diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
    index 38f387b..0fed2bf 100644
    a b public:  
    299299        virtual void getTimeAndDate(TimeDate &t) const;
    300300        virtual Common::TimerManager *getTimerManager();
    301301        virtual FilesystemFactory *getFilesystemFactory();
     302
    302303        virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
    303304};
    304305
    void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s,  
    12661267        }
    12671268}
    12681269
     1270void 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}
    12691287
    12701288static jint ScummVM_scummVMMain(JNIEnv* env, jobject self, jobjectArray args) {
    12711289        OSystem_Android* cpp_obj = OSystem_Android::fromJavaObject(env, self);
  • backends/platform/psp/osys_psp.cpp

    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() {  
    408408        sceKernelExitGame();
    409409}
    410410
     411void 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
    411418void OSystem_PSP::getTimeAndDate(TimeDate &td) const {
    412419        time_t curTime = time(0);
    413420        struct tm t = *localtime(&curTime);
  • backends/platform/psp/osys_psp.h

    diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h
    index 52b8f4e..d21c7e7 100644
    a b public:  
    153153
    154154        void quit();
    155155
     156        void logMessage(LogMessageType::Type type, const char *message);
     157
    156158        Common::SeekableReadStream *createConfigReadStream();
    157159        Common::WriteStream *createConfigWriteStream();
    158160
  • backends/platform/samsungtv/samsungtv.cpp

    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) {  
    5454        }
    5555}
    5656
     57void OSystem_SDL_SamsungTV::fatalError() {
     58        // FIXME
     59        for (;;) {}
     60}
     61
    5762#endif
  • backends/platform/samsungtv/samsungtv.h

    diff --git a/backends/platform/samsungtv/samsungtv.h b/backends/platform/samsungtv/samsungtv.h
    index b334438..59d1c24 100644
    a b public:  
    4343        virtual void setFeatureState(Feature f, bool enable);
    4444        virtual bool getFeatureState(Feature f);
    4545
     46        virtual void fatalError();
    4647protected:
    4748
    4849        virtual bool remapKey(SDL_Event &ev, Common::Event &event);
  • backends/platform/sdl/sdl.cpp

    diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
    index 8725a7d..324e714 100644
    a b void OSystem_SDL::quit() {  
    561561#endif
    562562}
    563563
     564void 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
    564588void OSystem_SDL::setupIcon() {
    565589        int x, y, w, h, ncols, nbytes, i;
    566590        unsigned int rgba[256];
  • backends/platform/sdl/sdl.h

    diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
    index e7f9a06..1e27feb 100644
    a b public:  
    202202        // Quit
    203203        virtual void quit(); // overloaded by CE backend
    204204
     205        // Logging
     206        virtual void logMessage(LogMessageType::Type type, const char *message);
     207
    205208        void deinit();
    206209
    207210        virtual void getTimeAndDate(TimeDate &t) const;
  • common/debug.cpp

    diff --git a/common/debug.cpp b/common/debug.cpp
    index 46f8e8b..23bdb6d 100644
    a b  
    2222 * $Id$
    2323 */
    2424
    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 
    2925#include "common/debug.h"
    3026#include "common/debug-channels.h"
    3127#include "common/util.h"
     28#include "common/system.h"
    3229
    3330#include <stdarg.h>     // For va_list etc.
    3431
    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 
    5132// TODO: Move gDebugLevel into namespace Common.
    5233int gDebugLevel = -1;
    5334
    static void debugHelper(const char *s, va_list va, bool caret = true) {  
    139120                strcat(buf, "\n");
    140121        }
    141122
    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.
    155127}
    156128
    157129void debug(const char *s, ...) {
  • common/system.cpp

    diff --git a/common/system.cpp b/common/system.cpp
    index 387e0df..a05690a 100644
    a b  
    2323 *
    2424 */
    2525
     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
    2630#include "common/system.h"
    2731
     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
    2847OSystem *g_system = 0;
    2948
    3049OSystem::OSystem() {
    bool OSystem::openCD(int drive) {  
    6180bool OSystem::pollCD() {
    6281        return false;
    6382}
     83
     84void OSystem::fatalError() {
     85        quit();
     86        exit(1);
     87}
     88
     89void 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
  • common/system.h

    diff --git a/common/system.h b/common/system.h
    index 0ff841e..58de7bc 100644
    a b struct TimeDate {  
    7272        int tm_year;    ///< year - 1900
    7373};
    7474
     75namespace LogMessageType {
     76
     77enum Type {
     78        kError,
     79        kWarning,
     80        kDebug
     81};
     82
     83} // End of namespace LogMessageType
     84
    7585/**
    7686 * Interface for ScummVM backends. If you want to port ScummVM to a system
    7787 * which is not currently covered by any of our backends, this is the place
    public:  
    977987        virtual void quit() = 0;
    978988
    979989        /**
     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        /**
    980997         * Set a window caption or any other comparable status display to the
    981998         * given value. The caption must be a pure ISO LATIN 1 string. Passing a
    982999         * string with a different encoding may lead to unexpected behavior,
    public:  
    10431060         */
    10441061        virtual Common::WriteStream *createConfigWriteStream() = 0;
    10451062
     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
    10461077        //@}
    10471078};
    10481079
  • common/textconsole.cpp

    diff --git a/common/textconsole.cpp b/common/textconsole.cpp
    index 246a9a1..866128e 100644
    a b  
    2222 * $Id$
    2323 */
    2424
    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 
    2925#include "common/textconsole.h"
    3026#include "common/system.h"
    3127
    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 
    5328namespace Common {
    5429
    5530static OutputFormatter s_errorOutputFormatter = 0;
    void warning(const char *s, ...) {  
    7853        vsnprintf(buf, STRINGBUFLEN, s, va);
    7954        va_end(va);
    8055
    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);
    8857
    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.
    9962}
    10063
    10164#endif
    void NORETURN_PRE error(const char *s, ...) {  
    12386        buf_output[STRINGBUFLEN-1] = '\0';
    12487        strcat(buf_output, "!\n");
    12588
    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.
    12993
    13094        // If there is an error handler, invoke it now
    13195        if (Common::s_errorHandler)
    13296                (*Common::s_errorHandler)(buf_output);
    13397
    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 
    15798#ifdef __SYMBIAN32__
    15899        Symbian::FatalError(buf_output);
    159100#endif
    160101
    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
    166102        if (g_system)
    167                 g_system->quit();
     103                g_system->fatalError();
    168104
    169105#if defined(SAMSUNGTV)
    170106        // FIXME