author | nemo |
Sun, 22 Dec 2013 13:44:28 -0500 | |
changeset 9814 | c740c865294d |
parent 9800 | 169fbb968bb3 |
child 9998 | 736015b847e3 |
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> |
9080 | 4 |
* Copyright (c) 2004-2013 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 |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 |
*/ |
|
19 |
||
20 |
#include "tcpBase.h" |
|
21 |
||
22 |
#include <QList> |
|
23 |
#include <QImage> |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
24 |
#include <QThread> |
184 | 25 |
|
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 |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
30 |
extern "C" void Game(char**arguments); |
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
|
31 |
extern "C" void GenLandPreview(int port); |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
32 |
|
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
|
33 |
|
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
|
34 |
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
|
35 |
: QObject(parent) |
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 |
port = 0; |
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 |
} |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
39 |
|
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
|
40 |
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
|
41 |
{ |
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 |
} |
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
|
43 |
|
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 |
void EngineInstance::start() |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
45 |
{ |
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
|
46 |
#if 0 |
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 |
char *args[11]; |
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 |
args[0] = "65000"; //ipcPort |
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
|
49 |
args[1] = "1024"; //cScreenWidth |
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
|
50 |
args[2] = "768"; //cScreenHeight |
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
|
51 |
args[3] = "0"; //cReducedQuality |
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
|
52 |
args[4] = "en.txt"; //cLocaleFName |
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
|
53 |
args[5] = "koda"; //UserNick |
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
|
54 |
args[6] = "1"; //SetSound |
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
|
55 |
args[7] = "1"; //SetMusic |
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
|
56 |
args[8] = "0"; //cAltDamage |
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
|
57 |
args[9]= datadir->absolutePath().toAscii().data(); //cPathPrefix |
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
|
58 |
args[10]= NULL; //recordFileName |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
59 |
Game(args); |
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
|
60 |
#endif |
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
|
61 |
GenLandPreview(port); |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
62 |
} |
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
|
63 |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
64 |
#endif |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
65 |
|
184 | 66 |
QList<TCPBase*> srvsList; |
389 | 67 |
QPointer<QTcpServer> TCPBase::IPCServer(0); |
184 | 68 |
|
419
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
69 |
TCPBase::~TCPBase() |
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
70 |
{ |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
71 |
// 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
|
72 |
srvsList.removeOne(this); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
73 |
|
7289
835bb2852579
Restore almost old TCPBase behaviour
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
74 |
if (IPCSocket) |
835bb2852579
Restore almost old TCPBase behaviour
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
75 |
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
|
76 |
|
419
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
77 |
} |
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
78 |
|
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
79 |
TCPBase::TCPBase(bool demoMode, QObject *parent) : |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
80 |
QObject(parent), |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
81 |
m_hasStarted(false), |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
82 |
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
|
83 |
m_connected(false), |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
84 |
IPCSocket(0) |
184 | 85 |
{ |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
86 |
if(!IPCServer) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
87 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
88 |
IPCServer = new QTcpServer(0); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
89 |
IPCServer->setMaxPendingConnections(1); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
90 |
if (!IPCServer->listen(QHostAddress::LocalHost)) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
91 |
{ |
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8635
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
} |
185 | 95 |
} |
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
|
96 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
97 |
ipc_port=IPCServer->serverPort(); |
184 | 98 |
} |
99 |
||
100 |
void TCPBase::NewConnection() |
|
101 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
102 |
if(IPCSocket) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
103 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
104 |
// connection should be already finished |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
105 |
return; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
106 |
} |
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
|
107 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
108 |
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
|
109 |
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
|
110 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
111 |
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
|
112 |
|
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
|
113 |
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
|
114 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
|
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
|
119 |
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
|
120 |
{ |
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
|
121 |
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
|
122 |
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
|
123 |
} |
184 | 124 |
} |
125 |
||
126 |
void TCPBase::RealStart() |
|
127 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
128 |
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
|
129 |
IPCSocket = 0; |
389 | 130 |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
131 |
#ifdef HWLIBRARY |
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
|
132 |
QThread *thread = new QThread; |
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
|
133 |
EngineInstance *instance = new 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
|
134 |
instance->port = IPCServer->serverPort(); |
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
|
135 |
|
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
|
136 |
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
|
137 |
|
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
thread->start(); |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
143 |
#else |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
144 |
QProcess * process; |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
145 |
process = new QProcess(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
146 |
connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
147 |
QStringList arguments=getArguments(); |
3697 | 148 |
|
9212 | 149 |
#ifdef QT_DEBUG |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
150 |
// redirect everything written on stdout/stderr |
8635 | 151 |
process->setProcessChannelMode(QProcess::ForwardedChannels); |
152 |
#endif |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
153 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
154 |
process->start(bindir->absolutePath() + "/hwengine", arguments); |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
155 |
#endif |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
156 |
m_hasStarted = true; |
184 | 157 |
} |
158 |
||
159 |
void TCPBase::ClientDisconnect() |
|
160 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
161 |
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
|
162 |
onClientDisconnect(); |
184 | 163 |
|
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
|
164 |
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
|
165 |
emit isReadyNow(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
166 |
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
|
167 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
168 |
deleteLater(); |
184 | 169 |
} |
170 |
||
171 |
void TCPBase::ClientRead() |
|
172 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
173 |
QByteArray readed=IPCSocket->readAll(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
174 |
if(readed.isEmpty()) return; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
175 |
readbuffer.append(readed); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
176 |
onClientRead(); |
184 | 177 |
} |
178 |
||
179 |
void TCPBase::StartProcessError(QProcess::ProcessError error) |
|
180 |
{ |
|
8799
44e520374cfc
drop QApplication in favor of HWApplication and minor refactor of MessageDialog
koda
parents:
8635
diff
changeset
|
181 |
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
|
182 |
ClientDisconnect(); |
184 | 183 |
} |
184 |
||
185 |
void TCPBase::tcpServerReady() |
|
186 |
{ |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
187 |
disconnect(srvsList.first(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); |
184 | 188 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
189 |
RealStart(); |
184 | 190 |
} |
191 |
||
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
192 |
void TCPBase::Start(bool couldCancelPreviousRequest) |
184 | 193 |
{ |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
194 |
if(srvsList.isEmpty()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
195 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
196 |
srvsList.push_back(this); |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
197 |
RealStart(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
198 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
199 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
200 |
{ |
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
201 |
TCPBase * last = srvsList.last(); |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
202 |
if(couldCancelPreviousRequest |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
203 |
&& 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
|
204 |
&& (last->isConnected() || !last->hasStarted()) |
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
205 |
&& (last->parent() == parent())) |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
206 |
{ |
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
207 |
srvsList.removeLast(); |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
208 |
last->deleteLater(); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
209 |
Start(couldCancelPreviousRequest); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
210 |
} else |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
211 |
{ |
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
|
212 |
connect(last, SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
213 |
srvsList.push_back(this); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
214 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
215 |
} |
184 | 216 |
} |
217 |
||
218 |
void TCPBase::onClientRead() |
|
219 |
{ |
|
220 |
} |
|
221 |
||
222 |
void TCPBase::onClientDisconnect() |
|
223 |
{ |
|
224 |
} |
|
225 |
||
226 |
void TCPBase::SendToClientFirst() |
|
227 |
{ |
|
228 |
} |
|
229 |
||
230 |
void TCPBase::SendIPC(const QByteArray & buf) |
|
231 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
232 |
if (buf.size() > MAXMSGCHARS) return; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
233 |
quint8 len = buf.size(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
234 |
RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); |
184 | 235 |
} |
236 |
||
237 |
void TCPBase::RawSendIPC(const QByteArray & buf) |
|
238 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
239 |
if (!IPCSocket) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
240 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
241 |
toSendBuf += buf; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
242 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
243 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
244 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
245 |
if (toSendBuf.size() > 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
246 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
247 |
IPCSocket->write(toSendBuf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
248 |
if(m_isDemoMode) demo.append(toSendBuf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
249 |
toSendBuf.clear(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
250 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
251 |
if(!buf.isEmpty()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
252 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
253 |
IPCSocket->write(buf); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
254 |
if(m_isDemoMode) demo.append(buf); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
255 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
256 |
} |
184 | 257 |
} |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
258 |
|
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
259 |
bool TCPBase::couldBeRemoved() |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
260 |
{ |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
261 |
return false; |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
262 |
} |
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
|
263 |
|
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
|
264 |
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
|
265 |
{ |
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
|
266 |
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
|
267 |
} |
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
|
268 |
|
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
|
269 |
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
|
270 |
{ |
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
|
271 |
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
|
272 |
} |
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
|
273 |
|
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
|
274 |
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
|
275 |
{ |
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
|
276 |
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
|
277 |
} |