all repos — mgba @ 016b64bf159ec49acd9ca727a943987fcafe42d7

mGBA Game Boy Advance Emulator

Qt: Initial logging throughout
Jeffrey Pfau jeffrey@endrift.com
Sat, 04 Jul 2015 01:24:37 -0700
commit

016b64bf159ec49acd9ca727a943987fcafe42d7

parent

ebca878c3177f1f97c9d78df6deb0aa7ee40e17f

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

@@ -5,6 +5,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "AudioDevice.h" +#include "LogController.h" + extern "C" { #include "gba/gba.h" #include "gba/audio.h"

@@ -24,6 +26,7 @@ }

void AudioDevice::setFormat(const QAudioFormat& format) { if (!m_context || !GBAThreadIsActive(m_context)) { + LOG(INFO) << tr("Can't set format of context-less audio device"); return; } #if RESAMPLE_LIBRARY == RESAMPLE_NN

@@ -49,6 +52,7 @@ maxSize = 0xFFFFFFFF;

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

@@ -68,5 +72,6 @@ #endif

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

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

#include "AudioProcessorQt.h" #include "AudioDevice.h" +#include "LogController.h" #include <QAudioOutput>

@@ -34,6 +35,7 @@ }

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

@@ -5,6 +5,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "AudioProcessorSDL.h" +#include "LogController.h" + extern "C" { #include "gba/supervisor/thread.h" }

@@ -23,6 +25,7 @@ }

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

@@ -5,6 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "CheatsModel.h" +#include "LogController.h" #include "VFileDevice.h" #include <QFont>

@@ -203,6 +204,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); return; } beginResetModel();
M src/platform/qt/GIFView.cppsrc/platform/qt/GIFView.cpp

@@ -8,6 +8,7 @@

#ifdef USE_MAGICK #include "GBAApp.h" +#include "LogController.h" #include <QMap>

@@ -34,6 +35,7 @@ }

void GIFView::startRecording() { if (!ImageMagickGIFEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) { + LOG(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

@@ -224,6 +224,7 @@ closeGame();

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

@@ -338,6 +339,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)); return; } threadInterrupt();

@@ -352,6 +354,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)); return; } threadInterrupt();
M src/platform/qt/LogController.cppsrc/platform/qt/LogController.cpp

@@ -7,10 +7,22 @@ #include "LogController.h"

using namespace QGBA; +LogController LogController::s_global(GBA_LOG_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(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); } void LogController::postLog(int level, const QString& string) {

@@ -33,6 +45,10 @@

void LogController::disableLevels(int levels) { m_logLevel &= ~levels; emit levelsDisabled(levels); +} + +LogController* LogController::global() { + return &s_global; } QString LogController::toString(int level) {
M src/platform/qt/LogController.hsrc/platform/qt/LogController.h

@@ -40,6 +40,7 @@ int levels() const { return m_logLevel; }

Stream operator()(int level); + static LogController* global(); static QString toString(int level); signals:

@@ -56,7 +57,11 @@ void disableLevels(int levels);

private: int m_logLevel; + + static LogController s_global; }; + +#define LOG(L) (*LogController::global())(GBA_LOG_ ## L) }
M src/platform/qt/MemoryModel.cppsrc/platform/qt/MemoryModel.cpp

@@ -7,6 +7,7 @@ #include "MemoryModel.h"

#include "GBAApp.h" #include "GameController.h" +#include "LogController.h" #include <QAction> #include <QApplication>

@@ -153,7 +154,7 @@ return;

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

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

#include "PaletteView.h" #include "GBAApp.h" +#include "LogController.h" #include "VFileDevice.h" #include <QFileDialog>

@@ -93,6 +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); m_controller->threadContinue(); return; }
M src/platform/qt/VideoView.cppsrc/platform/qt/VideoView.cpp

@@ -8,6 +8,7 @@

#ifdef USE_FFMPEG #include "GBAApp.h" +#include "LogController.h" #include <QMap>

@@ -198,6 +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); return; } m_ui.start->setEnabled(false);