Updated Opus encoder/decoder libraries to v1.3-RC-1 (2018-06-01) and Opus-Tools to...
[LameXP.git] / src / Thread_MessageHandler.cpp
blob27ab6067a9c4362c98898055ff4748455b0c7e56
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Thread_MessageHandler.h"
25 //Internal
26 #include "Global.h"
27 #include "IPCCommands.h"
29 //MUtils
30 #include <MUtils/IPCChannel.h>
32 //Qt
33 #include <QSharedMemory>
34 #include <QSystemSemaphore>
35 #include <QMessageBox>
37 //CRL
38 #include <limits.h>
40 #define TEST_FLAG(X) ((flags & (X)) == (X))
42 ////////////////////////////////////////////////////////////
43 // Constructor
44 ////////////////////////////////////////////////////////////
46 MessageHandlerThread::MessageHandlerThread(MUtils::IPCChannel *const ipcChannel)
48 m_ipcChannel(ipcChannel)
52 MessageHandlerThread::~MessageHandlerThread(void)
56 void MessageHandlerThread::run()
58 setTerminationEnabled(true);
59 QStringList params;
60 quint32 command = 0, flags = 0;
62 while(!m_aborted)
64 if(!m_ipcChannel->read(command, flags, params))
66 qWarning("Failed to read next IPC message!");
67 break;
70 if(command == IPC_CMD_NOOP)
72 continue;
75 switch(command)
77 case IPC_CMD_PING:
78 emit otherInstanceDetected();
79 break;
80 case IPC_CMD_ADD_FILE:
81 if(params.count() > 0 )
83 emit fileReceived(params.first());
85 break;
86 case IPC_CMD_ADD_FOLDER:
87 if(params.count() > 0 )
89 emit folderReceived(params.first(), TEST_FLAG(IPC_FLAG_ADD_RECURSIVE));
91 break;
92 case IPC_CMD_TERMINATE:
93 if(TEST_FLAG(IPC_FLAG_FORCE))
95 _exit(-2);
97 emit killSignalReceived();
98 break;
99 default:
100 qWarning("Received an unknown IPC message! (command=%u)", command);
101 break;
106 void MessageHandlerThread::stop(void)
108 if(!m_aborted)
110 m_aborted.ref();
111 m_ipcChannel->send(0, 0, QStringList());
115 ////////////////////////////////////////////////////////////
116 // EVENTS
117 ////////////////////////////////////////////////////////////
119 /*NONE*/