OSDN Git Service

Bump NVEncC binaries to version 5.01 + added more supported profiles by new NVEncC...
[x264-launcher/x264-launcher.git] / src / thread_ipc_send.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2020 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_ipc_send.h"
24
25 //Internal
26 #include "Global.h"
27 #include "cli.h"
28 #include "ipc.h"
29
30 //MUtils
31 #include <MUtils/Global.h>
32 #include <MUtils/IPCChannel.h>
33 #include <MUtils/OSSupport.h>
34
35 //Qt
36 #include <QStringList>
37 #include <QApplication>
38 #include <QFileInfo>
39 #include <QDir>
40
41 //CRT
42 #include <limits.h>
43
44 ////////////////////////////////////////////////////////////
45 // Constructor
46 ////////////////////////////////////////////////////////////
47
48 IPCThread_Send::IPCThread_Send(MUtils::IPCChannel *const ipcChannel)
49 :
50         m_ipcChannel(ipcChannel)
51 {
52 }
53
54 IPCThread_Send::~IPCThread_Send(void)
55 {
56 }
57
58 ////////////////////////////////////////////////////////////
59 // Thread Main
60 ////////////////////////////////////////////////////////////
61
62 void IPCThread_Send::run(void)
63 {
64         setTerminationEnabled(true);
65         AbstractThread::run();
66 }
67
68 int IPCThread_Send::threadMain(void)
69 {
70         bool bSentFiles = false;
71         const MUtils::OS::ArgumentMap &args = MUtils::OS::arguments();
72
73         quint32 flags = 0;
74         bool commandSent = false;
75
76         //Handle flags
77         if(args.contains(CLI_PARAM_FORCE_START))
78         {
79                 flags = ((flags | IPC_FLAG_FORCE_START) & (~IPC_FLAG_FORCE_ENQUEUE));
80         }
81         if(args.contains(CLI_PARAM_FORCE_ENQUEUE))
82         {
83                 flags = ((flags | IPC_FLAG_FORCE_ENQUEUE) & (~IPC_FLAG_FORCE_START));
84         }
85
86         //Process all command-line arguments
87         if(args.contains(CLI_PARAM_ADD_FILE))
88         {
89                 foreach(const QString &fileName, args.values(CLI_PARAM_ADD_FILE))
90                 {
91                         if(!m_ipcChannel->send(IPC_OPCODE_ADD_FILE, flags, QStringList() << fileName))
92                         {
93                                 qWarning("Failed to send IPC message!");
94                         }
95                         commandSent = true;
96                 }
97         }
98         if(args.contains(CLI_PARAM_ADD_JOB))
99         {
100                 foreach(const QString &options, args.values(CLI_PARAM_ADD_JOB))
101                 {
102                         const QStringList optionValues = options.split('|', QString::SkipEmptyParts);
103                         if(optionValues.count() == 3)
104                         {
105                                 if(!m_ipcChannel->send(IPC_OPCODE_ADD_JOB, flags, optionValues))
106                                 {
107                                         qWarning("Failed to send IPC message!");
108                                 }
109                         }
110                         else
111                         {
112                                 qWarning("Invalid number of arguments for parameter \"--%s\" detected!", CLI_PARAM_ADD_JOB);
113                         }
114                         commandSent = true;
115                 }
116         }
117
118         //If no argument has been sent yet, send a ping!
119         if(!commandSent)
120         {
121                 if(!m_ipcChannel->send(IPC_OPCODE_PING, 0, QStringList()))
122                 {
123                         qWarning("Failed to send IPC message!");
124                 }
125         }
126
127         return 1;
128 }
129
130 ////////////////////////////////////////////////////////////
131 // EVENTS
132 ////////////////////////////////////////////////////////////
133
134 /*NONE*/