Make message handler routine thread-safe.

This commit is contained in:
LoRd_MuldeR 2010-11-19 13:31:45 +01:00
parent 092e664ad1
commit 98dc212d68
6 changed files with 59 additions and 51 deletions

BIN
res/images/Working.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 0 #define VER_LAMEXP_MINOR_LO 0
#define VER_LAMEXP_BUILD 40 #define VER_LAMEXP_BUILD 41
#define VER_LAMEXP_SUFFIX TechPreview #define VER_LAMEXP_SUFFIX TechPreview
/* /*

View File

@ -35,6 +35,7 @@
#include <QSysInfo> #include <QSysInfo>
#include <QStringList> #include <QStringList>
#include <QSystemSemaphore> #include <QSystemSemaphore>
#include <QMutex>
//LameXP includes //LameXP includes
#include "Resource.h" #include "Resource.h"
@ -107,6 +108,9 @@ static QSystemSemaphore *g_lamexp_semaphore_write_ptr = NULL;
//Image formats //Image formats
static const char *g_lamexp_imageformats[] = {"png", "gif", "ico", "svg", NULL}; static const char *g_lamexp_imageformats[] = {"png", "gif", "ico", "svg", NULL};
//Global locks
static QMutex g_lamexp_message_mutex;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS // GLOBAL FUNCTIONS
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -172,6 +176,54 @@ const QDate &lamexp_version_date(void)
return g_lamexp_version_date; return g_lamexp_version_date;
} }
/*
* Qt message handler
*/
void lamexp_message_handler(QtMsgType type, const char *msg)
{
static HANDLE hConsole = NULL;
QMutexLocker lock(&g_lamexp_message_mutex);
if(!hConsole)
{
hConsole = CreateFile(L"CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if(hConsole == INVALID_HANDLE_VALUE) hConsole = NULL;
}
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
switch(type)
{
case QtCriticalMsg:
case QtFatalMsg:
fflush(stdout);
fflush(stderr);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
fprintf(stderr, "\nCRITICAL ERROR !!!\n%s\n\n", msg);
MessageBoxA(NULL, msg, "LameXP - CRITICAL ERROR", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
break;
case QtWarningMsg:
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
fprintf(stderr, "%s\n", msg);
fflush(stderr);
break;
default:
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
fprintf(stderr, "%s\n", msg);
fflush(stderr);
break;
}
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
if(type == QtCriticalMsg || type == QtFatalMsg)
{
FatalAppExit(0, L"The application has encountered a critical error and will exit now!");
TerminateProcess(GetCurrentProcess(), -1);
}
}
/* /*
* Initialize the console * Initialize the console
*/ */

View File

@ -31,10 +31,11 @@
//Win32 //Win32
#include <Windows.h> #include <Windows.h>
//Class declarations //Declarations
class QString; class QString;
class LockedFile; class LockedFile;
class QDate; class QDate;
enum QtMsgType;
//Types definitions //Types definitions
typedef struct typedef struct
@ -65,6 +66,7 @@ unsigned int lamexp_toolver_neroaac(void);
void lamexp_init_console(int argc, char* argv[]); void lamexp_init_console(int argc, char* argv[]);
bool lamexp_init_qt(int argc, char* argv[]); bool lamexp_init_qt(int argc, char* argv[]);
int lamexp_init_ipc(void); int lamexp_init_ipc(void);
void lamexp_message_handler(QtMsgType type, const char *msg);
void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0); void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0);
bool lamexp_check_tool(const QString &toolName); bool lamexp_check_tool(const QString &toolName);
const QString lamexp_lookup_tool(const QString &toolName); const QString lamexp_lookup_tool(const QString &toolName);

View File

@ -32,6 +32,7 @@
#include <QApplication> #include <QApplication>
#include <QMessageBox> #include <QMessageBox>
#include <QDate> #include <QDate>
#include <QMutex>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Main function // Main function
@ -134,54 +135,6 @@ int lamexp_main(int argc, char* argv[])
return iResult; return iResult;
} }
///////////////////////////////////////////////////////////////////////////////
// Message Handler
///////////////////////////////////////////////////////////////////////////////
static void lamexp_message_handler(QtMsgType type, const char *msg)
{
static HANDLE hConsole = NULL;
if(!hConsole)
{
hConsole = CreateFile(L"CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
}
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
switch(type)
{
case QtCriticalMsg:
case QtFatalMsg:
fflush(stdout);
fflush(stderr);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
fprintf(stderr, "\nCRITICAL ERROR !!!\n%s\n\n", msg);
MessageBoxA(NULL, msg, "LameXP - CRITICAL ERROR", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
break;
case QtWarningMsg:
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
fprintf(stderr, "%s\n", msg);
fflush(stderr);
break;
default:
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
fprintf(stderr, "%s\n", msg);
fflush(stderr);
break;
}
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
if(type == QtCriticalMsg || type == QtFatalMsg)
{
FatalAppExit(0, L"The application has encountered a critical error and will exit now!");
TerminateProcess(GetCurrentProcess(), -1);
}
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Applicaton entry point // Applicaton entry point
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -178,6 +178,7 @@ void InitializationThread::initNeroAac(void)
{ {
qWarning("Nero process failed to create!"); qWarning("Nero process failed to create!");
qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData()); qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
qDebug("File '%s' does exist?\n%s\n!", neroFileInfo[0].canonicalFilePath().toUtf8().constData(), (neroFileInfo[0].exists() ? "Yes, it still exists" : "Nope, it disappeared"));
process.kill(); process.kill();
process.waitForFinished(-1); process.waitForFinished(-1);
for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]); for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
@ -223,7 +224,7 @@ void InitializationThread::initNeroAac(void)
if(!(neroVersion > 0)) if(!(neroVersion > 0))
{ {
qWarning("Nero AAC version could not be determined!", neroVersion); qWarning("Nero AAC version could not be determined -> AAC encoding support will be disabled!", neroVersion);
for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]); for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
return; return;
} }