Add debug transmitter

This is in preparation to conveniently duplicate debug messages
to Window > Log. For cases where stdout/err is not easily accessible.
This commit is contained in:
Robin Gareus 2020-10-13 21:26:26 +02:00
parent 9ddd83d829
commit 9a4237ba83
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
7 changed files with 22 additions and 7 deletions

View File

@ -30,6 +30,7 @@
#include <boost/tokenizer.hpp>
#include "pbd/debug.h"
#include "pbd/error.h"
#include "pbd/i18n.h"
@ -62,6 +63,7 @@ DebugBits PBD::DEBUG::Threads = PBD::new_debug_bit ("threads");
DebugBits PBD::DEBUG::Locale = PBD::new_debug_bit ("locale");
DebugBits PBD::DEBUG::StringConvert = PBD::new_debug_bit ("stringconvert");
DebugBits PBD::DEBUG::DebugTimestamps = PBD::new_debug_bit ("debugtimestamps");
DebugBits PBD::DEBUG::DebugLogToGUI = PBD::new_debug_bit ("debuglogtogui");
/* These are debug bits that are used by backends. Since these are loaded dynamically,
after command-line parsing, defining them in code that is part of the backend
@ -105,6 +107,10 @@ PBD::debug_print (const char* prefix, string str)
} else {
printf ("%s: %s", prefix, str.c_str());
}
if ((PBD::debug_bits & DEBUG::DebugLogToGUI).any()) {
std::replace (str.begin (), str.end (), '\n', ' ');
debug << prefix << ": " << str << endmsg;
}
}
int

View File

@ -18,8 +18,8 @@
#include "pbd/error.h"
Transmitter PBD::error (Transmitter::Error);
Transmitter PBD::debug (Transmitter::Debug);
Transmitter PBD::info (Transmitter::Info);
Transmitter PBD::fatal (Transmitter::Fatal);
Transmitter PBD::warning (Transmitter::Warning);
Transmitter PBD::error (Transmitter::Error);
Transmitter PBD::fatal (Transmitter::Fatal);

View File

@ -63,6 +63,7 @@ namespace PBD {
LIBPBD_API extern DebugBits Locale;
LIBPBD_API extern DebugBits StringConvert;
LIBPBD_API extern DebugBits DebugTimestamps;
LIBPBD_API extern DebugBits DebugLogToGUI;
/* See notes in ../debug.cc on why these are defined here */

View File

@ -22,9 +22,10 @@
#include "transmitter.h"
namespace PBD {
LIBPBD_API extern Transmitter error;
LIBPBD_API extern Transmitter debug;
LIBPBD_API extern Transmitter info;
LIBPBD_API extern Transmitter warning;
LIBPBD_API extern Transmitter error;
LIBPBD_API extern Transmitter fatal;
}

View File

@ -31,6 +31,7 @@ class LIBPBD_API Transmitter : public std::stringstream
{
public:
enum Channel {
Debug,
Info,
Error,
Warning,
@ -54,6 +55,7 @@ class LIBPBD_API Transmitter : public std::stringstream
Channel channel;
PBD::Signal2<void, Channel, const char *> *send;
PBD::Signal2<void, Channel, const char *> debug;
PBD::Signal2<void, Channel, const char *> info;
PBD::Signal2<void, Channel, const char *> warning;
PBD::Signal2<void, Channel, const char *> error;

View File

@ -36,15 +36,17 @@ TextReceiver::receive (Transmitter::Channel chn, const char *str)
const char *prefix = "";
switch (chn) {
case Transmitter::Error:
prefix = ": [ERROR]: ";
break;
case Transmitter::Debug:
return;
case Transmitter::Info:
prefix = ": [INFO]: ";
break;
case Transmitter::Warning:
prefix = ": [WARNING]: ";
break;
case Transmitter::Error:
prefix = ": [ERROR]: ";
break;
case Transmitter::Fatal:
prefix = ": [FATAL]: ";
break;

View File

@ -40,6 +40,9 @@ Transmitter::Transmitter (Channel c)
case Info:
send = &info;
break;
case Debug:
send = &debug;
break;
case Fatal:
send = &fatal;
break;