OSDN Git Service

Set creation/modified time of the encoded file the same value as the original file...
[lamexp/LameXP.git] / src / Thread_MessageHandler.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 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.
10 //
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.
15 //
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.
19 //
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "Thread_MessageHandler.h"
24
25 //Internal
26 #include "Global.h"
27 #include "IPCCommands.h"
28
29 //MUtils
30 #include <MUtils/IPCChannel.h>
31
32 //Qt
33 #include <QSharedMemory>
34 #include <QSystemSemaphore>
35 #include <QMessageBox>
36
37 //CRL
38 #include <limits.h>
39
40 #define TEST_FLAG(X) ((flags & (X)) == (X))
41
42 ////////////////////////////////////////////////////////////
43 // Constructor
44 ////////////////////////////////////////////////////////////
45
46 MessageHandlerThread::MessageHandlerThread(MUtils::IPCChannel *const ipcChannel)
47 :
48         m_ipcChannel(ipcChannel)
49 {
50         m_aborted = false;
51 }
52
53 MessageHandlerThread::~MessageHandlerThread(void)
54 {
55 }
56
57 void MessageHandlerThread::run()
58 {
59         m_aborted = false;
60         setTerminationEnabled(true);
61         QStringList params;
62         quint32 command = 0, flags = 0;
63
64         while(!m_aborted)
65         {
66                 if(!m_ipcChannel->read(command, flags, params))
67                 {
68                         qWarning("Failed to read next IPC message!");
69                         break;
70                 }
71                 
72                 if(command == IPC_CMD_NOOP)
73                 {
74                         continue;
75                 }
76
77                 switch(command)
78                 {
79                 case IPC_CMD_PING:
80                         emit otherInstanceDetected();
81                         break;
82                 case IPC_CMD_ADD_FILE:
83                         if(params.count() > 0 )
84                         {
85                                 emit fileReceived(params.first());
86                         }
87                         break;
88                 case IPC_CMD_ADD_FOLDER:
89                         if(params.count() > 0 )
90                         {
91                                 emit folderReceived(params.first(), TEST_FLAG(IPC_FLAG_ADD_RECURSIVE));
92                         }
93                         break;
94                 case IPC_CMD_TERMINATE:
95                         if(TEST_FLAG(IPC_FLAG_FORCE))
96                         {
97                                 _exit(-2);
98                         }
99                         emit killSignalReceived();
100                         break;
101                 default:
102                         qWarning("Received an unknown IPC message! (command=%u)", command);
103                         break;
104                 }
105         }
106 }
107
108 void MessageHandlerThread::stop(void)
109 {
110         if(!m_aborted)
111         {
112                 m_aborted = true;
113                 m_ipcChannel->send(0, 0, QStringList());
114         }
115 }
116
117 ////////////////////////////////////////////////////////////
118 // EVENTS
119 ////////////////////////////////////////////////////////////
120
121 /*NONE*/