all repos — mgba @ d8ad87504d300af1e5a61affb4ae340f58e29cc9

mGBA Game Boy Advance Emulator

Qt: Use mLog instead of GBALog
Jeffrey Pfau jeffrey@endrift.com
Mon, 08 Feb 2016 05:26:32 -0800
commit

d8ad87504d300af1e5a61affb4ae340f58e29cc9

parent

5c81fc76d26a001f2b06945e17cbc1981d5bc0c1

M src/platform/qt/AudioDevice.cppsrc/platform/qt/AudioDevice.cpp

@@ -26,7 +26,7 @@ }

void AudioDevice::setFormat(const QAudioFormat& format) { if (!m_context || !mCoreThreadIsActive(m_context)) { - LOG(INFO) << tr("Can't set format of context-less audio device"); + LOG(QT, INFO) << tr("Can't set format of context-less audio device"); return; } double fauxClock = GBAAudioCalculateRatio(1, 60, 1); // TODO: Put back fpsTarget

@@ -46,7 +46,7 @@ maxSize = 0xFFFFFFFF;

} if (!m_context->core) { - LOG(WARN) << tr("Audio device is missing its core"); + LOG(QT, WARN) << tr("Audio device is missing its core"); return 0; }

@@ -62,6 +62,6 @@ return available * sizeof(GBAStereoSample);

} qint64 AudioDevice::writeData(const char*, qint64) { - LOG(WARN) << tr("Writing data to read-only audio device"); + LOG(QT, WARN) << tr("Writing data to read-only audio device"); return 0; }
M src/platform/qt/AudioProcessorQt.cppsrc/platform/qt/AudioProcessorQt.cpp

@@ -36,7 +36,7 @@ }

bool AudioProcessorQt::start() { if (!input()) { - LOG(WARN) << tr("Can't start an audio processor without input"); + LOG(QT, WARN) << tr("Can't start an audio processor without input"); return false; }
M src/platform/qt/AudioProcessorSDL.cppsrc/platform/qt/AudioProcessorSDL.cpp

@@ -25,7 +25,7 @@ }

bool AudioProcessorSDL::start() { if (!input()) { - LOG(WARN) << tr("Can't start an audio processor without input"); + LOG(QT, WARN) << tr("Can't start an audio processor without input"); return false; }
M src/platform/qt/CheatsModel.cppsrc/platform/qt/CheatsModel.cpp

@@ -211,7 +211,7 @@

void CheatsModel::loadFile(const QString& path) { VFile* vf = VFileDevice::open(path, O_RDONLY); if (!vf) { - LOG(WARN) << tr("Failed to open cheats file: %1").arg(path); + LOG(QT, WARN) << tr("Failed to open cheats file: %1").arg(path); return; } beginResetModel();
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -26,6 +26,8 @@ using namespace QGBA;

static GBAApp* g_app = nullptr; +mLOG_DEFINE_CATEGORY(QT, "Qt"); + GBAApp::GBAApp(int& argc, char* argv[]) : QApplication(argc, argv) , m_windows{}
M src/platform/qt/GBAApp.hsrc/platform/qt/GBAApp.h

@@ -15,8 +15,11 @@

struct NoIntroDB; extern "C" { +#include "core/log.h" #include "gba/sio.h" } + +mLOG_DECLARE_CATEGORY(QT); namespace QGBA {
M src/platform/qt/GIFView.cppsrc/platform/qt/GIFView.cpp

@@ -39,7 +39,7 @@ void GIFView::startRecording() {

int delayMs = m_ui.delayAuto->isChecked() ? -1 : m_ui.delayMs->value(); ImageMagickGIFEncoderSetParams(&m_encoder, m_ui.frameskip->value(), delayMs); if (!ImageMagickGIFEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) { - LOG(ERROR) << tr("Failed to open output GIF file: %1").arg(m_filename); + LOG(QT, ERROR) << tr("Failed to open output GIF file: %1").arg(m_filename); return; } m_ui.start->setEnabled(false);
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -21,6 +21,7 @@ extern "C" {

#include "core/config.h" #include "core/directories.h" #include "gba/audio.h" +#include "gba/bios.h" #include "gba/core.h" #include "gba/gba.h" #include "gba/serialize.h"

@@ -85,7 +86,7 @@ }

mRTCGenericSourceInit(&controller->m_rtc, context->core); context->core->setRTC(context->core, &controller->m_rtc.d); - GBA* gba = static_cast<GBA*>(context->core->board); + /*GBA* gba = static_cast<GBA*>(context->core->board); gba->luminanceSource = &controller->m_lux; gba->rumble = controller->m_inputController->rumble(); gba->rotationSource = controller->m_inputController->rotationSource();

@@ -99,7 +100,7 @@ gba->video.renderer->disableBG[0] = !controller->m_videoLayers[0];

gba->video.renderer->disableBG[1] = !controller->m_videoLayers[1]; gba->video.renderer->disableBG[2] = !controller->m_videoLayers[2]; gba->video.renderer->disableBG[3] = !controller->m_videoLayers[3]; - gba->video.renderer->disableOBJ = !controller->m_videoLayers[4]; + gba->video.renderer->disableOBJ = !controller->m_videoLayers[4];*/ // TODO: Put back fpsTarget if (mCoreLoadState(context->core, 0, controller->m_loadStateFlags)) {

@@ -135,21 +136,23 @@ QMetaObject::invokeMethod(controller, "closeGame");

return true; };*/ - /*m_threadContext.logHandler = [](mCoreThread* context, enum GBALogLevel level, const char* format, va_list args) { - static const char* stubMessage = "Stub software interrupt: %02X"; + m_threadContext.logger.d.log = [](mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) { + mThreadLogger* logContext = reinterpret_cast<mThreadLogger*>(logger); + mCoreThread* context = logContext->p; + static const char* savestateMessage = "State %i loaded"; static const char* savestateFailedMessage = "State %i failed to load"; if (!context) { return; } GameController* controller = static_cast<GameController*>(context->userData); - if (level == GBA_LOG_STUB && strncmp(stubMessage, format, strlen(stubMessage)) == 0) { + if (level == mLOG_STUB && category == _mLOG_CAT_GBA_BIOS()) { va_list argc; va_copy(argc, args); int immediate = va_arg(argc, int); va_end(argc); QMetaObject::invokeMethod(controller, "unimplementedBiosCall", Q_ARG(int, immediate)); - } else if (level == GBA_LOG_STATUS) { + } else if (category == _mLOG_CAT_STATUS()) { // Slot 0 is reserved for suspend points if (strncmp(savestateMessage, format, strlen(savestateMessage)) == 0) { va_list argc;

@@ -169,17 +172,17 @@ return;

} } } - if (level == GBA_LOG_FATAL) { + if (level == mLOG_FATAL) { QMetaObject::invokeMethod(controller, "crashGame", Q_ARG(const QString&, QString().vsprintf(format, args))); } else if (!(controller->m_logLevels & level)) { return; } QString message(QString().vsprintf(format, args)); - if (level == GBA_LOG_STATUS) { + if (category == _mLOG_CAT_STATUS()) { QMetaObject::invokeMethod(controller, "statusPosted", Q_ARG(const QString&, message)); } - QMetaObject::invokeMethod(controller, "postLog", Q_ARG(int, level), Q_ARG(const QString&, message)); - };*/ + QMetaObject::invokeMethod(controller, "postLog", Q_ARG(int, level), Q_ARG(int, category), Q_ARG(const QString&, message)); + }; m_threadContext.userData = this;

@@ -257,7 +260,7 @@ void GameController::loadGame(const QString& path) {

closeGame(); QFile file(path); if (!file.open(QIODevice::ReadOnly)) { - postLog(GBA_LOG_ERROR, tr("Failed to open game file: %1").arg(path)); + LOG(QT, ERROR) << tr("Failed to open game file: %1").arg(path); return; } file.close();

@@ -380,7 +383,7 @@ return;

} VFile* vf = VFileDevice::open(path, O_RDONLY); if (!vf) { - postLog(GBA_LOG_ERROR, tr("Failed to open snapshot file for reading: %1").arg(path)); + LOG(QT, ERROR) << tr("Failed to open snapshot file for reading: %1").arg(path); return; } threadInterrupt();

@@ -395,7 +398,7 @@ return;

} VFile* vf = VFileDevice::open(path, O_WRONLY | O_CREAT | O_TRUNC); if (!vf) { - postLog(GBA_LOG_ERROR, tr("Failed to open snapshot file for writing: %1").arg(path)); + LOG(QT, ERROR) << tr("Failed to open snapshot file for writing: %1").arg(path); return; } threadInterrupt();

@@ -635,7 +638,7 @@ void GameController::startAudio() {

bool started = false; QMetaObject::invokeMethod(m_audioProcessor, "start", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, started)); if (!started) { - LOG(ERROR) << tr("Failed to start audio processor"); + LOG(QT, ERROR) << tr("Failed to start audio processor"); // Don't freeze! m_audioSync = false; m_videoSync = true;
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -95,7 +95,7 @@

void luminanceValueChanged(int); void statusPosted(const QString& message); - void postLog(int level, const QString& log); + void postLog(int level, int category, const QString& log); public slots: void loadGame(const QString& path);
M src/platform/qt/LogController.cppsrc/platform/qt/LogController.cpp

@@ -7,29 +7,29 @@ #include "LogController.h"

using namespace QGBA; -LogController LogController::s_global(GBA_LOG_ALL); +LogController LogController::s_global(mLOG_ALL); LogController::LogController(int levels, QObject* parent) : QObject(parent) , m_logLevel(levels) { if (this != &s_global) { - connect(&s_global, SIGNAL(logPosted(int, const QString&)), this, SLOT(postLog(int, const QString&))); + connect(&s_global, SIGNAL(logPosted(int, int, const QString&)), this, SLOT(postLog(int, int, const QString&))); connect(this, SIGNAL(levelsSet(int)), &s_global, SLOT(setLevels(int))); connect(this, SIGNAL(levelsEnabled(int)), &s_global, SLOT(enableLevels(int))); connect(this, SIGNAL(levelsDisabled(int)), &s_global, SLOT(disableLevels(int))); } } -LogController::Stream LogController::operator()(int level) { - return Stream(this, level); +LogController::Stream LogController::operator()(int category, int level) { + return Stream(this, category, level); } -void LogController::postLog(int level, const QString& string) { +void LogController::postLog(int level, int category, const QString& string) { if (!(m_logLevel & level)) { return; } - emit logPosted(level, string); + emit logPosted(level, category, string); } void LogController::setLevels(int levels) {

@@ -53,38 +53,33 @@ }

QString LogController::toString(int level) { switch (level) { - case GBA_LOG_DEBUG: + case mLOG_DEBUG: return tr("DEBUG"); - case GBA_LOG_STUB: + case mLOG_STUB: return tr("STUB"); - case GBA_LOG_INFO: + case mLOG_INFO: return tr("INFO"); - case GBA_LOG_WARN: + case mLOG_WARN: return tr("WARN"); - case GBA_LOG_ERROR: + case mLOG_ERROR: return tr("ERROR"); - case GBA_LOG_FATAL: + case mLOG_FATAL: return tr("FATAL"); - case GBA_LOG_GAME_ERROR: + case mLOG_GAME_ERROR: return tr("GAME ERROR"); - case GBA_LOG_SWI: - return tr("SWI"); - case GBA_LOG_STATUS: - return tr("STATUS"); - case GBA_LOG_SIO: - return tr("SIO"); } return QString(); } -LogController::Stream::Stream(LogController* controller, int level) +LogController::Stream::Stream(LogController* controller, int level, int category) : m_log(controller) , m_level(level) + , m_category(category) { } LogController::Stream::~Stream() { - m_log->postLog(m_level, m_queue.join(" ")); + m_log->postLog(m_level, m_category, m_queue.join(" ")); } LogController::Stream& LogController::Stream::operator<<(const QString& string) {
M src/platform/qt/LogController.hsrc/platform/qt/LogController.h

@@ -6,6 +6,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef QGBA_LOG_CONTROLLER #define QGBA_LOG_CONTROLLER +#include "GBAApp.h" + #include <QObject> #include <QStringList>

@@ -21,13 +23,14 @@

private: class Stream { public: - Stream(LogController* controller, int level); + Stream(LogController* controller, int level, int category); ~Stream(); Stream& operator<<(const QString&); private: int m_level; + int m_category; LogController* m_log; QStringList m_queue;

@@ -38,19 +41,19 @@ LogController(int levels, QObject* parent = nullptr);

int levels() const { return m_logLevel; } - Stream operator()(int level); + Stream operator()(int category, int level); static LogController* global(); static QString toString(int level); signals: - void logPosted(int level, const QString& log); + void logPosted(int level, int category, const QString& log); void levelsSet(int levels); void levelsEnabled(int levels); void levelsDisabled(int levels); public slots: - void postLog(int level, const QString& string); + void postLog(int level, int category, const QString& string); void setLevels(int levels); void enableLevels(int levels); void disableLevels(int levels);

@@ -61,7 +64,7 @@

static LogController s_global; }; -#define LOG(L) (*LogController::global())(GBA_LOG_ ## L) +#define LOG(C, L) (*LogController::global())(_mLOG_CAT_ ## C (), mLOG_ ## L) }
M src/platform/qt/LogView.cppsrc/platform/qt/LogView.cpp

@@ -19,40 +19,31 @@ , m_lineLimit(DEFAULT_LINE_LIMIT)

{ m_ui.setupUi(this); connect(m_ui.levelDebug, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_DEBUG, set); + setLevel(mLOG_DEBUG, set); }); connect(m_ui.levelStub, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_STUB, set); + setLevel(mLOG_STUB, set); }); connect(m_ui.levelInfo, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_INFO, set); + setLevel(mLOG_INFO, set); }); connect(m_ui.levelWarn, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_WARN, set); + setLevel(mLOG_WARN, set); }); connect(m_ui.levelError, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_ERROR, set); + setLevel(mLOG_ERROR, set); }); connect(m_ui.levelFatal, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_FATAL, set); + setLevel(mLOG_FATAL, set); }); connect(m_ui.levelGameError, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_GAME_ERROR, set); - }); - connect(m_ui.levelSWI, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_SWI, set); - }); - connect(m_ui.levelStatus, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_STATUS, set); - }); - connect(m_ui.levelSIO, &QAbstractButton::toggled, [this](bool set) { - setLevel(GBA_LOG_SIO, set); + setLevel(mLOG_GAME_ERROR, set); }); connect(m_ui.clear, SIGNAL(clicked()), this, SLOT(clear())); connect(m_ui.maxLines, SIGNAL(valueChanged(int)), this, SLOT(setMaxLines(int))); m_ui.maxLines->setValue(DEFAULT_LINE_LIMIT); - connect(log, SIGNAL(logPosted(int, const QString&)), this, SLOT(postLog(int, const QString&))); + connect(log, SIGNAL(logPosted(int, int, const QString&)), this, SLOT(postLog(int, int, const QString&))); connect(log, SIGNAL(levelsSet(int)), this, SLOT(setLevels(int))); connect(log, &LogController::levelsEnabled, [this](int level) { bool s = blockSignals(true);

@@ -68,8 +59,8 @@ connect(this, SIGNAL(levelsEnabled(int)), log, SLOT(enableLevels(int)));

connect(this, SIGNAL(levelsDisabled(int)), log, SLOT(disableLevels(int))); } -void LogView::postLog(int level, const QString& log) { - QString line = QString("%1:\t%2").arg(LogController::toString(level)).arg(log); +void LogView::postLog(int level, int category, const QString& log) { + QString line = QString("[%1] %2:\t%3").arg(LogController::toString(level)).arg(mLogCategoryName(category)).arg(log); // TODO: Log to file m_pendingLines.enqueue(line); ++m_lines;

@@ -85,48 +76,36 @@ m_lines = 0;

} void LogView::setLevels(int levels) { - m_ui.levelDebug->setCheckState(levels & GBA_LOG_DEBUG ? Qt::Checked : Qt::Unchecked); - m_ui.levelStub->setCheckState(levels & GBA_LOG_STUB ? Qt::Checked : Qt::Unchecked); - m_ui.levelInfo->setCheckState(levels & GBA_LOG_INFO ? Qt::Checked : Qt::Unchecked); - m_ui.levelWarn->setCheckState(levels & GBA_LOG_WARN ? Qt::Checked : Qt::Unchecked); - m_ui.levelError->setCheckState(levels & GBA_LOG_ERROR ? Qt::Checked : Qt::Unchecked); - m_ui.levelFatal->setCheckState(levels & GBA_LOG_FATAL ? Qt::Checked : Qt::Unchecked); - m_ui.levelGameError->setCheckState(levels & GBA_LOG_GAME_ERROR ? Qt::Checked : Qt::Unchecked); - m_ui.levelSWI->setCheckState(levels & GBA_LOG_SWI ? Qt::Checked : Qt::Unchecked); - m_ui.levelStatus->setCheckState(levels & GBA_LOG_STATUS ? Qt::Checked : Qt::Unchecked); - m_ui.levelSIO->setCheckState(levels & GBA_LOG_SIO ? Qt::Checked : Qt::Unchecked); + m_ui.levelDebug->setCheckState(levels & mLOG_DEBUG ? Qt::Checked : Qt::Unchecked); + m_ui.levelStub->setCheckState(levels & mLOG_STUB ? Qt::Checked : Qt::Unchecked); + m_ui.levelInfo->setCheckState(levels & mLOG_INFO ? Qt::Checked : Qt::Unchecked); + m_ui.levelWarn->setCheckState(levels & mLOG_WARN ? Qt::Checked : Qt::Unchecked); + m_ui.levelError->setCheckState(levels & mLOG_ERROR ? Qt::Checked : Qt::Unchecked); + m_ui.levelFatal->setCheckState(levels & mLOG_FATAL ? Qt::Checked : Qt::Unchecked); + m_ui.levelGameError->setCheckState(levels & mLOG_GAME_ERROR ? Qt::Checked : Qt::Unchecked); } void LogView::setLevel(int level, bool set) { - if (level & GBA_LOG_DEBUG) { + if (level & mLOG_DEBUG) { m_ui.levelDebug->setCheckState(set ? Qt::Checked : Qt::Unchecked); } - if (level & GBA_LOG_STUB) { + if (level & mLOG_STUB) { m_ui.levelStub->setCheckState(set ? Qt::Checked : Qt::Unchecked); } - if (level & GBA_LOG_INFO) { + if (level & mLOG_INFO) { m_ui.levelInfo->setCheckState(set ? Qt::Checked : Qt::Unchecked); } - if (level & GBA_LOG_WARN) { + if (level & mLOG_WARN) { m_ui.levelWarn->setCheckState(set ? Qt::Checked : Qt::Unchecked); } - if (level & GBA_LOG_ERROR) { + if (level & mLOG_ERROR) { m_ui.levelError->setCheckState(set ? Qt::Checked : Qt::Unchecked); } - if (level & GBA_LOG_FATAL) { + if (level & mLOG_FATAL) { m_ui.levelFatal->setCheckState(set ? Qt::Checked : Qt::Unchecked); } - if (level & GBA_LOG_GAME_ERROR) { + if (level & mLOG_GAME_ERROR) { m_ui.levelGameError->setCheckState(set ? Qt::Checked : Qt::Unchecked); - } - if (level & GBA_LOG_SWI) { - m_ui.levelSWI->setCheckState(set ? Qt::Checked : Qt::Unchecked); - } - if (level & GBA_LOG_STATUS) { - m_ui.levelStatus->setCheckState(set ? Qt::Checked : Qt::Unchecked); - } - if (level & GBA_LOG_SIO) { - m_ui.levelSIO->setCheckState(set ? Qt::Checked : Qt::Unchecked); } if (set) {
M src/platform/qt/LogView.hsrc/platform/qt/LogView.h

@@ -30,7 +30,7 @@ void levelsEnabled(int levels);

void levelsDisabled(int levels); public slots: - void postLog(int level, const QString& log); + void postLog(int level, int category, const QString& log); void setLevels(int levels); void clear();
M src/platform/qt/LogView.uisrc/platform/qt/LogView.ui

@@ -99,30 +99,6 @@ <bool>false</bool>

</property> </widget> </item> - <item> - <widget class="QCheckBox" name="levelSWI"> - <property name="text"> - <string>SW Interrupt</string> - </property> - </widget> - </item> - <item> - <widget class="QCheckBox" name="levelStatus"> - <property name="text"> - <string>Status</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QCheckBox" name="levelSIO"> - <property name="text"> - <string>Serial I/O</string> - </property> - </widget> - </item> </layout> </widget> </item>
M src/platform/qt/MemoryModel.cppsrc/platform/qt/MemoryModel.cpp

@@ -158,7 +158,7 @@ return;

} QFile outfile(filename); if (!outfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - LOG(WARN) << tr("Failed to open output file: %1").arg(filename); + LOG(QT, WARN) << tr("Failed to open output file: %1").arg(filename); return; } QDataStream stream(&outfile);
M src/platform/qt/PaletteView.cppsrc/platform/qt/PaletteView.cpp

@@ -94,7 +94,7 @@ }

QString filename = dialog->selectedFiles()[0]; VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC); if (!vf) { - LOG(ERROR) << tr("Failed to open output palette file: %1").arg(filename); + LOG(QT, ERROR) << tr("Failed to open output palette file: %1").arg(filename); m_controller->threadContinue(); return; }
M src/platform/qt/VideoView.cppsrc/platform/qt/VideoView.cpp

@@ -199,7 +199,7 @@ if (!validateSettings()) {

return; } if (!FFmpegEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) { - LOG(ERROR) << tr("Failed to open output video file: %1").arg(m_filename); + LOG(QT, ERROR) << tr("Failed to open output video file: %1").arg(m_filename); return; } m_ui.start->setEnabled(false);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -121,7 +121,7 @@ #endif

connect(m_controller, SIGNAL(gamePaused(mCoreThread*)), &m_inputController, SLOT(resumeScreensaver())); connect(m_controller, SIGNAL(gameUnpaused(mCoreThread*)), m_display, SLOT(unpauseDrawing())); connect(m_controller, SIGNAL(gameUnpaused(mCoreThread*)), &m_inputController, SLOT(suspendScreensaver())); - connect(m_controller, SIGNAL(postLog(int, const QString&)), &m_log, SLOT(postLog(int, const QString&))); + connect(m_controller, SIGNAL(postLog(int, int, const QString&)), &m_log, SLOT(postLog(int, int, const QString&))); connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(recordFrame())); connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), m_display, SLOT(framePosted(const uint32_t*))); connect(m_controller, SIGNAL(gameCrashed(const QString&)), this, SLOT(gameCrashed(const QString&)));