1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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 ///////////////////////////////////////////////////////////////////////////////
28 class QSystemSemaphore;
30 class IPCReceiveThread;
32 class IPC : public QObject
35 friend class IPCReceiveThread;
36 friend class IPCSendThread;
42 static const int IPC_OPCODE_PING = 0;
43 static const int IPC_OPCODE_ADD_FILE = 1;
44 static const int IPC_OPCODE_ADD_JOB = 2;
45 static const int IPC_OPCODE_MAX = 3;
47 bool initialize(bool &firstInstance);
48 bool sendAsync(const int &command, const QStringList &args, const int timeout = 5000);
51 void startListening(void);
52 void stopListening(void);
55 void receivedStr(const QString &str);
58 bool popCommand(int &command, QStringList &args);
59 bool pushCommand(const int &command, const QStringList *args);
63 QSharedMemory *m_sharedMemory;
64 QSystemSemaphore *m_semaphoreRd;
65 QSystemSemaphore *m_semaphoreWr;
66 IPCReceiveThread *m_recvThread;
69 ///////////////////////////////////////////////////////////////////////////////
71 ///////////////////////////////////////////////////////////////////////////////
73 class IPCSendThread : public QThread
79 IPCSendThread(IPC *ipc, const int &command, const QStringList &args);
80 IPCSendThread::~IPCSendThread(void);
82 inline bool result(void) { return m_result; }
84 virtual void run(void);
87 volatile bool m_result;
90 const QStringList *m_args;
93 class IPCReceiveThread : public QThread
99 IPCReceiveThread(IPC *ipc);
100 inline void stop(void) { m_stopped = true; }
102 virtual void run(void);
105 void receivedCommand(const int &command, const QStringList &args);
108 void receiveLoop(void);
109 volatile bool m_stopped;