-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverthread.cpp
52 lines (45 loc) · 1.74 KB
/
serverthread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <QFile>
#include <QEventLoop>
#include "serverthread.h"
#include "modelmapper.h"
ServerThread::ServerThread(qintptr socketDescriptor, QObject *parent) :
#ifdef USETHREADPOOL
QRunnable()
#else
QThread(parent)
#endif
,m_socketDescriptor(socketDescriptor)
{
Q_UNUSED(parent)
}
ServerThread::~ServerThread()
{
}
void ServerThread::run()
{
SlotSocket *socket = new SlotSocket();
RequestParser *httpParser = new RequestParser();
ModelMapper *modelMapper = new ModelMapper();
if (!socket->setSocketDescriptor(m_socketDescriptor))
{
qDebug() << Q_FUNC_INFO <<"cannot set setSocketDescriptor";
return;
}
QObject::connect(socket, SIGNAL(read(QByteArray)), httpParser, SLOT(read(QByteArray)));
QObject::connect(httpParser, SIGNAL(write(QByteArray)), socket, SLOT(write(QByteArray)));
QObject::connect(httpParser, SIGNAL(httpGet(QHttpRequestHeader)), modelMapper, SLOT(getModel(QHttpRequestHeader)));
QObject::connect(httpParser, SIGNAL(httpPost(QHttpRequestHeader,QByteArray)), modelMapper, SLOT(postModel(QHttpRequestHeader,QByteArray)));
QObject::connect(modelMapper, SIGNAL(httpResponse(QHttpResponseHeader,QByteArray)), httpParser, SLOT(httpResponse(QHttpResponseHeader,QByteArray)));
QObject::connect(modelMapper, SIGNAL(httpResponseHead(QHttpResponseHeader)), httpParser, SLOT(httpResponseHead(QHttpResponseHeader)));
QObject::connect(modelMapper, SIGNAL(httpResponseContent(QByteArray)), httpParser, SLOT(httpResponseContent(QByteArray)));
QObject::connect(modelMapper, SIGNAL(httpResponseClose()), httpParser, SLOT(httpResponseClose()));
#ifdef USETHREADPOOL
QEventLoop loop;
loop.exec();
#else
exec();
#endif
if (socket) socket->deleteLater();
if (httpParser) httpParser->deleteLater();
if (modelMapper) modelMapper->deleteLater();
}