Сделал первый этап разделения Сервера и GUI

This commit is contained in:
krivoshein
2024-12-02 17:45:06 +03:00
parent 927b789486
commit b86717d212
48 changed files with 813 additions and 1182 deletions

View File

@@ -21,19 +21,18 @@ find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Network REQUIRED)
find_package(Qt5 COMPONENTS Sql REQUIRED)
find_package(Qt5 COMPONENTS LinguistTools REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Concurrent )
find_package(Qt5 REQUIRED COMPONENTS Concurrent)
find_package(Qt5 COMPONENTS Xml REQUIRED)
#set(TS_FILES ServerLMS_ru_RU.ts)
add_library(ServerLMS SHARED
ServerLMS_global.h
serverlmswidget.cpp
serverlmswidget.h
serverlmswidget.ui
messangerwidget.cpp
messangerwidget.h
messangerwidget.ui
# messangerwidget.cpp
# messangerwidget.h
# messangerwidget.ui
typesDataServerClient.h
Client.h
clienthandler.cpp
@@ -54,8 +53,9 @@ add_library(ServerLMS SHARED
Systems/sendsystem.h
Systems/tools.cpp
Systems/tools.h
providerdblms.cpp
providerdblms.h
resources.qrc
#${TS_FILES}
)
target_link_libraries(ServerLMS PRIVATE Qt5::Widgets)
@@ -64,25 +64,6 @@ target_link_libraries(ServerLMS PRIVATE Qt5::Concurrent)
target_link_libraries(ServerLMS PRIVATE Qt5::Sql)
target_link_libraries(ServerLMS PRIVATE Qt5::Xml)
#target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../SUO/InstructorsAndTrainees)
#target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../SUO/InstructorsAndTrainees/instructors)
#target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../SUO/InstructorsAndTrainees/trainees)
#target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../SUO/InstructorsAndTrainees/tasks)
#target_link_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../SUO/Debug64)
#target_link_libraries(ServerLMS PRIVATE libInstructorsAndTrainees.dll)
target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../DB_IaT/InstructorsAndTrainees)
target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../DB_IaT/InstructorsAndTrainees/instructors)
target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../DB_IaT/InstructorsAndTrainees/trainees)
target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../DB_IaT/InstructorsAndTrainees/tasks)
target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../DB_IaT/InstructorsAndTrainees/docTasks)
if(PROJECT_TYPE_DEBUG)
target_link_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../DB_IaT/Debug64)
elseif()
target_link_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../DB_IaT/Release64)
endif()
target_link_libraries(ServerLMS PRIVATE libInstructorsAndTrainees.dll)
target_include_directories(ServerLMS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../DB_LMS/DataBaseLMS)
if(PROJECT_TYPE_DEBUG)
@@ -94,5 +75,3 @@ target_link_libraries(ServerLMS PRIVATE libDataBaseLMS.dll)
target_compile_definitions(ServerLMS PRIVATE SERVERLMS_LIBRARY)
#qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})

View File

@@ -2,17 +2,16 @@
#include <clienthandler.h>
ProcessingSystem::ProcessingSystem(QObject *parent):
ProcessingSystem::ProcessingSystem(ProviderDBLMS* providerDBLMS, QObject *parent):
QObject(parent)
{
this->providerDBLMS = providerDBLMS;
}
void ProcessingSystem::initialize(DataParser *dataParser, ServerLMSWidget *server,InstructorsAndTraineesWidget *instructorsAndTrainees)
void ProcessingSystem::initialize(DataParser *dataParser, ServerLMSWidget *server)
{
this->server = server;
this->dataParser = dataParser;
this->pInstructorsAndTrainees = instructorsAndTrainees;
}
void ProcessingSystem::processingClientAutorization(ClientHandler *client, ClientAutorization clientAutorization)
@@ -33,25 +32,25 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien
QString traineeName;
QByteArray arrayAnswer;
if(pInstructorsAndTrainees->authorizationTrainee(clientAutorization.Login, clientAutorization.Password, "", ""))
if(providerDBLMS->authorizationTrainee(clientAutorization.Login, clientAutorization.Password, "", ""))
{//Авторизуется обучаемый
client->getClient()->setLogin(clientAutorization.Login);
emit sigUpdateListClients();
//KAV redact
instructorName = pInstructorsAndTrainees->getMainInstructorName();
traineeName = pInstructorsAndTrainees->getNameTraineeByLogin(clientAutorization.Login);
instructorName = providerDBLMS->getMainInstructorName();
traineeName = providerDBLMS->getNameTraineeByLogin(clientAutorization.Login);
arrayAnswer = dataParser->xmlAnswer_authorization(true, instructorName, traineeName, "trainee");
}
else if(pInstructorsAndTrainees->authorizationInstructor(clientAutorization.Login, clientAutorization.Password))
else if(providerDBLMS->authorizationInstructor(clientAutorization.Login, clientAutorization.Password))
{//Авторизуется инструктор
client->getClient()->setLogin(clientAutorization.Login);
emit sigUpdateListClients();
instructorName = pInstructorsAndTrainees->getNameInstructorByLogin(clientAutorization.Login);
instructorName = providerDBLMS->getNameInstructorByLogin(clientAutorization.Login);
arrayAnswer = dataParser->xmlAnswer_authorization(true, instructorName, instructorName, "instructor");
}

View File

@@ -6,7 +6,8 @@
#include <clienthandler.h>
#include <serverlmswidget.h>
#include "instructorsandtraineeswidget.h"
//#include "instructorsandtraineeswidget.h"
#include "providerdblms.h"
class SendSystem;
class ServerLMSWidget;
@@ -19,10 +20,9 @@ class ProcessingSystem : public QObject
{
Q_OBJECT
public:
explicit ProcessingSystem(QObject *parent = nullptr);
explicit ProcessingSystem(ProviderDBLMS* providerDBLMS, QObject *parent = nullptr);
void initialize(DataParser* dataParser,ServerLMSWidget *server,
InstructorsAndTraineesWidget *instructorsAndTrainees);
void initialize(DataParser* dataParser,ServerLMSWidget *server);
void processingClientAutorization(ClientHandler *client, ClientAutorization clientAutorization);
void processingClientMessage(ClientHandler *client, ClientMessage clientMessage);
void processingClientNotify(ClientHandler *client, ClientNotify clientNotify);
@@ -36,7 +36,8 @@ signals:
private:
ServerLMSWidget *server;
DataParser *dataParser;
InstructorsAndTraineesWidget *pInstructorsAndTrainees;
//InstructorsAndTraineesWidget *pInstructorsAndTrainees;
ProviderDBLMS* providerDBLMS;
};
#endif // PROCESSINGSYSTEM_H

View File

@@ -5,7 +5,7 @@
#include <QListWidget>
#include <QTranslator>
#include "ServerLMS_global.h"
#include "instructorsandtraineeswidget.h"
//#include "instructorsandtraineeswidget.h"
class DialogMsg
{

View File

@@ -0,0 +1,200 @@
#include "providerdblms.h"
ProviderDBLMS::ProviderDBLMS(QWidget *parentWidget, QObject *parent) :
QObject(parent),
dbLMS(nullptr)
{
dbLMS = new InterfaceDataBaseLMS(parentWidget);
//ConnectionToDB();
}
ProviderDBLMS::~ProviderDBLMS()
{
DisConnectionFromDB();
}
void ProviderDBLMS::ConnectionToDB()
{
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
if(dbLMS->ConnectionToDB())
{
Q_EMIT signal_BlockAutorization(false);
//Q_EMIT signal_NeedUpdateUI(true, true);
}
}
mtxAccess.unlock();
}
void ProviderDBLMS::DisConnectionFromDB()
{
mtxAccess.lock();
if(dbLMS->DBisConnected())
{
Q_EMIT signal_BlockAutorization(true);
dbLMS->DisConnectionFromDB();
//Q_EMIT signal_NeedUpdateUI(true, true);
}
mtxAccess.unlock();
}
QString ProviderDBLMS::getMainInstructorName()
{
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return QStringLiteral("");
}
//QString res = dbLMS->getNameInstructorByLogin(loginInstructorLoggedInLocal);
mtxAccess.unlock();
//return res;
return QStringLiteral("");
}
bool ProviderDBLMS::authorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name)
{
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return false;
}
Q_EMIT signal_BlockAutorization(true);
bool res = dbLMS->AuthorizationTrainee(login, password, classroom_name, computer_name);
Q_EMIT signal_BlockAutorization(false);
//if(res)
//Q_EMIT signal_NeedUpdateUI(false, true);
mtxAccess.unlock();
return res;
}
bool ProviderDBLMS::deAuthorizationTrainee(QString login)
{
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return false;
}
Q_EMIT signal_BlockAutorization(true);
bool res = dbLMS->deAuthorizationTrainee(login);
Q_EMIT signal_BlockAutorization(false);
//if(res)
//Q_EMIT signal_NeedUpdateUI(false, true);
mtxAccess.unlock();
return res;
}
QString ProviderDBLMS::getNameTraineeByLogin(QString login)
{
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return QStringLiteral("");
}
QString res = dbLMS->getNameTraineeByLogin(login);
mtxAccess.unlock();
return res;
}
bool ProviderDBLMS::authorizationInstructor(QString login, QString password)
{
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return false;
}
Q_EMIT signal_BlockAutorization(true);
bool res = dbLMS->AuthorizationInstructor(login, password);
Q_EMIT signal_BlockAutorization(false);
//if(res)
//Q_EMIT signal_NeedUpdateUI(true, false);
mtxAccess.unlock();
return res;
}
bool ProviderDBLMS::deAuthorizationInstructor(QString login)
{
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return false;
}
Q_EMIT signal_BlockAutorization(true);
bool res = dbLMS->deAuthorizationInstructor(login);
Q_EMIT signal_BlockAutorization(false);
/*
if(res)
{
if(loginInstructorLoggedInLocal == login)
{
loginInstructorLoggedInLocal = QStringLiteral("");
adminMode = false;
viewerInstructors->setAdminMode(adminMode);
viewerTrainees->setAdminMode(adminMode);
viewerInstructors->setAuthComplited(false);
viewerTrainees->setAuthComplited(false);
Q_EMIT signal_NeedUpdateUI(true, false);
}
else
Q_EMIT signal_NeedUpdateUI(true, false);
}*/
mtxAccess.unlock();
return res;
}
QString ProviderDBLMS::getNameInstructorByLogin(QString login)
{
mtxAccess.lock();
if(! dbLMS->DBisConnected())
{
mtxAccess.unlock();
return QStringLiteral("");
}
QString res = dbLMS->getNameInstructorByLogin(login);
mtxAccess.unlock();
return res;
}

View File

@@ -0,0 +1,39 @@
#ifndef PROVIDERDBLMS_H
#define PROVIDERDBLMS_H
#include <QObject>
#include "interfacedatabaselms.h"
class ProviderDBLMS : public QObject
{
Q_OBJECT
public:
explicit ProviderDBLMS(QWidget *parentWidget, QObject *parent = nullptr);
~ProviderDBLMS();
public:
QString getMainInstructorName();
//Авторизация обучаемого на клиенте
bool authorizationTrainee(QString login, QString password, QString classroom_name = QStringLiteral(""), QString computer_name = QStringLiteral(""));
bool deAuthorizationTrainee(QString login);
QString getNameTraineeByLogin(QString login);
//Авторизация инструктора на клиенте
bool authorizationInstructor(QString login, QString password);
bool deAuthorizationInstructor(QString login);
QString getNameInstructorByLogin(QString login);
Q_SIGNALS:
//сигнал о блокировке авторизации
void signal_BlockAutorization(bool block);
public:
void ConnectionToDB();
void DisConnectionFromDB();
private:
InterfaceDataBaseLMS* dbLMS;
QMutex mtxAccess;
};
#endif // PROVIDERDBLMS_H

View File

@@ -10,17 +10,17 @@
#include "ui_serverlmswidget.h"
//#include "instructorsAndTrainees.h"
#include "instructorsandtraineeswidget.h"
//#include "instructorsandtraineeswidget.h"
ServerLMSWidget::ServerLMSWidget(InstructorsAndTraineesWidget* instructorsAndTrainees, MessangerWidget* messangerWidget, QWidget *parent) :
ServerLMSWidget::ServerLMSWidget(/*MessangerWidget* messangerWidget, */QWidget *parent) :
QWidget(parent),
tcpServer(nullptr),
hostPort(6000),
stateServer(stoped),
stateBlockAutorization(/*unblocked*/blocked),
pInstructorsAndTrainees(instructorsAndTrainees),
pMessangerWidget(messangerWidget),
//pInstructorsAndTrainees(instructorsAndTrainees),
//pMessangerWidget(messangerWidget),
ui(new Ui::ServerLMSWidget)
{
ui->setupUi(this);
@@ -41,12 +41,14 @@ ServerLMSWidget::ServerLMSWidget(InstructorsAndTraineesWidget* instructorsAndTra
ui->comboTasks->addItem("Задача 4");
ui->comboTasks->addItem("Задача 5");
providerDBLMS = new ProviderDBLMS(this);
logger = new Logger(ui->listWidgetLogger);
connect(logger,&Logger::sigSendTextToLogger,this,&ServerLMSWidget::slotAddToLog,Qt::QueuedConnection);
logger->moveToThread(loggerThread);
processingSystem = new ProcessingSystem;
processingSystem = new ProcessingSystem(providerDBLMS);
dataParser = new DataParser(processingSystem);
updateController = new UpdateController;
@@ -56,20 +58,24 @@ ServerLMSWidget::ServerLMSWidget(InstructorsAndTraineesWidget* instructorsAndTra
updateThread->start();
updateController->initialize(nullptr,dataParser);
processingSystem->initialize(dataParser,this,instructorsAndTrainees);
processingSystem->initialize(dataParser,this);
logger->setTypeLog("widget");
connect(providerDBLMS, &ProviderDBLMS::signal_BlockAutorization, this, &ServerLMSWidget::slot_BlockAutorization);
//connect(processingSystem,&ProcessingSystem::sigAuthChanged,this,&ServerLMSWidget::signal_authorizationChanged); //Уже не требуется!
connect(processingSystem,&ProcessingSystem::sigUpdateListClients,this, &ServerLMSWidget::slotUpdateListClients);
connect(pMessangerWidget, &MessangerWidget::signal_msgToClientReady, this, &ServerLMSWidget::slot_msgToClientReady);
//connect(pMessangerWidget, &MessangerWidget::signal_msgToClientReady, this, &ServerLMSWidget::slot_msgToClientReady);
connect(updateController,&UpdateController::sigLogMessage,logger,&Logger::addTextToLogger);
connect(dataParser,&DataParser::sigLogMessage,logger,&Logger::addTextToLogger);
connect(processingSystem,&ProcessingSystem::sigLogMessage,logger,&Logger::addTextToLogger);
connect(processingSystem,&ProcessingSystem::sigAddToMessanger,this,&ServerLMSWidget::slotAddToMessanger,Qt::QueuedConnection);
//connect(processingSystem,&ProcessingSystem::sigAddToMessanger,this,&ServerLMSWidget::slotAddToMessanger,Qt::QueuedConnection);
connect(this,&ServerLMSWidget::sigLog,logger,&Logger::addTextToLogger);
providerDBLMS->ConnectionToDB();
on_btnStartServer_clicked();
first = true;
@@ -80,11 +86,11 @@ void ServerLMSWidget::autorizationHandler(QString login)
{
//Отмена авторизации в БД
if(pInstructorsAndTrainees->deAuthorizationTrainee(login))
if(providerDBLMS->deAuthorizationTrainee(login))
{//Деавторизовался обучаемый
}
else if(pInstructorsAndTrainees->deAuthorizationInstructor(login))
else if(providerDBLMS->deAuthorizationInstructor(login))
{//Деавторизовался инструктор
}
@@ -192,12 +198,12 @@ void ServerLMSWidget::slot_BlockAutorization(bool block)
else
unBlockAutorization();
}
/*
void ServerLMSWidget::slotAddToMessanger(QString login, QString text)
{
QString name = pInstructorsAndTrainees->getNameTraineeByLogin(login);
pMessangerWidget->addMsg(login, name, text, MessangerWidget::ETypeMsg::fromClient);
}
}*/
void ServerLMSWidget::removeClient(int idSocket)
{

View File

@@ -19,9 +19,10 @@
#include "typesDataServerClient.h"
#include "Client.h"
//#include "instructorsAndTrainees.h"
#include "instructorsandtraineeswidget.h"
#include "messangerwidget.h"
//#include "instructorsandtraineeswidget.h"
//#include "messangerwidget.h"
#include "multithreadserver.h"
#include "providerdblms.h"
namespace Ui {
class ServerLMSWidget;
@@ -41,7 +42,7 @@ class SERVERLMS_EXPORT ServerLMSWidget : public QWidget
Q_OBJECT
public:
explicit ServerLMSWidget(InstructorsAndTraineesWidget* instructorsAndTrainees, MessangerWidget* messangerWidget, QWidget *parent = nullptr);
explicit ServerLMSWidget(/*MessangerWidget* messangerWidget, */QWidget *parent = nullptr);
void autorizationHandler(QString login);
~ServerLMSWidget();
@@ -67,7 +68,7 @@ private slots:
//слот обработки сигнала о готовности нового сообщения на отправку клиенту от мессенджера
void slot_msgToClientReady(QString login, QString text);
void slotAddToLog(QString msg);
void slotAddToMessanger(QString login, QString text);
//void slotAddToMessanger(QString login, QString text);
public:
@@ -105,8 +106,8 @@ private:
EStateServer stateServer;
EStateBlockAutorization stateBlockAutorization;
InstructorsAndTraineesWidget* pInstructorsAndTrainees;
MessangerWidget* pMessangerWidget;
//InstructorsAndTraineesWidget* pInstructorsAndTrainees;
//MessangerWidget* pMessangerWidget;
QThread *updateThread;
QThread *loggerThread;
@@ -116,6 +117,8 @@ private:
UpdateController *updateController;
Logger *logger;
ProviderDBLMS* providerDBLMS;
bool first = true; // для тестов Unity
private: