Moved all IPC functions into the MUtilities libraries.
This commit is contained in:
parent
3a582a028c
commit
53b12027e6
@ -314,10 +314,8 @@ copy /Y "$(SolutionDir)\..\Prerequisites\VisualLeakDetector\bin\Win32\*.manifest
|
||||
<ClCompile Include="src\Filter_ToneAdjust.cpp" />
|
||||
<ClCompile Include="src\Genres.cpp" />
|
||||
<ClCompile Include="src\Global_Zero.cpp" />
|
||||
<ClCompile Include="src\Global_IPC.cpp" />
|
||||
<ClCompile Include="src\Global_Utils.cpp" />
|
||||
<ClCompile Include="src\Global_Version.cpp" />
|
||||
<ClCompile Include="src\Global_Win32.cpp" />
|
||||
<ClCompile Include="src\Global_Tools.cpp" />
|
||||
<ClCompile Include="src\LockedFile.cpp" />
|
||||
<ClCompile Include="src\Main.cpp" />
|
||||
|
@ -220,12 +220,6 @@
|
||||
<ClCompile Include="src\Global_Tools.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Global_Win32.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Global_IPC.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Global_Version.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -34,8 +34,8 @@
|
||||
#define VER_LAMEXP_MINOR_HI 1
|
||||
#define VER_LAMEXP_MINOR_LO 1
|
||||
#define VER_LAMEXP_TYPE Beta
|
||||
#define VER_LAMEXP_PATCH 7
|
||||
#define VER_LAMEXP_BUILD 1624
|
||||
#define VER_LAMEXP_PATCH 8
|
||||
#define VER_LAMEXP_BUILD 1628
|
||||
#define VER_LAMEXP_CONFG 1558
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -226,7 +226,7 @@ static const char *g_hydrogen_audio_url = "http://wiki.hydrogenaud.io/index.php?
|
||||
// Constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel_MetaInfo *metaInfo, SettingsModel *settingsModel, QWidget *parent)
|
||||
MainWindow::MainWindow(MUtils::IPCChannel *const ipcChannel, FileListModel *const fileListModel, AudioFileModel_MetaInfo *const metaInfo, SettingsModel *const settingsModel, QWidget *const parent)
|
||||
:
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
@ -678,7 +678,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel_MetaInfo *me
|
||||
connect(m_fileListModel, SIGNAL(rowAppended()), m_dropBox, SLOT(modelChanged()));
|
||||
|
||||
//Create message handler thread
|
||||
m_messageHandler = new MessageHandlerThread();
|
||||
m_messageHandler = new MessageHandlerThread(ipcChannel);
|
||||
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(folderReceived(QString, bool)), this, SLOT(addFolderDelayed(QString, bool)), Qt::QueuedConnection);
|
||||
|
@ -45,17 +45,24 @@ class WorkingBanner;
|
||||
class lamexp_icon_t;
|
||||
|
||||
//UIC forward declartion
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
//IPC forward declartion
|
||||
namespace MUtils
|
||||
{
|
||||
class IPCChannel;
|
||||
}
|
||||
|
||||
//MainWindow class
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(FileListModel *fileListModel, AudioFileModel_MetaInfo *metaInfo, SettingsModel *settingsModel, QWidget *parent = 0);
|
||||
MainWindow(MUtils::IPCChannel *const ipcChannel, FileListModel *const fileListModel, AudioFileModel_MetaInfo *const metaInfo, SettingsModel *const settingsModel, QWidget *const parent = 0);
|
||||
~MainWindow(void);
|
||||
|
||||
bool isAccepted() { return m_accepted; }
|
||||
|
@ -49,11 +49,8 @@ const QIcon &lamexp_app_icon(void);
|
||||
QStringList lamexp_available_codepages(bool noAliases = true);
|
||||
bool lamexp_check_tool(const QString &toolName);
|
||||
void lamexp_finalization(void);
|
||||
int lamexp_init_ipc(void);
|
||||
bool lamexp_install_translator(const QString &language);
|
||||
bool lamexp_install_translator_from_file(const QString &qmFile);
|
||||
void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
|
||||
void lamexp_ipc_send(unsigned int command, const char* message);
|
||||
const QString lamexp_lookup_tool(const QString &toolName);
|
||||
const char *lamexp_mulders_url(void);
|
||||
bool lamexp_portable_mode(void);
|
||||
|
@ -1,287 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// LameXP - Audio Encoder Front-End
|
||||
// Copyright (C) 2004-2014 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, but always including the *additional*
|
||||
// restrictions defined in the "License.txt" file.
|
||||
//
|
||||
// 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 "Global.h"
|
||||
|
||||
//MUtils
|
||||
#include <MUtils/Global.h>
|
||||
#include <MUtils/Exception.h>
|
||||
|
||||
//Qt includes
|
||||
#include <QSharedMemory>
|
||||
#include <QSystemSemaphore>
|
||||
#include <QWriteLocker>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TYPES
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const size_t g_lamexp_ipc_slots = 128;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int command;
|
||||
unsigned int reserved_1;
|
||||
unsigned int reserved_2;
|
||||
char parameter[4096];
|
||||
}
|
||||
lamexp_ipc_data_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int pos_write;
|
||||
unsigned int pos_read;
|
||||
lamexp_ipc_data_t data[g_lamexp_ipc_slots];
|
||||
}
|
||||
lamexp_ipc_t;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GLOBAL VARS
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Shared memory
|
||||
static const struct
|
||||
{
|
||||
char *sharedmem;
|
||||
char *semaphore_read;
|
||||
char *semaphore_read_mutex;
|
||||
char *semaphore_write;
|
||||
char *semaphore_write_mutex;
|
||||
}
|
||||
g_lamexp_ipc_uuid =
|
||||
{
|
||||
"{21A68A42-6923-43bb-9CF6-64BF151942EE}",
|
||||
"{7A605549-F58C-4d78-B4E5-06EFC34F405B}",
|
||||
"{60AA8D04-F6B8-497d-81EB-0F600F4A65B5}",
|
||||
"{726061D5-1615-4B82-871C-75FD93458E46}",
|
||||
"{1A616023-AA6A-4519-8AF3-F7736E899977}"
|
||||
};
|
||||
static struct
|
||||
{
|
||||
QSharedMemory *sharedmem;
|
||||
QSystemSemaphore *semaphore_read;
|
||||
QSystemSemaphore *semaphore_read_mutex;
|
||||
QSystemSemaphore *semaphore_write;
|
||||
QSystemSemaphore *semaphore_write_mutex;
|
||||
QReadWriteLock lock;
|
||||
}
|
||||
g_lamexp_ipc_ptr;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GLOBAL FUNCTIONS
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Initialize IPC
|
||||
*/
|
||||
int lamexp_init_ipc(void)
|
||||
{
|
||||
QWriteLocker writeLock(&g_lamexp_ipc_ptr.lock);
|
||||
|
||||
if(g_lamexp_ipc_ptr.sharedmem && g_lamexp_ipc_ptr.semaphore_read && g_lamexp_ipc_ptr.semaphore_write && g_lamexp_ipc_ptr.semaphore_read_mutex && g_lamexp_ipc_ptr.semaphore_write_mutex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_lamexp_ipc_ptr.semaphore_read = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_read), 0);
|
||||
g_lamexp_ipc_ptr.semaphore_write = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_write), 0);
|
||||
g_lamexp_ipc_ptr.semaphore_read_mutex = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_read_mutex), 0);
|
||||
g_lamexp_ipc_ptr.semaphore_write_mutex = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_write_mutex), 0);
|
||||
|
||||
if(g_lamexp_ipc_ptr.semaphore_read->error() != QSystemSemaphore::NoError)
|
||||
{
|
||||
QString errorMessage = g_lamexp_ipc_ptr.semaphore_read->errorString();
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
|
||||
qFatal("Failed to create system smaphore: %s", MUTILS_UTF8(errorMessage));
|
||||
return -1;
|
||||
}
|
||||
if(g_lamexp_ipc_ptr.semaphore_write->error() != QSystemSemaphore::NoError)
|
||||
{
|
||||
QString errorMessage = g_lamexp_ipc_ptr.semaphore_write->errorString();
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
|
||||
qFatal("Failed to create system smaphore: %s", MUTILS_UTF8(errorMessage));
|
||||
return -1;
|
||||
}
|
||||
if(g_lamexp_ipc_ptr.semaphore_read_mutex->error() != QSystemSemaphore::NoError)
|
||||
{
|
||||
QString errorMessage = g_lamexp_ipc_ptr.semaphore_read_mutex->errorString();
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
|
||||
qFatal("Failed to create system smaphore: %s", MUTILS_UTF8(errorMessage));
|
||||
return -1;
|
||||
}
|
||||
if(g_lamexp_ipc_ptr.semaphore_write_mutex->error() != QSystemSemaphore::NoError)
|
||||
{
|
||||
QString errorMessage = g_lamexp_ipc_ptr.semaphore_write_mutex->errorString();
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
|
||||
qFatal("Failed to create system smaphore: %s", MUTILS_UTF8(errorMessage));
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_lamexp_ipc_ptr.sharedmem = new QSharedMemory(QString(g_lamexp_ipc_uuid.sharedmem), NULL);
|
||||
|
||||
if(!g_lamexp_ipc_ptr.sharedmem->create(sizeof(lamexp_ipc_t)))
|
||||
{
|
||||
if(g_lamexp_ipc_ptr.sharedmem->error() == QSharedMemory::AlreadyExists)
|
||||
{
|
||||
g_lamexp_ipc_ptr.sharedmem->attach();
|
||||
if(g_lamexp_ipc_ptr.sharedmem->error() == QSharedMemory::NoError)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage = g_lamexp_ipc_ptr.sharedmem->errorString();
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.sharedmem);
|
||||
qFatal("Failed to attach to shared memory: %s", MUTILS_UTF8(errorMessage));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage = g_lamexp_ipc_ptr.sharedmem->errorString();
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.sharedmem);
|
||||
qFatal("Failed to create shared memory: %s", MUTILS_UTF8(errorMessage));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
memset(g_lamexp_ipc_ptr.sharedmem->data(), 0, sizeof(lamexp_ipc_t));
|
||||
g_lamexp_ipc_ptr.semaphore_write->release(g_lamexp_ipc_slots);
|
||||
g_lamexp_ipc_ptr.semaphore_read_mutex->release();
|
||||
g_lamexp_ipc_ptr.semaphore_write_mutex->release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* IPC send message
|
||||
*/
|
||||
void lamexp_ipc_send(unsigned int command, const char* message)
|
||||
{
|
||||
QReadLocker readLock(&g_lamexp_ipc_ptr.lock);
|
||||
|
||||
if(!g_lamexp_ipc_ptr.sharedmem || !g_lamexp_ipc_ptr.semaphore_read || !g_lamexp_ipc_ptr.semaphore_write || !g_lamexp_ipc_ptr.semaphore_read_mutex || !g_lamexp_ipc_ptr.semaphore_write_mutex)
|
||||
{
|
||||
MUTILS_THROW("Shared memory for IPC not initialized yet.");
|
||||
}
|
||||
|
||||
lamexp_ipc_data_t ipc_data;
|
||||
memset(&ipc_data, 0, sizeof(lamexp_ipc_data_t));
|
||||
ipc_data.command = command;
|
||||
|
||||
if(message)
|
||||
{
|
||||
strncpy_s(ipc_data.parameter, 4096, message, _TRUNCATE);
|
||||
}
|
||||
|
||||
if(g_lamexp_ipc_ptr.semaphore_write->acquire())
|
||||
{
|
||||
if(g_lamexp_ipc_ptr.semaphore_write_mutex->acquire())
|
||||
{
|
||||
lamexp_ipc_t *ptr = reinterpret_cast<lamexp_ipc_t*>(g_lamexp_ipc_ptr.sharedmem->data());
|
||||
memcpy(&ptr->data[ptr->pos_write], &ipc_data, sizeof(lamexp_ipc_data_t));
|
||||
ptr->pos_write = (ptr->pos_write + 1) % g_lamexp_ipc_slots;
|
||||
g_lamexp_ipc_ptr.semaphore_read->release();
|
||||
g_lamexp_ipc_ptr.semaphore_write_mutex->release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* IPC read message
|
||||
*/
|
||||
void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize)
|
||||
{
|
||||
QReadLocker readLock(&g_lamexp_ipc_ptr.lock);
|
||||
|
||||
*command = 0;
|
||||
message[0] = '\0';
|
||||
|
||||
if(!g_lamexp_ipc_ptr.sharedmem || !g_lamexp_ipc_ptr.semaphore_read || !g_lamexp_ipc_ptr.semaphore_write || !g_lamexp_ipc_ptr.semaphore_read_mutex || !g_lamexp_ipc_ptr.semaphore_write_mutex)
|
||||
{
|
||||
MUTILS_THROW("Shared memory for IPC not initialized yet.");
|
||||
}
|
||||
|
||||
lamexp_ipc_data_t ipc_data;
|
||||
memset(&ipc_data, 0, sizeof(lamexp_ipc_data_t));
|
||||
|
||||
if(g_lamexp_ipc_ptr.semaphore_read->acquire())
|
||||
{
|
||||
if(g_lamexp_ipc_ptr.semaphore_read_mutex->acquire())
|
||||
{
|
||||
lamexp_ipc_t *ptr = reinterpret_cast<lamexp_ipc_t*>(g_lamexp_ipc_ptr.sharedmem->data());
|
||||
memcpy(&ipc_data, &ptr->data[ptr->pos_read], sizeof(lamexp_ipc_data_t));
|
||||
ptr->pos_read = (ptr->pos_read + 1) % g_lamexp_ipc_slots;
|
||||
g_lamexp_ipc_ptr.semaphore_write->release();
|
||||
g_lamexp_ipc_ptr.semaphore_read_mutex->release();
|
||||
|
||||
if(!(ipc_data.reserved_1 || ipc_data.reserved_2))
|
||||
{
|
||||
*command = ipc_data.command;
|
||||
strncpy_s(message, buffSize, ipc_data.parameter, _TRUNCATE);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("Malformed IPC message, will be ignored");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// INITIALIZATION
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void _lamexp_global_init_ipcom(void)
|
||||
{
|
||||
MUTILS_ZERO_MEMORY(g_lamexp_ipc_ptr);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FINALIZATION
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void _lamexp_global_free_ipcom(void)
|
||||
{
|
||||
if(g_lamexp_ipc_ptr.sharedmem)
|
||||
{
|
||||
g_lamexp_ipc_ptr.sharedmem->detach();
|
||||
}
|
||||
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.sharedmem);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_read_mutex);
|
||||
MUTILS_DELETE(g_lamexp_ipc_ptr.semaphore_write_mutex);
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// LameXP - Audio Encoder Front-End
|
||||
// Copyright (C) 2004-2014 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, but always including the *additional*
|
||||
// restrictions defined in the "License.txt" file.
|
||||
//
|
||||
// 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 "Global.h"
|
||||
|
||||
//Target version
|
||||
#include "Targetver.h"
|
||||
|
||||
//Visual Leaks Detector
|
||||
#include <vld.h>
|
||||
|
||||
//Initialize static Qt plugins
|
||||
#ifdef QT_NODLL
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
Q_IMPORT_PLUGIN(qico)
|
||||
Q_IMPORT_PLUGIN(qsvg)
|
||||
#else
|
||||
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
|
||||
Q_IMPORT_PLUGIN(QICOPlugin)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//Localization
|
||||
const char* LAMEXP_DEFAULT_LANGID = "en";
|
||||
const char* LAMEXP_DEFAULT_TRANSLATION = "LameXP_EN.qm";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// INITIALIZATION
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void _lamexp_global_init_win32(void)
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FINALIZATION
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" void _lamexp_global_free_win32(void)
|
||||
{
|
||||
}
|
@ -28,6 +28,21 @@
|
||||
//Qt
|
||||
#include <QtGlobal>
|
||||
|
||||
//Initialize static Qt plugins
|
||||
#ifdef QT_NODLL
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
Q_IMPORT_PLUGIN(qico)
|
||||
Q_IMPORT_PLUGIN(qsvg)
|
||||
#else
|
||||
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
|
||||
Q_IMPORT_PLUGIN(QICOPlugin)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//Localization
|
||||
const char* LAMEXP_DEFAULT_LANGID = "en";
|
||||
const char* LAMEXP_DEFAULT_TRANSLATION = "LameXP_EN.qm";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GLOBAL FUNCTIONS
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -56,16 +71,12 @@ extern "C"
|
||||
{
|
||||
int mainCRTStartup(void);
|
||||
|
||||
void _lamexp_global_init_win32(void);
|
||||
void _lamexp_global_init_versn(void);
|
||||
void _lamexp_global_init_tools(void);
|
||||
void _lamexp_global_init_ipcom(void);
|
||||
void _lamexp_global_init_utils(void);
|
||||
|
||||
void _lamexp_global_free_win32(void);
|
||||
void _lamexp_global_free_versn(void);
|
||||
void _lamexp_global_free_tools(void);
|
||||
void _lamexp_global_free_ipcom(void);
|
||||
void _lamexp_global_free_utils(void);
|
||||
}
|
||||
|
||||
@ -81,10 +92,8 @@ extern "C" int lamexp_entry_point(void)
|
||||
}
|
||||
|
||||
//Call global initialization functions
|
||||
_lamexp_global_init_win32();
|
||||
_lamexp_global_init_versn();
|
||||
_lamexp_global_init_tools();
|
||||
_lamexp_global_init_ipcom();
|
||||
_lamexp_global_init_utils();
|
||||
|
||||
//Make sure we will pass the check
|
||||
@ -104,7 +113,5 @@ void lamexp_finalization(void)
|
||||
//Call global finalization functions, in proper order
|
||||
_lamexp_global_free_versn();
|
||||
_lamexp_global_free_tools();
|
||||
_lamexp_global_free_ipcom();
|
||||
_lamexp_global_free_utils();
|
||||
_lamexp_global_free_win32();
|
||||
}
|
||||
|
30
src/Main.cpp
30
src/Main.cpp
@ -40,6 +40,7 @@
|
||||
#include <MUtils/CPUFeatures.h>
|
||||
#include <MUtils/Terminal.h>
|
||||
#include <MUtils/Startup.h>
|
||||
#include <MUtils/IPCChannel.h>
|
||||
|
||||
//Qt includes
|
||||
#include <QApplication>
|
||||
@ -102,7 +103,7 @@ static int lamexp_main(int &argc, char **argv)
|
||||
if(!MUtils::Startup::init_qt(argc, argv, QLatin1String("LameXP - Audio Encoder Front-End")))
|
||||
{
|
||||
lamexp_finalization();
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Initialize application
|
||||
@ -123,13 +124,14 @@ static int lamexp_main(int &argc, char **argv)
|
||||
qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(lamexp_version_expires().toString(Qt::ISODate)).toLatin1().constData());
|
||||
}
|
||||
|
||||
//Check for multiple instances of LameXP
|
||||
if((iResult = lamexp_init_ipc()) != 0)
|
||||
//Initialize IPC
|
||||
MUtils::IPCChannel *ipcChannel = new MUtils::IPCChannel("LameXP", "MultiInstanceHandling");
|
||||
if((iResult = ipcChannel->initialize()) != MUtils::IPC_RET_SUCCESS_MASTER)
|
||||
{
|
||||
qDebug("LameXP is already running, connecting to running instance...");
|
||||
if(iResult == 1)
|
||||
if(iResult == MUtils::IPC_RET_SUCCESS_SLAVE)
|
||||
{
|
||||
MessageProducerThread *messageProducerThread = new MessageProducerThread();
|
||||
qDebug("LameXP is already running, connecting to running instance...");
|
||||
MessageProducerThread *messageProducerThread = new MessageProducerThread(ipcChannel);
|
||||
messageProducerThread->start();
|
||||
if(!messageProducerThread->wait(30000))
|
||||
{
|
||||
@ -138,13 +140,19 @@ static int lamexp_main(int &argc, char **argv)
|
||||
messageBox.exec();
|
||||
messageProducerThread->wait();
|
||||
MUTILS_DELETE(messageProducerThread);
|
||||
MUTILS_DELETE(ipcChannel);
|
||||
lamexp_finalization();
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
MUTILS_DELETE(messageProducerThread);
|
||||
}
|
||||
else
|
||||
{
|
||||
qFatal("The IPC initialization has failed!");
|
||||
}
|
||||
MUTILS_DELETE(ipcChannel);
|
||||
lamexp_finalization();
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//Kill application?
|
||||
@ -152,8 +160,9 @@ static int lamexp_main(int &argc, char **argv)
|
||||
{
|
||||
if(!arguments[i].compare("--kill", Qt::CaseInsensitive) || !arguments[i].compare("--force-kill", Qt::CaseInsensitive))
|
||||
{
|
||||
MUTILS_DELETE(ipcChannel);
|
||||
lamexp_finalization();
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +190,7 @@ static int lamexp_main(int &argc, char **argv)
|
||||
settingsModel->validate();
|
||||
|
||||
//Create main window
|
||||
MainWindow *poMainWindow = new MainWindow(fileListModel, metaInfo, settingsModel);
|
||||
MainWindow *poMainWindow = new MainWindow(ipcChannel, fileListModel, metaInfo, settingsModel);
|
||||
|
||||
//Main application loop
|
||||
while(bAccepted && (iShutdown <= shutdownFlag_None))
|
||||
@ -212,6 +221,7 @@ static int lamexp_main(int &argc, char **argv)
|
||||
|
||||
//Taskbar un-init
|
||||
WinSevenTaskbar::uninit();
|
||||
MUTILS_DELETE(ipcChannel);
|
||||
|
||||
//Final clean-up
|
||||
qDebug("Shutting down, please wait...\n");
|
||||
|
@ -22,19 +22,27 @@
|
||||
|
||||
#include "Thread_MessageHandler.h"
|
||||
|
||||
//Internal
|
||||
#include "Global.h"
|
||||
|
||||
//MUtils
|
||||
#include <MUtils/IPCChannel.h>
|
||||
|
||||
//Qt
|
||||
#include <QSharedMemory>
|
||||
#include <QSystemSemaphore>
|
||||
#include <QMessageBox>
|
||||
|
||||
//CRL
|
||||
#include <limits.h>
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
MessageHandlerThread::MessageHandlerThread(void)
|
||||
MessageHandlerThread::MessageHandlerThread(MUtils::IPCChannel *const ipcChannel)
|
||||
:
|
||||
m_ipcChannel(ipcChannel)
|
||||
{
|
||||
m_aborted = false;
|
||||
m_parameter = new char[4096];
|
||||
@ -53,7 +61,7 @@ void MessageHandlerThread::run()
|
||||
while(!m_aborted)
|
||||
{
|
||||
unsigned int command = 0;
|
||||
lamexp_ipc_read(&command, m_parameter, 4096);
|
||||
m_ipcChannel->read(command, m_parameter, 4096);
|
||||
if(!command) continue;
|
||||
|
||||
switch(command)
|
||||
@ -92,7 +100,7 @@ void MessageHandlerThread::stop(void)
|
||||
if(!m_aborted)
|
||||
{
|
||||
m_aborted = true;
|
||||
lamexp_ipc_send(0, NULL);
|
||||
m_ipcChannel->send(0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,4 +108,4 @@ void MessageHandlerThread::stop(void)
|
||||
// EVENTS
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
/*NONE*/
|
||||
/*NONE*/
|
||||
|
@ -24,16 +24,24 @@
|
||||
|
||||
#include <QThread>
|
||||
|
||||
namespace MUtils
|
||||
{
|
||||
class IPCChannel;
|
||||
}
|
||||
|
||||
class MessageHandlerThread: public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MessageHandlerThread(void);
|
||||
MessageHandlerThread(MUtils::IPCChannel *const ipcChannel);
|
||||
~MessageHandlerThread(void);
|
||||
void run();
|
||||
void stop(void);
|
||||
|
||||
protected:
|
||||
MUtils::IPCChannel *const m_ipcChannel;
|
||||
|
||||
private:
|
||||
char *m_parameter;
|
||||
volatile bool m_aborted;
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
//MUtils
|
||||
#include <MUtils/Global.h>
|
||||
#include <MUtils/IPCChannel.h>
|
||||
#include <MUtils/OSSupport.h>
|
||||
|
||||
//Qt
|
||||
@ -42,7 +43,9 @@
|
||||
// Constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
MessageProducerThread::MessageProducerThread(void)
|
||||
MessageProducerThread::MessageProducerThread(MUtils::IPCChannel *const ipcChannel)
|
||||
:
|
||||
m_ipcChannel(ipcChannel)
|
||||
{
|
||||
}
|
||||
|
||||
@ -60,12 +63,12 @@ void MessageProducerThread::run()
|
||||
{
|
||||
if(!arguments[i].compare("--kill", Qt::CaseInsensitive))
|
||||
{
|
||||
lamexp_ipc_send(666, NULL);
|
||||
m_ipcChannel->send(666, NULL);
|
||||
return;
|
||||
}
|
||||
if(!arguments[i].compare("--force-kill", Qt::CaseInsensitive))
|
||||
{
|
||||
lamexp_ipc_send(666, "Force!");
|
||||
m_ipcChannel->send(666, "Force!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -77,7 +80,7 @@ void MessageProducerThread::run()
|
||||
QFileInfo file = QFileInfo(arguments[++i]);
|
||||
if(file.exists() && file.isFile())
|
||||
{
|
||||
lamexp_ipc_send(1, MUTILS_UTF8(file.canonicalFilePath()));
|
||||
m_ipcChannel->send(1, MUTILS_UTF8(file.canonicalFilePath()));
|
||||
}
|
||||
bSentFiles = true;
|
||||
}
|
||||
@ -86,7 +89,7 @@ void MessageProducerThread::run()
|
||||
QDir dir = QDir(arguments[++i]);
|
||||
if(dir.exists())
|
||||
{
|
||||
lamexp_ipc_send(2, MUTILS_UTF8(dir.canonicalPath()));
|
||||
m_ipcChannel->send(2, MUTILS_UTF8(dir.canonicalPath()));
|
||||
}
|
||||
bSentFiles = true;
|
||||
}
|
||||
@ -95,7 +98,7 @@ void MessageProducerThread::run()
|
||||
QDir dir = QDir(arguments[++i]);
|
||||
if(dir.exists())
|
||||
{
|
||||
lamexp_ipc_send(3, MUTILS_UTF8(dir.canonicalPath()));
|
||||
m_ipcChannel->send(3, MUTILS_UTF8(dir.canonicalPath()));
|
||||
}
|
||||
bSentFiles = true;
|
||||
}
|
||||
@ -103,7 +106,7 @@ void MessageProducerThread::run()
|
||||
|
||||
if(!bSentFiles)
|
||||
{
|
||||
lamexp_ipc_send(UINT_MAX, "Use running instance!");
|
||||
m_ipcChannel->send(UINT_MAX, "Use running instance!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,12 +24,20 @@
|
||||
|
||||
#include <QThread>
|
||||
|
||||
namespace MUtils
|
||||
{
|
||||
class IPCChannel;
|
||||
}
|
||||
|
||||
class MessageProducerThread: public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MessageProducerThread(void);
|
||||
MessageProducerThread(MUtils::IPCChannel *const ipcChannel);
|
||||
~MessageProducerThread(void);
|
||||
void run();
|
||||
|
||||
protected:
|
||||
MUtils::IPCChannel *const m_ipcChannel;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user