Qt: Initial logging throughout

This commit is contained in:
Jeffrey Pfau 2015-07-04 01:24:37 -07:00
parent ebca878c31
commit 016b64bf15
11 changed files with 44 additions and 1 deletions

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AudioDevice.h" #include "AudioDevice.h"
#include "LogController.h"
extern "C" { extern "C" {
#include "gba/gba.h" #include "gba/gba.h"
#include "gba/audio.h" #include "gba/audio.h"
@ -24,6 +26,7 @@ AudioDevice::AudioDevice(QObject* parent)
void AudioDevice::setFormat(const QAudioFormat& format) { void AudioDevice::setFormat(const QAudioFormat& format) {
if (!m_context || !GBAThreadIsActive(m_context)) { if (!m_context || !GBAThreadIsActive(m_context)) {
LOG(INFO) << tr("Can't set format of context-less audio device");
return; return;
} }
#if RESAMPLE_LIBRARY == RESAMPLE_NN #if RESAMPLE_LIBRARY == RESAMPLE_NN
@ -49,6 +52,7 @@ qint64 AudioDevice::readData(char* data, qint64 maxSize) {
} }
if (!m_context->gba) { if (!m_context->gba) {
LOG(WARN) << tr("Audio device is missing its GBA");
return 0; return 0;
} }
@ -68,5 +72,6 @@ qint64 AudioDevice::readData(char* data, qint64 maxSize) {
} }
qint64 AudioDevice::writeData(const char*, qint64) { qint64 AudioDevice::writeData(const char*, qint64) {
LOG(WARN) << tr("Writing data to read-only audio device");
return 0; return 0;
} }

View File

@ -6,6 +6,7 @@
#include "AudioProcessorQt.h" #include "AudioProcessorQt.h"
#include "AudioDevice.h" #include "AudioDevice.h"
#include "LogController.h"
#include <QAudioOutput> #include <QAudioOutput>
@ -34,6 +35,7 @@ void AudioProcessorQt::setInput(GBAThread* input) {
void AudioProcessorQt::start() { void AudioProcessorQt::start() {
if (!input()) { if (!input()) {
LOG(WARN) << tr("Can't start an audio processor without input");
return; return;
} }

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AudioProcessorSDL.h" #include "AudioProcessorSDL.h"
#include "LogController.h"
extern "C" { extern "C" {
#include "gba/supervisor/thread.h" #include "gba/supervisor/thread.h"
} }
@ -23,6 +25,7 @@ AudioProcessorSDL::~AudioProcessorSDL() {
void AudioProcessorSDL::start() { void AudioProcessorSDL::start() {
if (!input()) { if (!input()) {
LOG(WARN) << tr("Can't start an audio processor without input");
return; return;
} }

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CheatsModel.h" #include "CheatsModel.h"
#include "LogController.h"
#include "VFileDevice.h" #include "VFileDevice.h"
#include <QFont> #include <QFont>
@ -203,6 +204,7 @@ void CheatsModel::endAppendRow() {
void CheatsModel::loadFile(const QString& path) { void CheatsModel::loadFile(const QString& path) {
VFile* vf = VFileDevice::open(path, O_RDONLY); VFile* vf = VFileDevice::open(path, O_RDONLY);
if (!vf) { if (!vf) {
LOG(WARN) << tr("Failed to open cheats file: %1").arg(path);
return; return;
} }
beginResetModel(); beginResetModel();

View File

@ -8,6 +8,7 @@
#ifdef USE_MAGICK #ifdef USE_MAGICK
#include "GBAApp.h" #include "GBAApp.h"
#include "LogController.h"
#include <QMap> #include <QMap>
@ -34,6 +35,7 @@ GIFView::~GIFView() {
void GIFView::startRecording() { void GIFView::startRecording() {
if (!ImageMagickGIFEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) { if (!ImageMagickGIFEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) {
LOG(ERROR) << tr("Failed to open output GIF file: %1").arg(m_filename);
return; return;
} }
m_ui.start->setEnabled(false); m_ui.start->setEnabled(false);

View File

@ -224,6 +224,7 @@ void GameController::loadGame(const QString& path, bool dirmode) {
if (!dirmode) { if (!dirmode) {
QFile file(path); QFile file(path);
if (!file.open(QIODevice::ReadOnly)) { if (!file.open(QIODevice::ReadOnly)) {
postLog(GBA_LOG_ERROR, tr("Failed to open game file: %1").arg(path));
return; return;
} }
file.close(); file.close();
@ -338,6 +339,7 @@ void GameController::importSharkport(const QString& path) {
} }
VFile* vf = VFileDevice::open(path, O_RDONLY); VFile* vf = VFileDevice::open(path, O_RDONLY);
if (!vf) { if (!vf) {
postLog(GBA_LOG_ERROR, tr("Failed to open snapshot file for reading: %1").arg(path));
return; return;
} }
threadInterrupt(); threadInterrupt();
@ -352,6 +354,7 @@ void GameController::exportSharkport(const QString& path) {
} }
VFile* vf = VFileDevice::open(path, O_WRONLY | O_CREAT | O_TRUNC); VFile* vf = VFileDevice::open(path, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) { if (!vf) {
postLog(GBA_LOG_ERROR, tr("Failed to open snapshot file for writing: %1").arg(path));
return; return;
} }
threadInterrupt(); threadInterrupt();

View File

@ -7,10 +7,22 @@
using namespace QGBA; using namespace QGBA;
LogController LogController::s_global(GBA_LOG_ALL);
LogController::LogController(int levels, QObject* parent) LogController::LogController(int levels, QObject* parent)
: QObject(parent) : QObject(parent)
, m_logLevel(levels) , 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) { void LogController::postLog(int level, const QString& string) {
@ -35,6 +47,10 @@ void LogController::disableLevels(int levels) {
emit levelsDisabled(levels); emit levelsDisabled(levels);
} }
LogController* LogController::global() {
return &s_global;
}
QString LogController::toString(int level) { QString LogController::toString(int level) {
switch (level) { switch (level) {
case GBA_LOG_DEBUG: case GBA_LOG_DEBUG:

View File

@ -40,6 +40,7 @@ public:
Stream operator()(int level); Stream operator()(int level);
static LogController* global();
static QString toString(int level); static QString toString(int level);
signals: signals:
@ -56,8 +57,12 @@ public slots:
private: private:
int m_logLevel; int m_logLevel;
static LogController s_global;
}; };
#define LOG(L) (*LogController::global())(GBA_LOG_ ## L)
} }
#endif #endif

View File

@ -7,6 +7,7 @@
#include "GBAApp.h" #include "GBAApp.h"
#include "GameController.h" #include "GameController.h"
#include "LogController.h"
#include <QAction> #include <QAction>
#include <QApplication> #include <QApplication>
@ -153,7 +154,7 @@ void MemoryModel::save() {
} }
QFile outfile(filename); QFile outfile(filename);
if (!outfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { if (!outfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
// TODO: Log LOG(WARN) << tr("Failed to open output file: %1").arg(filename);
return; return;
} }
QDataStream stream(&outfile); QDataStream stream(&outfile);

View File

@ -6,6 +6,7 @@
#include "PaletteView.h" #include "PaletteView.h"
#include "GBAApp.h" #include "GBAApp.h"
#include "LogController.h"
#include "VFileDevice.h" #include "VFileDevice.h"
#include <QFileDialog> #include <QFileDialog>
@ -93,6 +94,7 @@ void PaletteView::exportPalette(int start, int length) {
QString filename = dialog->selectedFiles()[0]; QString filename = dialog->selectedFiles()[0];
VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC); VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) { if (!vf) {
LOG(ERROR) << tr("Failed to open output palette file: %1").arg(filename);
m_controller->threadContinue(); m_controller->threadContinue();
return; return;
} }

View File

@ -8,6 +8,7 @@
#ifdef USE_FFMPEG #ifdef USE_FFMPEG
#include "GBAApp.h" #include "GBAApp.h"
#include "LogController.h"
#include <QMap> #include <QMap>
@ -198,6 +199,7 @@ void VideoView::startRecording() {
return; return;
} }
if (!FFmpegEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) { if (!FFmpegEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) {
LOG(ERROR) << tr("Failed to open output video file: %1").arg(m_filename);
return; return;
} }
m_ui.start->setEnabled(false); m_ui.start->setEnabled(false);