refract Server 0

This commit is contained in:
2026-02-06 14:47:20 +03:00
parent 8ab4238537
commit 4b98d00faf
17 changed files with 549 additions and 333 deletions

View File

@@ -1,27 +1,39 @@
#include "multithreadserver.h"
MultiThreadServer::MultiThreadServer(ServerLMSWidget *widget,UpdateController *updateController,ProcessingSystem *processingSystem,
MultiThreadServer::MultiThreadServer(UpdateController *updateController, DocsUpdater *docsUpdater,ProcessingSystem *processingSystem,
DataParser *dataParser,qint16 hostPort, QObject *parent ):
QTcpServer(parent),
serverLmsWidget(widget),
mutex(nullptr),
hostPort(hostPort),
processingSystem(processingSystem),
updateController(updateController),
docsUpdater(docsUpdater),
dataParser(dataParser),
stateServer(stoped),
stateBlockAutorization(blocked)
{
clientsMap = new QMap<int,ClientHandler*>;
mutex = new QMutex;
connect(this, &MultiThreadServer::signal_updateDocsXML, docsUpdater, &DocsUpdater::slot_updateDocsXML);
}
MultiThreadServer::~MultiThreadServer()
{
delete mutex;
}
void MultiThreadServer::incomingConnection(qintptr socketDesriptor)
{
ClientHandler* newClient = new ClientHandler;
connect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize, Qt::AutoConnection/*Qt::DirectConnection*/);
connect(newClient,&ClientHandler::signal_updateDocsXML,this,&MultiThreadServer::slot_UpdateDocs);
//connect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize, Qt::AutoConnection/*Qt::DirectConnection*/);
connect(newClient,&ClientHandler::sigClientDisconnected,this,&MultiThreadServer::slotDisconnectClient,Qt::AutoConnection);
emit sigInitClient(socketDesriptor,serverLmsWidget,updateController,dataParser);
disconnect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize);
//emit sigInitClient(socketDesriptor,serverLmsWidget,updateController,dataParser, getMutex());
newClient->initialize(socketDesriptor,updateController,dataParser, getMutex());
//disconnect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize);
addClient(socketDesriptor,newClient);
@@ -40,19 +52,18 @@ bool MultiThreadServer::startServer()
{
if(stateServer == stoped)
{
//connect(tcpServer, &QTcpServer::newConnection, this, &ServerLMSWidget::slotNewConnection,Qt::AutoConnection);
if(!listen(QHostAddress::Any, hostPort))
{
stateServer = stoped;
emit signal_StateServer(stateServer, stateBlockAutorization);
Logger::instance().log("SERVER: start ERROR");
return false;
}
else
{
stateServer = started;
stateServer = started;
slot_BlockAutorization(false, "SERVER", "StopServer");
emit signal_StateServer(stateServer, stateBlockAutorization);
Logger::instance().log("SERVER: start OK");
return true;
}
@@ -71,6 +82,7 @@ bool MultiThreadServer::stopServer()
close();
stateServer = stoped;
slot_BlockAutorization(true, "SERVER", "StopServer");
emit signal_StateServer(stateServer, stateBlockAutorization);
Logger::instance().log("SERVER: stop OK");
return true;
}
@@ -83,9 +95,20 @@ QMap<int, ClientHandler *> *MultiThreadServer::getClientsMap() const
return clientsMap;
}
QStringList MultiThreadServer::getClientFullNameList()
{
QStringList list;
for(ClientHandler* handler : *getClientsMap())
{
QString clientFullName = handler->getClient()->getFullName();
list.append(clientFullName);
}
return list;
}
void MultiThreadServer::updateClientList()
{
serverLmsWidget->slot_UpdateListClients();
emit signal_UpdateListClients(getClientFullNameList());
}
void MultiThreadServer::disableClients()
@@ -151,8 +174,8 @@ void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPo
emit signalStopSendFile();
Logger::instance().log("SERVER: Client " + login + " disconnected");
serverLmsWidget->slot_UpdateListClients();
serverLmsWidget->getProcessingSystem()->processingClientDeAutorization(login);
emit signal_UpdateListClients(getClientFullNameList());
processingSystem->processingClientDeAutorization(login);
}
bool MultiThreadServer::slot_BlockAutorization(bool block, QString whoFullName, QString type)
@@ -259,15 +282,30 @@ bool MultiThreadServer::slot_BlockAutorization(bool block, QString whoFullName,
return res;
}
void MultiThreadServer::slot_StartServer()
{
startServer();
}
void MultiThreadServer::slot_StopServer()
{
stopServer();
}
void MultiThreadServer::slot_UpdateDocs()
{
emit signal_updateDocsXML();
}
void MultiThreadServer::removeClient(int idSocket)
{
clientsMap->remove(idSocket);
serverLmsWidget->slot_UpdateListClients();
emit signal_UpdateListClients(getClientFullNameList());
}
void MultiThreadServer::addClient(qintptr descriptor, ClientHandler *client)
{
(*clientsMap)[descriptor] = client;
serverLmsWidget->slot_UpdateListClients();
emit signal_UpdateListClients(getClientFullNameList());
}