Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#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 begin #######
|
||||
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);
|
||||
}
|
||||
// ####### ClientMessageFactory end #######
|
||||
|
||||
|
||||
// ####### ClientMessage begin #######
|
||||
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"))
|
||||
{}
|
||||
// ####### ClientMessage end #######
|
||||
|
||||
// ####### SendBiteRequest begin #######
|
||||
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;
|
||||
}
|
||||
|
||||
} // namespace ClientMessages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#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
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The ClientMessageFactory class creates ClientMessages which will then be processed
|
||||
*/
|
||||
class ClientMessageFactory final : public LtsWebSocket::AbstractClientMessageFactory
|
||||
{
|
||||
public:
|
||||
explicit ClientMessageFactory(DataManager *dataManager);
|
||||
|
||||
/**
|
||||
* @brief create Only way to create a ClientMessage object
|
||||
* @param message Text message which will be converted to a ClientMessage object
|
||||
* @return A ClientMessage object, which represents a concrete ClientMessage
|
||||
*/
|
||||
LtsWebSocket::AbstractClientMessage *createMessage(LtsWebSocket::ReplyHandler *client,
|
||||
const QString &message);
|
||||
|
||||
private:
|
||||
DataManager *m_dataManager;
|
||||
|
||||
}; // class ClientMessageFactory
|
||||
|
||||
/**
|
||||
* @brief The ClientMessage class is an abstract base class for concrete ClientMessage objects
|
||||
*/
|
||||
class ClientMessage : public LtsWebSocket::AbstractClientMessage
|
||||
{
|
||||
protected: // method
|
||||
explicit ClientMessage(DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data = QJsonValue());
|
||||
|
||||
protected: // attributes
|
||||
DataManager *m_dataManager;
|
||||
LOGGER_T m_logger;
|
||||
}; // class ClientMessage
|
||||
|
||||
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;
|
||||
}; // class SendBiteRequest
|
||||
|
||||
} // namespace ClientMessages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ReplyMessage class is an abstract base class for all possible messages which are sent to the client
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#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
|
||||
{
|
||||
|
||||
// ####### ReplyMessage begin #######
|
||||
|
||||
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)
|
||||
{
|
||||
//we could skip the whole sub class here!
|
||||
}
|
||||
// ####### ReplyMessage end #######
|
||||
|
||||
// ####### OkMessage begin #######
|
||||
OkMessage::OkMessage(const OkMessage::OkData &data)
|
||||
: ReplyMessage(OK(), 1, data.uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({
|
||||
{MESSAGE_TYPE(), data.messageType},
|
||||
{INFO(), data.info}
|
||||
}));
|
||||
}
|
||||
// ####### OkMessage end #######
|
||||
|
||||
// ####### ErrorMessage begin #######
|
||||
ErrorMessage::ErrorMessage(const ErrorMessage::ErrorData &data)
|
||||
: ReplyMessage(ERROR_(), -1, data.uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
m_jsonRepresentation.insert(DATA(),
|
||||
QJsonObject({
|
||||
{ERROR_CLASS(), data.errorClass},
|
||||
{ERROR_MESSAGE(), data.errorMessage}
|
||||
}));
|
||||
}
|
||||
|
||||
// ####### ErrorMessage end #######
|
||||
|
||||
// ####### BiteDataMessage begin #######
|
||||
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) // Todo: Check whether typeId is correct
|
||||
{
|
||||
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}
|
||||
}));
|
||||
}
|
||||
// ####### BiteDataMessage end #######
|
||||
|
||||
PositionMessage::PositionMessage(const PositionMessage::PositionData &data, const QString &uuid)
|
||||
: ReplyMessage(POSITION_DATA(), 3, uuid) // Todo: Check whether typeId is correct
|
||||
{
|
||||
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}
|
||||
}));
|
||||
}
|
||||
|
||||
// ####### PositionMessage end #######
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The ReplyMessage class is an abstract base class for all possible messages which are sent to the client
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Fritsche, SLSE, 2017-09-07
|
||||
*/
|
||||
#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; //!< QVector requires this; don't use directly
|
||||
|
||||
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: // methods
|
||||
explicit ReplyMessage(const QString &type, const int typeId, const QString &uuid);
|
||||
|
||||
}; // class Reply Message
|
||||
|
||||
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 ErrorMessage
|
||||
|
||||
|
||||
class OkMessage final
|
||||
: public ReplyMessage
|
||||
{
|
||||
public:
|
||||
struct OkData
|
||||
{
|
||||
QString uuid;
|
||||
QString messageType;
|
||||
QString info;
|
||||
};
|
||||
|
||||
explicit OkMessage(const OkData &data);
|
||||
}; // class OkMessage
|
||||
|
||||
|
||||
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);
|
||||
}; // BiteDataMessage
|
||||
|
||||
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);
|
||||
}; // PositionsMessage
|
||||
|
||||
} // namespace Messages
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The DataManager class handles data to be send to the websocket
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#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);
|
||||
}
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The DataManager class handles data to be send to the websocket
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <LtsWebSocket/data_manager_base_dl.h>
|
||||
#include <TrainingAreaBase/tab_db.h>
|
||||
#include "logger.h"
|
||||
|
||||
namespace TrainingAreaBase
|
||||
{
|
||||
class MainHandler;
|
||||
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The DataManager class is a convenience class for managing base DL data
|
||||
*/
|
||||
class DataManager final : public LtsWebSocket::DataManagerBaseDl<DatabaseInterface>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief DataManager Constructor
|
||||
* @param mainHandler Source for needed handlers
|
||||
*/
|
||||
explicit DataManager(MainHandler *mainHandler);
|
||||
|
||||
LtsWebSocket::ReplyMessage *sendBiteRequest(const QString &uuid, int equipNo);
|
||||
|
||||
private:
|
||||
MainHandler* m_mainHandler;
|
||||
}; // class DataManager
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Header file which holds all occuring JSON keys
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <OcBaseDownload/WebSocketInterface/json_keys.h>
|
||||
|
||||
namespace TrainingAreaBase
|
||||
{
|
||||
namespace WebSocketInterface
|
||||
{
|
||||
/**
|
||||
* @brief Namespace which holds all occuring JSON keys as const QString objects
|
||||
*/
|
||||
namespace JsonKeys
|
||||
{
|
||||
inline QString DATA() { return QLatin1String("data"); }
|
||||
inline QString UUID_() { return QStringLiteral("uuid"); } // Windows: typedef GUID UUUID; ...
|
||||
inline QString TYPE() { return QStringLiteral("type"); }
|
||||
|
||||
// types for client --> server messages
|
||||
inline QString SEND_BITE_REQUEST() { return QStringLiteral("sendBiteRequest"); }
|
||||
|
||||
// types for server --> client messages
|
||||
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"); }
|
||||
|
||||
// data keys
|
||||
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"); }
|
||||
|
||||
|
||||
} // namespace JsonKeys
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#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;
|
||||
}
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for the WebSocket Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Philipp Dassow, SLST, 2017-12-05
|
||||
*/
|
||||
#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;
|
||||
|
||||
/**
|
||||
* @brief The WebSocketInterfaceHandler class is the main class for the WebSocketInterface
|
||||
*/
|
||||
class WebSocketInterfaceHandler final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* @brief WebSocketInterfaceHandler Constructor
|
||||
* @param mainHandler MainHandler to get the HandlerStructureElement from
|
||||
*/
|
||||
explicit WebSocketInterfaceHandler(MainHandler *mainHandler, QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief ~WebSocketInterfaceHandler Destructor
|
||||
*/
|
||||
~WebSocketInterfaceHandler();
|
||||
|
||||
/**
|
||||
* @brief init Initialises all needed classes for the WebSocketInterface
|
||||
* @return True on success, otherwise false
|
||||
*/
|
||||
bool init();
|
||||
|
||||
bool sendToAllClients(Messages::ReplyMessage *message);
|
||||
/**
|
||||
* @brief webSocketPort returns the listen port
|
||||
* @return listen port
|
||||
*/
|
||||
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;
|
||||
}; // class WebSocketInterfaceHandle
|
||||
|
||||
} // namespace WebSocketInterface
|
||||
} // namespace TrainingAreaBase
|
||||
Reference in new issue
Block a user