Comparar comentimentos
1 Cometimentos
dev
...
WIP/refact
Autor(a) | SHA1 | Data | |
---|---|---|---|
7afbc60195 |
@ -1,16 +1,50 @@
|
||||
#include <QtConcurrent>
|
||||
#include "ipcpreviewworker.h"
|
||||
#include "previewgeneratormapfunctor.h"
|
||||
IPCPreviewWorker::IPCPreviewWorker()
|
||||
IPCPreviewWorker::IPCPreviewWorker(QLocalSocket *peer)
|
||||
{
|
||||
this->peer = peer;
|
||||
this->connect(&previewWorkerWatcher, &QFutureWatcher<QByteArray>::resultReadyAt, this,
|
||||
[this](int index) { emit previewGenerated(previewWorkerWatcher.resultAt(index)); });
|
||||
connect(&previewWorkerWatcher, &QFutureWatcher<QByteArray>::finished, this, [this] { emit finished(); });
|
||||
[this](int index)
|
||||
{
|
||||
if(this->peer != nullptr)
|
||||
{
|
||||
QDataStream stream{this->peer};
|
||||
stream << previewWorkerWatcher.resultAt(index);
|
||||
this->peer->flush();
|
||||
}
|
||||
});
|
||||
connect(&previewWorkerWatcher, &QFutureWatcher<QByteArray>::finished, this, &IPCPreviewWorker::shutdownSocket);
|
||||
connect(this->peer, &QLocalSocket::disconnected, this, &IPCPreviewWorker::shutdownSocket);
|
||||
}
|
||||
|
||||
void IPCPreviewWorker::start(RenderConfig config, const QVector<RenderTarget> &targets, QLocalSocket *peer)
|
||||
void IPCPreviewWorker::shutdownSocket()
|
||||
{
|
||||
if(cleaned)
|
||||
{
|
||||
return;
|
||||
}
|
||||
cleaned = true;
|
||||
if(this->peer != nullptr)
|
||||
{
|
||||
if(this->peer->state() == QLocalSocket::ConnectedState)
|
||||
{
|
||||
this->peer->flush();
|
||||
this->peer->waitForBytesWritten();
|
||||
this->peer->disconnectFromServer();
|
||||
if(this->peer->state() != QLocalSocket::UnconnectedState)
|
||||
{
|
||||
this->peer->waitForDisconnected();
|
||||
}
|
||||
}
|
||||
delete this->peer;
|
||||
this->peer = nullptr;
|
||||
}
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void IPCPreviewWorker::start(RenderConfig config, const QVector<RenderTarget> &targets)
|
||||
{
|
||||
stop();
|
||||
auto mapFunctor = PreviewGeneratorMapFunctor();
|
||||
mapFunctor.setRenderConfig(config);
|
||||
|
||||
|
@ -11,13 +11,17 @@ class IPCPreviewWorker : public QObject
|
||||
Q_OBJECT
|
||||
private:
|
||||
QFutureWatcher<QByteArray> previewWorkerWatcher;
|
||||
QLocalSocket *peer;
|
||||
bool cleaned = false;
|
||||
|
||||
public:
|
||||
IPCPreviewWorker();
|
||||
void start(RenderConfig config, const QVector<RenderTarget> &targets, QLocalSocket *peer);
|
||||
IPCPreviewWorker(QLocalSocket *peer);
|
||||
void start(RenderConfig config, const QVector<RenderTarget> &targets);
|
||||
void stop();
|
||||
private slots:
|
||||
void shutdownSocket();
|
||||
|
||||
signals:
|
||||
void previewGenerated(QByteArray);
|
||||
void finished();
|
||||
};
|
||||
|
||||
|
@ -18,8 +18,6 @@ IpcServer::IpcServer()
|
||||
/* Only 1, we are doing work for the GUI, not a service for general availability */
|
||||
this->spawningServer.setMaxPendingConnections(1);
|
||||
connect(&this->spawningServer, &QLocalServer::newConnection, this, &IpcServer::spawnerNewConnection);
|
||||
connect(&this->previewWorker, &IPCPreviewWorker::previewGenerated, this, &IpcServer::handlePreviewGenerated);
|
||||
connect(&this->previewWorker, &IPCPreviewWorker::finished, this, [this] { this->currentSocket->flush(); });
|
||||
}
|
||||
|
||||
bool IpcServer::startSpawner(QString socketPath)
|
||||
@ -31,8 +29,6 @@ bool IpcServer::startSpawner(QString socketPath)
|
||||
void IpcServer::spawnerNewConnection()
|
||||
{
|
||||
QLocalSocket *socket = this->spawningServer.nextPendingConnection();
|
||||
connect(socket, &QLocalSocket::disconnected, socket, &QLocalSocket::deleteLater);
|
||||
this->currentSocket = socket;
|
||||
if(socket != nullptr)
|
||||
{
|
||||
if(!socket->waitForReadyRead())
|
||||
@ -53,21 +49,22 @@ void IpcServer::spawnerNewConnection()
|
||||
stream.startTransaction();
|
||||
stream >> renderConfig >> targets;
|
||||
} while(!stream.commitTransaction() && socket->state() == QLocalSocket::ConnectedState);
|
||||
|
||||
stream << targets.count();
|
||||
socket->flush();
|
||||
previewWorker.start(renderConfig, targets, socket);
|
||||
if(socket->state() == QLocalSocket::ConnectedState)
|
||||
{
|
||||
stream << targets.count();
|
||||
socket->flush();
|
||||
IPCPreviewWorker *previewWorker = new IPCPreviewWorker(socket);
|
||||
connect(previewWorker, &IPCPreviewWorker::finished, this, [previewWorker] { delete previewWorker; });
|
||||
previewWorker->start(renderConfig, targets);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete socket;
|
||||
}
|
||||
}
|
||||
if(command == StopGeneratePreviews)
|
||||
{
|
||||
previewWorker.stop();
|
||||
/* TODO: implement */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IpcServer::handlePreviewGenerated(QByteArray ba)
|
||||
{
|
||||
QDataStream stream{this->currentSocket};
|
||||
stream << ba;
|
||||
this->currentSocket->flush();
|
||||
}
|
||||
|
@ -10,13 +10,10 @@ class IpcServer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
IPCPreviewWorker previewWorker;
|
||||
QLocalServer spawningServer;
|
||||
QLocalSocket *currentSocket = nullptr;
|
||||
SaveFileResult addFile(QString file);
|
||||
private slots:
|
||||
void spawnerNewConnection();
|
||||
void handlePreviewGenerated(QByteArray ba);
|
||||
|
||||
public:
|
||||
IpcServer();
|
||||
|
Carregando…
Criar uma nova questão referindo esta
Bloquear um utilizador