OSDN Git Service

Updated Visual Studio 2012 to "Update 1" (final release).
[lamexp/LameXP.git] / src / Thread_MessageHandler.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Thread_MessageHandler.h"
23
24 #include "Global.h"
25
26 #include <QSharedMemory>
27 #include <QSystemSemaphore>
28 #include <QMessageBox>
29
30 #include <limits.h>
31
32 ////////////////////////////////////////////////////////////
33 // Constructor
34 ////////////////////////////////////////////////////////////
35
36 MessageHandlerThread::MessageHandlerThread(void)
37 {
38         m_aborted = false;
39         m_parameter = new char[4096];
40 }
41
42 MessageHandlerThread::~MessageHandlerThread(void)
43 {
44         delete [] m_parameter;
45 }
46
47 void MessageHandlerThread::run()
48 {
49         m_aborted = false;
50         setTerminationEnabled(true);
51
52         while(!m_aborted)
53         {
54                 unsigned int command = 0;
55                 lamexp_ipc_read(&command, m_parameter, 4096);
56                 if(!command) continue;
57
58                 switch(command)
59                 {
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!"))
71                         {
72                                 ExitProcess(-2);
73                         }
74                         else
75                         {
76                                 emit killSignalReceived();
77                         }
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;
85                 }
86         }
87 }
88
89 void MessageHandlerThread::stop(void)
90 {
91         if(!m_aborted)
92         {
93                 m_aborted = true;
94                 lamexp_ipc_send(0, NULL);
95         }
96 }
97
98 ////////////////////////////////////////////////////////////
99 // EVENTS
100 ////////////////////////////////////////////////////////////
101
102 /*NONE*/