feat: add disconnect behaviour

This commit is contained in:
semenov
2024-09-10 17:47:52 +03:00
parent c779e3c210
commit a831e29ddc
17 changed files with 110 additions and 61 deletions

View File

@@ -31,6 +31,9 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
while(socket->bytesAvailable())
{
if (socket->state() != QTcpSocket::ConnectedState) return;
if(packetType == PacketType::TYPE_NONE){ //определение первичного пакета
stream.startTransaction();

View File

@@ -1,5 +1,5 @@
#include "tcpclient.h"
#include "updatecontroller.h"
#include "UpdateController.h"
#include "externalexecuter.h"
#include <QDir>
@@ -7,7 +7,10 @@
TCPClient::TCPClient(QObject *parent) :
QObject(parent)
{
socket = NULL;
//socket = NULL;
socket = new QTcpSocket();
socket->setParent(this);
socket->moveToThread(this->thread());
}
void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter)
@@ -15,6 +18,7 @@ void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *external
this->recognizeSystem = recognize;
this->externalExecuter = externalExecuter;
emit sigSendDebugLog(Tools::getTime() + " Client started");
}
@@ -26,8 +30,6 @@ void TCPClient::setConnect(ServerSettings *serverSettings)
return;
}
socket = new QTcpSocket(this);
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::slotReadyRead,Qt::DirectConnection);
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::setDisconnect);
connect(socket,&QTcpSocket::connected,this,&TCPClient::slotConnectNotify);
@@ -98,6 +100,7 @@ void TCPClient::sendUnityConnect()
void TCPClient::setDisconnect()
{
socket->disconnect();
emit sigServerDisconnect();
emit sigSendDebugLog("Server disabled");
}

View File

@@ -10,7 +10,7 @@
#include <QCoreApplication>
#include "Core\recognizesystem.h"
#include "Core\tools.h"
#include "Core\updatecontroller.h"
#include "Core\UpdateController.h"
#include "Core\externalexecuter.h"
class UpdateController;
@@ -37,6 +37,7 @@ signals:
void sigSendDebugLog(QString message);
void sigRecognize(QTcpSocket *socket);
void sigConnectionState(bool flag);
void sigServerDisconnect();
QByteArray sigGetXmlAnswer(QString);
public slots:

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2024-09-09T16:42:06. -->
<!-- Written by QtCreator 4.11.1, 2024-09-10T17:46:14. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<AuthData Login="O1" Password="1111" InstructorName="Администратор" ClientName="Иванов И.И." AccessType="trainee"/>
<AuthData Login="O4" Password="4444" InstructorName="Администратор" ClientName="Зайцев З.З." AccessType="trainee"/>

View File

@@ -186,7 +186,9 @@
<FileData Path="/Application/RRJLoader/RRJ_Data/ScriptingAssemblies.json" Hash="bc1156dee1f08ecf1afb66a3cbd653a9"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/sharedassets0.assets" Hash="92ce18bfb39496d9601f59fe561fcc89"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/sharedassets0.assets.resS" Hash="897317a657f377346d8932827dc78da0"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/file0.txt" Hash="6df5b19544bd9db4fe37e5e650647f86"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/file0.txt" Hash="063bcc07e60b845f3cdcb3b6c199a284"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/file1.txt" Hash="1ab8bddcb7c7f90685063b56acb2d3f9"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/file2.txt" Hash="bf4a8fdb8e3c197c08dc104cf4fff6e4"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/RRJ-95NEW-100/docs.xml" Hash="fcad1626c1ef3851931bf68a1aa054c6"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/RUS/024.31.00a.xml" Hash="e730fbd64cd77dd163732cfaf2bd0e75"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/Sounds/UI/ir_begin.wav" Hash="2e0057ee08c7b6fa07d28863a40d1cbf"/>
@@ -196,7 +198,7 @@
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/Sounds/UI/Navigation Start.wav" Hash="b82aa79f496456ffc5b952b484af25f5"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/Sounds/UI/Proximity Connection.wav" Hash="00882d550b9389c6183ee3da0b668b2d"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/StreamingAssets/Sounds/UI/Proximity Notification.wav" Hash="e15f0210410a574af39b07840ccbe4cc"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/Temp/UserData.xml" Hash="229331a9f2b42840aa928b55856e9e47"/>
<FileData Path="/Application/RRJLoader/RRJ_Data/Temp/UserData.xml" Hash="dfff243a25de3ace91512413a2908330"/>
<FileData Path="/Application/RRJLoader/UnityCrashHandler64.exe" Hash="ea440810e323f7b7ca54727cd23d068e"/>
<FileData Path="/Application/RRJLoader/UnityPlayer.dll" Hash="0486f8cc69625acdb24a62855754b228"/>
</FileDataList>

View File

@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<ClientAutorization Login="O1" Password="1111"/>
<ClientAutorization Login="O4" Password="4444"/>

Binary file not shown.

Binary file not shown.

View File

@@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_MainWindow_t {
QByteArrayData data[25];
char stringdata0[439];
QByteArrayData data[26];
char stringdata0[460];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@@ -56,7 +56,8 @@ QT_MOC_LITERAL(20, 361, 29), // "on_languageComboBox_activated"
QT_MOC_LITERAL(21, 391, 4), // "arg1"
QT_MOC_LITERAL(22, 396, 17), // "slotDisableNotify"
QT_MOC_LITERAL(23, 414, 19), // "slotConnectionState"
QT_MOC_LITERAL(24, 434, 4) // "flag"
QT_MOC_LITERAL(24, 434, 4), // "flag"
QT_MOC_LITERAL(25, 439, 20) // "slotServerDisconnect"
},
"MainWindow\0sigInitializeClient\0\0"
@@ -72,7 +73,7 @@ QT_MOC_LITERAL(24, 434, 4) // "flag"
"on_connectButton_clicked\0"
"on_languageComboBox_activated\0arg1\0"
"slotDisableNotify\0slotConnectionState\0"
"flag"
"flag\0slotServerDisconnect"
};
#undef QT_MOC_LITERAL
@@ -82,7 +83,7 @@ static const uint qt_meta_data_MainWindow[] = {
8, // revision
0, // classname
0, 0, // classinfo
14, 14, // methods
15, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@@ -90,22 +91,23 @@ static const uint qt_meta_data_MainWindow[] = {
5, // signalCount
// signals: name, argc, parameters, tag, flags
1, 2, 84, 2, 0x06 /* Public */,
7, 1, 89, 2, 0x06 /* Public */,
10, 0, 92, 2, 0x06 /* Public */,
11, 0, 93, 2, 0x06 /* Public */,
12, 1, 94, 2, 0x06 /* Public */,
1, 2, 89, 2, 0x06 /* Public */,
7, 1, 94, 2, 0x06 /* Public */,
10, 0, 97, 2, 0x06 /* Public */,
11, 0, 98, 2, 0x06 /* Public */,
12, 1, 99, 2, 0x06 /* Public */,
// slots: name, argc, parameters, tag, flags
14, 0, 97, 2, 0x08 /* Private */,
15, 0, 98, 2, 0x08 /* Private */,
16, 0, 99, 2, 0x08 /* Private */,
17, 0, 100, 2, 0x08 /* Private */,
18, 0, 101, 2, 0x08 /* Private */,
19, 0, 102, 2, 0x08 /* Private */,
20, 1, 103, 2, 0x08 /* Private */,
22, 0, 106, 2, 0x08 /* Private */,
23, 1, 107, 2, 0x08 /* Private */,
14, 0, 102, 2, 0x08 /* Private */,
15, 0, 103, 2, 0x08 /* Private */,
16, 0, 104, 2, 0x08 /* Private */,
17, 0, 105, 2, 0x08 /* Private */,
18, 0, 106, 2, 0x08 /* Private */,
19, 0, 107, 2, 0x08 /* Private */,
20, 1, 108, 2, 0x08 /* Private */,
22, 0, 111, 2, 0x08 /* Private */,
23, 1, 112, 2, 0x08 /* Private */,
25, 0, 115, 2, 0x08 /* Private */,
// signals: parameters
QMetaType::Void, 0x80000000 | 3, 0x80000000 | 5, 4, 6,
@@ -124,6 +126,7 @@ static const uint qt_meta_data_MainWindow[] = {
QMetaType::Void, QMetaType::QString, 21,
QMetaType::Void,
QMetaType::Void, QMetaType::Bool, 24,
QMetaType::Void,
0 // eod
};
@@ -148,6 +151,7 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
case 11: _t->on_languageComboBox_activated((*reinterpret_cast< const QString(*)>(_a[1]))); break;
case 12: _t->slotDisableNotify(); break;
case 13: _t->slotConnectionState((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 14: _t->slotServerDisconnect(); break;
default: ;
}
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
@@ -232,13 +236,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 14)
if (_id < 15)
qt_static_metacall(this, _c, _id, _a);
_id -= 14;
_id -= 15;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 14)
if (_id < 15)
qt_static_metacall(this, _c, _id, _a);
_id -= 14;
_id -= 15;
}
return _id;
}

Binary file not shown.

View File

@@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_TCPClient_t {
QByteArrayData data[13];
char stringdata0[158];
QByteArrayData data[14];
char stringdata0[178];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@@ -41,17 +41,18 @@ QT_MOC_LITERAL(5, 48, 11), // "QTcpSocket*"
QT_MOC_LITERAL(6, 60, 6), // "socket"
QT_MOC_LITERAL(7, 67, 18), // "sigConnectionState"
QT_MOC_LITERAL(8, 86, 4), // "flag"
QT_MOC_LITERAL(9, 91, 15), // "sigGetXmlAnswer"
QT_MOC_LITERAL(10, 107, 18), // "slotMessageEntered"
QT_MOC_LITERAL(11, 126, 17), // "slotConnectNotify"
QT_MOC_LITERAL(12, 144, 13) // "slotReadyRead"
QT_MOC_LITERAL(9, 91, 19), // "sigServerDisconnect"
QT_MOC_LITERAL(10, 111, 15), // "sigGetXmlAnswer"
QT_MOC_LITERAL(11, 127, 18), // "slotMessageEntered"
QT_MOC_LITERAL(12, 146, 17), // "slotConnectNotify"
QT_MOC_LITERAL(13, 164, 13) // "slotReadyRead"
},
"TCPClient\0sigSendDebugLog\0\0message\0"
"sigRecognize\0QTcpSocket*\0socket\0"
"sigConnectionState\0flag\0sigGetXmlAnswer\0"
"slotMessageEntered\0slotConnectNotify\0"
"slotReadyRead"
"sigConnectionState\0flag\0sigServerDisconnect\0"
"sigGetXmlAnswer\0slotMessageEntered\0"
"slotConnectNotify\0slotReadyRead"
};
#undef QT_MOC_LITERAL
@@ -61,28 +62,30 @@ static const uint qt_meta_data_TCPClient[] = {
8, // revision
0, // classname
0, 0, // classinfo
7, 14, // methods
8, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
4, // signalCount
5, // signalCount
// signals: name, argc, parameters, tag, flags
1, 1, 49, 2, 0x06 /* Public */,
4, 1, 52, 2, 0x06 /* Public */,
7, 1, 55, 2, 0x06 /* Public */,
9, 1, 58, 2, 0x06 /* Public */,
1, 1, 54, 2, 0x06 /* Public */,
4, 1, 57, 2, 0x06 /* Public */,
7, 1, 60, 2, 0x06 /* Public */,
9, 0, 63, 2, 0x06 /* Public */,
10, 1, 64, 2, 0x06 /* Public */,
// slots: name, argc, parameters, tag, flags
10, 1, 61, 2, 0x0a /* Public */,
11, 0, 64, 2, 0x0a /* Public */,
12, 0, 65, 2, 0x08 /* Private */,
11, 1, 67, 2, 0x0a /* Public */,
12, 0, 70, 2, 0x0a /* Public */,
13, 0, 71, 2, 0x08 /* Private */,
// signals: parameters
QMetaType::Void, QMetaType::QString, 3,
QMetaType::Void, 0x80000000 | 5, 6,
QMetaType::Void, QMetaType::Bool, 8,
QMetaType::Void,
QMetaType::QByteArray, QMetaType::QString, 2,
// slots: parameters
@@ -102,11 +105,12 @@ void TCPClient::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, v
case 0: _t->sigSendDebugLog((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 1: _t->sigRecognize((*reinterpret_cast< QTcpSocket*(*)>(_a[1]))); break;
case 2: _t->sigConnectionState((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 3: { QByteArray _r = _t->sigGetXmlAnswer((*reinterpret_cast< QString(*)>(_a[1])));
case 3: _t->sigServerDisconnect(); break;
case 4: { QByteArray _r = _t->sigGetXmlAnswer((*reinterpret_cast< QString(*)>(_a[1])));
if (_a[0]) *reinterpret_cast< QByteArray*>(_a[0]) = std::move(_r); } break;
case 4: _t->slotMessageEntered((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 5: _t->slotConnectNotify(); break;
case 6: _t->slotReadyRead(); break;
case 5: _t->slotMessageEntered((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 6: _t->slotConnectNotify(); break;
case 7: _t->slotReadyRead(); break;
default: ;
}
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
@@ -143,10 +147,17 @@ void TCPClient::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, v
return;
}
}
{
using _t = void (TCPClient::*)();
if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&TCPClient::sigServerDisconnect)) {
*result = 3;
return;
}
}
{
using _t = QByteArray (TCPClient::*)(QString );
if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&TCPClient::sigGetXmlAnswer)) {
*result = 3;
*result = 4;
return;
}
}
@@ -182,13 +193,13 @@ int TCPClient::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 7)
if (_id < 8)
qt_static_metacall(this, _c, _id, _a);
_id -= 7;
_id -= 8;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 7)
if (_id < 8)
qt_static_metacall(this, _c, _id, _a);
_id -= 7;
_id -= 8;
}
return _id;
}
@@ -215,11 +226,17 @@ void TCPClient::sigConnectionState(bool _t1)
}
// SIGNAL 3
void TCPClient::sigServerDisconnect()
{
QMetaObject::activate(this, &staticMetaObject, 3, nullptr);
}
// SIGNAL 4
QByteArray TCPClient::sigGetXmlAnswer(QString _t1)
{
QByteArray _t0{};
void *_a[] = { const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t0))), const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t1))) };
QMetaObject::activate(this, &staticMetaObject, 3, _a);
QMetaObject::activate(this, &staticMetaObject, 4, _a);
return _t0;
}
QT_WARNING_POP

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -67,7 +67,9 @@ void MainWindow::initialize()
connect(this,&MainWindow::sigSetConnect,client,&TCPClient::setConnect,Qt::AutoConnection);
connect(this,&MainWindow::sigSendMessage,client,&TCPClient::slotMessageEntered,Qt::AutoConnection);
connect(this,&MainWindow::sigSendClientAuthorization,client,&TCPClient::sendClientAutorization,Qt::AutoConnection);
connect(client,&TCPClient::sigConnectionState,this,&MainWindow::slotConnectionState,Qt::AutoConnection);
connect(client,&TCPClient::sigServerDisconnect,this,&MainWindow::slotServerDisconnect);
connect(this,&MainWindow::sigCalculateHash,updateController,&UpdateController::calculateHash);
@@ -135,6 +137,7 @@ void MainWindow::setNeedUpdate(bool flag,quint64 size, quint64 fileCount)
void MainWindow::lostConnection()
{
ui->loadingProgressBar->setValue(0);
slotConnectionState(false);
}
void MainWindow::checkLoginResult(ServerAuthorization *serverAuth)
@@ -229,6 +232,19 @@ void MainWindow::slotConnectionState(bool flag)
timer->start(3000);
}
void MainWindow::slotServerDisconnect()
{
ui->loadingProgressBar->hide();
ui->updateButton->hide();
ui->displayGroupWidget->hide();
ui->autostartCheckBox->hide();
ui->loginWidget->show();
ui->inlineTextDebug->setText("");
ui->updateButton->setEnabled(false);
slotConnectionState(false);
}
void MainWindow::slotDisableNotify()
{

View File

@@ -57,6 +57,8 @@ private slots:
void slotConnectionState(bool flag);
void slotServerDisconnect();
private:
Ui::MainWindow *ui;
QTranslator translator;
@@ -83,5 +85,6 @@ private:
void checkLanguage(QString language);
void autoStart();
void loadStaticData();
void bindClient();
};
#endif // MAINWINDOW_H