Commit acb27cce authored by Casian Andrei's avatar Casian Andrei
Browse files

Remake debug system using the shiny new debug from Amarok

Remove Backend::logMessage().
Convert the old Backend::m_debugLevel to Debug::DebugLevel.
Small adjustments to the debug things, including null debug.
PHONON_VLC_DEBUG env has the same functionality, except for the value 2,
where it has some less output.
__FUNCTION__ --> Q_FUNC_INFO everywhere

Limited testing done, but it's just debug stuff.
parent 0547b64a
......@@ -28,6 +28,7 @@
#include <vlc/vlc.h>
#include "backend.h"
#include "debug.h"
#include "devicemanager.h"
#include "mediaobject.h"
......@@ -88,7 +89,7 @@ void AudioOutput::setVolume(qreal volume)
const int previous_volume = libvlc_audio_get_volume(m_player);
m_volume = volume;
libvlc_audio_set_volume(m_player, (int)(m_volume * 50));
qDebug() << __FUNCTION__ << "Volume changed to - " << (int)(m_volume * 100) << " From " << previous_volume;
debug() << "Volume changed from" << previous_volume << "to" << (int)(m_volume * 100);
emit volumeChanged(m_volume);
}
}
......@@ -108,7 +109,7 @@ bool AudioOutput::setOutputDevice(int device)
if (PulseSupport::getInstance()->isActive()) {
m_deviceIndex = device;
libvlc_audio_output_set(m_player, "pulse");
qDebug() << "set aout pulse";
debug() << "Setting aout to pulse";
return true;
}
#endif
......@@ -122,8 +123,8 @@ bool AudioOutput::setOutputDevice(int device)
}
m_deviceIndex = device;
const QByteArray deviceName = deviceList.at(device).name;
libvlc_audio_output_set(m_player, (char *) deviceList.at(device).name.data());
qDebug() << "set aout " << deviceList.at(device).name.data();
libvlc_audio_output_set(m_player, deviceName.data());
debug() << "Setting aout to" << deviceName;
// if (deviceName == DEFAULT_ID) {
// libvlc_audio_device_set(p_vlc_instance, DEFAULT, vlc_exception);
// vlcExceptionRaised();
......@@ -152,7 +153,7 @@ void AudioOutput::updateVolume()
if (m_player) {
const int previous_volume = libvlc_audio_get_volume(m_player);
libvlc_audio_set_volume(m_player, (int)(m_volume * 50));
qDebug() << __FUNCTION__ << "Volume changed to - " << (int)(m_volume * 50) << " From " << previous_volume;
debug() << "Volume changed from" << previous_volume << "to" << (int)(m_volume * 100);
}
}
......
......@@ -56,7 +56,7 @@ public:
* \param p_back Parent backend
* \param p_parent A parent object
*/
AudioOutput(QObject *p_parent);
AudioOutput(QObject *parent);
~AudioOutput();
/* Overload */
......
......@@ -84,11 +84,11 @@ Backend::Backend(QObject *parent, const QVariantList &)
if (debugLevel > 3) { // 3 is maximum
debugLevel = 3;
}
m_debugLevel = (DebugLevel)debugLevel;
Debug::setMinimumDebugLevel((Debug::DebugLevel)((int) Debug::DEBUG_NONE - 1 - debugLevel));
// Actual libVLC initialisation
if (LibVLC::init(m_debugLevel)) {
logMessage(QString("Using VLC version %0").arg(libvlc_get_version()));
if (LibVLC::init()) {
debug() << "Using VLC version %0" << libvlc_get_version();
} else {
#ifdef __GNUC__
#warning TODO - this error message is about as useful as a cooling unit in the arctic
......@@ -103,7 +103,7 @@ Backend::Backend(QObject *parent, const QVariantList &)
" please report a bug with your distributor."));
msg.setDetailedText(LibVLC::errorMessage());
msg.exec();
qCritical("Phonon::VLC::vlcInit: Failed to initialize VLC");
fatal() << "Phonon::VLC::vlcInit: Failed to initialize VLC";
}
m_deviceManager = new DeviceManager(this);
......@@ -134,11 +134,11 @@ QObject *Backend::createObject(BackendInterface::Class c, QObject *parent, const
switch (cex) {
case Phonon::Experimental::BackendInterface::AvCaptureClass:
logMessage("createObject() : AvCapture created - WARNING: Experimental!");
warning() << "createObject() : AvCapture created - WARNING: Experimental!";
return new Experimental::AvCapture(parent);
default:
if ((quint32) cex >= (quint32) Phonon::Experimental::BackendInterface::VideoDataOutputClass)
logMessage("createObject() - experimental : Backend object not available");
warning() << "createObject() - experimental : Backend object not available";
}
#endif // PHONON_VLC_NO_EXPERIMENTAL
......@@ -146,7 +146,7 @@ QObject *Backend::createObject(BackendInterface::Class c, QObject *parent, const
case MediaObjectClass:
return new MediaObject(parent);
case VolumeFaderEffectClass:
logMessage("createObject() : VolumeFaderEffect not implemented");
debug() << "createObject() : VolumeFaderEffect not implemented";
break;
case AudioOutputClass: {
AudioOutput *ao = new AudioOutput(parent);
......@@ -155,21 +155,21 @@ QObject *Backend::createObject(BackendInterface::Class c, QObject *parent, const
}
case AudioDataOutputClass:
return new AudioDataOutput(parent);
logMessage("createObject() : AudioDataOutput created - WARNING: POSSIBLY INCORRECTLY IMPLEMENTED");
warning() << "createObject() : AudioDataOutput created - WARNING: POSSIBLY INCORRECTLY IMPLEMENTED";
break;
case VisualizationClass:
logMessage("createObject() : Visualization not implemented");
error() << "createObject() : Visualization not implemented";
break;
case VideoDataOutputClass:
// return new Phonon::VLC::VideoDataOutput(this, parent);
logMessage("createObject() : VideoDataOutput not implemented");
error() << "createObject() : VideoDataOutput not implemented";
break;
case EffectClass:
return new Effect(m_effectManager, args[0].toInt(), parent);
case VideoWidgetClass:
return new VideoWidget(qobject_cast<QWidget *>(parent));
default:
logMessage("createObject() : Backend object not available");
error() << "createObject() : Backend object not available";
}
return 0;
}
......@@ -365,7 +365,7 @@ bool Backend::startConnectionChange(QSet<QObject *> objects)
{
//FIXME
foreach(QObject * object, objects) {
logMessage(QString("Object: %0").arg(object->metaObject()->className()));
debug() << "Object:" << object->metaObject()->className();
}
// There is nothing we can do but hope the connection changes will not take too long
......@@ -376,9 +376,7 @@ bool Backend::startConnectionChange(QSet<QObject *> objects)
bool Backend::connectNodes(QObject *source, QObject *sink)
{
logMessage(QString("Backend connected %0 to %1")
.arg(source->metaObject()->className())
.arg(sink->metaObject()->className()));
debug() << "Backend connected" << source->metaObject()->className() << "to" << sink->metaObject()->className();
SinkNode *sinkNode = dynamic_cast<SinkNode *>(sink);
if (sinkNode) {
......@@ -407,10 +405,7 @@ bool Backend::connectNodes(QObject *source, QObject *sink)
*/
}
logMessage(QString("Linking %0 to %1 failed")
.arg(source->metaObject()->className())
.arg(sink->metaObject()->className()),
Warning);
warning() << "Linking" << source->metaObject()->className() << "to" << sink->metaObject()->className() << "failed";
return false;
}
......@@ -450,7 +445,7 @@ bool Backend::disconnectNodes(QObject *source, QObject *sink)
bool Backend::endConnectionChange(QSet<QObject *> objects)
{
foreach(QObject * object, objects) {
logMessage(QString("Object: %0").arg(object->metaObject()->className()));
debug() << "Object:" << object->metaObject()->className();
}
return true;
......@@ -466,30 +461,9 @@ EffectManager *Backend::effectManager() const
return m_effectManager;
}
Backend::DebugLevel Backend::debugLevel() const
Debug::DebugLevel Backend::debugLevel() const
{
return m_debugLevel;
}
void Backend::logMessage(const QString &message, int priority, QObject *obj) const
{
if (debugLevel() > 0) {
QString output;
if (obj) {
// Strip away namespace from className
QString className(obj->metaObject()->className());
const int nameLength = className.length() - className.lastIndexOf(':') - 1;
className = className.right(nameLength);
output.sprintf("%s %s (%s %p)", message.toLatin1().constData(),
obj->objectName().toLatin1().constData(),
className.toLatin1().constData(), static_cast<void *>(obj));
} else {
output = message;
}
if (priority <= (int)debugLevel()) {
qDebug() << QString("PVLC(%1): %2").arg(priority).arg(output);
}
}
return Debug::minimumDebugLevel();
}
}
......
......@@ -24,8 +24,8 @@
#ifndef Phonon_VLC_BACKEND_H
#define Phonon_VLC_BACKEND_H
#include "devicemanager.h"
#include "audiooutput.h"
#include "debug.h"
#include <phonon/objectdescription.h>
#include <phonon/backendinterface.h>
......@@ -45,6 +45,7 @@ namespace Phonon
namespace VLC
{
class AudioOutput;
class DeviceManager;
class EffectManager;
/** \brief Backend class for Phonon-VLC.
......@@ -73,8 +74,6 @@ public:
*/
static Backend *self;
enum DebugLevel {NoDebug, Warning, Info, Debug};
/**
* Constructs the backend. Sets the backend properties, fetches the debug level from the
* environment, initializes libVLC, constructs the device and effect managers, initializes
......@@ -161,26 +160,17 @@ public:
bool endConnectionChange(QSet<QObject *>);
/**
* Return a debuglevel that is determined by the
* PHONON_VLC_DEBUG environment variable.
* Return the current debug level.
*
* \li Warning - important warnings
* \li Info - general info
* \li Debug - gives extra info
* The debug level can be set by the PHONON_VLC_DEBUG environment variable.
* \li 0 - Only fatal errors are shown
* \li 1 - Fatal and non-fatal errors
* \li 2 - All errors and warnings
* \li 3 - Everything
*
* \return The debug level.
*/
DebugLevel debugLevel() const;
/**
* Print a conditional debug message based on the current debug level
* If obj is provided, classname and objectname will be printed as well
*
* \param message Debug message
* \param priority Priority of the debug message, see debugLevel()
* \param obj Who gives the message, or some object relevant for the message
*/
void logMessage(const QString &message, int priority = 2, QObject *obj = 0) const;
Debug::DebugLevel debugLevel() const;
Q_SIGNALS:
void objectDescriptionChanged(ObjectDescriptionType);
......@@ -191,7 +181,6 @@ private:
DeviceManager *m_deviceManager;
EffectManager *m_effectManager;
DebugLevel m_debugLevel;
};
}
......
......@@ -27,6 +27,7 @@
#include <iostream>
#include <unistd.h>
#include <kdebug.h>
// Define Application wide prefix
#ifndef APP_PREFIX
......@@ -39,8 +40,8 @@ QMutex Debug::mutex( QMutex::Recursive );
using namespace Debug;
static bool s_debugEnabled = true;
static bool s_debugColorsEnabled = true;
static DebugLevel s_debugLevel = DEBUG_NONE;
IndentPrivate::IndentPrivate(QObject* parent)
: QObject(parent)
......@@ -71,11 +72,11 @@ static QString toString( DebugLevel level )
{
switch( level )
{
case KDEBUG_WARN:
case DEBUG_WARN:
return "[WARNING]";
case KDEBUG_ERROR:
case DEBUG_ERROR:
return "[ERROR__]";
case KDEBUG_FATAL:
case DEBUG_FATAL:
return "[FATAL__]";
default:
return QString();
......@@ -85,10 +86,10 @@ static QString toString( DebugLevel level )
static int toColor( DebugLevel level )
{
switch( level ) {
case KDEBUG_WARN:
case DEBUG_WARN:
return 3; // red
case KDEBUG_ERROR:
case KDEBUG_FATAL:
case DEBUG_ERROR:
case DEBUG_FATAL:
return 1; // yellow
default:
return 0; // default: black
......@@ -118,7 +119,7 @@ QString Debug::indent()
bool Debug::debugEnabled()
{
return s_debugEnabled;
return s_debugLevel < DEBUG_NONE;
}
bool Debug::debugColorEnabled()
......@@ -126,9 +127,9 @@ bool Debug::debugColorEnabled()
return s_debugColorsEnabled;
}
void Debug::setDebugEnabled( bool enable )
DebugLevel Debug::minimumDebugLevel()
{
s_debugEnabled = enable;
return s_debugLevel;
}
void Debug::setColoredDebug( bool enable )
......@@ -136,20 +137,22 @@ void Debug::setColoredDebug( bool enable )
s_debugColorsEnabled = enable;
}
void Debug::setMinimumDebugLevel(DebugLevel level)
{
s_debugLevel = level;
}
QDebug Debug::dbgstream( DebugLevel level )
{
#ifdef __GNUC__
#warning FIXME
#endif
// if( !debugEnabled() )
// return kDebugDevNull();
if ( level < s_debugLevel )
return nullDebug();
mutex.lock();
const QString currentIndent = indent();
mutex.unlock();
QString text = QString("%1%2").arg( APP_PREFIX ).arg( currentIndent );
if ( level > KDEBUG_INFO )
if ( level > DEBUG_INFO )
text.append( ' ' + reverseColorize( toString(level), toColor( level ) ) );
return QDebug( QtDebugMsg ) << qPrintable( text );
......@@ -218,7 +221,7 @@ Block::~Block()
<< qPrintable( colorize( QString( "END__:" ), m_color ) )
<< m_label
<< qPrintable( reverseColorize( QString( "[DELAY Took (quite long) %3s]")
.arg( QString::number(duration, 'g', 2) ), toColor( KDEBUG_WARN ) ) );
.arg( QString::number(duration, 'g', 2) ), toColor( DEBUG_WARN ) ) );
}
}
......
......@@ -42,13 +42,6 @@
#define __PRETTY_FUNCTION__ __FILE__
#endif
// Debug prefix, override if needed
#ifndef DEBUG_PREFIX
#define AMAROK_PREFIX ""
#else
#define AMAROK_PREFIX "[" DEBUG_PREFIX "]"
#endif
/**
* @namespace Debug
* @short kdebug with indentation functionality and convenience macros
......@@ -82,33 +75,28 @@ namespace Debug
{
extern QMutex mutex;
// from kdebug.h
enum DebugLevel {
KDEBUG_INFO = 0,
KDEBUG_WARN = 1,
KDEBUG_ERROR = 2,
KDEBUG_FATAL = 3
DEBUG_INFO = 0,
DEBUG_WARN = 1,
DEBUG_ERROR = 2,
DEBUG_FATAL = 3,
DEBUG_NONE = 4
};
QDebug dbgstream( DebugLevel level = KDEBUG_INFO );
QDebug dbgstream( DebugLevel level = DEBUG_INFO );
bool debugEnabled();
bool debugColorEnabled();
void setDebugEnabled( bool enable );
DebugLevel minimumDebugLevel();
void setColoredDebug( bool enable );
void setMinimumDebugLevel( DebugLevel level );
QString indent();
static inline QDebug dbgstreamwrapper( DebugLevel level ) {
#ifdef DEBUG_PREFIX
return dbgstream( level ) << AMAROK_PREFIX;
#else
return dbgstream( level );
#endif
}
static inline QDebug dbgstreamwrapper( DebugLevel level ) { return dbgstream( level ); }
static inline QDebug debug() { return dbgstreamwrapper( KDEBUG_INFO ); }
static inline QDebug warning() { return dbgstreamwrapper( KDEBUG_WARN ); }
static inline QDebug error() { return dbgstreamwrapper( KDEBUG_ERROR ); }
static inline QDebug fatal() { return dbgstreamwrapper( KDEBUG_FATAL ); }
static inline QDebug debug() { return dbgstreamwrapper( DEBUG_INFO ); }
static inline QDebug warning() { return dbgstreamwrapper( DEBUG_WARN ); }
static inline QDebug error() { return dbgstreamwrapper( DEBUG_ERROR ); }
static inline QDebug fatal() { return dbgstreamwrapper( DEBUG_FATAL ); }
void perfLog( const QString &message, const QString &func );
}
......
/*
Copyright (c) 2010 Kevin Funk <krf@electrostorm.net>
Copyright (c) 2011 Casian Andrei <skeletk13@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -34,4 +35,23 @@ public:
QString m_string;
};
/*
* From kdelibs/kdecore/io
*/
class NoDebugStream: public QIODevice
{
// Q_OBJECT
public:
NoDebugStream() { open(WriteOnly); }
bool isSequential() const { return true; }
qint64 readData(char *, qint64) { return 0; /* eof */ }
qint64 readLineData(char *, qint64) { return 0; /* eof */ }
qint64 writeData(const char *, qint64 len) { return len; }
} devnull;
QDebug nullDebug()
{
return QDebug(&devnull);
}
#endif // DEBUGPRIVATE_H
......@@ -30,6 +30,7 @@
#include <vlc/vlc.h>
#include "backend.h"
#include "debug.h"
#include "libvlc.h"
QT_BEGIN_NAMESPACE
......@@ -56,6 +57,7 @@ DeviceManager::DeviceManager(Backend *parent)
: QObject(parent)
, m_backend(parent)
{
Q_ASSERT(parent);
updateDeviceList();
}
......@@ -118,11 +120,14 @@ void DeviceManager::updateDeviceSublist(const QList<DeviceInfo> &newDevices, QLi
int odc = deviceList.count();
for (int i = 0 ; i < ndc ; ++i) {
if (deviceId(newDevices[i].name) == -1) {
int id = deviceId(newDevices[i].name);
if (id == -1) {
// This is a new device, add it
deviceList.append(newDevices[i]);
emit deviceAdded(deviceId(newDevices[i].name));
qDebug() << "added device " << newDevices[i].name.data() << "id" << deviceId(newDevices[i].name);
id = deviceId(newDevices[i].name);
emit deviceAdded(id);
debug() << "Added backend device" << newDevices[i].name.data() << "with id" << id;
}
}
......@@ -179,7 +184,7 @@ void DeviceManager::updateDeviceList()
// Get the list of available audio outputs
libvlc_audio_output_t *p_ao_list = libvlc_audio_output_list_get(libvlc);
if (!p_ao_list) {
qDebug() << "libvlc exception:" << libvlc_errmsg();
error() << "libVLC:" << LibVLC::errorMessage();
}
libvlc_audio_output_t *p_start = p_ao_list;
......
......@@ -28,6 +28,8 @@
#include <vlc/libvlc.h>
#include "debug.h"
LibVLC *LibVLC::self;
LibVLC::LibVLC() :
......@@ -42,7 +44,7 @@ LibVLC::~LibVLC()
self = 0;
}
bool LibVLC::init(int debugLevel)
bool LibVLC::init()
{
Q_ASSERT_X(!self, "LibVLC", "there should be only one LibVLC object");
LibVLC::self = new LibVLC;
......@@ -68,6 +70,7 @@ bool LibVLC::init(int debugLevel)
args << QByteArray("--config=").append(QFile::encodeName(configFileName));
}
int debugLevel = 3 - (int) Debug::minimumDebugLevel();
if (debugLevel > 0) {
args << QByteArray("--verbose=").append(QString::number(debugLevel));
args << QByteArray("--extraintf=logger");
......@@ -104,7 +107,7 @@ bool LibVLC::init(int debugLevel)
// Create and initialize a libvlc instance (it should be done only once)
self->m_vlcInstance = libvlc_new(sizeof(vlcArgs) / sizeof(*vlcArgs), vlcArgs);
if (!self->m_vlcInstance) {
qCritical() << "libvlc exception:" << libvlc_errmsg();
fatal() << "libVLC:" << LibVLC::errorMessage();
return false;
}
return true;
......@@ -241,9 +244,9 @@ QString LibVLC::vlcPath()
if (!m_vlcLibrary->resolve("libvlc_exception_init")) { //"libvlc_exception_init" not contained in 1.1+
return path;
} else {
qDebug("Cannot resolve the symbol or load VLC library");
debug() << "Cannot resolve the symbol or load VLC library";
}
qWarning() << m_vlcLibrary->errorString();
warning() << m_vlcLibrary->errorString();
}
vlcUnload();
......
......@@ -84,7 +84,7 @@ public:
*
* \return VLC initialization result
*/
static bool init(int debugLevl);
static bool init();
/**
* \returns the most recent error message of libvlc
......
......@@ -25,6 +25,9 @@
#include <vlc/vlc.h>
#include "debug.h"
#include "libvlc.h"
namespace Phonon
{
namespace VLC
......@@ -62,9 +65,7 @@ bool MediaController::hasInterface(Interface iface) const
return true;
break;
default:
qCritical() << __FUNCTION__
<< "Error: unsupported AddonInterface::Interface"
<< iface;
error() << Q_FUNC_INFO << "unsupported AddonInterface::Interface" << iface;
}
return false;
......@@ -85,22 +86,20 @@ QVariant MediaController::interfaceCall(Interface iface, int i_command, const QL
return currentChapter();
// case AddonInterface::setCurrentChapter:
// if( arguments.isEmpty() || !arguments.first().canConvert<ChapterDescription>()) {
// qCritical() << __FUNCTION__ << "Error: arguments invalid";
// error() << Q_FUNC_INFO << "arguments invalid";
// return false;
// }
// setCurrentChapter(arguments.first().value<ChapterDescription>());
// return true;
case AddonInterface::setChapter:
if (arguments.isEmpty() || !arguments.first().canConvert(QVariant::Int)) {
qCritical() << __FUNCTION__ << "Error: arguments invalid";
error() << Q_FUNC_INFO << "arguments invalid";
return false;
}
setCurrentChapter(arguments.first().toInt());
return true;
default:
qCritical() << __FUNCTION__
<< "Error: unsupported AddonInterface::ChapterInterface command:"
<< i_command;
error() << Q_FUNC_INFO << "unsupported AddonInterface::ChapterInterface command:" << i_command;
}
break;
case AddonInterface::TitleInterface:
......@@ -115,14 +114,14 @@ QVariant MediaController::interfaceCall(Interface iface, int i_command, const QL
return currentTitle();
// case AddonInterface::setCurrentTitle:
// if( arguments.isEmpty() || !arguments.first().canConvert<TitleDescription>()) {
// qCritical() << __FUNCTION__ << "Error: arguments invalid";
// error() << Q_FUNC_INFO << " arguments invalid";
// return false;
// }
// setCurrentTitle(arguments.first().value<TitleDescription>());
// return true;
case AddonInterface::setTitle:
if (arguments.isEmpty() || !arguments.first().canConvert(QVariant::Int)) {
qCritical() << __FUNCTION__ << "Error: arguments invalid";
error() << Q_FUNC_INFO << "arguments invalid";
return false;
}
setCurrentTitle(arguments.first().toInt());
......@@ -131,15 +130,13 @@ QVariant MediaController::interfaceCall(Interface iface, int i_command, const QL
return autoplayTitles();
case AddonInterface::setAutoplayTitles:
if (arguments.isEmpty() || !arguments.first().canConvert(QVariant::Bool)) {
qCritical() << __FUNCTION__ << "Error: arguments invalid"