Adds initial intermediate qt6 porting state

This commit is contained in:
torsten committed 2026-08-17 17:54:56 +02:00
1 parent 99136e9460
commit d176b5e0d7
11247 files changed
+1891537

No files matched your search

@@ -0,0 +1,66 @@
#include "client_message.h"
#include "WebSocketInterface/Messages/reply_message.h"
#include "WebSocketInterface/json_keys.h"
#include "WebSocketInterface/data_manager.h"
#include <QtCore/QJsonDocument>
#include <QtCore/QUuid>
namespace TrainingAreaBase
{
namespace WebSocketInterface
{
namespace ClientMessages
{
using namespace JsonKeys;
ClientMessageFactory::ClientMessageFactory(DataManager *dataManager)
: LtsWebSocket::AbstractClientMessageFactory(getLogger("ClientMessageFactory"))
, m_dataManager(dataManager)
{}
LtsWebSocket::AbstractClientMessage *ClientMessageFactory::createMessage(LtsWebSocket::ReplyHandler *client,
const QString &message)
{
LtsWebSocket::AbstractClientMessage *result = checkAttributes(client, message);
if (result)
return result;
if (m_type == WebSocketInterface::JsonKeys::SEND_BITE_REQUEST())
result = new SendBiteRequest(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
return checkResult(client, message, result);
}
ClientMessage::ClientMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: LtsWebSocket::AbstractClientMessage(client, type, typeId, uuid, data)
, m_dataManager(dataManager)
, m_logger(getLogger("ClientMessage"))
{}
SendBiteRequest::SendBiteRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data)
: ClientMessage(dataManager, client, type, typeId, uuid, data)
{}
void SendBiteRequest::process()
{
m_client->addReply(m_dataManager->sendBiteRequest(m_uuid, m_data.toObject().value(WebSocketInterface::JsonKeys::EQUIP_NO()).toInt()));
}
bool SendBiteRequest::hasValidData() const
{
return true;
}
}
}
}
@@ -0,0 +1,61 @@
#pragma once
#include <QtCore/QJsonObject>
#include <LtsWebSocket/client_message_factory.h>
#include <LtsWebSocket/client_message.h>
#include "logger.h"
namespace TrainingAreaBase
{
namespace WebSocketInterface
{
class DataManager;
namespace ClientMessages
{
class ClientMessageFactory final : public LtsWebSocket::AbstractClientMessageFactory
{
public:
explicit ClientMessageFactory(DataManager *dataManager);
LtsWebSocket::AbstractClientMessage *createMessage(LtsWebSocket::ReplyHandler *client,
const QString &message);
private:
DataManager *m_dataManager;
};
class ClientMessage : public LtsWebSocket::AbstractClientMessage
{
protected:
explicit ClientMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data = QJsonValue());
protected:
DataManager *m_dataManager;
LOGGER_T m_logger;
};
class SendBiteRequest : public ClientMessage
{
public:
explicit SendBiteRequest(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
void process();
bool hasValidData() const;
};
}
}
}
@@ -0,0 +1,122 @@
#include "WebSocketInterface/Messages/reply_message.h"
#include "WebSocketInterface/json_keys.h"
#include <QtCore/QUuid>
#include <QtCore/QJsonDocument>
#include <QtGlobal>
namespace TrainingAreaBase
{
namespace WebSocketInterface
{
using namespace JsonKeys;
namespace Messages
{
QString ReplyMessage::toJsonString() const
{
return QString::fromUtf8(QJsonDocument(m_jsonRepresentation).toJson(QJsonDocument::Compact));
}
ReplyMessage::ReplyMessage(const QString &type, const int typeId, const QString &uuid)
: LtsWebSocket::ReplyMessage(type, typeId, uuid)
{
}
OkMessage::OkMessage(const OkMessage::OkData &data)
: ReplyMessage(OK(), 1, data.uuid)
{
m_jsonRepresentation.insert(DATA(),
QJsonObject({
{MESSAGE_TYPE(), data.messageType},
{INFO(), data.info}
}));
}
ErrorMessage::ErrorMessage(const ErrorMessage::ErrorData &data)
: ReplyMessage(ERROR_(), -1, data.uuid)
{
m_jsonRepresentation.insert(DATA(),
QJsonObject({
{ERROR_CLASS(), data.errorClass},
{ERROR_MESSAGE(), data.errorMessage}
}));
}
QJsonObject BiteDataMessage::ErrorText::toJson() const
{
return QJsonObject({{LANG(), lang},
{_TEXT(), text}
});
}
QJsonObject BiteDataMessage::ConfigurationError::toJson() const
{
return QJsonObject({{COMPONENT_NAME(), componentName},
{_TEXT(), text}
});
}
QJsonObject BiteDataMessage::BasicError::toJson() const
{
return QJsonObject({{ERROR_TEXT(), text}});
}
QJsonObject BiteDataMessage::BiteError::toJson() const
{
return QJsonObject({{ERROR_TEXT(), vecToPath(errorTexts)},
{DEVICE_ID(), deviceId},
{SUBDEVICE(), subDevice},
{UNIQUE_ID(), uniqueId},
{ERROR_NO(), errorNo},
});
}
BiteDataMessage::BiteDataMessage(const BiteDataMessage::BiteData &data, const QString &uuid)
: ReplyMessage(BITE_DATA(), 2, uuid)
{
m_jsonRepresentation.insert(DATA(),
QJsonObject({{EQUIP_NO(), data.equipNo},
{BOX(), data.box},
{LAST_UPDATE(), data.lastUpdate},
{BITE_ERRORS(), vecToPath(data.biteErrors)},
{CONFIGURATION_ERRORS(), vecToPath(data.configurationErrors)},
{BASIC_ERRORS(), vecToPath(data.basicErrors)},
{LAST_POSITION_UPDATE(), data.lastPositionUpdate},
{IS_LICENSED(), data.isLicensed}
}));
}
PositionMessage::PositionMessage(const PositionMessage::PositionData &data, const QString &uuid)
: ReplyMessage(POSITION_DATA(), 3, uuid)
{
m_jsonRepresentation.insert(DATA(),
QJsonObject({{EQUIP_NO(), data.equipNo},
{POS_LAT(), data.pos.lat()},
{POS_LON(), data.pos.lon()},
{POS_Z(), data.pos.z()},
{LAST_POSITION_UPDATE(), data.gpsTime}
}));
}
}
}
}
@@ -0,0 +1,160 @@
#pragma once
#include <QtCore/QVector>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
#include <QtCore/QString>
#include <LtsWebSocket/reply_message.h>
#include <Core/core.hpp>
namespace TrainingAreaBase
{
namespace WebSocketInterface
{
namespace Messages
{
class ReplyMessage : public LtsWebSocket::ReplyMessage
{
public:
ReplyMessage() = default;
virtual ~ReplyMessage() = default;
virtual QString toJsonString() const;
protected:
template<typename T>
static QJsonArray vecToPath(const QVector<T> &data)
{
QJsonArray result;
for (const T &p : data)
result.append(p.toJson());
return result;
}
protected:
explicit ReplyMessage(const QString &type, const int typeId, const QString &uuid);
};
class ErrorMessage final
: public ReplyMessage
{
public:
struct ErrorData
{
int errorClass = 0;
QString uuid;
QString errorMessage;
ErrorData() = default;
explicit ErrorData(int errorClass_, const QString &uuid_, const QString &errorMessage_)
: errorClass(errorClass_)
, uuid(uuid_)
, errorMessage(errorMessage_)
{}
};
explicit ErrorMessage(const ErrorData &data);
explicit ErrorMessage(int errorClass, const QString &uuid, const QString &errorMessage)
: ErrorMessage(ErrorData(errorClass, uuid, errorMessage))
{}
};
class OkMessage final
: public ReplyMessage
{
public:
struct OkData
{
QString uuid;
QString messageType;
QString info;
};
explicit OkMessage(const OkData &data);
};
class BiteDataMessage final
: public ReplyMessage
{
public:
struct ErrorText
{
QString lang;
QString text;
QJsonObject toJson() const;
};
struct BiteError
{
QVector<ErrorText> errorTexts;
int deviceId = 0;
int subDevice = 0;
int uniqueId = 0;
int errorNo = 0;
QJsonObject toJson() const;
};
struct ConfigurationError
{
QString componentName;
QString text;
QJsonObject toJson() const;
};
struct BasicError
{
QString text;
QJsonObject toJson() const;
};
struct BiteData
{
int equipNo = 0;
int box = 0;
QString lastUpdate;
QVector<BiteError> biteErrors;
QVector<ConfigurationError> configurationErrors;
QVector<BasicError> basicErrors;
QString lastPositionUpdate;
bool isLicensed;
QJsonObject toJson() const;
};
explicit BiteDataMessage(const BiteData &data, const QString &uuid);
};
class PositionMessage final
: public ReplyMessage
{
public:
struct PositionData
{
int equipNo = 0;
Core::GeoPosition pos;
qint64 gpsTime = 0;
};
QJsonObject toJson() const;
explicit PositionMessage(const PositionData &data, const QString &uuid);
};
}
}
}
@@ -0,0 +1,43 @@
#include "data_manager.h"
#include "Messages/reply_message.h"
#include "main_handler.h"
#include "json_keys.h"
#include <ngldb/nsqlquery.h>
namespace TrainingAreaBase
{
namespace WebSocketInterface
{
static int s_requestId = 1;
DataManager::DataManager(MainHandler *mainHandler)
: LtsWebSocket::DataManagerBaseDl<DatabaseInterface>(mainHandler->db(), getLogger("DataManager"))
, m_mainHandler(mainHandler)
{}
LtsWebSocket::ReplyMessage* DataManager::sendBiteRequest(const QString &uuid, int equipNo)
{
DemandBiteRequest request;
request.equipmentNumbers().push_back(equipNo);
request.withSelfTest(true);
request.requestId(s_requestId++);
rti::core::SampleIdentity sampleIdentity;
m_mainHandler->ftsHandler()->onDemandBiteRequest(sampleIdentity, request);
Messages::OkMessage::OkData data;
data.messageType = JsonKeys::OK();
data.info = QStringLiteral("BiteRequest sent");
data.uuid = uuid;
return new Messages::OkMessage(data);
}
}
}
@@ -0,0 +1,32 @@
#pragma once
#include <LtsWebSocket/data_manager_base_dl.h>
#include <TrainingAreaBase/tab_db.h>
#include "logger.h"
namespace TrainingAreaBase
{
class MainHandler;
namespace WebSocketInterface
{
class DataManager final : public LtsWebSocket::DataManagerBaseDl<DatabaseInterface>
{
public:
explicit DataManager(MainHandler *mainHandler);
LtsWebSocket::ReplyMessage *sendBiteRequest(const QString &uuid, int equipNo);
private:
MainHandler* m_mainHandler;
};
}
}
@@ -0,0 +1,72 @@
#pragma once
#include <QString>
#include <OcBaseDownload/WebSocketInterface/json_keys.h>
namespace TrainingAreaBase
{
namespace WebSocketInterface
{
namespace JsonKeys
{
inline QString DATA() { return QLatin1String("data"); }
inline QString UUID_() { return QStringLiteral("uuid"); }
inline QString TYPE() { return QStringLiteral("type"); }
inline QString SEND_BITE_REQUEST() { return QStringLiteral("sendBiteRequest"); }
inline QString BITE_DATA() { return QStringLiteral("biteData"); }
inline QString POSITION_DATA() { return QStringLiteral("positionData"); }
inline QString OK() { return QStringLiteral("ok");}
inline QString ERROR_() { return QLatin1String("error"); }
inline QString EXERCISE_ID() { return QStringLiteral("exerciseId"); }
inline QString FILE_CATEGORY() { return QStringLiteral("fileCategory"); }
inline QString FILE_ID() { return QStringLiteral("fileId"); }
inline QString FILE_SIZE() { return QStringLiteral("fileSize"); }
inline QString FILE_STATUS() { return QStringLiteral("fileStatus"); }
inline QString FOLDER_ID() { return QStringLiteral("folderId"); }
inline QString IS_TEMPLATE() { return QStringLiteral("isTemplate"); }
inline QString NAME() { return QStringLiteral("name"); }
inline QString OPERATOR_ID() { return QStringLiteral("operatorID"); }
inline QString PHASE_ID() { return QStringLiteral("phaseId"); }
inline QString PROPERTIES() { return QStringLiteral("properties"); }
inline QString EQUIP_NO() { return QLatin1String("equipNo"); }
inline QString BOX() { return QLatin1String("box"); }
inline QString LAST_UPDATE() { return QLatin1String("lastUpdate"); }
inline QString BITE_ERRORS() { return QLatin1String("biteErrors"); }
inline QString ERROR_TEXT() { return QLatin1String("errorText"); }
inline QString LANG() { return QLatin1String("lang"); }
inline QString _TEXT() { return QLatin1String("text"); }
inline QString DEVICE_ID() { return QLatin1String("deviceId"); }
inline QString SUBDEVICE() { return QLatin1String("subdevice"); }
inline QString UNIQUE_ID() { return QLatin1String("uniqueId"); }
inline QString ERROR_NO() { return QLatin1String("errorNo"); }
inline QString CONFIGURATION_ERRORS() { return QLatin1String("configurationErrors"); }
inline QString COMPONENT_NAME() { return QLatin1String("componentName"); }
inline QString BASIC_ERRORS() { return QLatin1String("basicErrors"); }
inline QString LAST_POSITION_UPDATE() { return QLatin1String("lastPositionUpdate"); }
inline QString IS_LICENSED() { return QLatin1String("isLicensed"); }
inline QString POS_LAT() { return QLatin1String("posX"); }
inline QString POS_LON() { return QLatin1String("posY"); }
inline QString POS_Z() { return QLatin1String("posZ"); }
inline QString INFO() { return QLatin1String("info"); }
inline QString ERROR_CLASS() { return QLatin1String("errorClass"); }
inline QString ERROR_MESSAGE() { return QLatin1String("errorMessage"); }
inline QString MESSAGE_TYPE() { return QLatin1String("msgType"); }
}
}
}
@@ -0,0 +1,75 @@
#include "websocket_interface_handler.h"
#include "main_handler.h"
#include "data_manager.h"
#include "WebSocketInterface/Messages/client_message.h"
#include "WebSocketInterface/Messages/reply_message.h"
#include "settings.h"
namespace TrainingAreaBase
{
namespace WebSocketInterface
{
WebSocketInterfaceHandler::WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent)
: QObject(parent)
, m_webSocketServer(nullptr)
, m_messageFactory(nullptr)
, m_dataManager(nullptr)
, m_mainHandler(mainHandler)
, m_logger(getLogger("WebSocketInterfaceHandler"))
{
}
WebSocketInterfaceHandler::~WebSocketInterfaceHandler()
{
cleanup();
}
bool WebSocketInterfaceHandler::init()
{
cleanup();
DEBUG_LOG(m_logger) << "... ok";
m_dataManager = new DataManager(m_mainHandler);
m_messageFactory = new ClientMessages::ClientMessageFactory(m_dataManager);
m_webSocketServer = new LtsWebSocket::LtsWebSocketServer(m_messageFactory, this);
DEBUG_LOG(m_logger) << "Initialising LtsWebSocketServer";
if (!m_webSocketServer->init(QStringLiteral("TAB"), Settings::getWebSocketServerPortRange(1)))
{
ERROR_LOG(m_logger) << "Failed to initialise LtsWebSocketServer";
return false;
}
DEBUG_LOG(m_logger) << "... ok";
DEBUG_LOG(m_logger) << "Connection signals and slots";
DEBUG_LOG(m_logger) << "... ok";
return true;
}
bool WebSocketInterfaceHandler::sendToAllClients(WebSocketInterface::Messages::ReplyMessage *message)
{
if(!m_webSocketServer)
return false;
m_webSocketServer->sendToAllClients(message);
return true;
}
void WebSocketInterfaceHandler::cleanup()
{
delete m_webSocketServer;
delete m_messageFactory;
delete m_dataManager;
}
}
}
@@ -0,0 +1,61 @@
#pragma once
#include <QtCore/QObject>
#include <LtsWebSocket/lts_web_socket_server.h>
#include "logger.h"
namespace TrainingAreaBase
{
class MainHandler;
namespace WebSocketInterface
{
namespace ClientMessages
{
class ClientMessageFactory;
}
namespace Messages
{
class ReplyMessage;
}
class DataManager;
class WebSocketInterfaceHandler final : public QObject
{
Q_OBJECT
public:
explicit WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent = nullptr);
~WebSocketInterfaceHandler();
bool init();
bool sendToAllClients(Messages::ReplyMessage *message);
unsigned short serverWebSocketPort() { return m_webSocketServer->webSocketPort(); }
private:
void cleanup();
private:
LtsWebSocket::LtsWebSocketServer *m_webSocketServer;
ClientMessages::ClientMessageFactory *m_messageFactory;
DataManager *m_dataManager;
MainHandler *m_mainHandler;
LOGGER_T m_logger;
};
}
}