mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
117 lines
3.2 KiB
C++
117 lines
3.2 KiB
C++
#include "connectortoserver.h"
|
|
#include <QThread>
|
|
|
|
ConnectorToServer::ConnectorToServer(QObject *parent) :
|
|
QObject(parent),
|
|
connectionThread(nullptr),
|
|
client(nullptr),
|
|
dataParser(nullptr),
|
|
sendSystem(nullptr),
|
|
recognizeSystem(nullptr)
|
|
{
|
|
initialize();
|
|
}
|
|
|
|
bool ConnectorToServer::authorizationInstructorLocal(QString login, QString password)
|
|
{
|
|
if (!client->getIsConnected())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ClientAutorization *autorization = new ClientAutorization;
|
|
autorization->Login = login;
|
|
autorization->Password = password;
|
|
autorization->TypeClient = TypeClientAutorization::TYPE_GUI;
|
|
|
|
dataParser->createAuthMessage(autorization);
|
|
emit sigSendAutorization();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ConnectorToServer::deAuthorizationInstructorLocal(QString login)
|
|
{
|
|
if (!client->getIsConnected())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ClientDeAutorization *deAutorization = new ClientDeAutorization;
|
|
deAutorization->Login = login;
|
|
|
|
dataParser->createDeAuthMessage(deAutorization);
|
|
emit sigSendDeAutorization();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ConnectorToServer::queryGetListInstructors()
|
|
{
|
|
if (!client->getIsConnected())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ClientQueryToDB *queryToDB = new ClientQueryToDB;
|
|
queryToDB->typeQuery = TypeQueryToDB::TYPE_QUERY_GET_LIST_INSTRUCTORS;
|
|
|
|
dataParser->createQueryToDBMessage(queryToDB);
|
|
emit sigSendQueryToDB();
|
|
}
|
|
|
|
QList<Instructor> ConnectorToServer::getListInstructors()
|
|
{
|
|
return listInstructors;
|
|
}
|
|
|
|
void ConnectorToServer::slot_AnswerQueryToDB(QList<Instructor>* listInstructors)
|
|
{
|
|
this->listInstructors = *listInstructors;
|
|
emit signal_UpdateDB(true, false);
|
|
}
|
|
|
|
void ConnectorToServer::initialize()
|
|
{
|
|
createObjects();
|
|
|
|
bindConnection();
|
|
|
|
emit sigInitializeClient(recognizeSystem,sendSystem,connectionThread);
|
|
|
|
emit sigSetConnect(dataParser->getServerSettings(),connectionThread);
|
|
}
|
|
|
|
void ConnectorToServer::bindConnection()
|
|
{
|
|
connect(this,&ConnectorToServer::sigInitializeClient,client,&TCPClient::initialize,Qt::AutoConnection);
|
|
connect(this,&ConnectorToServer::sigSetConnect,client,&TCPClient::setConnect,Qt::AutoConnection);
|
|
connect(this,&ConnectorToServer::sigSendAutorization,sendSystem,&SendSystem::sendClientAutorization);
|
|
connect(this,&ConnectorToServer::sigSendDeAutorization,sendSystem,&SendSystem::sendClientAutorization);
|
|
|
|
connect(this,&ConnectorToServer::sigSendQueryToDB,sendSystem,&SendSystem::sendClientQueryToDB);
|
|
|
|
connect(recognizeSystem,&RecognizeSystem::sigAuth,this,&ConnectorToServer::sigLoginResult);
|
|
connect(recognizeSystem,&RecognizeSystem::sigDeAuth,this,&ConnectorToServer::sigDeLoginResult);
|
|
connect(recognizeSystem,&RecognizeSystem::sigAnswerQueryToDB,this,&ConnectorToServer::slot_AnswerQueryToDB);
|
|
}
|
|
|
|
void ConnectorToServer::createObjects()
|
|
{
|
|
connectionThread = new QThread;
|
|
|
|
client = new TCPClient;
|
|
client->moveToThread(connectionThread);
|
|
|
|
dataParser = new DataParser;
|
|
|
|
sendSystem = new SendSystem;
|
|
sendSystem->moveToThread(connectionThread);
|
|
|
|
recognizeSystem = new RecognizeSystem;
|
|
recognizeSystem->moveToThread(connectionThread);
|
|
|
|
connectionThread->start();
|
|
connectionThread->setPriority(QThread::HighestPriority);
|
|
}
|