looqs/gui/ipcserver.cpp

60 řádky
1.4 KiB
C++
Surový Normální zobrazení Historie

#include <QFile>
#include <QDesktopServices>
#include <QSettings>
#include <QProcess>
#include <QUrl>
#include <QLocalSocket>
#include <QDataStream>
#include "ipcserver.h"
2022-04-24 12:34:34 +02:00
#include "common.h"
#include "databasefactory.h"
#include "../shared/logger.h"
2022-05-27 09:26:37 +02:00
#include "renderconfig.h"
#include "rendertarget.h"
#include "ipcpreviewworker.h"
IpcServer::IpcServer()
{
connect(&this->spawningServer, &QLocalServer::newConnection, this, &IpcServer::spawnerNewConnection);
}
bool IpcServer::startSpawner(QString socketPath)
{
QFile::remove(socketPath);
return this->spawningServer.listen(socketPath);
}
void IpcServer::spawnerNewConnection()
{
2022-05-27 09:26:37 +02:00
QLocalSocket *socket = this->spawningServer.nextPendingConnection();
connect(socket, &QLocalSocket::disconnected, socket, &QLocalSocket::deleteLater);
if(socket != nullptr)
{
if(!socket->waitForReadyRead())
{
return;
}
2022-05-27 09:26:37 +02:00
QDataStream stream(socket);
IPCCommand command;
stream >> command;
if(command == GeneratePreviews)
{
2022-05-27 09:26:37 +02:00
IPCPreviewWorker *worker = new IPCPreviewWorker();
RenderConfig renderConfig;
QVector<RenderTarget> targets;
2022-05-27 09:26:37 +02:00
do
{
/* TODO: this is not entirely robust */
socket->waitForReadyRead(100);
stream.startTransaction();
stream >> renderConfig >> targets;
} while(!stream.commitTransaction() && socket->state() == QLocalSocket::ConnectedState);
stream << targets.count();
socket->flush();
worker->start(renderConfig, targets, socket);
}
}
}