author | unc0rr |
Thu, 06 Mar 2014 00:18:51 +0400 | |
changeset 10177 | 0f9042536c46 |
parent 10175 | c92668840ea8 |
child 10248 | 7b9b44a051f8 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
486 | 3 |
* Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com> |
9998 | 4 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
184 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
9 |
* |
|
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. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
184 | 18 |
*/ |
19 |
||
20 |
#include <QList> |
|
21 |
#include <QImage> |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
22 |
#include <QThread> |
10175
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
23 |
#include <QApplication> |
184 | 24 |
|
10175
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
25 |
#include "tcpBase.h" |
184 | 26 |
#include "hwconsts.h" |
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8635
diff
changeset
|
27 |
#include "MessageDialog.h" |
184 | 28 |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
29 |
#ifdef HWLIBRARY |
10175
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
30 |
extern "C" { |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
31 |
void RunEngine(int argc, char ** argv); |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
32 |
|
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
33 |
int operatingsystem_parameter_argc; |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
34 |
char ** operatingsystem_parameter_argv; |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
35 |
} |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
36 |
|
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
37 |
|
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
38 |
EngineInstance::EngineInstance(QObject *parent) |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
39 |
: QObject(parent) |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
40 |
{ |
10175
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
41 |
|
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
42 |
} |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
43 |
|
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
44 |
EngineInstance::~EngineInstance() |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
45 |
{ |
10177 | 46 |
qDebug() << "EngineInstance delete" << QThread::currentThreadId(); |
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
47 |
} |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
48 |
|
10175
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
49 |
void EngineInstance::setArguments(const QStringList & arguments) |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
50 |
{ |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
51 |
m_arguments.clear(); |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
52 |
m_arguments << qApp->arguments().at(0).toUtf8(); |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
53 |
|
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
54 |
m_argv.resize(arguments.size() + 1); |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
55 |
m_argv[0] = m_arguments.last().data(); |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
56 |
|
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
57 |
int i = 1; |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
58 |
foreach(const QString & s, arguments) |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
59 |
{ |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
60 |
m_arguments << s.toUtf8(); |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
61 |
m_argv[i] = m_arguments.last().data(); |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
62 |
++i; |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
63 |
} |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
64 |
} |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
65 |
|
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
66 |
void EngineInstance::start() |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
67 |
{ |
10177 | 68 |
qDebug() << "EngineInstance start" << QThread::currentThreadId(); |
69 |
||
10175
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
70 |
RunEngine(m_argv.size(), m_argv.data()); |
10177 | 71 |
|
72 |
emit finished(); |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
73 |
} |
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
74 |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
75 |
#endif |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
76 |
|
184 | 77 |
QList<TCPBase*> srvsList; |
389 | 78 |
QPointer<QTcpServer> TCPBase::IPCServer(0); |
184 | 79 |
|
419
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
80 |
TCPBase::~TCPBase() |
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
81 |
{ |
10177 | 82 |
if(m_hasStarted) |
83 |
{ |
|
84 |
if(IPCSocket) |
|
85 |
IPCSocket->close(); |
|
86 |
||
87 |
if(m_connected) |
|
88 |
{ |
|
89 |
#ifdef HWLIBRARY |
|
90 |
if(!thread) |
|
91 |
qDebug("WTF"); |
|
92 |
thread->quit(); |
|
93 |
thread->wait(); |
|
94 |
#else |
|
95 |
process->waitForFinished(1000); |
|
96 |
#endif |
|
97 |
} |
|
98 |
} |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
99 |
// make sure this object is not in the server list anymore |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
100 |
srvsList.removeOne(this); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
101 |
|
7289
835bb2852579
Restore almost old TCPBase behaviour
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
102 |
if (IPCSocket) |
835bb2852579
Restore almost old TCPBase behaviour
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
103 |
IPCSocket->deleteLater(); |
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
104 |
|
419
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
105 |
} |
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
106 |
|
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
107 |
TCPBase::TCPBase(bool demoMode, QObject *parent) : |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
108 |
QObject(parent), |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
109 |
m_hasStarted(false), |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
110 |
m_isDemoMode(demoMode), |
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
111 |
m_connected(false), |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
112 |
IPCSocket(0) |
184 | 113 |
{ |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
114 |
if(!IPCServer) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
115 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
116 |
IPCServer = new QTcpServer(0); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
117 |
IPCServer->setMaxPendingConnections(1); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
118 |
if (!IPCServer->listen(QHostAddress::LocalHost)) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
119 |
{ |
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8635
diff
changeset
|
120 |
MessageDialog::ShowFatalMessage(tr("Unable to start server at %1.").arg(IPCServer->errorString())); |
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
121 |
exit(0); // FIXME - should be graceful exit here (lower Critical -> Warning above when implemented) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
122 |
} |
185 | 123 |
} |
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
124 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
125 |
ipc_port=IPCServer->serverPort(); |
184 | 126 |
} |
127 |
||
128 |
void TCPBase::NewConnection() |
|
129 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
130 |
if(IPCSocket) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
131 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
132 |
// connection should be already finished |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
133 |
return; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
134 |
} |
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
135 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
136 |
disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
137 |
IPCSocket = IPCServer->nextPendingConnection(); |
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
138 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
139 |
if(!IPCSocket) return; |
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
140 |
|
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
141 |
m_connected = true; |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
142 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
143 |
connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
144 |
connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
145 |
SendToClientFirst(); |
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
146 |
|
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
147 |
if(simultaneousRun()) |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
148 |
{ |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
149 |
srvsList.removeOne(this); |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
150 |
emit isReadyNow(); |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
151 |
} |
184 | 152 |
} |
153 |
||
154 |
void TCPBase::RealStart() |
|
155 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
156 |
connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
157 |
IPCSocket = 0; |
389 | 158 |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
159 |
#ifdef HWLIBRARY |
10177 | 160 |
thread = new QThread(this); |
10175
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
161 |
EngineInstance *instance = new EngineInstance(); |
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
162 |
instance->setArguments(getArguments()); |
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
163 |
|
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
164 |
instance->moveToThread(thread); |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
165 |
|
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
166 |
connect(thread, SIGNAL(started()), instance, SLOT(start(void))); |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
167 |
connect(instance, SIGNAL(finished()), thread, SLOT(quit())); |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
168 |
connect(instance, SIGNAL(finished()), instance, SLOT(deleteLater())); |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
169 |
connect(instance, SIGNAL(finished()), thread, SLOT(deleteLater())); |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8082
diff
changeset
|
170 |
thread->start(); |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
171 |
#else |
10177 | 172 |
process = new QProcess(this); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
173 |
connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); |
10175
c92668840ea8
Remove game/preview functions split in library mode, just let normal procedure run instead:
unc0rr
parents:
10108
diff
changeset
|
174 |
QStringList arguments = getArguments(); |
3697 | 175 |
|
9212 | 176 |
#ifdef QT_DEBUG |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
177 |
// redirect everything written on stdout/stderr |
8635 | 178 |
process->setProcessChannelMode(QProcess::ForwardedChannels); |
179 |
#endif |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
180 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
181 |
process->start(bindir->absolutePath() + "/hwengine", arguments); |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
182 |
#endif |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
183 |
m_hasStarted = true; |
184 | 184 |
} |
185 |
||
186 |
void TCPBase::ClientDisconnect() |
|
187 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
188 |
disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
189 |
onClientDisconnect(); |
184 | 190 |
|
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
191 |
if(!simultaneousRun()) |
10177 | 192 |
{ |
193 |
#ifdef HWLIBRARY |
|
194 |
thread->quit(); |
|
195 |
thread->wait(); |
|
196 |
#endif |
|
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
197 |
emit isReadyNow(); |
10177 | 198 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
199 |
IPCSocket->deleteLater(); |
7673
e06b83cbde74
fix a segfault related to tcp servers deleting themselves without removing themselves from the internal server list first.
sheepluva
parents:
7615
diff
changeset
|
200 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
201 |
deleteLater(); |
184 | 202 |
} |
203 |
||
204 |
void TCPBase::ClientRead() |
|
205 |
{ |
|
10177 | 206 |
QByteArray read = IPCSocket->readAll(); |
207 |
if(read.isEmpty()) return; |
|
208 |
readbuffer.append(read); |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
209 |
onClientRead(); |
184 | 210 |
} |
211 |
||
212 |
void TCPBase::StartProcessError(QProcess::ProcessError error) |
|
213 |
{ |
|
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8635
diff
changeset
|
214 |
MessageDialog::ShowFatalMessage(tr("Unable to run engine at %1\nError code: %2").arg(bindir->absolutePath() + "/hwengine").arg(error)); |
7587
688076d61b83
Don't leave frontend in engine waiting state when there's error occured on attempt to start engine
unc0rr
parents:
6952
diff
changeset
|
215 |
ClientDisconnect(); |
184 | 216 |
} |
217 |
||
218 |
void TCPBase::tcpServerReady() |
|
219 |
{ |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
220 |
disconnect(srvsList.first(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); |
184 | 221 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
222 |
RealStart(); |
184 | 223 |
} |
224 |
||
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
225 |
void TCPBase::Start(bool couldCancelPreviousRequest) |
184 | 226 |
{ |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
227 |
if(srvsList.isEmpty()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
228 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
229 |
srvsList.push_back(this); |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
230 |
RealStart(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
231 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
232 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
233 |
{ |
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
234 |
TCPBase * last = srvsList.last(); |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
235 |
if(couldCancelPreviousRequest |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
236 |
&& last->couldBeRemoved() |
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
237 |
&& (last->isConnected() || !last->hasStarted()) |
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
238 |
&& (last->parent() == parent())) |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
239 |
{ |
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
240 |
srvsList.removeLast(); |
10177 | 241 |
delete last; |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
242 |
Start(couldCancelPreviousRequest); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
243 |
} else |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
244 |
{ |
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
245 |
connect(last, SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
246 |
srvsList.push_back(this); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
247 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
248 |
} |
184 | 249 |
} |
250 |
||
251 |
void TCPBase::onClientRead() |
|
252 |
{ |
|
253 |
} |
|
254 |
||
255 |
void TCPBase::onClientDisconnect() |
|
256 |
{ |
|
257 |
} |
|
258 |
||
259 |
void TCPBase::SendToClientFirst() |
|
260 |
{ |
|
261 |
} |
|
262 |
||
263 |
void TCPBase::SendIPC(const QByteArray & buf) |
|
264 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
265 |
if (buf.size() > MAXMSGCHARS) return; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
266 |
quint8 len = buf.size(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
267 |
RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); |
184 | 268 |
} |
269 |
||
270 |
void TCPBase::RawSendIPC(const QByteArray & buf) |
|
271 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
272 |
if (!IPCSocket) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
273 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
274 |
toSendBuf += buf; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
275 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
276 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
277 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
278 |
if (toSendBuf.size() > 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
279 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
280 |
IPCSocket->write(toSendBuf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
281 |
if(m_isDemoMode) demo.append(toSendBuf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
282 |
toSendBuf.clear(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
283 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
284 |
if(!buf.isEmpty()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
285 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
286 |
IPCSocket->write(buf); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
287 |
if(m_isDemoMode) demo.append(buf); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
288 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
289 |
} |
184 | 290 |
} |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
291 |
|
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
292 |
bool TCPBase::couldBeRemoved() |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
293 |
{ |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
294 |
return false; |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
295 |
} |
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
296 |
|
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
297 |
bool TCPBase::isConnected() |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
298 |
{ |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
299 |
return m_connected; |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
300 |
} |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
301 |
|
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
302 |
bool TCPBase::simultaneousRun() |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
303 |
{ |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
304 |
return false; |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
305 |
} |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
306 |
|
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
307 |
bool TCPBase::hasStarted() |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
308 |
{ |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
309 |
return m_hasStarted; |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9212
diff
changeset
|
310 |
} |