2010-11-08 19:29:36 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2014-01-01 17:05:52 +01:00
|
|
|
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-08 19:29:36 +01:00
|
|
|
//
|
|
|
|
// 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
|
2013-10-23 20:56:57 +02:00
|
|
|
// (at your option) any later version, but always including the *additional*
|
|
|
|
// restrictions defined in the "License.txt" file.
|
2010-11-08 19:29:36 +01:00
|
|
|
//
|
|
|
|
// 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_MessageHandler.h"
|
|
|
|
|
2014-12-13 23:27:47 +01:00
|
|
|
//Internal
|
2010-11-08 19:29:36 +01:00
|
|
|
#include "Global.h"
|
2014-12-14 19:33:28 +01:00
|
|
|
#include "IPCCommands.h"
|
2010-11-08 19:29:36 +01:00
|
|
|
|
2014-12-13 23:27:47 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/IPCChannel.h>
|
|
|
|
|
|
|
|
//Qt
|
2010-11-08 19:29:36 +01:00
|
|
|
#include <QSharedMemory>
|
|
|
|
#include <QSystemSemaphore>
|
2010-11-08 21:47:35 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2014-12-13 23:27:47 +01:00
|
|
|
//CRL
|
2010-11-08 21:47:35 +01:00
|
|
|
#include <limits.h>
|
2010-11-08 19:29:36 +01:00
|
|
|
|
2014-12-14 19:33:28 +01:00
|
|
|
#define TEST_FLAG(X) ((flags & (X)) == (X))
|
|
|
|
|
2010-11-08 19:29:36 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-13 23:27:47 +01:00
|
|
|
MessageHandlerThread::MessageHandlerThread(MUtils::IPCChannel *const ipcChannel)
|
|
|
|
:
|
|
|
|
m_ipcChannel(ipcChannel)
|
2010-11-08 19:29:36 +01:00
|
|
|
{
|
2010-11-08 21:47:35 +01:00
|
|
|
m_aborted = false;
|
2014-12-14 19:33:28 +01:00
|
|
|
m_parameter = new char[MUtils::IPCChannel::MAX_MESSAGE_LEN];
|
2010-11-08 21:47:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageHandlerThread::~MessageHandlerThread(void)
|
|
|
|
{
|
|
|
|
delete [] m_parameter;
|
2010-11-08 19:29:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessageHandlerThread::run()
|
|
|
|
{
|
2010-11-08 21:47:35 +01:00
|
|
|
m_aborted = false;
|
|
|
|
setTerminationEnabled(true);
|
|
|
|
|
|
|
|
while(!m_aborted)
|
|
|
|
{
|
2014-12-14 19:33:28 +01:00
|
|
|
unsigned int command = 0, flags = 0;
|
|
|
|
if(!m_ipcChannel->read(command, flags, m_parameter, MUtils::IPCChannel::MAX_MESSAGE_LEN))
|
|
|
|
{
|
|
|
|
qWarning("Failed to read next IPC message!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(command == IPC_CMD_NOOP)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-08 21:47:35 +01:00
|
|
|
|
|
|
|
switch(command)
|
|
|
|
{
|
2014-12-14 19:33:28 +01:00
|
|
|
case IPC_CMD_PING:
|
|
|
|
emit otherInstanceDetected();
|
2010-11-08 21:47:35 +01:00
|
|
|
break;
|
2014-12-14 19:33:28 +01:00
|
|
|
case IPC_CMD_ADD_FILE:
|
|
|
|
emit fileReceived(QString::fromUtf8(m_parameter));
|
2011-06-11 17:18:30 +02:00
|
|
|
break;
|
2014-12-14 19:33:28 +01:00
|
|
|
case IPC_CMD_ADD_FOLDER:
|
|
|
|
emit folderReceived(QString::fromUtf8(m_parameter), TEST_FLAG(IPC_FLAG_ADD_RECURSIVE));
|
2011-06-11 17:18:30 +02:00
|
|
|
break;
|
2014-12-14 19:33:28 +01:00
|
|
|
case IPC_CMD_TERMINATE:
|
|
|
|
if(TEST_FLAG(IPC_FLAG_FORCE))
|
2010-11-09 22:06:11 +01:00
|
|
|
{
|
2013-10-07 00:01:15 +02:00
|
|
|
_exit(-2);
|
2010-11-09 22:06:11 +01:00
|
|
|
}
|
2014-12-14 19:33:28 +01:00
|
|
|
emit killSignalReceived();
|
2010-11-08 21:47:35 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("Received an unknown IPC message! (command=%u)", command);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageHandlerThread::stop(void)
|
|
|
|
{
|
|
|
|
if(!m_aborted)
|
2010-11-08 19:29:36 +01:00
|
|
|
{
|
2010-11-08 21:47:35 +01:00
|
|
|
m_aborted = true;
|
2014-12-14 19:33:28 +01:00
|
|
|
m_ipcChannel->send(0, 0, NULL);
|
2010-11-08 19:29:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// EVENTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-13 23:27:47 +01:00
|
|
|
/*NONE*/
|