OSDN Git Service

Added detection of 64-Bit QAAC encoder + fixed a regression in def8a9cd6e13defb09a4d2...
[lamexp/LameXP.git] / src / Thread_MessageHandler.cpp
index 6bd09de..3b4ab48 100644 (file)
@@ -1,11 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // 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
-// (at your option) any later version.
+// (at your option) any later version, but always including the *additional*
+// restrictions defined in the "License.txt" file.
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "Thread_MessageHandler.h"
 
+//Internal
 #include "Global.h"
+#include "IPCCommands.h"
 
+//MUtils
+#include <MUtils/IPCChannel.h>
+
+//Qt
 #include <QSharedMemory>
 #include <QSystemSemaphore>
 #include <QMessageBox>
 
+//CRL
 #include <limits.h>
 
+#define TEST_FLAG(X) ((flags & (X)) == (X))
+
 ////////////////////////////////////////////////////////////
 // Constructor
 ////////////////////////////////////////////////////////////
 
-MessageHandlerThread::MessageHandlerThread(void)
+MessageHandlerThread::MessageHandlerThread(MUtils::IPCChannel *const ipcChannel)
+:
+       m_ipcChannel(ipcChannel)
 {
        m_aborted = false;
-       m_parameter = new char[4096];
 }
 
 MessageHandlerThread::~MessageHandlerThread(void)
 {
-       delete [] m_parameter;
 }
 
 void MessageHandlerThread::run()
 {
        m_aborted = false;
        setTerminationEnabled(true);
+       QStringList params;
+       quint32 command = 0, flags = 0;
 
        while(!m_aborted)
        {
-               unsigned int command = 0;
-               lamexp_ipc_read(&command, m_parameter, 4096);
-               if(!command) continue;
+               if(!m_ipcChannel->read(command, flags, params))
+               {
+                       qWarning("Failed to read next IPC message!");
+                       break;
+               }
+               
+               if(command == IPC_CMD_NOOP)
+               {
+                       continue;
+               }
 
                switch(command)
                {
-               case 1:
-                       emit fileReceived(QString::fromUtf8(m_parameter));
-                       break;
-               case UINT_MAX:
+               case IPC_CMD_PING:
                        emit otherInstanceDetected();
                        break;
+               case IPC_CMD_ADD_FILE:
+                       if(params.count() > 0 )
+                       {
+                               emit fileReceived(params.first());
+                       }
+                       break;
+               case IPC_CMD_ADD_FOLDER:
+                       if(params.count() > 0 )
+                       {
+                               emit folderReceived(params.first(), TEST_FLAG(IPC_FLAG_ADD_RECURSIVE));
+                       }
+                       break;
+               case IPC_CMD_TERMINATE:
+                       if(TEST_FLAG(IPC_FLAG_FORCE))
+                       {
+                               _exit(-2);
+                       }
+                       emit killSignalReceived();
+                       break;
                default:
                        qWarning("Received an unknown IPC message! (command=%u)", command);
                        break;
@@ -75,13 +110,12 @@ void MessageHandlerThread::stop(void)
        if(!m_aborted)
        {
                m_aborted = true;
-               lamexp_ipc_send(0, "");
+               m_ipcChannel->send(0, 0, QStringList());
        }
-
 }
 
 ////////////////////////////////////////////////////////////
 // EVENTS
 ////////////////////////////////////////////////////////////
 
-/*NONE*/
\ No newline at end of file
+/*NONE*/