More code refactoring: Moved most of the Win32 API dependencies into wrapper function...
[LameXP.git] / src / Thread_MessageHandler.cpp
blob05444f44e6681296c431f63364afef03c7dc47c3
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Thread_MessageHandler.h"
24 #include "Global.h"
26 #include <QSharedMemory>
27 #include <QSystemSemaphore>
28 #include <QMessageBox>
30 #include <limits.h>
32 ////////////////////////////////////////////////////////////
33 // Constructor
34 ////////////////////////////////////////////////////////////
36 MessageHandlerThread::MessageHandlerThread(void)
38 m_aborted = false;
39 m_parameter = new char[4096];
42 MessageHandlerThread::~MessageHandlerThread(void)
44 delete [] m_parameter;
47 void MessageHandlerThread::run()
49 m_aborted = false;
50 setTerminationEnabled(true);
52 while(!m_aborted)
54 unsigned int command = 0;
55 lamexp_ipc_read(&command, m_parameter, 4096);
56 if(!command) continue;
58 switch(command)
60 case 1:
61 emit fileReceived(QString::fromUtf8(m_parameter));
62 break;
63 case 2:
64 emit folderReceived(QString::fromUtf8(m_parameter), false);
65 break;
66 case 3:
67 emit folderReceived(QString::fromUtf8(m_parameter), true);
68 break;
69 case 666:
70 if(!_stricmp(m_parameter, "Force!"))
72 _exit(-2);
74 else
76 emit killSignalReceived();
78 break;
79 case UINT_MAX:
80 emit otherInstanceDetected();
81 break;
82 default:
83 qWarning("Received an unknown IPC message! (command=%u)", command);
84 break;
89 void MessageHandlerThread::stop(void)
91 if(!m_aborted)
93 m_aborted = true;
94 lamexp_ipc_send(0, NULL);
98 ////////////////////////////////////////////////////////////
99 // EVENTS
100 ////////////////////////////////////////////////////////////
102 /*NONE*/