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);
50 inline bool isInitialized(void) { return (m_initialized >= 0); }
51 inline bool isListening(void);
54 bool startListening(void);
55 bool stopListening(void);
58 void receivedCommand(const int &command, const QStringList &args);
61 bool popCommand(int &command, QStringList &args, volatile bool *abortFlag);
62 bool pushCommand(const int &command, const QStringList *args);
66 QSharedMemory *m_sharedMemory;
67 QSystemSemaphore *m_semaphoreRd;
68 QSystemSemaphore *m_semaphoreWr;
69 IPCReceiveThread *m_recvThread;
72 ///////////////////////////////////////////////////////////////////////////////
74 ///////////////////////////////////////////////////////////////////////////////
76 class IPCSendThread : public QThread
82 IPCSendThread(IPC *ipc, const int &command, const QStringList &args);
83 IPCSendThread::~IPCSendThread(void);
85 inline bool result(void) { return m_result; }
87 virtual void run(void);
90 volatile bool m_result;
93 const QStringList *m_args;
96 class IPCReceiveThread : public QThread
102 IPCReceiveThread(IPC *ipc);
103 inline void stop(void) { m_stopped = true; }
105 virtual void run(void);
108 void receivedCommand(const int &command, const QStringList &args);
111 void receiveLoop(void);
112 volatile bool m_stopped;
116 ///////////////////////////////////////////////////////////////////////////////
118 ///////////////////////////////////////////////////////////////////////////////
120 inline bool IPC::isListening(void)
122 return (m_recvThread && m_recvThread->isRunning());