- cmake/FindRTI.cmake: Add INTERFACE placeholder targets when RTI not found - cmake/FindRTI.cmake: Force BUILD_RTI=OFF when RTI not installed - Lts/Common/LtsSession/CMakeLists.txt: Make LtsSessionDataDds conditional on BUILD_RTI - Lts/Viewer/CMakeLists.txt: Make LtsDataView conditional on BUILD_RTI - Lts/Plugins/*/CMakeLists.txt: 97 plugin files wrapped in BUILD_RTI conditionals - cmake/NGLMacros.cmake: Fix NGL_ADD_BIG_RESOURCES macro (removed premature return()) - Multiple Qt6 API fixes: QLinkedList→std::list, QStringRef→QStringView, etc. - BUILD_RTI_FIXES_SUMMARY.md: Comprehensive documentation of all fixes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
82 lines
2.1 KiB
C++
Executable File
82 lines
2.1 KiB
C++
Executable File
|
|
|
|
|
|
#include "socketreader.h"
|
|
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
|
|
#include <QtNetwork/QTcpSocket>
|
|
#include <QtCore/QTimer>
|
|
#include <QtCore/QCoreApplication>
|
|
#include <QtCore/QMetaEnum>
|
|
|
|
namespace HighLevelArchitecture {
|
|
|
|
SocketReader::SocketReader(QObject *parent)
|
|
: QThread(parent)
|
|
, m_socket(new QTcpSocket(this))
|
|
, m_hlaRequestIdentifier(0)
|
|
.getNGLLogger("SocketReader"))
|
|
{
|
|
}
|
|
|
|
bool SocketReader::init(const QString &host, quint16 port, int hlaRequestIdentifier)
|
|
{
|
|
DEBUG_LOG() << "SR " << hlaRequestIdentifier << ": Trying to establish connection to " << host << ":" << port;
|
|
|
|
m_hlaRequestIdentifier = hlaRequestIdentifier;
|
|
connect(m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
|
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
|
|
|
|
m_socket->connectToHost(host, port, QIODevice::ReadOnly);
|
|
return m_socket->waitForConnected(1000);
|
|
}
|
|
|
|
SocketReader::~SocketReader()
|
|
{
|
|
m_socket->disconnectFromHost();
|
|
|
|
if (m_socket->state() != QAbstractSocket::UnconnectedState &&
|
|
!m_socket->waitForDisconnected(1000))
|
|
m_socket->abort();
|
|
|
|
delete m_socket;
|
|
m_socket = 0;
|
|
}
|
|
|
|
void SocketReader::onReadyRead()
|
|
{
|
|
|
|
|
|
|
|
DEBUG_LOG() << "SR "<< m_hlaRequestIdentifier << ": Data received, transmitting";
|
|
QByteArray ba(m_socket->readAll());
|
|
TRACE_LOG() << "SR "<< m_hlaRequestIdentifier << ": Data contents: " << ba.constData();
|
|
emit newData(ba, m_hlaRequestIdentifier);
|
|
}
|
|
|
|
void SocketReader::stopThread()
|
|
{
|
|
QTimer::singleShot(0, this, SLOT(quit()));
|
|
while (!isFinished())
|
|
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
deleteLater();
|
|
}
|
|
|
|
void SocketReader::onSocketError(const QAbstractSocket::SocketError &error)
|
|
{
|
|
QString errorValue;
|
|
QMetaObject meta = QAbstractSocket::staticMetaObject;
|
|
for (int i=0; i < meta.enumeratorCount(); ++i) {
|
|
QMetaEnum m = meta.enumerator(i);
|
|
if (QString::fromLatin1(m.name()) == QLatin1String("SocketError")) {
|
|
errorValue = QLatin1String(m.valueToKey(error));
|
|
break;
|
|
}
|
|
}
|
|
|
|
ERROR_LOG() << "SR "<< m_hlaRequestIdentifier << ": Socket Error: " << errorValue;
|
|
}
|
|
|
|
}
|