mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b656c2959 | |||
| a0e54c0e18 | |||
| a1f3e04fad | |||
| 517515e94e | |||
| 594aa8311e | |||
|
|
a3d6c2899b | ||
|
|
c16e99cc3e | ||
|
|
f2e36d35e4 |
@@ -15,6 +15,7 @@ kanban-plugin: board
|
||||
- [ ] QT клиент: сделать отключение кнопки обновить при появлении inline Инициализация
|
||||
- [ ] 16.27 от 22.12
|
||||
- [ ] Unity: ошибка при проигрывании - нажать на среднюю кнопку мыши
|
||||
- [ ] не работает выключение QT клиента призагрузке
|
||||
|
||||
|
||||
## feature client Unity
|
||||
|
||||
@@ -41,5 +41,29 @@
|
||||
7. Unity: отправка в базовую версию
|
||||
|
||||
Сервер:
|
||||
1. Выключение сервера -> рассылка все клиентам DISABLE. Клиенты должны отключится от сети
|
||||
2.
|
||||
1. Загрузка контента с нуля и логин 2х машин под QT
|
||||
2. Загрузка контента с нуля и разлогин 2х машин под QT
|
||||
3. Загрузка контента с нуля попытка обновления с QT клиента (под инструктором)
|
||||
4. Загрузка контента с нуля попытка восстановления с QT клиента (под инструктором)
|
||||
5. Загрузка контента с нуля и отправка сообщений между машинами Unity -> Unity
|
||||
6. Загрузка контента с нуля выполнение задачи с Unity
|
||||
7. Загрузка контента с нуля отправка FIM с Unity
|
||||
8. Загрузка контента с нуля и отправка сообщений между машинами GUI -> Unity
|
||||
9. Загрузка контента с нуля и изменение CFI
|
||||
10. Загрузка контента с нуля логин 2х машин под Unity
|
||||
11. Загрузка контента c нуля редактирование пользователей (Инструктор, обучаемый, группы)
|
||||
12. Загрузка контента с нуля назначение FIM ГУИ
|
||||
13. Загрузка контента с нуля назначение AMM ГУИ
|
||||
14. Загрузка контента с нуля назначение FIM удаление и проверка ГУИ
|
||||
15. Загрузка контента с нуля назначение AMM удаление ГУИ
|
||||
16. Загрузка контента с нуля Авторизация 2х ГУИ
|
||||
17. Загрузка контента с нуля Деавторизация 2х ГУИ
|
||||
18. Загрузка контента с нуля переключение версии контента ГУИ
|
||||
19. Загрузка контента с нуля удаление версии контента ГУИ
|
||||
20. Загрузка контента с нуля копирование версии контента ГУИ
|
||||
21. Загрузка контента с нуля запрос DOCS ГУИ
|
||||
|
||||
22. Назначение задач с 2х ГУИ параллельно (10 задач) (1 пользователю)
|
||||
23. При просмотре задачи инструктором, меняется ее статус
|
||||
24. Блокировка сервера в момент авторизации между QT и Unity
|
||||
25. Попытка выгрузки изменений (Unity залогинен под одной версией) QT сервер изменил версию и далее через восстановление
|
||||
@@ -22,7 +22,6 @@ enum PacketType
|
||||
TYPE_FILESIZE = 20,
|
||||
TYPE_BIGXML = 21,
|
||||
UPDATE_DOCS_COMPLETE = 22,
|
||||
TYPE_CFIUPDATE = 23,
|
||||
TYPE_UPDATEDCFI = 24,
|
||||
|
||||
TYPE_XMLANSWER_MESSAGE_FOR_GUI = 90,
|
||||
@@ -108,7 +107,7 @@ inline QString enumToString(PacketType value) {
|
||||
case PacketType::RECALCULATE_DOCS: return "RECALCULATE_DOCS";
|
||||
case PacketType::GET_DOCS: return "GET_DOCS";
|
||||
case PacketType::SEND_HASH: return "SEND_HASH";
|
||||
case PacketType::TYPE_CFIUPDATE: return "CFI_UPDATE";
|
||||
case PacketType::TYPE_UPDATEDCFI: return "UPDATED_CFI";
|
||||
|
||||
default: return "Unknown";
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ void CommonClientHandler::slot_DocsChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::sendXmlAnswer(QByteArray array)
|
||||
void CommonClientHandler::sendUpdatedCFI(QByteArray array)
|
||||
{
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
|
||||
void slot_DocsChanged();
|
||||
|
||||
void sendXmlAnswer(QByteArray array);
|
||||
void sendUpdatedCFI(QByteArray array);
|
||||
|
||||
public slots:
|
||||
void slot_sendPacketToAllClients(PacketType packetType, bool flOnlyGUI);
|
||||
|
||||
@@ -266,7 +266,7 @@ void ProcessingSystem::processingCFIUpdate(QByteArray array)
|
||||
|
||||
cfiController->unLockAccessToCfiXML();
|
||||
|
||||
commonClientServer->sendXmlAnswer(result);
|
||||
commonClientServer->sendUpdatedCFI(result);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingEntryUnityClient(ClientHandler *client)
|
||||
@@ -652,7 +652,7 @@ void ProcessingSystem::processingClientQueryTasksXML(ClientHandler *client, Clie
|
||||
nameFile = tasksFIMfileName;
|
||||
pathFile = updateController->getPathAdditionalFile(nameFile);
|
||||
Logger::instance().log(pathFile);
|
||||
client->sendFileBlock(pathFile);
|
||||
client->sendFileBlock_forGUI(pathFile);
|
||||
client->sendPacketType(PacketType::TYPE_XMLANSWER_QUERY_TASKS_XML_FIM);
|
||||
}
|
||||
else if(clientQueryTasksXML.Type == "amm")
|
||||
@@ -660,7 +660,7 @@ void ProcessingSystem::processingClientQueryTasksXML(ClientHandler *client, Clie
|
||||
nameFile = tasksAMMfileName;
|
||||
pathFile = updateController->getPathAdditionalFile(nameFile);
|
||||
docsUpdater->lockAccessToDocsXML();
|
||||
client->sendFileBlock(pathFile);
|
||||
client->sendFileBlock_forGUI(pathFile);
|
||||
client->sendPacketType(PacketType::TYPE_XMLANSWER_QUERY_TASKS_XML_AMM);
|
||||
docsUpdater->unLockAccessToDocsXML();
|
||||
}
|
||||
@@ -735,6 +735,13 @@ void ProcessingSystem::processingClientNotify(ClientHandler *client, ClientNotif
|
||||
{
|
||||
chatSystem->sendOldMessages(clientData->getId());
|
||||
}
|
||||
else if (clientNotify.Code == commandGetCFI)
|
||||
{
|
||||
QByteArray result;
|
||||
QString path = updateController->getPathAdditionalFile(cfiListFileName);
|
||||
Tools::loadFileXMLtoByteArray(path,result);
|
||||
client->sendXmlAnswer(result,PacketType::TYPE_UPDATEDCFI);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessingSystem::setCurrentDataInfo(DataInfo *dataInfo)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "recognizesystem.h"
|
||||
|
||||
RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||
QObject(parent)
|
||||
QObject(parent),
|
||||
globalMutex(nullptr)
|
||||
{
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
filePath.clear();
|
||||
@@ -13,7 +14,7 @@ QObject(parent)
|
||||
|
||||
}
|
||||
|
||||
void RecognizeSystem::initialize(UpdateController *updateController,DataParser* dataParser,SendSystem *sendSystem, ClientHandler *handler)
|
||||
void RecognizeSystem::initialize(UpdateController *updateController,DataParser* dataParser, QMutex *globalMutex,SendSystem *sendSystem, ClientHandler *handler)
|
||||
{
|
||||
qDebug() << "RecognizeSystem::initialize thread ID " << QThread::currentThreadId();
|
||||
|
||||
@@ -22,6 +23,7 @@ void RecognizeSystem::initialize(UpdateController *updateController,DataParser*
|
||||
this->clientHandler = handler;
|
||||
this->sendSystem = sendSystem;
|
||||
socket = handler->getSocket();
|
||||
this->globalMutex = globalMutex;
|
||||
|
||||
connect(this,&RecognizeSystem::sigCalculateHash,updateController,&UpdateController::calculateFullHashWithSetup,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigChangeVersion,updateController,&UpdateController::changeAssetVersion,Qt::AutoConnection);
|
||||
@@ -29,7 +31,7 @@ void RecognizeSystem::initialize(UpdateController *updateController,DataParser*
|
||||
connect(this,&RecognizeSystem::sigCopyVersion,updateController,&UpdateController::createCopyVersion,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigXmlParser,dataParser->getProcessParser(),&ProcessParser::slot_read,Qt::AutoConnection);
|
||||
//connect(this,&RecognizeSystem::sigRecalculateDocs,server,&ServerLMSWidget::slot_UpdateDocs,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigSendDocs,sendSystem,&SendSystem::sendDocs,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigSendDocs_forQtClient,sendSystem,&SendSystem::slot_sendDocs_forQtClient,Qt::AutoConnection);
|
||||
}
|
||||
|
||||
void RecognizeSystem::recognize()
|
||||
@@ -403,7 +405,7 @@ void RecognizeSystem::recognize()
|
||||
|
||||
if (updateController->checkDuplicate(result[1]))
|
||||
{
|
||||
sendSystem->sendNotify(commandDuplicateVerName);
|
||||
sendSystem->slot_sendNotify(commandDuplicateVerName);
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
break;
|
||||
}
|
||||
@@ -425,11 +427,11 @@ void RecognizeSystem::recognize()
|
||||
|
||||
if (versionName == baseNameVersion)
|
||||
{
|
||||
sendSystem->sendNotify(commandTryBaseDelete);
|
||||
sendSystem->slot_sendNotify(commandTryBaseDelete);
|
||||
}
|
||||
else if (versionName == updateController->getCurrentVersionName())
|
||||
{
|
||||
sendSystem->sendNotify(commandTryActiveDelete);
|
||||
sendSystem->slot_sendNotify(commandTryActiveDelete);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -452,7 +454,7 @@ void RecognizeSystem::recognize()
|
||||
|
||||
if(packetType == PacketType::GET_DOCS)
|
||||
{
|
||||
emit sigSendDocs(updateController->getPathAdditionalFile(tasksAMMfileName));
|
||||
emit sigSendDocs_forQtClient(updateController->getPathAdditionalFile(tasksAMMfileName));
|
||||
}
|
||||
|
||||
if (packetType == PacketType::SEND_HASH)
|
||||
@@ -509,11 +511,6 @@ void RecognizeSystem::recognize()
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
client->setClientHash(hash);
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_CFIUPDATE)
|
||||
{
|
||||
qDebug() << "CFI HELLO";
|
||||
}
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class RecognizeSystem : public QObject
|
||||
|
||||
public:
|
||||
RecognizeSystem(QObject *parent = nullptr);
|
||||
void initialize(UpdateController *updateController,DataParser *dataParser, SendSystem *sendSystem, ClientHandler *handler);
|
||||
void initialize(UpdateController *updateController,DataParser *dataParser, QMutex *globalMutex, SendSystem *sendSystem, ClientHandler *handler);
|
||||
void recognize();
|
||||
~RecognizeSystem();
|
||||
|
||||
@@ -34,7 +34,7 @@ signals:
|
||||
void sigDeleteVersion(QString versionName);
|
||||
void sigCopyVersion(QString versionName,QString newVersionName,QString author);
|
||||
//void sigRecalculateDocs();
|
||||
void sigSendDocs(QString docsPath);
|
||||
void sigSendDocs_forQtClient(QString docsPath);
|
||||
|
||||
void signal_updateDocsXML();
|
||||
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
QString filePath;
|
||||
ClientHandler *clientHandler;
|
||||
QMutex *mutex;
|
||||
QMutex *globalMutex;
|
||||
|
||||
QTcpSocket *socket;
|
||||
|
||||
|
||||
@@ -1,88 +1,370 @@
|
||||
#include "sendsystem.h"
|
||||
|
||||
SendSystem::SendSystem(QObject *parent) : QObject(parent)
|
||||
SendSystem::SendSystem(QObject *parent) :
|
||||
QObject(parent),
|
||||
client(nullptr),
|
||||
socket(nullptr),
|
||||
dataParser(nullptr),
|
||||
globalMutex(nullptr),
|
||||
buffer(nullptr),
|
||||
type(TypeClientAutorization::TYPE_GUI),
|
||||
flSendingStopped(false),
|
||||
flWaitWritenToSocket(false),
|
||||
bytesWritedToSocket(0),
|
||||
fileSize(0),
|
||||
countSend(0)
|
||||
{
|
||||
isSendStopped = false;
|
||||
qDebug() << "SendSystem init thread ID " << QThread::currentThreadId();
|
||||
|
||||
buffer = new char[sendFileBlockSize];
|
||||
}
|
||||
|
||||
void SendSystem::initialize(DataParser *dataParser,QMutex *globalMutex)
|
||||
SendSystem::~SendSystem()
|
||||
{
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
|
||||
void SendSystem::initialize(DataParser *dataParser, QMutex *globalMutex)
|
||||
{
|
||||
qDebug() << "SendSystem::initialize thread ID " << QThread::currentThreadId();
|
||||
|
||||
this->dataParser = dataParser;
|
||||
//connect(this,&SendSystem::sigSendXMLmessage,dataParser->ClientAnswer(),&ClientAnswerParser::message,Qt::AutoConnection); //сигнал не используется
|
||||
connect(this,&SendSystem::sigSendNotify,dataParser->ClientAnswer(),&ClientAnswerParser::notify,Qt::DirectConnection); //потому что возвращает значение
|
||||
//connect(this,&SendSystem::sigSendVersion,dataParser->ClientAnswer(),&ClientAnswerParser::currentVersion,Qt::AutoConnection); //сигнал не используется
|
||||
this->globalMutex = globalMutex;
|
||||
|
||||
mutex = globalMutex;
|
||||
connect(this, &SendSystem::sigSendNotify, dataParser->ClientAnswer(), &ClientAnswerParser::notify, Qt::DirectConnection); //потому что возвращает значение
|
||||
}
|
||||
|
||||
void SendSystem::setClient(Client *client,QTcpSocket *socket)
|
||||
void SendSystem::setClient(Client *client, QTcpSocket *socket)
|
||||
{
|
||||
this->socket = socket;
|
||||
this->type = client->getClientType();
|
||||
qDebug() << "SendSystem::setClient thread ID " << QThread::currentThreadId();
|
||||
|
||||
this->socket = socket;
|
||||
this->client = client;
|
||||
isSendStopped = false;
|
||||
|
||||
this->type = client->getClientType();
|
||||
|
||||
flSendingStopped = false;
|
||||
}
|
||||
|
||||
void SendSystem::sendNotify(QString notify)
|
||||
void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList)
|
||||
{
|
||||
qDebug() << "SendSystem::sendNotify thread ID " << QThread::currentThreadId();
|
||||
QListIterator<FileData> clientIterator(deleteList);
|
||||
|
||||
while(clientIterator.hasNext())
|
||||
{
|
||||
FileData data = clientIterator.next();
|
||||
|
||||
slot_sendDeleteBlock(data.path);
|
||||
if(slot_getIsSendingStopped())
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " isSendStopped", LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QListIterator<FileData> serverIterator(fileSendList);
|
||||
|
||||
while(serverIterator.hasNext())
|
||||
{
|
||||
FileData data = serverIterator.next();
|
||||
|
||||
if (data.hash == "FOLDER")
|
||||
{
|
||||
slot_sendFolderBlock(data.path);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot_sendFileBlock_forQtClient(data.path);
|
||||
}
|
||||
|
||||
if(slot_getIsSendingStopped())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
slot_sendPacketType(PacketType::UPDATE_FILES_COMPLETE);
|
||||
}
|
||||
|
||||
bool SendSystem::waitWrittenData(QString marker, int msec)
|
||||
{
|
||||
bool success = socket->waitForBytesWritten(msec);
|
||||
if(success)
|
||||
{
|
||||
//qInfo() << "Data sended OK. <" + marker + ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "WaitForBytesWritten timeout. <" + marker + ">";
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
void SendSystem::slot_BytesWrittenToSocket(qint64 bytes)
|
||||
{
|
||||
flWaitWritenToSocket = false;
|
||||
bytesWritedToSocket = bytes;
|
||||
}
|
||||
|
||||
bool SendSystem::slot_getIsSendingStopped() const
|
||||
{
|
||||
return flSendingStopped;
|
||||
}
|
||||
|
||||
void SendSystem::slot_stopSending()
|
||||
{
|
||||
flSendingStopped = true;
|
||||
}
|
||||
|
||||
void SendSystem::slot_socketClose()
|
||||
{
|
||||
socket->close();
|
||||
}
|
||||
|
||||
|
||||
void SendSystem::slot_sendVersion()
|
||||
{
|
||||
QByteArray data = dataParser->ClientAnswer()->currentVersion();
|
||||
slot_sendXmlAnswer(data);
|
||||
}
|
||||
|
||||
void SendSystem::slot_sendNotify(QString notify)
|
||||
{
|
||||
auto answer = emit sigSendNotify(notify);
|
||||
sendXmlAnswer(answer);
|
||||
slot_sendXmlAnswer(answer);
|
||||
}
|
||||
|
||||
void SendSystem::sendFileBlock(QString path)
|
||||
void SendSystem::slot_sendPacketType(PacketType packetType)
|
||||
{
|
||||
QFile file(path);
|
||||
QFileInfo fileInfo(file);
|
||||
Logger::instance().log(" SEND TO: " + client->getLogin() + " " + enumToString(packetType), LogLevel::DEBUG);
|
||||
if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT ||
|
||||
client->getClientType() == TypeClientAutorization::TYPE_GUI)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
stream << packetType;
|
||||
|
||||
if(isSendStopped)
|
||||
waitWrittenData("sendPacketType");
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray message;
|
||||
int type = (int)packetType;
|
||||
message.append(reinterpret_cast<char*>(&type), sizeof(int));
|
||||
socket->write(message);
|
||||
}
|
||||
}
|
||||
|
||||
void SendSystem::slot_sendXmlAnswer(QByteArray array, PacketType packetType)
|
||||
{
|
||||
Logger::instance().log("SEND TO: "+ client->getLogin() + " " + enumToString(packetType) + "\n Text: " +
|
||||
QString(array), LogLevel::DEBUG);
|
||||
|
||||
if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT ||
|
||||
client->getClientType() == TypeClientAutorization::TYPE_GUI)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << packetType;
|
||||
stream << array;
|
||||
|
||||
waitWrittenData("sendXmlAnswer");
|
||||
}
|
||||
else
|
||||
{
|
||||
slot_sendPacketType(packetType);
|
||||
QByteArray message;
|
||||
int size = array.length();
|
||||
message.append(reinterpret_cast<char*>(&size), sizeof(int));
|
||||
socket->write(message);
|
||||
socket->write(array);
|
||||
}
|
||||
}
|
||||
|
||||
void SendSystem::slot_sendDocs_forQtClient(QString docsPath)
|
||||
{
|
||||
slot_sendFileBlock_forQtClient(docsPath);
|
||||
}
|
||||
|
||||
void SendSystem::slot_sendNeedUpdate(bool flag, quint64 size, quint64 fileCount, quint64 deleteCount)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
stream << PacketType::TYPE_NEEDUPDATE;
|
||||
stream << flag;
|
||||
stream << size;
|
||||
stream << fileCount;
|
||||
stream << deleteCount;
|
||||
|
||||
waitWrittenData("sendNeedUpdate");
|
||||
}
|
||||
|
||||
void SendSystem::slot_sendFolderBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FOLDER;
|
||||
stream << path;
|
||||
|
||||
waitWrittenData("sendFolderBlock");
|
||||
}
|
||||
|
||||
void SendSystem::slot_sendDeleteBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_DELETE;
|
||||
stream << path;
|
||||
|
||||
waitWrittenData("sendDeleteBlock");
|
||||
}
|
||||
|
||||
void SendSystem::slot_sendFileBlock_forGUI(QString path)
|
||||
{
|
||||
//qDebug() << "SendSystem::sendFileBlock path: " << path;
|
||||
|
||||
if(slot_getIsSendingStopped())
|
||||
{ //Поведение на случай отключения клиента
|
||||
file.close();
|
||||
Logger::instance().log("UNLOCK STOP MUTEX : " + client->getLogin(),LogLevel::ERROR);
|
||||
Logger::instance().log("Client: " + client->getLogin() + " isSendingStopped", LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
QFile file(path);
|
||||
QFileInfo fileInfo(file);
|
||||
|
||||
fileSize = file.size();
|
||||
|
||||
if (fileSize == 0)
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " WARNING! Zero size " + fileInfo.fileName(),LogLevel::ERROR);
|
||||
Logger::instance().log(path,LogLevel::ERROR);
|
||||
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File zero size " + fileInfo.fileName(), LogLevel::ERROR);
|
||||
Logger::instance().log(path, LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||
if(!file.open(QFile::ReadOnly))
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File not open: " + fileInfo.fileName(), LogLevel::ERROR);
|
||||
Logger::instance().log(path, LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
countSend = 0;
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FILE;
|
||||
stream << path << fileSize;
|
||||
|
||||
if(file.open(QFile::ReadOnly))
|
||||
{
|
||||
while(!file.atEnd())
|
||||
{
|
||||
QByteArray data = file.read(sendFileBlockSize);
|
||||
stream << data;
|
||||
//socket->waitForBytesWritten(10);
|
||||
waitWrittenData("sendFileBlock:header " + fileInfo.fileName());
|
||||
|
||||
if(socket->state() == QAbstractSocket::UnconnectedState) break;
|
||||
countSend++;
|
||||
while(!file.atEnd())
|
||||
{
|
||||
if(socket->state() == QAbstractSocket::UnconnectedState)
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " UnconnectedState", LogLevel::ERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
//emit sigSendToLogger(Tools::getTime() + " send file " + fileInfo.fileName());
|
||||
QByteArray data = file.read(sendFileBlockSize);
|
||||
stream << data;
|
||||
|
||||
waitWrittenData(QString("sendFileBlock:data (size %1) ").arg(data.size()) + fileInfo.fileName());
|
||||
|
||||
countSend++;
|
||||
}
|
||||
|
||||
file.close();
|
||||
countSend = 0;
|
||||
}
|
||||
|
||||
void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
||||
void SendSystem::slot_sendFileBlock_forQtClient(QString path)
|
||||
{
|
||||
if(client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT ||
|
||||
client->getClientType() == TypeClientAutorization::TYPE_GUI)
|
||||
//qDebug() << "SendSystem::sendFileBlock path: " << path;
|
||||
|
||||
if(slot_getIsSendingStopped())
|
||||
{ //Поведение на случай отключения клиента
|
||||
Logger::instance().log("Client: " + client->getLogin() + " isSendingStopped", LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(path);
|
||||
QFileInfo fileInfo(file);
|
||||
|
||||
fileSize = file.size();
|
||||
|
||||
if (fileSize == 0)
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File zero size " + fileInfo.fileName(), LogLevel::ERROR);
|
||||
Logger::instance().log(path, LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!file.open(QFile::ReadOnly))
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File not open: " + fileInfo.fileName(), LogLevel::ERROR);
|
||||
Logger::instance().log(path, LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
countSend = 0;
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FILE;
|
||||
stream << path << fileSize;
|
||||
|
||||
waitWrittenData("sendFileBlock:header " + fileInfo.fileName());
|
||||
|
||||
connect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
|
||||
|
||||
while(!file.atEnd())
|
||||
{
|
||||
if(socket->state() == QAbstractSocket::UnconnectedState)
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " UnconnectedState", LogLevel::ERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
qint64 readBytes = file.read(buffer, sendFileBlockSize);
|
||||
if(readBytes <= 0)
|
||||
break;
|
||||
|
||||
flWaitWritenToSocket = true;
|
||||
|
||||
while(!socket->write(buffer, readBytes))
|
||||
{
|
||||
qCritical() << "socket->write ERROR. size " + QString::number(readBytes);
|
||||
int i = 0;
|
||||
i++;
|
||||
}
|
||||
while(flWaitWritenToSocket)
|
||||
{
|
||||
QCoreApplication::processEvents(); // Обеспечиваем обработку сообщений
|
||||
int i = 0;
|
||||
i++;
|
||||
}
|
||||
|
||||
waitWrittenData(QString("sendFileBlock:data (readBytes %1, num %2) ").arg(QString::number(readBytes), QString::number(countSend)) + fileInfo.fileName());
|
||||
|
||||
countSend++;
|
||||
}
|
||||
|
||||
disconnect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
|
||||
|
||||
file.close();
|
||||
countSend = 0;
|
||||
}
|
||||
|
||||
void SendSystem::slot_sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
||||
{
|
||||
if(client->getClientType() == TypeClientAutorization::TYPE_GUI)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
@@ -99,17 +381,52 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
||||
stream << packetType; //Отправляем тип блока
|
||||
stream << size;
|
||||
|
||||
waitWrittenData("sendFileBlockByteArray");
|
||||
|
||||
while (bytesSended < size)
|
||||
{
|
||||
QByteArray chunk = array.mid(bytesSended,sendFileBlockSize);
|
||||
QByteArray chunk = array.mid(bytesSended, sendFileBlockSize);
|
||||
stream << chunk;
|
||||
//bytesSended = socket->write(chunk);
|
||||
|
||||
waitWrittenData("sendFileBlockByteArray");
|
||||
|
||||
bytesSended += chunk.length();
|
||||
}
|
||||
}
|
||||
else if(client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
qint64 size = array.size();
|
||||
qint64 bytesSended = 0;
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
Logger::instance().log(" WARNING! Zero size ",LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
stream << packetType; //Отправляем тип блока
|
||||
stream << size;
|
||||
|
||||
waitWrittenData("sendFileBlockByteArray");
|
||||
|
||||
while (bytesSended < size)
|
||||
{
|
||||
QByteArray chunk = array.mid(bytesSended, sendFileBlockSize);
|
||||
//stream << chunk;
|
||||
bytesSended = socket->write(chunk);
|
||||
|
||||
waitWrittenData("sendFileBlockByteArray");
|
||||
|
||||
bytesSended += chunk.length();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sendPacketType(packetType);
|
||||
slot_sendPacketType(packetType);
|
||||
qint64 size = array.size();
|
||||
qint64 bytesSended = 0;
|
||||
|
||||
@@ -125,7 +442,7 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
QByteArray chunk = array.mid(bytesSended,sendFileBlockSize);
|
||||
QByteArray chunk = array.mid(bytesSended, sendFileBlockSize);
|
||||
bytesSended = socket->write(chunk);
|
||||
|
||||
size -= bytesSended;
|
||||
@@ -134,206 +451,86 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
||||
}
|
||||
}
|
||||
|
||||
void SendSystem::sendVersion()
|
||||
void SendSystem::slot_sendFileBlockWithRename_Hash_forQtClient(QString path, QString newName)
|
||||
{
|
||||
QByteArray data = dataParser->ClientAnswer()->currentVersion();
|
||||
sendXmlAnswer(data);
|
||||
}
|
||||
//qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId();
|
||||
|
||||
void SendSystem::sendFileBlockWithRename(QString path, QString newName)
|
||||
{
|
||||
qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId();
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
if(slot_getIsSendingStopped())
|
||||
{ //Поведение на случай отключения клиента
|
||||
Logger::instance().log("Client: " + client->getLogin() + " isSendingStopped", LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(Tools::createRootPath(path));
|
||||
QFileInfo fileInfo(file);
|
||||
fileSize = fileInfo.size();
|
||||
|
||||
if(fileSize == 0){
|
||||
Logger::instance().log("Client: " + client->getLogin() + " WARNING! Zero size " + fileInfo.fileName(),LogLevel::ERROR);
|
||||
if (fileSize == 0)
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File zero size " + fileInfo.fileName(), LogLevel::ERROR);
|
||||
Logger::instance().log(path, LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!file.open(QFile::ReadOnly))
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File not open: " + fileInfo.fileName(), LogLevel::ERROR);
|
||||
Logger::instance().log(path, LogLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
QString pathForSend = Tools::createFolderPath(path) + "/" + staticDataFolderName + newName;
|
||||
|
||||
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||
countSend = 0;
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FILE;
|
||||
stream << pathForSend << fileSize;
|
||||
|
||||
if(isSendStopped) { //Поведение на случай отключения клиента
|
||||
waitWrittenData("sendFileBlockWithRename");
|
||||
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
connect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
|
||||
|
||||
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
if(file.open(QFile::ReadOnly)){
|
||||
while(!file.atEnd()){
|
||||
QByteArray data = file.read(sendFileBlockSize);
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
countSend++;
|
||||
while(!file.atEnd())
|
||||
{
|
||||
if(socket->state() == QAbstractSocket::UnconnectedState)
|
||||
{
|
||||
Logger::instance().log("Client: " + client->getLogin() + " UnconnectedState", LogLevel::ERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
Logger::instance().log("Send file " + fileInfo.fileName());
|
||||
qint64 readBytes = file.read(buffer, sendFileBlockSize);
|
||||
if(readBytes <= 0)
|
||||
break;
|
||||
|
||||
flWaitWritenToSocket = true;
|
||||
|
||||
while(!socket->write(buffer, readBytes))
|
||||
{
|
||||
qCritical() << "socket->write ERROR. size " + QString::number(readBytes);
|
||||
int i = 0;
|
||||
i++;
|
||||
}
|
||||
while(flWaitWritenToSocket)
|
||||
{
|
||||
QCoreApplication::processEvents(); // Обеспечиваем обработку сообщений
|
||||
int i = 0;
|
||||
i++;
|
||||
}
|
||||
|
||||
waitWrittenData(QString("sendFileBlock:data (readBytes %1, num %2) ").arg(QString::number(readBytes), QString::number(countSend)) + fileInfo.fileName());
|
||||
|
||||
countSend++;
|
||||
}
|
||||
|
||||
disconnect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
|
||||
|
||||
file.close();
|
||||
countSend = 0;
|
||||
socket->waitForBytesWritten();
|
||||
socket->waitForReadyRead(100);
|
||||
|
||||
sendNotify(commandHashCompleteClient);
|
||||
}
|
||||
|
||||
void SendSystem::sendFolderBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FOLDER;
|
||||
stream << path;
|
||||
}
|
||||
|
||||
void SendSystem::sendDeleteBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_DELETE;
|
||||
stream << path;
|
||||
qDebug() << "DELETE: " + path;
|
||||
socket->waitForReadyRead(10);
|
||||
}
|
||||
|
||||
void SendSystem::sendPacketType(PacketType packetType)
|
||||
{
|
||||
Logger::instance().log(" SEND TO: " + client->getLogin() + " " + enumToString(packetType), LogLevel::DEBUG);
|
||||
if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT ||
|
||||
client->getClientType() == TypeClientAutorization::TYPE_GUI)
|
||||
{
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
stream << packetType;
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray message;
|
||||
int type = (int)packetType;
|
||||
message.append(reinterpret_cast<char*>(&type), sizeof(int));
|
||||
socket->write(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType)
|
||||
{
|
||||
qDebug() << "SendSystem::sendXmlAnswer thread ID " << QThread::currentThreadId();
|
||||
|
||||
Logger::instance().log("SEND TO: "+ client->getLogin() + " " + enumToString(packetType) + "\n Text: " +
|
||||
QString(array),LogLevel::DEBUG);
|
||||
|
||||
if (client->getClientType() == TypeClientAutorization::TYPE_QT_CLIENT ||
|
||||
client->getClientType() == TypeClientAutorization::TYPE_GUI)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << packetType;
|
||||
stream << array;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
else
|
||||
{
|
||||
sendPacketType(packetType);
|
||||
QByteArray message;
|
||||
int size = array.length();
|
||||
message.append(reinterpret_cast<char*>(&size), sizeof(int));
|
||||
socket->write(message);
|
||||
socket->write(array);
|
||||
}
|
||||
}
|
||||
|
||||
void SendSystem::sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
stream << PacketType::TYPE_NEEDUPDATE;
|
||||
stream << flag;
|
||||
stream << size;
|
||||
stream << fileCount;
|
||||
stream << deleteCount;
|
||||
}
|
||||
|
||||
void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList){
|
||||
|
||||
QMutexLocker locker(mutex);
|
||||
QListIterator<FileData> clientIterator(deleteList);
|
||||
|
||||
while(clientIterator.hasNext())
|
||||
{
|
||||
FileData data = clientIterator.next();
|
||||
|
||||
sendDeleteBlock(data.path);
|
||||
if(getIsSendStopped())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QListIterator<FileData> serverIterator(fileSendList);
|
||||
|
||||
while(serverIterator.hasNext())
|
||||
{
|
||||
FileData data = serverIterator.next();
|
||||
|
||||
if (data.hash == "FOLDER")
|
||||
{
|
||||
sendFolderBlock(data.path);
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
else
|
||||
{
|
||||
sendFileBlock(data.path);
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
if(isSendStopped)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendPacketType(PacketType::UPDATE_FILES_COMPLETE);
|
||||
}
|
||||
|
||||
|
||||
void SendSystem::socketClose()
|
||||
{
|
||||
socket->close();
|
||||
}
|
||||
|
||||
void SendSystem::sendStop()
|
||||
{
|
||||
isSendStopped = true;
|
||||
}
|
||||
|
||||
void SendSystem::sendDocs(QString docsPath)
|
||||
{
|
||||
sendFileBlock(docsPath);
|
||||
}
|
||||
|
||||
bool SendSystem::getIsSendStopped() const
|
||||
{
|
||||
return isSendStopped;
|
||||
}
|
||||
|
||||
SendSystem::~SendSystem()
|
||||
{
|
||||
//waitWrittenData("sendFileBlockWithRename");
|
||||
//socket->waitForReadyRead(100);
|
||||
|
||||
slot_sendNotify(commandHashCompleteClient);
|
||||
}
|
||||
|
||||
@@ -13,55 +13,69 @@
|
||||
|
||||
class DataParser;
|
||||
class FileData;
|
||||
|
||||
class SendSystem : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SendSystem(QObject* parent = nullptr);
|
||||
~SendSystem();
|
||||
|
||||
void initialize(DataParser* dataParser,QMutex *globalMutex);
|
||||
void setClient(Client* client,QTcpSocket *socket);
|
||||
void sendMessageBlock(QString message);
|
||||
void sendFileBlock(QString path);
|
||||
void sendFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||
void sendFileBlockWithRename(QString path,QString newName);
|
||||
void sendFolderBlock(QString path);
|
||||
void sendDeleteBlock(QString path);
|
||||
void sendPacketType(PacketType packet);
|
||||
void sendNotify(QString notify);
|
||||
void sendStop();
|
||||
void sendDocs(QString docPath);
|
||||
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
|
||||
void sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount);
|
||||
|
||||
void updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList);
|
||||
|
||||
bool getIsSendStopped() const;
|
||||
private:
|
||||
bool waitWrittenData(QString marker, int msec = 500);
|
||||
|
||||
~SendSystem();
|
||||
public slots:
|
||||
void slot_BytesWrittenToSocket(qint64 bytes);
|
||||
|
||||
bool slot_getIsSendingStopped() const;
|
||||
void slot_stopSending();
|
||||
|
||||
void updateFilesFULL(QList<FileData> fileSendList, QList<FileData> deleteList);
|
||||
public slots:
|
||||
void socketClose();
|
||||
void sendVersion();
|
||||
void slot_socketClose();
|
||||
|
||||
void slot_sendVersion();
|
||||
|
||||
void slot_sendNotify(QString notify);
|
||||
void slot_sendPacketType(PacketType packet);
|
||||
void slot_sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
|
||||
|
||||
void slot_sendDocs_forQtClient(QString docPath);
|
||||
|
||||
void slot_sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount);
|
||||
|
||||
void slot_sendFolderBlock(QString path);
|
||||
void slot_sendDeleteBlock(QString path);
|
||||
|
||||
void slot_sendFileBlock_forGUI(QString path);
|
||||
void slot_sendFileBlock_forQtClient(QString path);
|
||||
void slot_sendFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||
void slot_sendFileBlockWithRename_Hash_forQtClient(QString path,QString newName);
|
||||
|
||||
signals:
|
||||
void sigLoadHash();
|
||||
//QByteArray sigSendXMLmessage(QString loginFrom, QString loginTo, QString text, QString userType); //сигнал не используется
|
||||
QByteArray sigSendNotify(QString message);
|
||||
//QByteArray sigSendVersion(); //сигнал не используется
|
||||
|
||||
private:
|
||||
Client *client;
|
||||
QTcpSocket* socket;
|
||||
DataParser* dataParser;
|
||||
quint64 fileSize;
|
||||
QMutex *mutex;
|
||||
QWaitCondition *waitCondition;
|
||||
int countSend;
|
||||
bool isSendStopped;
|
||||
|
||||
QMutex *globalMutex; //Не используется (но пока оставлен)
|
||||
|
||||
char* buffer;
|
||||
|
||||
TypeClientAutorization type;
|
||||
|
||||
bool flSendingStopped;
|
||||
|
||||
bool flWaitWritenToSocket;
|
||||
qint64 bytesWritedToSocket;
|
||||
|
||||
qint64 fileSize;
|
||||
int countSend;
|
||||
};
|
||||
|
||||
#endif // SENDSYSTEM_H
|
||||
|
||||
@@ -55,9 +55,11 @@ static const QString commandUnchangable = "UNCHANGEABLE";
|
||||
static const QString commandUpdateFilesClient = "update";
|
||||
static const QString commandGetTasks = "GETTASKS";
|
||||
static const QString commandeGetOfflineMessages = "GETOFFLINEMESSAGE";
|
||||
static const QString commandGetCFI = "GETCFI";
|
||||
|
||||
//static quint64 fileBlockSize = 1460;
|
||||
static quint64 sendFileBlockSize = 256000;
|
||||
const int BLOCK_SIZE = 1024 * 1024; // Размер блока
|
||||
static quint64 sendFileBlockSize = /*256000*/BLOCK_SIZE;
|
||||
static quint64 readFileBlockSize = 65535;
|
||||
//1025*250
|
||||
|
||||
|
||||
@@ -54,10 +54,12 @@ void UpdateController::changeAssetVersion(QString versionName)
|
||||
|
||||
currentStreamingPath = assetManager->setVersion(versionName);
|
||||
setUpCurrentServerHash();
|
||||
emit sigUpdateDocsXML();
|
||||
|
||||
commonClientHandler->slot_sendPacketToAllClients(PacketType::HASH_READY, false);
|
||||
commonClientHandler->sendCurrentVersionToAllClient();
|
||||
|
||||
emit sigUpdateDocsXML();
|
||||
|
||||
//commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE);
|
||||
res = emit signal_BlockAutorization(false, "SERVER", "ChangeAssetVersion");
|
||||
}
|
||||
@@ -91,7 +93,6 @@ void UpdateController::compareFiles(ClientHandler* handler, QByteArray array)
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
|
||||
void UpdateController::showHash()
|
||||
{
|
||||
for(FileData& str : serverDataList){
|
||||
@@ -281,6 +282,7 @@ bool UpdateController::checkNeedUpdate(ClientHandler *handler)
|
||||
{
|
||||
if(item.path.contains("Temp")) continue;
|
||||
if(item.path.contains("docs.xml")) continue;
|
||||
if(item.path.contains("CfiList.xml")) continue;
|
||||
|
||||
if (!serverDataList.contains(item))
|
||||
{
|
||||
@@ -292,6 +294,7 @@ bool UpdateController::checkNeedUpdate(ClientHandler *handler)
|
||||
{
|
||||
if(item.path.contains("Temp")) continue;
|
||||
if(item.path.contains("docs.xml")) continue;
|
||||
if(item.path.contains("CfiList.xml")) continue;
|
||||
|
||||
if (!clientDataList.contains(item))
|
||||
{
|
||||
@@ -564,8 +567,6 @@ void UpdateController::xmlFileDataParse(QByteArray array)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
StreamingVersionData* UpdateController::getCurrentVersion()
|
||||
{
|
||||
return assetManager->getCurrentVersionData();
|
||||
@@ -608,6 +609,7 @@ bool UpdateController::checkRequiredFolder()
|
||||
|
||||
return required;
|
||||
}
|
||||
|
||||
UpdateController::~UpdateController()
|
||||
{
|
||||
|
||||
|
||||
@@ -14,14 +14,15 @@ ClientHandler::ClientHandler( QObject *parent):
|
||||
void ClientHandler::initialize(int descriptor,
|
||||
UpdateController *updateController,DataParser *dataParser, QMutex *mutex)
|
||||
{
|
||||
this->socket = new QTcpSocket;
|
||||
this->thread = new QThread;
|
||||
qDebug() << "ClientHandler::initialize thread ID " << QThread::currentThreadId();
|
||||
|
||||
socket = new QTcpSocket;
|
||||
thread = new QThread;
|
||||
|
||||
QIODevice::OpenMode openMode = socket->openMode();
|
||||
socket->setParent(nullptr);
|
||||
socket->setSocketDescriptor(descriptor);
|
||||
|
||||
qDebug() << "ClientHandler::initialize thread ID " << QThread::currentThreadId();
|
||||
|
||||
sendSystem = new SendSystem;
|
||||
recognizeSystem = new RecognizeSystem;
|
||||
|
||||
@@ -41,28 +42,29 @@ void ClientHandler::initialize(int descriptor,
|
||||
|
||||
connect(recognizeSystem,&RecognizeSystem::signal_updateDocsXML,this,&ClientHandler::signal_updateDocsXML);
|
||||
|
||||
connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::sendXmlAnswer,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection/*Qt::DirectConnection*/);
|
||||
connect(this,&ClientHandler::sigFileBlock,sendSystem,&SendSystem::sendFileBlock,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigFileBlockByteArray,sendSystem,&SendSystem::sendFileBlockByteArray,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,/*Qt::AutoConnection*/Qt::DirectConnection); //Возвращает значение
|
||||
connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::sendDeleteBlock,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigNeedUpdate,sendSystem,&SendSystem::sendNeedUpdate,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendNotify,sendSystem,&SendSystem::sendNotify,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendFileBlockWithRename,sendSystem,&SendSystem::sendFileBlockWithRename,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendVersion,sendSystem,&SendSystem::sendVersion,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSocketClose,sendSystem,&SendSystem::socketClose,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendXmlAnswer,sendSystem,&SendSystem::slot_sendXmlAnswer,Qt::AutoConnection);
|
||||
//connect(this,&ClientHandler::sigInitSender,sendSystem,&SendSystem::initialize,Qt::AutoConnection/*Qt::DirectConnection*/);
|
||||
connect(this,&ClientHandler::sigFileBlock_forGUI,sendSystem,&SendSystem::slot_sendFileBlock_forGUI,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigFileBlockByteArray,sendSystem,&SendSystem::slot_sendFileBlockByteArray,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::slot_sendFolderBlock,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::slot_getIsSendingStopped,/*Qt::AutoConnection*/Qt::DirectConnection); //Возвращает значение
|
||||
connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::slot_sendDeleteBlock,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigNeedUpdate,sendSystem,&SendSystem::slot_sendNeedUpdate,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendNotify,sendSystem,&SendSystem::slot_sendNotify,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendFileBlockWithRename_Hash_forQtClient,sendSystem,&SendSystem::slot_sendFileBlockWithRename_Hash_forQtClient,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendVersion,sendSystem,&SendSystem::slot_sendVersion,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSocketClose,sendSystem,&SendSystem::slot_socketClose,Qt::AutoConnection);
|
||||
//connect(this,&ClientHandler::sigSocketFlush,sendSystem,&SendSystem::socketFlush,Qt::AutoConnection); //не используется
|
||||
connect(this,&ClientHandler::sigSendPacketType,sendSystem,&SendSystem::sendPacketType,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendStop,sendSystem,&SendSystem::sendStop,Qt::DirectConnection);
|
||||
connect(this,&ClientHandler::sigSendPacketType,sendSystem,&SendSystem::slot_sendPacketType,Qt::AutoConnection);
|
||||
connect(this,&ClientHandler::sigSendStop,sendSystem,&SendSystem::slot_stopSending,Qt::DirectConnection);
|
||||
|
||||
connect(socket,&QTcpSocket::readyRead,this,&ClientHandler::initClientType,Qt::AutoConnection);
|
||||
initClientType();
|
||||
|
||||
recognizeSystem->initialize(updateController,dataParser,sendSystem, this);
|
||||
recognizeSystem->initialize(updateController,dataParser, mutex,sendSystem, this);
|
||||
sendSystem->setClient(client,socket);
|
||||
emit sigInitSender(dataParser, mutex);
|
||||
sendSystem->initialize(dataParser, mutex);
|
||||
//emit sigInitSender(dataParser, mutex);
|
||||
|
||||
Logger::instance().log("SERVER: Client connected");
|
||||
}
|
||||
@@ -99,7 +101,7 @@ void ClientHandler::initClientType()
|
||||
void ClientHandler::sendHash()
|
||||
{
|
||||
QString path = "\\" + hashFileName;
|
||||
emit sigSendFileBlockWithRename(path,"/serverHash.xml");
|
||||
emit sigSendFileBlockWithRename_Hash_forQtClient(path,"/serverHash.xml");
|
||||
//emit sigSendNotify("HASHSENDCOMPLETE");
|
||||
}
|
||||
|
||||
@@ -133,9 +135,9 @@ void ClientHandler::sendXmlAnswer(QByteArray array, PacketType packetType)
|
||||
emit sigSendXmlAnswer(array, packetType);
|
||||
}
|
||||
|
||||
void ClientHandler::sendFileBlock(QString path)
|
||||
void ClientHandler::sendFileBlock_forGUI(QString path)
|
||||
{
|
||||
emit sigFileBlock(path);
|
||||
emit sigFileBlock_forGUI(path);
|
||||
}
|
||||
|
||||
void ClientHandler::sendFileBlockByteArray(QByteArray array, PacketType packetType)
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
void initSender(DataParser *dataParser);
|
||||
void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
|
||||
void sendFolderBlock(QString path);
|
||||
void sendFileBlock(QString path);
|
||||
void sendFileBlock_forGUI(QString path);
|
||||
void sendFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||
bool getIsSendStopped();
|
||||
void sendDeleteBlock(QString path);
|
||||
@@ -51,9 +51,9 @@ public:
|
||||
|
||||
signals:
|
||||
void sigSendXmlAnswer(QByteArray array, PacketType packetType);
|
||||
void sigInitSender (DataParser *dataParse, QMutex *mutex);
|
||||
//void sigInitSender (DataParser *dataParse, QMutex *mutex);
|
||||
void sigFolderBlock(QString path);
|
||||
void sigFileBlock(QString path);
|
||||
void sigFileBlock_forGUI(QString path);
|
||||
void sigFileBlockByteArray(QByteArray array, PacketType packetType);
|
||||
bool sigGetIsSendStopped();
|
||||
void sigSendDeleteBlock(QString path);
|
||||
@@ -62,7 +62,7 @@ signals:
|
||||
void sigSendHash();
|
||||
void sigRecognize(ClientHandler *handler);
|
||||
void sigSendNotify(QString notify);
|
||||
void sigSendFileBlockWithRename (QString path,QString newName);
|
||||
void sigSendFileBlockWithRename_Hash_forQtClient (QString path,QString newName);
|
||||
void sigSocketClose();
|
||||
//bool sigSocketFlush(); //не используется
|
||||
void sigSendVersion();
|
||||
@@ -71,6 +71,10 @@ signals:
|
||||
|
||||
void signal_updateDocsXML();
|
||||
|
||||
private:
|
||||
void initClientType();
|
||||
void packetTypeInit(PacketType packet, Client *client);
|
||||
|
||||
public :
|
||||
QThread *thread;
|
||||
QTcpSocket *socket;
|
||||
@@ -82,11 +86,7 @@ private:
|
||||
UpdateController *updateController;
|
||||
RecognizeSystem *recognizeSystem;
|
||||
Client *client;
|
||||
|
||||
SendSystem *sendSystem;
|
||||
|
||||
void initClientType();
|
||||
void packetTypeInit(PacketType packet, Client *client);
|
||||
SendSystem *sendSystem;
|
||||
};
|
||||
|
||||
#endif // CLIENTHANDLER_H
|
||||
|
||||
@@ -4,6 +4,7 @@ MultiThreadServer::MultiThreadServer(UpdateController *updateController, DocsUpd
|
||||
DataParser *dataParser,qint16 hostPort, QObject *parent ):
|
||||
QTcpServer(parent),
|
||||
mutex(nullptr),
|
||||
clientsMap(nullptr),
|
||||
hostPort(hostPort),
|
||||
processingSystem(processingSystem),
|
||||
updateController(updateController),
|
||||
@@ -23,6 +24,7 @@ MultiThreadServer::MultiThreadServer(UpdateController *updateController, DocsUpd
|
||||
MultiThreadServer::~MultiThreadServer()
|
||||
{
|
||||
delete mutex;
|
||||
delete clientsMap;
|
||||
}
|
||||
|
||||
void MultiThreadServer::incomingConnection(qintptr socketDesriptor)
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
{
|
||||
return stateBlockAutorization;
|
||||
}
|
||||
EStateServer getStateServer()
|
||||
EStateServer getStateServer() const
|
||||
{
|
||||
return stateServer;
|
||||
}
|
||||
@@ -58,6 +58,9 @@ private:
|
||||
emit signal_StateServer(stateServer, stateBlockAutorization);
|
||||
}
|
||||
|
||||
void removeClient(int idSocket);
|
||||
void addClient(qintptr descriptor, ClientHandler *client);
|
||||
|
||||
signals:
|
||||
//void sigInitClient(int descriptor, ServerLMSWidget *serverWidget,
|
||||
// UpdateController *updateController, DataParser *dataParser, QMutex *mutex);
|
||||
@@ -95,10 +98,7 @@ private:
|
||||
|
||||
EStateServer stateServer;
|
||||
EStateBlockAutorization stateBlockAutorization;
|
||||
QMap<QString, QString> blockersMap;
|
||||
|
||||
void removeClient(int idSocket);
|
||||
void addClient(qintptr descriptor, ClientHandler *client);
|
||||
QMap<QString, QString> blockersMap;
|
||||
};
|
||||
|
||||
#endif // MULTITHREADSERVER_H
|
||||
|
||||
Reference in New Issue
Block a user