Move IPC sender to separate thread + implement kill IPC command + improve deployment script

This commit is contained in:
LoRd_MuldeR 2010-11-09 22:06:11 +01:00
parent 9ce7dfc75f
commit a7a637c412
12 changed files with 236 additions and 35 deletions

View File

@ -28,8 +28,8 @@
/> />
<Tool <Tool
Name="VCCustomBuildTool" Name="VCCustomBuildTool"
CommandLine="copy &quot;$(QTDIR)\plugins\imageformats\q???d4.dll&quot; &quot;$(TargetDir)\imageformats&quot;&#x0D;&#x0A;" CommandLine=""
Outputs="&quot;$(TargetDir)\imageformats\qgifd4.dll&quot;" Outputs=""
/> />
<Tool <Tool
Name="VCXMLDataGeneratorTool" Name="VCXMLDataGeneratorTool"
@ -92,6 +92,8 @@
/> />
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
Description="Copy plugin DLL&apos;s"
CommandLine="copy &quot;$(QTDIR)\plugins\imageformats\q???d4.dll&quot; &quot;$(TargetDir)\imageformats&quot;"
/> />
</Configuration> </Configuration>
<Configuration <Configuration
@ -106,8 +108,8 @@
/> />
<Tool <Tool
Name="VCCustomBuildTool" Name="VCCustomBuildTool"
CommandLine="copy &quot;$(QTDIR)\plugins\imageformats\q???4.dll&quot; &quot;$(TargetDir)\imageformats&quot;&#x0D;&#x0A;" CommandLine=""
Outputs="&quot;$(TargetDir)\imageformats\qgif4.dll&quot;" Outputs=""
/> />
<Tool <Tool
Name="VCXMLDataGeneratorTool" Name="VCXMLDataGeneratorTool"
@ -180,6 +182,8 @@
/> />
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
Description="Copy plugin DLL&apos;s"
CommandLine="copy &quot;$(QTDIR)\plugins\imageformats\q???4.dll&quot; &quot;$(TargetDir)\imageformats&quot;"
/> />
</Configuration> </Configuration>
</Configurations> </Configurations>
@ -247,6 +251,10 @@
RelativePath=".\src\Thread_MessageHandler.cpp" RelativePath=".\src\Thread_MessageHandler.cpp"
> >
</File> </File>
<File
RelativePath=".\src\Thread_MessageProducer.cpp"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Header Files" Name="Header Files"
@ -472,6 +480,30 @@
<File <File
RelativePath=".\src\Thread_MessageHandler.h" RelativePath=".\src\Thread_MessageHandler.h"
> >
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
Description="MOC &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot; -o &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
Description="MOC &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot; -o &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\Thread_MessageProducer.h"
>
<FileConfiguration <FileConfiguration
Name="Debug|Win32" Name="Debug|Win32"
> >
@ -535,6 +567,10 @@
RelativePath=".\tmp\MOC_Thread_MessageHandler.cpp" RelativePath=".\tmp\MOC_Thread_MessageHandler.cpp"
> >
</File> </File>
<File
RelativePath=".\tmp\MOC_Thread_MessageProducer.cpp"
>
</File>
<File <File
RelativePath=".\tmp\RCC_Icons.cpp" RelativePath=".\tmp\RCC_Icons.cpp"
> >

View File

@ -1,9 +1,31 @@
@echo off @echo off
call _paths.bat set "LAMEXP_BUILD_SUCCESS=NO"
echo ---------------------------------------------------------------- echo ----------------------------------------------------------------
echo Solution File: %1 echo Solution File: %1
echo Configuration: %~n2 echo Configuration: %~n2
echo ---------------------------------------------------------------- echo ----------------------------------------------------------------
call _paths.bat
call "%PATH_MSVC90%\VC\bin\vcvars32.bat" call "%PATH_MSVC90%\VC\bin\vcvars32.bat"
call "%PATH_QTMSVC%\bin\qtvars.bat" call "%PATH_QTMSVC%\bin\qtvars.bat"
msbuild.exe /property:Configuration=%~n2 /target:Clean,Rebuild /verbosity:d %1 REM -----------------------------------------------------------------
msbuild.exe /property:Configuration=%~n2 /target:Clean /verbosity:d %1
if exist "%~d1%~p1bin\%~n2\*.exe" (
echo.
echo CLEANUP HAS FAILED!
echo.
GOTO:EOF
)
if exist "%~d1%~p1obj\%~n2\*.obj" (
echo.
echo CLEANUP HAS FAILED!
echo.
GOTO:EOF
)
echo ----------------------------------------------------------------
msbuild.exe /property:Configuration=%~n2 /target:Rebuild /verbosity:d %1
echo ----------------------------------------------------------------
if not exist "%~d1%~p1bin\%~n2\%~n1.exe" (
echo BUILD HAS FAILED!
exit
)
set "LAMEXP_BUILD_SUCCESS=YES"

View File

@ -1,5 +1,6 @@
@echo off @echo off
set "PATH_SEVENZ=E:\7-Zip\7z.exe" set "PATH_SEVENZ=E:\7-Zip\7z.exe"
set "PATH_MPRESS=E:\MPress\mpress.exe" set "PATH_MPRESS=E:\MPress\mpress.exe"
set "PATH_UPXBIN=E:\MPUI\installer\upx.exe"
set "PATH_MSVC90=D:\Microsoft Visual Studio 9.0" set "PATH_MSVC90=D:\Microsoft Visual Studio 9.0"
set "PATH_QTMSVC=E:\Qt\MSVC\4.7.0" set "PATH_QTMSVC=E:\Qt\MSVC\4.7.0"

View File

@ -16,7 +16,7 @@ if exist "%OUT_FILE%" (
REM ------------------------------------------ REM ------------------------------------------
call _build.bat "..\..\LameXP.sln" Release call _build.bat "..\..\LameXP.sln" Release
REM ------------------------------------------ REM ------------------------------------------
if not exist "%OUT_PATH%\LameXP.exe" ( if not "%LAMEXP_BUILD_SUCCESS%"=="YES" (
echo. echo.
echo BUILD HAS FAILED !!! echo BUILD HAS FAILED !!!
echo. echo.
@ -36,10 +36,10 @@ copy "%QTDIR%\bin\QtSvg4.dll" "%TEMP_DIR%"
copy "%QTDIR%\plugins\imageformats\q???4.dll" "%TEMP_DIR%\imageformats" copy "%QTDIR%\plugins\imageformats\q???4.dll" "%TEMP_DIR%\imageformats"
REM ------------------------------------------ REM ------------------------------------------
for %%f in ("%TEMP_DIR%\*.exe") do ( for %%f in ("%TEMP_DIR%\*.exe") do (
"%PATH_MPRESS%" -s "%%f" "%PATH_UPXBIN%" --best --lzma "%%f"
) )
for %%f in ("%TEMP_DIR%\*.dll") do ( for %%f in ("%TEMP_DIR%\*.dll") do (
"%PATH_MPRESS%" -s "%%f" "%PATH_UPXBIN%" --best --lzma "%%f"
) )
REM ------------------------------------------ REM ------------------------------------------
copy "..\Redist\*.*" "%TEMP_DIR%" copy "..\Redist\*.*" "%TEMP_DIR%"

View File

@ -149,6 +149,7 @@ MainWindow::MainWindow(QWidget *parent)
m_delayedFileTimer = new QTimer(); m_delayedFileTimer = new QTimer();
connect(m_messageHandler, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection); connect(m_messageHandler, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection);
connect(m_messageHandler, SIGNAL(fileReceived(QString)), this, SLOT(addFileDelayed(QString)), Qt::QueuedConnection); connect(m_messageHandler, SIGNAL(fileReceived(QString)), this, SLOT(addFileDelayed(QString)), Qt::QueuedConnection);
connect(m_messageHandler, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection);
connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles())); connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
m_messageHandler->start(); m_messageHandler->start();
} }
@ -159,12 +160,18 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow(void) MainWindow::~MainWindow(void)
{ {
while(m_messageHandler->isRunning()) //Stop message handler thread
if(m_messageHandler && m_messageHandler->isRunning())
{ {
m_messageHandler->stop(); m_messageHandler->stop();
m_messageHandler->wait(); if(!m_messageHandler->wait(10000))
{
m_messageHandler->terminate();
m_messageHandler->wait();
}
} }
//Free memory
LAMEXP_DELETE(m_tabActionGroup); LAMEXP_DELETE(m_tabActionGroup);
LAMEXP_DELETE(m_styleActionGroup); LAMEXP_DELETE(m_styleActionGroup);
LAMEXP_DELETE(m_fileListModel); LAMEXP_DELETE(m_fileListModel);

View File

@ -332,7 +332,10 @@ void lamexp_ipc_send(unsigned int command, const char* message)
lamexp_ipc_t *lamexp_ipc = new lamexp_ipc_t; lamexp_ipc_t *lamexp_ipc = new lamexp_ipc_t;
memset(lamexp_ipc, 0, sizeof(lamexp_ipc_t)); memset(lamexp_ipc, 0, sizeof(lamexp_ipc_t));
lamexp_ipc->command = command; lamexp_ipc->command = command;
strcpy_s(lamexp_ipc->parameter, 4096, message); if(message)
{
strcpy_s(lamexp_ipc->parameter, 4096, message);
}
if(g_lamexp_semaphore_write_ptr->acquire()) if(g_lamexp_semaphore_write_ptr->acquire())
{ {
@ -383,22 +386,7 @@ void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize)
*/ */
void lamexp_handle_multiple_instanced(void) void lamexp_handle_multiple_instanced(void)
{ {
QStringList arguments = QApplication::arguments();
bool bSentFiles = false;
for(int i = 0; i < arguments.count() - 1; i++)
{
if(!arguments[i].compare("--add", Qt::CaseInsensitive))
{
lamexp_ipc_send(1, arguments[++i].toUtf8().constData());
bSentFiles = true;
}
}
if(!bSentFiles)
{
lamexp_ipc_send(UINT_MAX, "Use running instance!");
}
} }
/* /*

View File

@ -24,6 +24,7 @@
#include "Dialog_SplashScreen.h" #include "Dialog_SplashScreen.h"
#include "Dialog_MainWindow.h" #include "Dialog_MainWindow.h"
#include "Thread_Initialization.h" #include "Thread_Initialization.h"
#include "Thread_MessageProducer.h"
//Qt includes //Qt includes
#include <QApplication> #include <QApplication>
@ -36,6 +37,8 @@
int lamexp_main(int argc, char* argv[]) int lamexp_main(int argc, char* argv[])
{ {
int iResult = -1;
//Init console //Init console
lamexp_init_console(argc, argv); lamexp_init_console(argc, argv);
@ -69,16 +72,34 @@ int lamexp_main(int argc, char* argv[])
} }
//Check for multiple instances of LameXP //Check for multiple instances of LameXP
int iResult = lamexp_init_ipc(); if((iResult = lamexp_init_ipc()) != 0)
if(iResult > 0)
{ {
qDebug("LameXP is already running, connecting to running instance..."); qDebug("LameXP is already running, connecting to running instance...");
lamexp_handle_multiple_instanced(); if(iResult == 1)
{
MessageProducerThread *messageProducerThread = new MessageProducerThread();
messageProducerThread->start();
if(!messageProducerThread->wait(30000))
{
messageProducerThread->terminate();
QMessageBox messageBox(QMessageBox::Critical, "LameXP", "LameXP is already running, but the running instance doesn't respond!", QMessageBox::NoButton, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
messageBox.exec();
messageProducerThread->wait();
LAMEXP_DELETE(messageProducerThread);
return -1;
}
LAMEXP_DELETE(messageProducerThread);
}
return 0; return 0;
} }
else if(iResult < 0)
//Kill application?
for(int i = 0; i < argc; i++)
{ {
return -1; if(!_stricmp("--kill", argv[i]) || !_stricmp("--force-kill", argv[i]))
{
return 0;
}
} }
//Show splash screen //Show splash screen

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 7 #define VER_LAMEXP_BUILD 8
#define VER_LAMEXP_SUFFIX TechPreview #define VER_LAMEXP_SUFFIX TechPreview
/* /*

View File

@ -60,6 +60,16 @@ void MessageHandlerThread::run()
case 1: case 1:
emit fileReceived(QString::fromUtf8(m_parameter)); emit fileReceived(QString::fromUtf8(m_parameter));
break; break;
case 666:
if(!_stricmp(m_parameter, "Force!"))
{
ExitProcess(-2);
}
else
{
emit killSignalReceived();
}
break;
case UINT_MAX: case UINT_MAX:
emit otherInstanceDetected(); emit otherInstanceDetected();
break; break;
@ -77,7 +87,6 @@ void MessageHandlerThread::stop(void)
m_aborted = true; m_aborted = true;
lamexp_ipc_send(0, ""); lamexp_ipc_send(0, "");
} }
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -40,4 +40,5 @@ private:
signals: signals:
void otherInstanceDetected(void); void otherInstanceDetected(void);
void fileReceived(const QString &filePath); void fileReceived(const QString &filePath);
void killSignalReceived(void);
}; };

View File

@ -0,0 +1,82 @@
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
// Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
#include "Thread_MessageProducer.h"
#include "Global.h"
#include <QStringList>
#include <QApplication>
#include <limits.h>
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
MessageProducerThread::MessageProducerThread(void)
{
}
MessageProducerThread::~MessageProducerThread(void)
{
}
void MessageProducerThread::run()
{
setTerminationEnabled(true);
bool bSentFiles = false;
QStringList arguments = QApplication::arguments();
for(int i = 0; i < arguments.count(); i++)
{
if(!arguments[i].compare("--kill", Qt::CaseInsensitive))
{
lamexp_ipc_send(666, NULL);
return;
}
if(!arguments[i].compare("--force-kill", Qt::CaseInsensitive))
{
lamexp_ipc_send(666, "Force!");
return;
}
}
for(int i = 0; i < arguments.count() - 1; i++)
{
if(!arguments[i].compare("--add", Qt::CaseInsensitive))
{
lamexp_ipc_send(1, arguments[++i].toUtf8().constData());
bSentFiles = true;
}
}
if(!bSentFiles)
{
lamexp_ipc_send(UINT_MAX, "Use running instance!");
}
}
////////////////////////////////////////////////////////////
// EVENTS
////////////////////////////////////////////////////////////
/*NONE*/

View File

@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
// Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QThread>
class MessageProducerThread: public QThread
{
Q_OBJECT
public:
MessageProducerThread(void);
~MessageProducerThread(void);
void run();
};