? message.patch Index: debug.cc =================================================================== RCS file: /home/kde/kdelibs/arts/mcop/debug.cc,v retrieving revision 1.5 diff -u -r1.5 debug.cc --- debug.cc 2001/03/20 12:53:30 1.5 +++ debug.cc 2001/07/24 19:10:02 @@ -25,11 +25,13 @@ #include #include #include +#include "thread.h" static int arts_debug_level = Arts::Debug::lInfo; static bool arts_debug_abort = false; static const char *arts_debug_prefix = ""; static char *messageAppName = 0; +static Arts::Mutex *arts_debug_mutex = 0; namespace Arts { @@ -39,8 +41,8 @@ * always sent to standard error because they tend to be very verbose. * Note that the external application is run in the background to * avoid blocking the sound server. -*/ -void display_message(Debug::Level level, const char *msg) { + */ +void output_message(Debug::Level level, const char *msg) { char buff[1024]; /* default to text output if no message app is defined or if it is a debug message. */ @@ -66,6 +68,42 @@ system(buff); } +/* + * Display a message using output_message. If the message is the same + * as the previous one, just increment a count but don't display + * it. This prevents flooding the user with duplicate warnings. If the + * message is not the same as the previous one, then we report the + * previously repeated message (if any) and reset the last message and + * count. + */ +void display_message(Debug::Level level, const char *msg) { + static char lastMsg[1024]; + static Debug::Level lastLevel; + static int msgCount = 0; + + if(arts_debug_mutex) + arts_debug_mutex->lock(); + + if (!strncmp(msg, lastMsg, 1024)) + { + msgCount++; + } else { + if (msgCount > 0) + { + char buff[1024]; + sprintf(buff, "%s\n(The previous message was repeated %d times.)", lastMsg, msgCount); + output_message(lastLevel, buff); + } + strncpy(lastMsg, msg, 1024); + lastLevel = level; + msgCount = 0; + output_message(level, msg); + } + + if(arts_debug_mutex) + arts_debug_mutex->unlock(); +} + static class DebugInitFromEnv { public: DebugInitFromEnv() { @@ -156,4 +194,19 @@ { messageAppName = (char*) realloc(messageAppName, strlen(appName)+1); strcpy(messageAppName, appName); +} + +void Arts::Debug::initMutex() +{ + arts_return_if_fail(arts_debug_mutex == 0); + + arts_debug_mutex = new Arts::Mutex(); +} + +void Arts::Debug::freeMutex() +{ + arts_return_if_fail(arts_debug_mutex != 0); + + delete arts_debug_mutex; + arts_debug_mutex = 0; } Index: debug.h =================================================================== RCS file: /home/kde/kdelibs/arts/mcop/debug.h,v retrieving revision 1.3 diff -u -r1.3 debug.h --- debug.h 2001/03/20 12:53:30 1.3 +++ debug.h 2001/07/24 19:10:03 @@ -97,6 +97,10 @@ public: enum Level { lFatal = 3, lWarning = 2, lInfo = 1, lDebug = 0 }; + /** + * Initializes at which is the minimum level to react to. If you + * call this, call this before creating the Arts::Dispatcher object. + */ static void init(const char *prefix, Level level); static void fatal(const char *fmt,...); // print on stderr & abort @@ -104,11 +108,14 @@ static void info(const char *fmt,...); // print on stdout static void debug(const char *fmt,...); // print on stdout -/* - * This method sets the name of an external application to display messages - * graphically. - */ + /** + * This method sets the name of an external application to + * display messages graphically. + */ static void messageApp(const char *appName); + + static void initMutex(); // called from the dispatcher constructor + static void freeMutex(); // called from the dispatcher destructor }; }; Index: dispatcher.cc =================================================================== RCS file: /home/kde/kdelibs/arts/mcop/dispatcher.cc,v retrieving revision 1.59 diff -u -r1.59 dispatcher.cc --- dispatcher.cc 2001/04/28 18:07:03 1.59 +++ dispatcher.cc 2001/07/24 19:10:06 @@ -153,6 +153,9 @@ lock(); + /* makes arts_debug/arts_message/arts_return_if_fail/... threadsafe */ + Debug::initMutex(); + generateServerID(); if(ioManager) @@ -387,6 +390,9 @@ << GenericDataPacket::_dataPacketCount() << " data packets alive." << endl; } + + Debug::freeMutex(); + unlock(); /* private data pointer */