refactoring

This commit is contained in:
semenov
2024-08-30 14:51:01 +03:00
parent 6a71f421fd
commit f333afe2b4
45 changed files with 592 additions and 410 deletions

View File

@@ -10,50 +10,50 @@ TCPClient::TCPClient(QObject *parent) :
socket = NULL;
}
void TCPClient::Initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter)
void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter)
{
this->recognizeSystem = recognize;
this->externalExecuter = externalExecuter;
emit onSendDebugLog(Tools::GetTime() + " Client started");
emit sigSendDebugLog(Tools::GetTime() + " Client started");
}
void TCPClient::SetConnect(ServerSettings *serverSettings)
void TCPClient::setConnect(ServerSettings *serverSettings)
{
if (socket != NULL && socket->state() == QTcpSocket::ConnectedState)
{
emit onSendDebugLog("already connected");
emit sigSendDebugLog("already connected");
return;
}
socket = new QTcpSocket(this);
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::onReadyRead,Qt::DirectConnection);
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::SetDisconnect);
connect(this,&TCPClient::Recognize,recognizeSystem,&RecognizeSystem::Recognize,Qt::DirectConnection);
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::slotReadyRead,Qt::DirectConnection);
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::setDisconnect);
connect(this,&TCPClient::sigRecognize,recognizeSystem,&RecognizeSystem::recognize,Qt::DirectConnection);
socket->connectToHost(serverSettings->Address,serverSettings->Port.toShort());
emit onSendDebugLog("Try connect...");
emit sigSendDebugLog("Try connect...");
socket->waitForReadyRead();
if(socket->state() != QTcpSocket::ConnectedState){
emit onSendDebugLog("Connect invalid");
emit ConnectionState(false);
emit sigSendDebugLog("Connect invalid");
emit sigConnectionState(false);
return;
}else{
emit onSendDebugLog("Connect complete");
emit ConnectionState(true);
emit sigSendDebugLog("Connect complete");
emit sigConnectionState(true);
}
}
void TCPClient::SendClientAutorization()
void TCPClient::sendClientAutorization()
{
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
if(socket->state() != QTcpSocket::ConnectedState){
emit ConnectionState(false);
emit sigConnectionState(false);
return;
}
@@ -66,7 +66,7 @@ void TCPClient::SendClientAutorization()
socket->waitForBytesWritten();
}
void TCPClient::SendFile()
void TCPClient::sendFile()
{
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
@@ -97,7 +97,7 @@ void TCPClient::SendFile()
countSend = 0;
}
void TCPClient::SendUnityConnect()
void TCPClient::sendUnityConnect()
{
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
@@ -105,10 +105,10 @@ void TCPClient::SendUnityConnect()
socket->waitForBytesWritten();
}
void TCPClient::SetDisconnect()
void TCPClient::setDisconnect()
{
socket->disconnect();
emit onSendDebugLog("Server disabled");
emit sigSendDebugLog("Server disabled");
}
void TCPClient::sendDisable()
@@ -117,29 +117,24 @@ void TCPClient::sendDisable()
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
QByteArray data;
data = emit signalGetXmlAnswer("END");
data = emit sigGetXmlAnswer("END");
stream << PacketType::TYPE_XMLANSWER;
stream << data;
waitWrites();
}
void TCPClient::waitWrites()
{
socket->waitForBytesWritten();
}
void TCPClient::WaitRead(int time)
void TCPClient::waitRead(int time)
{
socket->waitForReadyRead(time);
}
QTcpSocket *TCPClient::GetSocket()
QTcpSocket *TCPClient::getSocket()
{
return socket;
}
void TCPClient::MessageEntered(QString message)
void TCPClient::slotMessageEntered(QString message)
{
QDataStream stream(socket);
QByteArray data;
@@ -153,36 +148,36 @@ void TCPClient::MessageEntered(QString message)
stream << message;
socket->waitForBytesWritten();
SendFile();
emit onSendDebugLog(Tools::GetTime() + " Local checkFile sended");
sendFile();
emit sigSendDebugLog(Tools::GetTime() + " Local checkFile sended");
socket->waitForReadyRead(1000);
}
else if(message == "update"){
emit onSendDebugLog("Update started");
emit sigSendDebugLog("Update started");
stream << PacketType::TYPE_COMMAND;
stream << message;
socket->waitForBytesWritten();
}
else if(message == "run"){
externalExecuter->CallApp();
externalExecuter->callApp();
}
}else{
emit onSendDebugLog("WRONG SOCKET AFTER ENTERED");
emit sigSendDebugLog("WRONG SOCKET AFTER ENTERED");
}
}
void TCPClient::onReadyRead()
void TCPClient::slotReadyRead()
{
if(!socket){
emit onSendDebugLog("WRONG SOCKET");
emit sigSendDebugLog("WRONG SOCKET");
return;
}
// qDebug() << "Transaction before recognize: " << socket->isTransactionStarted();
// if(socket->isTransactionStarted()) return;
emit Recognize(socket);
emit sigRecognize(socket);
}
TCPClient::~TCPClient()