Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+68
@@ -0,0 +1,68 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
# Uncomment if necessary
|
||||
#ADD_SUBDIRECTORY(UnitTests)
|
||||
#ADD_SUBDIRECTORY(ModuleTests)
|
||||
|
||||
SET(xml_FILE wms_service.xml)
|
||||
|
||||
# --- Executable proxyWarehouseManagement (pWMS) -------------------------------------------------
|
||||
#
|
||||
SET(SRCS_exe
|
||||
main.cpp
|
||||
main_handler.cpp
|
||||
main_handler.h
|
||||
data_manager.cpp
|
||||
data_manager.h
|
||||
dds_handler.cpp
|
||||
dds_handler.h
|
||||
dds_handler_exercise.cpp
|
||||
dds_handler_exercise.h
|
||||
exercises_handler.cpp
|
||||
exercises_handler.h
|
||||
exercise_participant_handler.cpp
|
||||
exercise_participant_handler.h
|
||||
interface_wms2ecc_impl.cpp
|
||||
interface_wms2ecc_impl.h
|
||||
logger.cpp
|
||||
logger.h
|
||||
settings.cpp
|
||||
settings.h
|
||||
${xml_FILE}
|
||||
)
|
||||
|
||||
# Generate wms.sql, wms.xml
|
||||
CODEGEN_SQL(SRCS_exe ${xml_FILE})
|
||||
# make sure xml file is properly installed
|
||||
CODEGEN_HANDLE_SVC_XML(SRCS_exe ${xml_FILE})
|
||||
|
||||
NGL_ADD_SVC_ICON(SRCS_exe)
|
||||
NGL_ADD_EXECUTABLE(AAR SV svcWarehouseManagement ${SRCS_exe})
|
||||
NGL_TARGET_LINK_LIBRARIES(svcWarehouseManagement
|
||||
Qt5::Core
|
||||
Qt5::Network
|
||||
svcCoreClient
|
||||
svcExmClient # Read exercise topics
|
||||
svcPpmClient
|
||||
ddsconnector
|
||||
ddsQoS
|
||||
ddsdts
|
||||
ProjectConfig
|
||||
LtsCommandLineParser
|
||||
LtsWebSocketServer
|
||||
NGLLogger
|
||||
nglcoreapplication
|
||||
nglsettings
|
||||
ngltools
|
||||
Qt5::WebSockets
|
||||
wms_json_ds
|
||||
)
|
||||
NGL_INSTALL_TARGET(svcWarehouseManagement)
|
||||
NGL_INSTALL(AAR SV FILES log4cxx_wms.props DESTINATION bin)
|
||||
NGL_ADD_TARGET_LINK(svcWarehouseManagement pWMS)
|
||||
|
||||
# TODO: install link in binary, too
|
||||
+380
@@ -0,0 +1,380 @@
|
||||
/**
|
||||
* MainHandler for TetraRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
#include "data_manager.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <nglsettings/nglsettings_connections.h>
|
||||
#include <WMS_Interface/wms_ecc_equipmenttypes.h>
|
||||
#include <WMS_Interface/wms_ecc_exercises.h>
|
||||
#include <WMS_Interface/wms_ecc_playerInfo.h>
|
||||
#include <WMS_Interface/wms_ecc_registration.h>
|
||||
|
||||
#include <LtsWebSocket/json_keys.h>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
|
||||
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 == LtsWebSocket::JsonKeys::ERROR_())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error in message: " << message;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (m_type == WebSocketInterface::JsonKeys::EQUIPMENT_TYPES_REPLY())
|
||||
result = new EquipmentTypesReply(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
|
||||
|
||||
if (m_type == WebSocketInterface::JsonKeys::EXERCISES_REQUEST())
|
||||
result = new ExercisesRequest(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
|
||||
|
||||
if (m_type == WebSocketInterface::JsonKeys::PARTICIPANTS_REQUEST())
|
||||
result = new ParticipantRequest(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
|
||||
|
||||
if (m_type == WebSocketInterface::JsonKeys::PARTICIPANT_REGISTER_IN_EXCON_REQUEST())
|
||||
result = new ParticipantRegisterInExconRequest(m_dataManager, client, m_type, m_typeId, m_uuid, m_data);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "message: " << message;
|
||||
Q_ASSERT(result);
|
||||
}
|
||||
|
||||
return checkResult(client, message, result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
EquipmentTypesReply::EquipmentTypesReply(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 EquipmentTypesReply::process()
|
||||
{
|
||||
::EquipmentTypes eTypes = ::EquipmentTypes::fromJsonAll(m_data.toObject());
|
||||
m_dataManager->handleEquipmentTypes(eTypes); // send per FTC to Ppm ex_0
|
||||
}
|
||||
|
||||
|
||||
ExercisesRequest::ExercisesRequest(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 ExercisesRequest::process()
|
||||
{
|
||||
m_client->addReply(new ExerciseReply(m_dataManager->getWms2Ecc()));
|
||||
}
|
||||
|
||||
ParticipantRequest::ParticipantRequest(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 ParticipantRequest::process()
|
||||
{
|
||||
const int requestedExerciseId = m_data.toObject()[::WebSocketInterface::JsonKeys::EXERCISE_ID()].toInt();
|
||||
m_client->addReply(new ParticipantReply(m_dataManager->getWms2Ecc(), requestedExerciseId));
|
||||
}
|
||||
|
||||
ParticipantRegisterInExconRequest::ParticipantRegisterInExconRequest(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 ParticipantRegisterInExconRequest::process()
|
||||
{
|
||||
QJsonObject obj = m_data.toObject();
|
||||
|
||||
//qWarning() << "IN ParticipantRegisterInExconRequest: obj: " << obj;
|
||||
Registration reg = Registration::fromJson(obj);
|
||||
|
||||
m_dataManager->registerParticipant(reg);
|
||||
}
|
||||
|
||||
|
||||
DataManager::DataManager(const std::shared_ptr<IWMS2ECC_Impl> &wms2ecc, const std::shared_ptr<DdsHandler> &ddsHandler, const std::shared_ptr<ExercisesHandler> &exHandler)
|
||||
: QObject()
|
||||
, m_messageFactory(nullptr)
|
||||
, m_clientConnection(nullptr)
|
||||
, m_wsReconnectTimer(new QTimer(this))
|
||||
, m_wms2ecc(wms2ecc)
|
||||
, m_ddsHandler(ddsHandler)
|
||||
, m_exercisesHandler(exHandler)
|
||||
, m_logger(getLogger("MainHandler"))
|
||||
{
|
||||
connect(m_wsReconnectTimer, &QTimer::timeout,
|
||||
this, &DataManager::openWebSocket);
|
||||
|
||||
m_messageFactory = new ClientMessageFactory(this);
|
||||
DEBUG_LOG(m_logger) << "WarehouseManagement/WmsServer = " << Settings::wmsServerName();
|
||||
}
|
||||
|
||||
DataManager::~DataManager()
|
||||
{
|
||||
closeWebSocket();
|
||||
delete m_wsReconnectTimer;
|
||||
m_wsReconnectTimer = nullptr;
|
||||
|
||||
delete m_messageFactory;
|
||||
}
|
||||
|
||||
|
||||
bool DataManager::init()
|
||||
{
|
||||
QTimer::singleShot(0, this, &DataManager::openWebSocket);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DataManager::openWebSocket()
|
||||
{
|
||||
closeWebSocket();
|
||||
QWebSocket *wsSocket = new QWebSocket;
|
||||
m_clientConnection = new LtsWebSocket::ClientConnection(wsSocket, this);
|
||||
|
||||
connect(m_clientConnection, &LtsWebSocket::ClientConnection::newTextMessage,
|
||||
this, &DataManager::newTextMessageFromClient);
|
||||
|
||||
m_clientConnection->init();
|
||||
connect(wsSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
|
||||
this, &DataManager::onWebSocketError);
|
||||
connect(wsSocket, &QWebSocket::connected,
|
||||
this, &DataManager::onWebSocketConnected);
|
||||
connect(wsSocket, &QWebSocket::disconnected,
|
||||
this, &DataManager::onWebSocketDisconnected);
|
||||
|
||||
int port = NGL::Connections::port(NGL::Connections::eConnection::ZSLV);
|
||||
QString url = QStringLiteral("ws://") + Settings::wmsServerName() + QStringLiteral(":") + QString::number(port);
|
||||
wsSocket->open(QUrl::fromEncoded(url.toLocal8Bit()));
|
||||
INFO_LOG(m_logger) << "Trying to listen on " << url;
|
||||
|
||||
m_wsReconnectTimer->start(5000);
|
||||
}
|
||||
|
||||
void DataManager::closeWebSocket()
|
||||
{
|
||||
if (m_clientConnection)
|
||||
{
|
||||
m_clientConnection->disconnect(this);
|
||||
m_clientConnection->deleteLater();
|
||||
m_clientConnection = nullptr;
|
||||
}
|
||||
m_wsReconnectTimer->stop();
|
||||
}
|
||||
|
||||
void DataManager::onWebSocketError(QAbstractSocket::SocketError error)
|
||||
{
|
||||
Q_UNUSED(error)
|
||||
// TODO
|
||||
}
|
||||
|
||||
void DataManager::onWebSocketConnected()
|
||||
{
|
||||
if (m_wsReconnectTimer)
|
||||
m_wsReconnectTimer->stop(); // no reconnect - we're connected now
|
||||
|
||||
addEquipmentTypeRequest();
|
||||
sendAllExercises();
|
||||
sendAllParticipants();
|
||||
}
|
||||
|
||||
void DataManager::onWebSocketDisconnected()
|
||||
{
|
||||
if (m_wsReconnectTimer)
|
||||
m_wsReconnectTimer->start(5000);
|
||||
}
|
||||
|
||||
bool DataManager::addEquipmentTypeRequest()
|
||||
{
|
||||
if (!m_clientConnection)
|
||||
return false;
|
||||
|
||||
// should be 'addRequest' but does the same
|
||||
m_clientConnection->addReply(new EquipmentTypeRequest);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataManager::sendAllExercises()
|
||||
{
|
||||
if (!m_clientConnection)
|
||||
return false;
|
||||
|
||||
// should be 'addRequest' but does the same
|
||||
m_clientConnection->addReply(new ExerciseReply(m_wms2ecc));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataManager::sendAllParticipants()
|
||||
{
|
||||
if (!m_clientConnection)
|
||||
return false;
|
||||
|
||||
const IWMS2ECC::exerciseMap exercises = m_wms2ecc->getExercises();
|
||||
for (const IWMS2ECC::Exercise &ex : exercises)
|
||||
m_clientConnection->addReply(new ParticipantReply(m_wms2ecc, ex.id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ExerciseReply::ExerciseReply(const std::shared_ptr<IWMS2ECC_Impl> &wms2ecc)
|
||||
: LtsWebSocket::ReplyMessage(WebSocketInterface::JsonKeys::EXERCISES_REPLY(), 1, QStringLiteral("zwei")) // Todo: Check whether typeId is correct
|
||||
{
|
||||
EXCON::Exercises convert;
|
||||
convert.setExercises(wms2ecc->getExercises());
|
||||
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), convert.toJsonAll());
|
||||
}
|
||||
|
||||
ExerciseUpdate::ExerciseUpdate(const IWMS2ECC::Exercise &data, DataModification modType)
|
||||
: LtsWebSocket::ReplyMessage(WebSocketInterface::JsonKeys::EXERCISE_UPDATE(), 2, QStringLiteral("zwei")) // Todo: Check whether typeId is correct
|
||||
{
|
||||
EXCON::Exercises convert;
|
||||
QJsonObject obj = convert.toJson(data);
|
||||
obj[::WebSocketInterface::JsonKeys::DATA_MODIFICATION()] = (int)modType;
|
||||
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), obj);
|
||||
}
|
||||
|
||||
ParticipantReply::ParticipantReply(const std::shared_ptr<IWMS2ECC_Impl> &wms2ecc, int exerciseId)
|
||||
: LtsWebSocket::ReplyMessage(WebSocketInterface::JsonKeys::PARTICIPANTS_REPLY(), 3, QStringLiteral("vier")) // Todo: Check whether typeId is correct
|
||||
{
|
||||
PlayerInfo convert;
|
||||
convert.setAllPlayerInfo(wms2ecc->getAllPlayers(exerciseId));
|
||||
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), convert.toJsonAll());
|
||||
}
|
||||
|
||||
ParticipantUpdate::ParticipantUpdate(const IWMS2ECC::PlayerInfo &pl, DataModification modType)
|
||||
: LtsWebSocket::ReplyMessage(WebSocketInterface::JsonKeys::PARTICIPANTS_UPDATE(), 4, QStringLiteral("fuenf")) // Todo: Check whether typeId is correct
|
||||
{
|
||||
QJsonObject obj = PlayerInfo::toJson(pl);
|
||||
obj[::WebSocketInterface::JsonKeys::DATA_MODIFICATION()] = (int) modType;
|
||||
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), obj);
|
||||
}
|
||||
|
||||
ParticipantRegisterInExconReply::ParticipantRegisterInExconReply(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue)
|
||||
: LtsWebSocket::ReplyMessage(WebSocketInterface::JsonKeys::PARTICIPANT_REGISTER_IN_EXCON_REPLY(), 5, QStringLiteral("zwei")) // Todo: Check whether typeId is correct
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj[::WebSocketInterface::JsonKeys::EXERCISE_ID()] = exerciseId;
|
||||
obj[::WebSocketInterface::JsonKeys::PARTICIPANT_ID()] = participantId;
|
||||
obj[::WebSocketInterface::JsonKeys::REGISTRATION_RETURN_VALUE()] = (int) retValue.underlying();
|
||||
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), obj);
|
||||
}
|
||||
|
||||
void DataManager::handleEquipmentTypes(const ::EquipmentTypes &eTypes)
|
||||
{
|
||||
const IWMS2ECC::equipTypeMap equipTypeMap = eTypes.getEquipmentTypes();
|
||||
|
||||
INFO_LOG(m_logger) << "equipTypeMap size: " << equipTypeMap.size();
|
||||
ParticipantManagement::ModifyEquipmentTypeDataRequest request;
|
||||
request.deleteAll(true);
|
||||
auto &dataVec = request.data();
|
||||
dataVec.reserve(equipTypeMap.size());
|
||||
for (const IWMS2ECC::EquipmentType &et : equipTypeMap)
|
||||
{
|
||||
ParticipantManagement::EquipmentType pEt;
|
||||
pEt.id(et.id);
|
||||
pEt.name(et.name.toStdString());
|
||||
pEt.minEquipNo(et.minEquipNo);
|
||||
pEt.maxEquipNo(et.maxEquipNo);
|
||||
pEt.traPlayerTypeId(et.taPlayerTypeId);
|
||||
pEt.deletedInWms(et.deletedInWMS);
|
||||
pEt.traVulnerabilityModelId(et.taVulnerabilityModelId);
|
||||
ParticipantManagement::WmsTypeClass wmsTypeClass = static_cast<ParticipantManagement::WmsTypeClass_def::type>(et.specialType);
|
||||
pEt.wmsTypeClass(wmsTypeClass);
|
||||
dataVec.push_back(std::move(pEt));
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "dataVec size: " << dataVec.size() << ", " << request;
|
||||
|
||||
m_ddsHandler->ppmFtc()->modifyEquipmentTypeDataRequest(request, this);
|
||||
}
|
||||
|
||||
void DataManager::onModifyEquipmentTypeDataReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
if (replyObject.error())
|
||||
ERROR_LOG(m_logger) << "Error while modifying equipmentType: " << replyObject.str();
|
||||
else
|
||||
INFO_LOG(m_logger) << "onModifyEquipmentTypeDataReply ok";
|
||||
}
|
||||
|
||||
void DataManager::newTextMessageFromClient(LtsWebSocket::ClientConnection *client, const QString &message)
|
||||
{
|
||||
LtsWebSocket::AbstractClientMessage *clientMessage = nullptr;
|
||||
auto result = m_messageFactory->parseMessage(message);
|
||||
if (QJsonParseError::NoError == result.error)
|
||||
clientMessage = m_messageFactory->createMessage(client, message);
|
||||
else
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not parse incoming message: '" << message << "', error: " << result.errorString();
|
||||
clientMessage = new LtsWebSocket::InvalidMessage(client, QString(), QStringLiteral("Got message which is not JSON conform"));
|
||||
}
|
||||
|
||||
if (clientMessage)
|
||||
clientMessage->process();
|
||||
|
||||
delete clientMessage;
|
||||
}
|
||||
|
||||
void DataManager::onParticipantChanged(const ParticipantManagement::Participant &data,
|
||||
DataModification modType,
|
||||
int exerciseId)
|
||||
{
|
||||
if (!m_clientConnection || !m_wms2ecc)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "partyId: " << data.partyId() << "participantId: " << data.id();
|
||||
IWMS2ECC::PlayerInfo pl = m_wms2ecc->convert(data, exerciseId);
|
||||
pl.playerId = (exerciseId* 1000000) + pl.playerId;
|
||||
m_clientConnection->addReply(new ParticipantUpdate(pl, modType));
|
||||
}
|
||||
|
||||
void DataManager::onExerciseChanged(const ExerciseManagement::Exercise &data, DataModification modType)
|
||||
{
|
||||
if (!m_clientConnection)
|
||||
return;
|
||||
|
||||
INFO_LOG(m_logger) << "IN onExerciseChanged: ExerciseUpdate: id = " << data.id();
|
||||
IWMS2ECC::Exercise exeData = IWMS2ECC_Impl::convert(data);
|
||||
|
||||
m_clientConnection->addReply(new ExerciseUpdate(exeData, modType));
|
||||
}
|
||||
|
||||
void DataManager::onRegistrationReturnValue(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue)
|
||||
{
|
||||
m_clientConnection->addReply(new ParticipantRegisterInExconReply(exerciseId, participantId, retValue));
|
||||
}
|
||||
|
||||
void DataManager::registerParticipant(const Registration ®)
|
||||
{
|
||||
ParticipantManagement::ParticipantAssignState state = IWMS2ECC_Impl::convert(reg.getAssignment());
|
||||
INFO_LOG(m_logger) << "ParticipantAssignState: " << state;
|
||||
|
||||
INFO_LOG(m_logger) << "Registration: participant: " << reg.getPlayerId() << ", exerciseId: " << reg.getExerciseId();
|
||||
|
||||
dds::core::optional<int> equipNo;
|
||||
dds::core::optional<QString> identification;
|
||||
dds::core::optional<QString> info;
|
||||
if (reg.isEquipNoSet())
|
||||
equipNo.set(reg.getEquipNo());
|
||||
if (reg.isAliasSet())
|
||||
identification.set(reg.getAlias());
|
||||
if (reg.isInfoSet())
|
||||
info.set(reg.getInfo());
|
||||
m_exercisesHandler->registerParticipant(reg.getExerciseId(), reg.getPlayerId(), state,
|
||||
equipNo, identification, info);
|
||||
}
|
||||
} // namespace WarehouseManagement
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
/**
|
||||
* MainHandler for TetraRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "dds_handler.h"
|
||||
#include "exercises_handler.h"
|
||||
#include "interface_wms2ecc_impl.h"
|
||||
#include <WMS_Interface/json_keys.h>
|
||||
#include <ParticipantManagement/ppm_ftc.h>
|
||||
|
||||
#include "logger.h"
|
||||
#include <QWebSocket>
|
||||
#include <QTimer>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
#include <LtsWebSocket/client_connection.h>
|
||||
#include <LtsWebSocket/client_message_factory.h>
|
||||
|
||||
class EquipmentTypes;
|
||||
class Registration;
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
class DataManager;
|
||||
/**
|
||||
* @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
|
||||
|
||||
class ClientMessage : public LtsWebSocket::AbstractClientMessage
|
||||
{
|
||||
protected: // method
|
||||
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)
|
||||
{}
|
||||
|
||||
protected: // attributes
|
||||
DataManager *m_dataManager;
|
||||
}; // class ClientMessage
|
||||
|
||||
class EquipmentTypesReply final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit EquipmentTypesReply (DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
|
||||
|
||||
void process() override;
|
||||
bool hasValidData() const override { return true; }
|
||||
}; // class EquipmentTypesReply
|
||||
|
||||
class ExercisesRequest final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit ExercisesRequest (DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
|
||||
|
||||
void process() override;
|
||||
bool hasValidData() const override { return true; }
|
||||
}; // class ExercisesRequest
|
||||
|
||||
class ParticipantRequest final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit ParticipantRequest (DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
|
||||
|
||||
void process() override;
|
||||
bool hasValidData() const override { return true; }
|
||||
}; // class ParticipantRequest
|
||||
|
||||
|
||||
|
||||
class EquipmentTypeRequest : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
EquipmentTypeRequest()
|
||||
: LtsWebSocket::ReplyMessage(WebSocketInterface::JsonKeys::EQUIPMENT_TYPES_REQUEST(), 1, QStringLiteral("eins"))
|
||||
{}
|
||||
};
|
||||
|
||||
class ExerciseReply : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit ExerciseReply(const std::shared_ptr<IWMS2ECC_Impl> &wms2ecc);
|
||||
};
|
||||
|
||||
class ExerciseUpdate : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit ExerciseUpdate(const IWMS2ECC::Exercise &data, DataModification modType);
|
||||
};
|
||||
|
||||
class ParticipantReply : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit ParticipantReply(const std::shared_ptr<IWMS2ECC_Impl> &wms2ecc, int exerciseId);
|
||||
|
||||
};
|
||||
|
||||
class ParticipantUpdate : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit ParticipantUpdate(const IWMS2ECC::PlayerInfo &pl, DataModification modType);
|
||||
};
|
||||
|
||||
class ParticipantRegisterInExconRequest final : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit ParticipantRegisterInExconRequest (DataManager *dataManager, LtsWebSocket::ReplyHandler *client, const QString &type, const int typeId, const QString &uuid, const QJsonValue &data);
|
||||
|
||||
void process() override;
|
||||
bool hasValidData() const override { return true; }
|
||||
}; // class ParticipantRegisterInExconRequest
|
||||
|
||||
|
||||
class ParticipantRegisterInExconReply : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit ParticipantRegisterInExconReply(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class DataManager : public QObject
|
||||
, ParticipantManagement::Interface::Ftc::ModifyEquipmentTypeDataReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DataManager(const std::shared_ptr<IWMS2ECC_Impl> &wms2ecc, const std::shared_ptr<DdsHandler> &ddsHandler, const std::shared_ptr<ExercisesHandler> &exHandler);
|
||||
~DataManager();
|
||||
|
||||
bool init();
|
||||
|
||||
std::shared_ptr<IWMS2ECC_Impl> getWms2Ecc() { return m_wms2ecc; }
|
||||
void handleEquipmentTypes(const ::EquipmentTypes &eTypes);
|
||||
void registerParticipant(const Registration ®);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType, int exerciseId);
|
||||
void onExerciseChanged(const ExerciseManagement::Exercise &data, DataModification modType);
|
||||
void onRegistrationReturnValue(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue);
|
||||
|
||||
private Q_SLOTS:
|
||||
void openWebSocket();
|
||||
void closeWebSocket();
|
||||
void onWebSocketError(QAbstractSocket::SocketError error);
|
||||
void onWebSocketConnected();
|
||||
void onWebSocketDisconnected();
|
||||
|
||||
bool addEquipmentTypeRequest();
|
||||
bool sendAllExercises();
|
||||
bool sendAllParticipants();
|
||||
void newTextMessageFromClient(LtsWebSocket::ClientConnection *client, const QString &message);
|
||||
void onModifyEquipmentTypeDataReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
|
||||
private:
|
||||
|
||||
ClientMessageFactory *m_messageFactory;
|
||||
LtsWebSocket::ClientConnection *m_clientConnection;
|
||||
QTimer *m_wsReconnectTimer;
|
||||
std::shared_ptr<IWMS2ECC_Impl> m_wms2ecc;
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler;
|
||||
std::shared_ptr<ExercisesHandler> m_exercisesHandler;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace WarehouseManagement
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* DdsHandler for DDS
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
|
||||
#include "dds_handler.h"
|
||||
|
||||
#include <DDS/Core/pacemaker.h>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
|
||||
DdsHandler::DdsHandler(int domainId)
|
||||
: m_ddsConnector(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Global, 0))
|
||||
, m_logger(getLogger("DdsHandler"))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "DdsHandler(" << domainId << ") for partition: " << m_ddsConnector->getDefaultPartition();
|
||||
}
|
||||
|
||||
bool DdsHandler::init(const QStringList &qosFileList)
|
||||
{
|
||||
if (!m_ddsConnector->init(qosFileList))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error initializing dds connections - aborting";
|
||||
return false;
|
||||
}
|
||||
|
||||
// default initialize Publisher and Subscriber
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
|
||||
// Pacemaker
|
||||
m_pacemaker = std::make_shared<Core::Pacemaker>(m_ddsConnector);
|
||||
|
||||
m_exmDtc = ExerciseManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bool bRet = m_exmDtc->enableExercise();
|
||||
INFO_LOG(m_logger) << "Exm dtc initialised";
|
||||
|
||||
m_ppmDtc = ParticipantManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bRet &= m_ppmDtc->enableType();
|
||||
bRet &= m_ppmDtc->enableParty();
|
||||
|
||||
m_ppmFtc = ParticipantManagement::Interface::Ftc::create(m_ddsConnector);
|
||||
bRet &= m_ppmFtc->enableModifyEquipmentTypeData();
|
||||
|
||||
m_pacemaker->setNewState(Core::RunningState::inner_enum::Starting);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
} // Namespace WarehouseManagement
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* DdsHandler for DDS
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <ExerciseManagement/exm_dtc.h>
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
#include <ParticipantManagement/ppm_ftc.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace Core
|
||||
{
|
||||
class Pacemaker;
|
||||
namespace Interface
|
||||
{
|
||||
class Dts;
|
||||
}
|
||||
}
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
/**
|
||||
* @brief DdsHandler for Ex_0 partition
|
||||
* All other handlers are created on demand and they're using the
|
||||
* domain participant from this (main) DdsHandler
|
||||
*/
|
||||
class DdsHandler
|
||||
{
|
||||
public:
|
||||
explicit DdsHandler(int domainId);
|
||||
|
||||
bool init(const QStringList &qosFileList = QStringList());
|
||||
|
||||
std::shared_ptr<Core::Pacemaker> pacemaker() const { return m_pacemaker; }
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> exmDtc() const { return m_exmDtc; }
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> ppmDtc() const { return m_ppmDtc; }
|
||||
std::shared_ptr<ParticipantManagement::Interface::Ftc> ppmFtc() const { return m_ppmFtc; }
|
||||
std::shared_ptr<DDSConnector::DdsConnector> dds() const { return m_ddsConnector; }
|
||||
dds::domain::DomainParticipant getDomainParticipant() const { return m_ddsConnector->getDomainParticipant(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
|
||||
std::shared_ptr<Core::Pacemaker> m_pacemaker;
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ppmFtc;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* DdsHandler for DDS
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
|
||||
#include "dds_handler_exercise.h"
|
||||
|
||||
#include <DDS/Core/pacemaker.h>
|
||||
#include <dds/domain/DomainParticipant.hpp>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
|
||||
DdsHandlerExercise::DdsHandlerExercise(const dds::domain::DomainParticipant &dp, int exerciseId)
|
||||
: m_ddsConnector(new DDSConnector::DdsConnector(dp, IDL::PartitionType::Exercise, exerciseId))
|
||||
, m_logger(getLogger("DdsHandlerExercise"))
|
||||
{
|
||||
m_ddsConnector->setDomainParticipant(dp);
|
||||
DEBUG_LOG(m_logger) << "DdsHandlerExercise for partition: " << m_ddsConnector->getDefaultPartition();
|
||||
}
|
||||
|
||||
bool DdsHandlerExercise::init(const QStringList &qosFileList)
|
||||
{
|
||||
if (!m_ddsConnector->init(qosFileList))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error initializing dds connections - aborting";
|
||||
return false;
|
||||
}
|
||||
|
||||
// default initialize Publisher and Subscriber
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
|
||||
m_ppmDtc = ParticipantManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bool bRet = m_ppmDtc->enableParty() &&
|
||||
m_ppmDtc->enableParticipant();
|
||||
|
||||
m_ppmFtc = ParticipantManagement::Interface::Ftc::create(m_ddsConnector);
|
||||
bRet &= m_ppmFtc->enableRegisterParticipant();
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
} // Namespace WarehouseManagement
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* DdsHandler for DDS
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
#include <ParticipantManagement/ppm_ftc.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
using PpmDtc = std::shared_ptr<ParticipantManagement::Interface::Dtc>;
|
||||
using PpmFtc = std::shared_ptr<ParticipantManagement::Interface::Ftc>;
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
/**
|
||||
* @brief DdsHandler for Ex_N partition
|
||||
* The DomainParticipant must be given from the outside (e.g. from the ex_0 handler)
|
||||
*/
|
||||
class DdsHandlerExercise
|
||||
{
|
||||
public:
|
||||
DdsHandlerExercise(const dds::domain::DomainParticipant &dp, int exerciseId);
|
||||
|
||||
bool init(const QStringList &qosFileList = QStringList());
|
||||
|
||||
PpmDtc ppmDtc() const
|
||||
{
|
||||
return m_ppmDtc;
|
||||
}
|
||||
|
||||
PpmFtc ppmFtc() const
|
||||
{
|
||||
return m_ppmFtc;
|
||||
}
|
||||
|
||||
int getExerciseId() const
|
||||
{
|
||||
return m_ddsConnector->getPartitionId();
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
|
||||
PpmDtc m_ppmDtc;
|
||||
PpmFtc m_ppmFtc;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
/**
|
||||
* Exercises Handler - checks the avilable exercises and creates subhandlers fort each of them
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
|
||||
#include "exercise_participant_handler.h"
|
||||
#include "exercises_handler.h"
|
||||
#include "dds_handler_exercise.h"
|
||||
|
||||
using namespace WarehouseManagement;
|
||||
|
||||
ExerciseParticipantHandler::ExerciseParticipantHandler(const dds::domain::DomainParticipant &domainParticipant,
|
||||
int exerciseId,
|
||||
ExercisesHandler *exercisesHandler)
|
||||
: m_exerciseId(exerciseId)
|
||||
, m_ddsHandlerExercise(new DdsHandlerExercise(domainParticipant, exerciseId))
|
||||
, m_exercisesHandler(exercisesHandler)
|
||||
, m_logger(getLogger(QLatin1String("ExerciseParticipantHandler.") + QString::number(exerciseId)))
|
||||
{}
|
||||
|
||||
ExerciseParticipantHandler::~ExerciseParticipantHandler()
|
||||
{
|
||||
m_ddsHandlerExercise.reset();
|
||||
}
|
||||
|
||||
bool ExerciseParticipantHandler::init()
|
||||
{
|
||||
if (!m_ddsHandlerExercise->init())
|
||||
return false;
|
||||
|
||||
auto cbParty = [this](const ParticipantManagement::Party &party)
|
||||
{
|
||||
onPartyChanged(party, DataModification::eAdded);
|
||||
};
|
||||
m_ddsHandlerExercise->ppmDtc()->partys(cbParty);
|
||||
|
||||
auto cpParticipant = [this](const ParticipantManagement::Participant &participant)
|
||||
{
|
||||
onParticipantChanged(participant, DataModification::eAdded);
|
||||
};
|
||||
m_ddsHandlerExercise->ppmDtc()->participants(cpParticipant);
|
||||
|
||||
|
||||
connect(m_ddsHandlerExercise->ppmDtc().get(), &ParticipantManagement::Interface::Dtc::participantChanged,
|
||||
this, &ExerciseParticipantHandler::onParticipantChanged);
|
||||
connect(m_ddsHandlerExercise->ppmDtc().get(), &ParticipantManagement::Interface::Dtc::partyChanged,
|
||||
this, &ExerciseParticipantHandler::onPartyChanged);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ParticipantManagement::Party ExerciseParticipantHandler::getParty(int partyId) const
|
||||
{
|
||||
return m_partyMap.value(partyId);
|
||||
}
|
||||
|
||||
QString ExerciseParticipantHandler::getHierarchyFromParticipant(int participantId, const QMap<int, ParticipantManagement::Participant> &allParticipants) const
|
||||
{
|
||||
return allParticipants.isEmpty() ?
|
||||
m_ddsHandlerExercise->ppmDtc()->hierarchyFromParticipant(participantId) :
|
||||
m_ddsHandlerExercise->ppmDtc()->hierarchyFromParticipant(participantId, allParticipants);
|
||||
}
|
||||
|
||||
ParticipantManagement::Participant ExerciseParticipantHandler::getParticipant(int participantId) const
|
||||
{
|
||||
return m_ddsHandlerExercise->ppmDtc()->participant(participantId);
|
||||
}
|
||||
|
||||
QMap<qint32, ParticipantManagement::Participant> ExerciseParticipantHandler::getParticipants() const
|
||||
{
|
||||
return m_ddsHandlerExercise->ppmDtc()->participants();
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::registerParticipant(qint32 participantId,
|
||||
ParticipantManagement::ParticipantAssignState assignState,
|
||||
const dds::core::optional<int> &equipNo,
|
||||
const dds::core::optional<QString> &identification,
|
||||
const dds::core::optional<QString> &info)
|
||||
{
|
||||
ParticipantManagement::RegisterParticipantRequest req;
|
||||
req.assignState(assignState);
|
||||
|
||||
if (equipNo.is_set())
|
||||
req.equipmentNumber(equipNo.get());
|
||||
if (identification.is_set())
|
||||
req.identification(identification.get().toStdString());
|
||||
if (info.is_set())
|
||||
req.info(info.get().toStdString());
|
||||
if (!equipNo.is_set() || !info.is_set() || !identification.is_set())
|
||||
{
|
||||
const auto participant = m_ddsHandlerExercise->ppmDtc()->participant(participantId);
|
||||
if (!equipNo.is_set() && participant.equipmentNumber().is_set())
|
||||
req.equipmentNumber(participant.equipmentNumber().get());
|
||||
if (!info.is_set())
|
||||
req.info(participant.info());
|
||||
if (!identification.is_set())
|
||||
req.identification(participant.identification());
|
||||
}
|
||||
req.participantId(participantId);
|
||||
|
||||
INFO_LOG(m_logger) << "IN ::registerParticipant, ParticipantId: " << participantId
|
||||
<< ", equipNo: " << equipNo << ", assignState: " << assignState;
|
||||
|
||||
m_ddsHandlerExercise->ppmFtc()->registerParticipantRequest(req, this);
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::onRegisterParticipantReply(const ParticipantManagement::RegisterReply &reply)
|
||||
{
|
||||
INFO_LOG(m_logger) << "RegisterReply id " << reply.id()
|
||||
<< " - registerReturnValue: " << reply.registerReturnValue()
|
||||
<< " for exercise " << reply.exerciseId();
|
||||
|
||||
// TODO: better idea please :)
|
||||
Core::FunctionReplyObject fro;
|
||||
fro.setStr(reply.errorString().c_str());
|
||||
for (const auto &arg : reply.errorParams())
|
||||
fro = fro.arg(arg);
|
||||
// send data via signal
|
||||
|
||||
emit registrationReturnValue(reply.exerciseId(), reply.id(), reply.registerReturnValue());
|
||||
|
||||
if (fro.error())
|
||||
ERROR_LOG(m_logger) << "Error: " << fro();
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::participantAdded(const ParticipantManagement::Participant &participant)
|
||||
{
|
||||
// check if participant has equipment number
|
||||
if (!participant.equipmentNumber().is_set() || participant.equipmentNumber().get() == 0)
|
||||
{
|
||||
// no -> all ok
|
||||
INFO_LOG(m_logger) << "New participant but no equipment number - ignoring";
|
||||
return;
|
||||
}
|
||||
addParticipant(participant.id(), participant.equipmentNumber().get());
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::participantModified(const ParticipantManagement::Participant &participant)
|
||||
{
|
||||
// what can happen:
|
||||
// - 1: participant is not in our map
|
||||
// - 1.1: participant has no equipment number -> ignore
|
||||
// - 1.2: participant has equipment number -> add participant to our map
|
||||
// - 2_ participant is in our map -> participant had an equipment number
|
||||
// - 2.1: participant has same equipment number -> ignore
|
||||
// - 2.2: participant has no longer an equipment number -> remove participant from our map
|
||||
// - 2.3: participant has other equipment number -> modify participant for new equipment number
|
||||
|
||||
const auto itEquipNumber = m_participantId2EquipmentNumber.constFind(participant.id());
|
||||
if (itEquipNumber == m_participantId2EquipmentNumber.constEnd())
|
||||
{
|
||||
// 1: participant is not in our map
|
||||
// no entry for this participant in our map ...
|
||||
if (!participant.equipmentNumber().is_set() || participant.equipmentNumber() == 0)
|
||||
{
|
||||
// 1.1: participant has no equipment number -> ignore
|
||||
return;
|
||||
}
|
||||
// 1.2: participant has equipment number -> add participant to our map
|
||||
addParticipant(participant.id(), participant.equipmentNumber().get());
|
||||
return;
|
||||
}
|
||||
|
||||
// 2: participant is in our map -> participant had an equipment number
|
||||
if (itEquipNumber.value() == participant.equipmentNumber())
|
||||
{
|
||||
// 2.1: participant has same equipment number -> ignore
|
||||
return;
|
||||
}
|
||||
if (participant.equipmentNumber().is_set())
|
||||
{
|
||||
INFO_LOG(m_logger) << "Participant with id " << participant.id() << " changed its equipment number from "
|
||||
<< itEquipNumber.value() << " to " << participant.equipmentNumber().get();
|
||||
}
|
||||
|
||||
if (participant.equipmentNumber() == 0)
|
||||
{
|
||||
// 2.2: participant has no longer an equipment number -> remove participant from our map
|
||||
removeParticipant(participant.id(), participant.equipmentNumber().get());
|
||||
return;
|
||||
}
|
||||
|
||||
// 2.3: participant has other equipment number -> modify participant for new equipment number
|
||||
removeParticipant(itEquipNumber.key(), itEquipNumber.value());
|
||||
if (participant.equipmentNumber().is_set())
|
||||
addParticipant(participant.id(), participant.equipmentNumber().get());
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::participantRemoved(const ParticipantManagement::Participant &participant)
|
||||
{
|
||||
// check if participant is in our map
|
||||
const auto itEquipNumber = m_participantId2EquipmentNumber.find(participant.id());
|
||||
if (itEquipNumber == m_participantId2EquipmentNumber.end())
|
||||
{
|
||||
// no -> all ok
|
||||
INFO_LOG(m_logger) << "Participant was removed but has no equipment number - ignoring";
|
||||
return;
|
||||
}
|
||||
removeParticipant(itEquipNumber.key(), itEquipNumber.value());
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::emitChangedForInferiors(const ParticipantManagement::Participant &participant)
|
||||
{
|
||||
for (const int inferior : participant.inferiorIds())
|
||||
{
|
||||
const auto inf = m_ddsHandlerExercise->ppmDtc()->participant(inferior);
|
||||
if (inf.id() != 0)
|
||||
emit participantChanged(inf, DataModification::eModified, m_exerciseId);
|
||||
emitChangedForInferiors(inf);
|
||||
}
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::addParticipant(int participantId, int equipmentNumber)
|
||||
{
|
||||
m_participantId2EquipmentNumber.insert(participantId, equipmentNumber);
|
||||
|
||||
ParticipantInfoStruct pis;
|
||||
pis.equipmentNumber = equipmentNumber;
|
||||
pis.participantId = participantId;
|
||||
pis.exerciseId = m_ddsHandlerExercise->getExerciseId();
|
||||
|
||||
m_exercisesHandler->addParticipant(pis);
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::removeParticipant(int participantId, int equipmentNumber)
|
||||
{
|
||||
m_participantId2EquipmentNumber.remove(participantId);
|
||||
|
||||
ParticipantInfoStruct pis;
|
||||
pis.equipmentNumber = equipmentNumber;
|
||||
pis.participantId = participantId;
|
||||
pis.exerciseId = m_ddsHandlerExercise->getExerciseId();
|
||||
|
||||
m_exercisesHandler->removeParticipant(pis);
|
||||
}
|
||||
|
||||
|
||||
void ExerciseParticipantHandler::onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType)
|
||||
{
|
||||
switch (modType)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
participantAdded(data);
|
||||
break;
|
||||
case DataModification::eModified:
|
||||
participantModified(data);
|
||||
break;
|
||||
case DataModification::eRemoved:
|
||||
participantRemoved(data);
|
||||
break;
|
||||
}
|
||||
emit participantChanged(data, modType, m_exerciseId);
|
||||
emitChangedForInferiors(data);
|
||||
}
|
||||
|
||||
void ExerciseParticipantHandler::onPartyChanged(const ParticipantManagement::Party &data, DataModification modType)
|
||||
{
|
||||
switch (modType)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
case DataModification::eModified:
|
||||
m_partyMap[data.id()] = data;
|
||||
break;
|
||||
case DataModification::eRemoved:
|
||||
m_partyMap.remove(data.id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Exercise Handler - checks the avilable exercises and creates subhandlers fort each of them
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include "dds_handler_exercise.h"
|
||||
|
||||
#include <ParticipantManagement/ppm_ftc.h>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
class ExercisesHandler;
|
||||
class ExerciseParticipantHandler : public QObject,
|
||||
protected ParticipantManagement::Interface::Ftc::RegisterParticipantReplyHandler
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
ExerciseParticipantHandler(const dds::domain::DomainParticipant &domainParticipant,
|
||||
int exerciseId,
|
||||
ExercisesHandler *exercisesHandler);
|
||||
~ExerciseParticipantHandler();
|
||||
|
||||
bool init();
|
||||
ParticipantManagement::Party getParty(int partyId) const;
|
||||
QString getHierarchyFromParticipant(int participantId, const QMap<int, ParticipantManagement::Participant> &allParticipants) const;
|
||||
QMap<qint32, ParticipantManagement::Participant> getParticipants() const;
|
||||
ParticipantManagement::Participant getParticipant(int participantId) const;
|
||||
|
||||
void registerParticipant(qint32 participantId,
|
||||
ParticipantManagement::ParticipantAssignState assignState,
|
||||
const dds::core::optional<int> &equipNo,
|
||||
const dds::core::optional<QString> &identification,
|
||||
const dds::core::optional<QString> &info);
|
||||
|
||||
Q_SIGNALS:
|
||||
void registrationReturnValue(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue);
|
||||
void participantChanged(const ParticipantManagement::Participant&, DataModification modType, int exerciseId);
|
||||
|
||||
private:
|
||||
void participantAdded(const ParticipantManagement::Participant &participant);
|
||||
void participantModified(const ParticipantManagement::Participant &participant);
|
||||
void participantRemoved(const ParticipantManagement::Participant &participant);
|
||||
void emitChangedForInferiors(const ParticipantManagement::Participant &participant);
|
||||
|
||||
void addParticipant(int participantId, int equipmentNumber);
|
||||
void removeParticipant(int participantId, int equipmentNumber);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType);
|
||||
void onPartyChanged(const ParticipantManagement::Party &data, DataModification modType);
|
||||
void onRegisterParticipantReply(const ParticipantManagement::RegisterReply &reply) override final;
|
||||
|
||||
private:
|
||||
int m_exerciseId;
|
||||
std::shared_ptr<DdsHandlerExercise> m_ddsHandlerExercise; // for the specific exercise
|
||||
ExercisesHandler *m_exercisesHandler;
|
||||
// QMultiMap<participantId, equipmentId>
|
||||
QHash<int, int> m_participantId2EquipmentNumber;
|
||||
QHash<int, ParticipantManagement::Party> m_partyMap;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
} // namespace WarehouseManagement
|
||||
+286
@@ -0,0 +1,286 @@
|
||||
/**
|
||||
* Exercises Handler - checks the avilable exercises and creates subhandlers fort each of them
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
|
||||
#include "exercises_handler.h"
|
||||
#include "exercise_participant_handler.h"
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
|
||||
ExercisesHandler::ExercisesHandler(const std::shared_ptr<DdsHandler> &ddsHandler)
|
||||
: m_ddsHandler(ddsHandler)
|
||||
, m_logger(getLogger("ExercisesHandler"))
|
||||
{}
|
||||
|
||||
ExercisesHandler::~ExercisesHandler()
|
||||
{
|
||||
qDeleteAll(m_exerciseHandler);
|
||||
}
|
||||
|
||||
bool ExercisesHandler::init()
|
||||
{
|
||||
connect(m_ddsHandler->exmDtc().get(), &ExerciseManagement::Interface::Dtc::exerciseChanged,
|
||||
this, &ExercisesHandler::onExerciseChanged);
|
||||
|
||||
auto cb = [this](const ExerciseManagement::Exercise &exercise)
|
||||
{
|
||||
exerciseAdded(exercise.id());
|
||||
};
|
||||
m_ddsHandler->exmDtc()->exercises(cb);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QMap<qint32, ExerciseManagement::Exercise> ExercisesHandler::getExercises() const
|
||||
{
|
||||
INFO_LOG(m_logger) << "IN getExercises";
|
||||
m_ddsHandler->exmDtc()->waitForHistoricalDataExercise();
|
||||
return m_ddsHandler->exmDtc()->exercises();
|
||||
}
|
||||
|
||||
ParticipantManagement::Type ExercisesHandler::participantType(int typeId) const
|
||||
{
|
||||
m_ddsHandler->ppmDtc()->waitForHistoricalDataType();
|
||||
return m_ddsHandler->ppmDtc()->type(typeId);
|
||||
}
|
||||
|
||||
ParticipantManagement::TypeClass ExercisesHandler::typeClassIdFromEquipmentTypeId(int equipTypeId) const
|
||||
{
|
||||
m_ddsHandler->ppmDtc()->waitForHistoricalDataType();
|
||||
ParticipantManagement::TypeClass ret = ParticipantManagement::TypeClass::Unknown;
|
||||
std::function<bool(const ParticipantManagement::Type &data)> cb =
|
||||
[equipTypeId, &ret](const ParticipantManagement::Type &t) -> bool
|
||||
{
|
||||
if (t.equipmentTypeId() != equipTypeId)
|
||||
return false;
|
||||
ret = t.typeClass();
|
||||
return true;
|
||||
};
|
||||
m_ddsHandler->ppmDtc()->types(cb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ParticipantManagement::Party ExercisesHandler::getParty(int partyId, int exerciseId) const
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "getParty: " << partyId << ", exId: " << exerciseId;
|
||||
auto it = m_exerciseHandler.find(exerciseId);
|
||||
if (it == m_exerciseHandler.end())
|
||||
return ParticipantManagement::Party();
|
||||
|
||||
return it.value()->getParty(partyId);
|
||||
}
|
||||
|
||||
QString ExercisesHandler::getHierarchyFromParticipant(int participantId, int exerciseId, const QMap<int, ParticipantManagement::Participant> &allParticipants) const
|
||||
{
|
||||
auto it = m_exerciseHandler.find(exerciseId);
|
||||
if (it == m_exerciseHandler.end())
|
||||
return QString();
|
||||
|
||||
return it.value()->getHierarchyFromParticipant(participantId, allParticipants);
|
||||
}
|
||||
ParticipantManagement::Participant ExercisesHandler::getParticipant(int participantId, int exerciseId) const
|
||||
{
|
||||
auto it = m_exerciseHandler.find(exerciseId);
|
||||
if (it == m_exerciseHandler.end())
|
||||
return ParticipantManagement::Participant();
|
||||
|
||||
return it.value()->getParticipant(participantId);
|
||||
}
|
||||
|
||||
QMap<qint32, ParticipantManagement::Participant> ExercisesHandler::getParticipants(int exerciseId) const
|
||||
{
|
||||
auto it = m_exerciseHandler.find(exerciseId);
|
||||
if (it == m_exerciseHandler.end())
|
||||
return QMap<qint32, ParticipantManagement::Participant>();
|
||||
|
||||
return it.value()->getParticipants();
|
||||
}
|
||||
|
||||
bool ExercisesHandler::registerParticipant(int exerciseId, qint32 participantId,
|
||||
ParticipantManagement::ParticipantAssignState assignState,
|
||||
const dds::core::optional<int> &equipNo,
|
||||
const dds::core::optional<QString> &identification,
|
||||
const dds::core::optional<QString> &info)
|
||||
{
|
||||
auto it = m_exerciseHandler.find(exerciseId);
|
||||
if (it == m_exerciseHandler.end())
|
||||
return false;
|
||||
it.value()->registerParticipant(participantId, assignState, equipNo, identification, info);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExercisesHandler::unregisterParticipant(int exerciseId, qint32 equipNo)
|
||||
{
|
||||
if (!m_exerciseHandler.contains(exerciseId))
|
||||
return false;
|
||||
|
||||
if (!m_participants.contains(equipNo))
|
||||
return false;
|
||||
|
||||
const QList<ParticipantInfoStruct> listPis = m_participants.values(equipNo);
|
||||
|
||||
qint32 participantId = -1;
|
||||
for(ParticipantInfoStruct pis : listPis)
|
||||
{
|
||||
if (pis.exerciseId != exerciseId)
|
||||
continue;
|
||||
|
||||
participantId = pis.participantId;
|
||||
}
|
||||
|
||||
if (participantId == -1)
|
||||
return false;
|
||||
|
||||
// NotAssigned with equipNo 0
|
||||
ParticipantManagement::ParticipantAssignState assignState = ParticipantManagement::ParticipantAssignState_def::NotAssigned;
|
||||
|
||||
m_exerciseHandler.value(exerciseId)->registerParticipant(participantId, assignState, 0, {}, {});
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExercisesHandler::modifyEquipmentTypes(const std::vector<ParticipantManagement::EquipmentType> &vectorEquipTypes)
|
||||
{
|
||||
ParticipantManagement::ModifyEquipmentTypeDataRequest req;
|
||||
|
||||
req.data(vectorEquipTypes);
|
||||
req.deleteAll(true);
|
||||
return m_ddsHandler->ppmFtc()->modifyEquipmentTypeDataRequest(req, this);
|
||||
}
|
||||
|
||||
void ExercisesHandler::onModifyEquipmentTypeDataReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
if (replyObject.error())
|
||||
ERROR_LOG(m_logger) << replyObject();
|
||||
}
|
||||
|
||||
bool ExercisesHandler::addParticipant(const ParticipantInfoStruct &pis)
|
||||
{
|
||||
m_participants.insert(pis.equipmentNumber, pis);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExercisesHandler::modifyParticipant(const ParticipantInfoStruct &pis)
|
||||
{
|
||||
auto it = findParticipant(pis);
|
||||
if (it == m_participants.end())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Trying to modify a participant which is not in our map. mod: "
|
||||
<< pis;
|
||||
return false;
|
||||
}
|
||||
it.value() = pis;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExercisesHandler::removeParticipant(const ParticipantInfoStruct &pis)
|
||||
{
|
||||
auto it = findParticipant(pis);
|
||||
if (it == m_participants.end())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Trying to remove a participant which is not in our map. mod: "
|
||||
<< pis;
|
||||
return false;
|
||||
}
|
||||
m_participants.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<ParticipantInfoStruct> ExercisesHandler::infoStructForEquipment(int equipmentNumber) const
|
||||
{
|
||||
QVector<ParticipantInfoStruct> ret;
|
||||
|
||||
auto it = m_participants.find(equipmentNumber);
|
||||
if (it == m_participants.end()) {
|
||||
// TODO: create temporary participant entry for ex_0 etc.
|
||||
}
|
||||
while (it == m_participants.end() && it.value().equipmentNumber == equipmentNumber) {
|
||||
ret += it.value();
|
||||
++it;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ExercisesHandler::exerciseAdded(int exerciseId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Exercise with id " << exerciseId << " created";
|
||||
auto it = m_exerciseHandler.find(exerciseId);
|
||||
if (it != m_exerciseHandler.end())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Exercise with id " << exerciseId
|
||||
<< " added but it was already in our list - recreating handler";
|
||||
delete it.value();
|
||||
m_exerciseHandler.erase(it);
|
||||
}
|
||||
ExerciseParticipantHandler *exH = new ExerciseParticipantHandler(m_ddsHandler->getDomainParticipant(), exerciseId, this);
|
||||
if (!exH->init())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error initializing ExerciseHandler for exercise " << exerciseId;
|
||||
delete exH;
|
||||
return;
|
||||
}
|
||||
connect(exH, &ExerciseParticipantHandler::registrationReturnValue,
|
||||
this, &ExercisesHandler::registrationReturnValue);
|
||||
connect(exH, &ExerciseParticipantHandler::participantChanged,
|
||||
this, &ExercisesHandler::participantChanged);
|
||||
INFO_LOG(m_logger) << "Successfully created exercise handler for exercise " << exerciseId;
|
||||
m_exerciseHandler[exerciseId] = exH;
|
||||
}
|
||||
|
||||
void ExercisesHandler::exerciseRemoved(int exerciseId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Exercise with id " << exerciseId << " removed";
|
||||
auto it = m_exerciseHandler.find(exerciseId);
|
||||
if (it == m_exerciseHandler.end())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Exercise removed but it was not found in our internal map";
|
||||
return;
|
||||
}
|
||||
delete it.value();
|
||||
m_exerciseHandler.erase(it);
|
||||
}
|
||||
|
||||
QMultiHash<int, ParticipantInfoStruct>::iterator ExercisesHandler::findParticipant(const ParticipantInfoStruct &pis)
|
||||
{
|
||||
auto it = m_participants.find(pis.equipmentNumber);
|
||||
while (it != m_participants.end() && it.value().equipmentNumber == pis.equipmentNumber)
|
||||
{
|
||||
if (it.value().exerciseId == pis.exerciseId)
|
||||
return it;
|
||||
++it;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
void ExercisesHandler::onExerciseChanged(const ExerciseManagement::Exercise &data, DataModification modType)
|
||||
{
|
||||
if (!data.sendToWMS())
|
||||
{
|
||||
if (m_exerciseHandler.contains(data.id()))
|
||||
exerciseRemoved(data.id());
|
||||
|
||||
emit exerciseChanged(data, DataModification::eRemoved);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_exerciseHandler.contains(data.id()))
|
||||
{
|
||||
modType = DataModification::eAdded;
|
||||
exerciseAdded(data.id());
|
||||
}
|
||||
else
|
||||
{
|
||||
modType = DataModification::eModified;
|
||||
}
|
||||
emit exerciseChanged(data, modType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace WarehouseManagement
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Exercises Handler - checks the avilable exercises and creates subhandlers fort each of them
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
#include "dds_handler.h"
|
||||
#include <ParticipantManagement/ppm.hpp>
|
||||
#include <dds/core/Optional.hpp>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
struct ParticipantInfoStruct
|
||||
{
|
||||
int equipmentNumber = 0;
|
||||
int participantId = 0;
|
||||
int exerciseId = 0;
|
||||
};
|
||||
inline std::ostream &operator <<(std::ostream &stream, const ParticipantInfoStruct &pis)
|
||||
{
|
||||
stream << "exerciseId = " << pis.exerciseId
|
||||
<< ", participantId = " << pis.participantId
|
||||
<< ", equipmentNumber = " << pis.equipmentNumber;
|
||||
return stream;
|
||||
}
|
||||
|
||||
class ExerciseParticipantHandler;
|
||||
class ExercisesHandler : public QObject,
|
||||
protected ParticipantManagement::Interface::Ftc::ModifyEquipmentTypeDataReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ExercisesHandler(const std::shared_ptr<DdsHandler> &ddsHandler);
|
||||
~ExercisesHandler();
|
||||
|
||||
bool init();
|
||||
|
||||
QMap<qint32, ExerciseManagement::Exercise> getExercises() const;
|
||||
ParticipantManagement::Party getParty(int partyId, int exerciseId) const;
|
||||
ParticipantManagement::Participant getParticipant(int participantId, int exerciseId) const;
|
||||
QString getHierarchyFromParticipant(int participantId, int exerciseId, const QMap<int, ParticipantManagement::Participant> &allParticipants) const;
|
||||
QMap<qint32, ParticipantManagement::Participant> getParticipants(int exerciseId) const;
|
||||
ParticipantManagement::Type participantType(int typeId) const;
|
||||
ParticipantManagement::TypeClass typeClassIdFromEquipmentTypeId(int equipTypeId) const;
|
||||
|
||||
bool registerParticipant(int exerciseId, qint32 participantId,
|
||||
ParticipantManagement::ParticipantAssignState assignState,
|
||||
const dds::core::optional<int> &equipNo,
|
||||
const dds::core::optional<QString> &identification,
|
||||
const dds::core::optional<QString> &info);
|
||||
|
||||
bool unregisterParticipant(int exerciseId, qint32 equipNo);
|
||||
|
||||
bool modifyEquipmentTypes(const std::vector<ParticipantManagement::EquipmentType> &vectorEquipTypes);
|
||||
|
||||
// key is the equipment number + exerciseId
|
||||
bool addParticipant(const ParticipantInfoStruct &pis);
|
||||
// key is the equipment number + exerciseId
|
||||
bool modifyParticipant(const ParticipantInfoStruct &pis);
|
||||
// key is the equipment number + exerciseId
|
||||
bool removeParticipant(const ParticipantInfoStruct &pis);
|
||||
|
||||
QVector<ParticipantInfoStruct> infoStructForEquipment(int equipmentNumber) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void registrationReturnValue(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue);
|
||||
void participantChanged(const ParticipantManagement::Participant &data, DataModification modType, int exerciseId);
|
||||
void exerciseChanged(const ExerciseManagement::Exercise &data, DataModification modType);
|
||||
|
||||
private:
|
||||
void exerciseAdded(int exerciseId);
|
||||
void exerciseRemoved(int exerciseId);
|
||||
QMultiHash<int, ParticipantInfoStruct>::iterator findParticipant(const ParticipantInfoStruct &pis);
|
||||
private Q_SLOTS:
|
||||
void onExerciseChanged(const ExerciseManagement::Exercise &data, DataModification modType);
|
||||
void onModifyEquipmentTypeDataReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler;
|
||||
|
||||
QHash<int, ExerciseParticipantHandler *> m_exerciseHandler;
|
||||
// QMultiMap<equipmentNumber, ParticipantInfoStruct>
|
||||
QMultiHash<int, ParticipantInfoStruct> m_participants;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
} // namespace WarehouseManagement
|
||||
+498
@@ -0,0 +1,498 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Interface Impl zwischen WMS und ECC
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "interface_wms2ecc_impl.h"
|
||||
#include "exercises_handler.h"
|
||||
|
||||
#include <ExerciseManagement/exm.hpp>
|
||||
#include <ExerciseManagement/exm_translation.h>
|
||||
#include <ParticipantManagement/ppm.hpp>
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
|
||||
IWMS2ECC_Impl::IWMS2ECC_Impl(const std::shared_ptr<ExercisesHandler> &exercisesHandler)
|
||||
: m_exercisesHandler(exercisesHandler)
|
||||
, m_logger(getLogger("Wms2Ecc"))
|
||||
{
|
||||
connect(m_exercisesHandler.get(), &ExercisesHandler::registrationReturnValue,
|
||||
this, &IWMS2ECC_Impl::onRegistrationReturnValue);
|
||||
}
|
||||
|
||||
IWMS2ECC::Exercise IWMS2ECC_Impl::convert(const ExerciseManagement::Exercise &ex)
|
||||
{
|
||||
IWMS2ECC::Exercise ret;
|
||||
ret.id = ex.id();
|
||||
ret.name = QString::fromStdString(ex.name());
|
||||
if (ex.state() == ExerciseManagement::ExerciseState_def::Started ||
|
||||
ex.state() == ExerciseManagement::ExerciseState_def::Paused)
|
||||
ret.actExercise = 1;
|
||||
else
|
||||
ret.actExercise = 0;
|
||||
|
||||
ret.start = ex.beginTime() / 1000; // ms -> s
|
||||
ret.end = ex.endTime() / 1000; // ms -> s
|
||||
ret.stateAsString = ExerciseManagement::toString(ex.state());
|
||||
return ret;
|
||||
}
|
||||
|
||||
IWMS2ECC::PlayerInfo IWMS2ECC_Impl::convert(const ParticipantManagement::Participant &part, int exerciseId, const QMap<int, ParticipantManagement::Participant> &allParticipants) const
|
||||
{
|
||||
IWMS2ECC::PlayerInfo pi;
|
||||
|
||||
pi.alias = QString::fromStdString(part.identification());
|
||||
pi.assignState = convert(part.assignState());
|
||||
pi.designator = QString::fromStdString(part.designator());
|
||||
if (part.equipmentNumber().is_set())
|
||||
pi.equipNo = part.equipmentNumber().get();
|
||||
else if (part.assignState() == ParticipantManagement::ParticipantAssignState_def::HandoutExcon)
|
||||
pi.equipNo = 0;
|
||||
|
||||
pi.exerciseId = exerciseId;
|
||||
pi.forceId = part.partyId();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Force Id = " << pi.forceId;
|
||||
|
||||
pi.info = QString::fromStdString(part.info());
|
||||
pi.parentPlayerId = part.superiorId();
|
||||
pi.playerId = part.id();
|
||||
pi.playerState = part.isDeleted() ? IWMS2ECC::PlayerState::DELETED : IWMS2ECC::PlayerState::FOUND;
|
||||
|
||||
pi.tactIdent = QString::fromStdString(part.tacticalIdentifier());
|
||||
const ParticipantManagement::Type partType = m_exercisesHandler->participantType(part.typeId());
|
||||
if (partType.id() == part.typeId())
|
||||
{
|
||||
pi.equipTypeId = partType.equipmentTypeId();
|
||||
pi.typeClassId = convert(partType.typeClass());
|
||||
TRACE_LOG(m_logger) << "Found participant type with id " << part.typeId() << ", " << pi.typeClassId << ", " << pi.equipTypeId;
|
||||
}
|
||||
else
|
||||
WARNING_LOG(m_logger) << "Can not find participant type with id " << part.typeId();
|
||||
pi.typeId = part.typeId();
|
||||
pi.isDeleted = part.isDeleted();
|
||||
|
||||
pi.hierarchy = m_exercisesHandler->getHierarchyFromParticipant(part.id(), exerciseId, allParticipants);
|
||||
const ParticipantManagement::Party party = m_exercisesHandler->getParty(part.partyId(), exerciseId);
|
||||
pi.forceName = QString::fromStdString(party.name());
|
||||
|
||||
pi.symbolColor = party.color();
|
||||
|
||||
DEBUG_LOG(m_logger) << "party.name: " << pi.forceName;
|
||||
DEBUG_LOG(m_logger) << "symbolColor: " << pi.symbolColor << ", playerId: " << pi.playerId << ", exerciseId: " << exerciseId;
|
||||
// TODO
|
||||
//pi.symbolPNG
|
||||
return pi;
|
||||
}
|
||||
|
||||
IWMS2ECC::exerciseMap IWMS2ECC_Impl::getExercises() const
|
||||
{
|
||||
const QMap<qint32, ExerciseManagement::Exercise> exMap = m_exercisesHandler->getExercises();
|
||||
IWMS2ECC::exerciseMap retMap;
|
||||
for (const ExerciseManagement::Exercise &ex : exMap)
|
||||
{
|
||||
if (ex.sendToWMS())
|
||||
retMap.insert(ex.id(), convert(ex));
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "IN getExercises, exMap.size(): " << exMap.size()
|
||||
<< ", retMap.size: " << retMap.size();
|
||||
return retMap;
|
||||
}
|
||||
|
||||
IWMS2ECC::Exercise IWMS2ECC_Impl::getActualExercise() const
|
||||
{
|
||||
return IWMS2ECC::Exercise();
|
||||
}
|
||||
|
||||
int IWMS2ECC_Impl::getPlayerId(int equipNo, int exerciseId) const
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
Q_UNUSED(equipNo);
|
||||
Q_UNUSED(exerciseId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int IWMS2ECC_Impl::getEquipNo(int playerId, int exerciseId) const
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
Q_UNUSED(playerId);
|
||||
Q_UNUSED(exerciseId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
QMap<int, IWMS2ECC::PlayerInfo> IWMS2ECC_Impl::getAllPlayers(int exerciseId) const
|
||||
{
|
||||
return getAllParticipants(exerciseId);
|
||||
}
|
||||
|
||||
QMap<int, IWMS2ECC::PlayerInfo> IWMS2ECC_Impl::getAllParticipants(int exerciseId) const
|
||||
{
|
||||
INFO_LOG(m_logger) << "IN getAllParticipants";
|
||||
QMap<int, IWMS2ECC::PlayerInfo> retMap;
|
||||
|
||||
const QMap<qint32, ParticipantManagement::Participant> map = m_exercisesHandler->getParticipants(exerciseId);
|
||||
|
||||
INFO_LOG(m_logger) << "getAllPlayers map.size() : " << map.size();
|
||||
|
||||
for (const ParticipantManagement::Participant &exePart : map)
|
||||
{
|
||||
IWMS2ECC::PlayerInfo pi = convert(exePart, exerciseId, map);
|
||||
|
||||
// add exerciseId and 1000000 to partcipantId to distinguish the different exercises
|
||||
// if there are more than one current exercise
|
||||
pi.playerId = (exerciseId * 1000000) + pi.playerId;
|
||||
pi.parentPlayerId = (exerciseId * 1000000) + pi.parentPlayerId;
|
||||
|
||||
if (pi.playerState == PlayerState::FOUND)
|
||||
retMap.insert(pi.playerId, pi);
|
||||
}
|
||||
return retMap;
|
||||
}
|
||||
|
||||
QMap<int, IWMS2ECC::PlayerInfo> IWMS2ECC_Impl::getAllVehicles(int exerciseId) const
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
Q_UNUSED(exerciseId);
|
||||
return {};
|
||||
}
|
||||
|
||||
IWMS2ECC::RegisterReturnValue IWMS2ECC_Impl::registerPlayer(int playerId, int equipNo, const IWMS2ECC::PlayerAssignState &playerAssignState,
|
||||
const QString &alias, const QString &info, int exerciseId)
|
||||
{
|
||||
ParticipantManagement::ParticipantAssignState assignState = convert(playerAssignState);
|
||||
m_exercisesHandler->registerParticipant(exerciseId, playerId, assignState, equipNo, alias, info);
|
||||
|
||||
return IWMS2ECC::RegistrationFailed;
|
||||
}
|
||||
|
||||
void IWMS2ECC_Impl::onRegistrationReturnValue(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue)
|
||||
{
|
||||
INFO_LOG(m_logger) << "IN onRegistrationReturnValue ";
|
||||
INFO_LOG(m_logger) << "exerciseId: " << exerciseId << ", participantId: " << participantId << ", retValue: " << retValue;
|
||||
emit registrationReturnValue(exerciseId, participantId, convert(retValue));
|
||||
}
|
||||
|
||||
|
||||
IWMS2ECC::UnregisterReturnValue IWMS2ECC_Impl::unregister(int equipNo, int exerciseId)
|
||||
{
|
||||
if (!m_exercisesHandler->unregisterParticipant(exerciseId, equipNo))
|
||||
return IWMS2ECC::UnregisterFailed;
|
||||
return IWMS2ECC::UnregisterOk; // ok -> unregister is in progress
|
||||
}
|
||||
|
||||
IWMS2ECC::PlayerInfo IWMS2ECC_Impl::getPlayerInfo(int playerId, int exerciseId)
|
||||
{
|
||||
|
||||
DEBUG_LOG(m_logger) << "IN getPlayerInfo: "
|
||||
<< " playerId = " << playerId << ", exerciseId = " << exerciseId;
|
||||
|
||||
if (playerId <= 0 || exerciseId <= 0)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Invalid Player (0,0)";
|
||||
IWMS2ECC::PlayerInfo pi;
|
||||
pi.playerState = NOT_FOUND;
|
||||
return pi;
|
||||
}
|
||||
|
||||
// HR 10.04.14 vorerst mit zurueckgeben
|
||||
// Nur Player zurueckgeben, die nicht(!) von EXCON angemeldet sind ( != HANDOUT_EXCON(1))
|
||||
|
||||
ParticipantManagement::Participant part = m_exercisesHandler->getParticipant(playerId, exerciseId);
|
||||
|
||||
IWMS2ECC::PlayerInfo pi;
|
||||
if (part.assignState() == ParticipantManagement::ParticipantAssignState_def::HandoutExcon)
|
||||
{
|
||||
pi.playerState = NOT_FOUND;
|
||||
return pi;
|
||||
}
|
||||
|
||||
pi = convert(part, exerciseId);
|
||||
|
||||
pi.forceName = QString::fromStdString(m_exercisesHandler->getParty(part.partyId(), exerciseId).name());
|
||||
//pi.symbolPNG = getSymbol(q.value(4).toInt(), exerciseId, teamData.color, teamData.role);
|
||||
|
||||
pi.playerState = FOUND;
|
||||
|
||||
INFO_LOG(m_logger) << "Player (" << pi.playerId << "," << exerciseId << ") found: "
|
||||
<< "AssignState: " << pi.assignState << ", forceName: " << pi.forceName;
|
||||
|
||||
return pi;
|
||||
}
|
||||
|
||||
QMap<int, int> IWMS2ECC_Impl::getEquipRequirements(int exerciseId) const
|
||||
{
|
||||
/*
|
||||
QString tableName = getTableName( exerciseId, "tln");
|
||||
|
||||
NSqlQuery q;
|
||||
|
||||
QString stmt = "SELECT count(ty.typausstg_id), ty.typausstg_id from " + tableName + " t, typen ty "
|
||||
"WHERE ty.id = t.typ_id AND t.ausstattung = 1 AND t.loeschkennung = 0 "
|
||||
"GROUP BY ty.typausstg_id";
|
||||
*/
|
||||
|
||||
const QMap<qint32, ParticipantManagement::Participant> map = m_exercisesHandler->getParticipants(exerciseId);
|
||||
|
||||
INFO_LOG(m_logger) << "getAllPlayers map.size() : " << map.size();
|
||||
|
||||
QMap<int, int> reqPartTypes;
|
||||
|
||||
for (const ParticipantManagement::Participant &part : map)
|
||||
{
|
||||
if (part.isDeleted())
|
||||
continue;
|
||||
|
||||
reqPartTypes[part.typeId()]++;
|
||||
}
|
||||
|
||||
QMap<int, int> reqEquipTypes;
|
||||
QMap<int, int>::ConstIterator cIt = reqPartTypes.constBegin();
|
||||
for (; cIt != reqPartTypes.constEnd(); ++cIt)
|
||||
{
|
||||
const int typeId = cIt.key();
|
||||
const ParticipantManagement::Type partType = m_exercisesHandler->participantType(typeId);
|
||||
if (partType.id() == typeId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Key: " << typeId;
|
||||
ParticipantManagement::TypeClass typeClass = partType.typeClass();
|
||||
int equipTypeId = partType.equipmentTypeId();
|
||||
if (typeClass != ParticipantManagement::TypeClass_def::Unit && typeClass != ParticipantManagement::TypeClass_def::SupportUnit)
|
||||
{
|
||||
reqEquipTypes[equipTypeId] = cIt.value();
|
||||
DEBUG_LOG(m_logger) << "equipTypeId: " << equipTypeId << ", amount: " << cIt.value();
|
||||
}
|
||||
}
|
||||
else
|
||||
WARNING_LOG(m_logger) << "Can not find participant type with id " << typeId;
|
||||
}
|
||||
return reqEquipTypes;
|
||||
}
|
||||
|
||||
// TODO: really needed?
|
||||
int IWMS2ECC_Impl::getTypeClassId(int equipTypeId) const
|
||||
{
|
||||
return convert(m_exercisesHandler->typeClassIdFromEquipmentTypeId(equipTypeId));
|
||||
}
|
||||
|
||||
QByteArray IWMS2ECC_Impl::getSymbol(int symbolId, int exerciseId, const QColor &color, int role) const
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
Q_UNUSED(symbolId);
|
||||
Q_UNUSED(exerciseId);
|
||||
Q_UNUSED(color);
|
||||
Q_UNUSED(role);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
IWMS2ECC::EquipmentType IWMS2ECC_Impl::convert(const ParticipantManagement::EquipmentType &et)
|
||||
{
|
||||
IWMS2ECC::EquipmentType ret;
|
||||
ret.id = et.id();
|
||||
ret.name = QString::fromStdString(et.name());
|
||||
ret.minEquipNo = et.minEquipNo();
|
||||
ret.maxEquipNo = et.maxEquipNo();
|
||||
ret.specialType = int(et.wmsTypeClass().underlying());
|
||||
ret.taVulnerabilityModelId = et.traVulnerabilityModelId();
|
||||
ret.taPlayerTypeId = et.traPlayerTypeId();
|
||||
ret.deletedInWMS = et.deletedInWms();
|
||||
return ret;
|
||||
}
|
||||
|
||||
ParticipantManagement::EquipmentType IWMS2ECC_Impl::convert(const IWMS2ECC::EquipmentType &et)
|
||||
{
|
||||
ParticipantManagement::EquipmentType ret;
|
||||
ret.id(et.id);
|
||||
ret.name(et.name.toStdString());
|
||||
ret.minEquipNo(et.minEquipNo);
|
||||
ret.maxEquipNo(et.maxEquipNo);
|
||||
ParticipantManagement::WmsTypeClass wmsTypeClass = convert(et.specialType);
|
||||
ret.wmsTypeClass(wmsTypeClass);
|
||||
ret.traVulnerabilityModelId(et.taVulnerabilityModelId);
|
||||
ret.traPlayerTypeId(et.taPlayerTypeId);
|
||||
ret.deletedInWms(et.deletedInWMS);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ParticipantManagement::WmsTypeClass IWMS2ECC_Impl::convert(int specialType)
|
||||
{
|
||||
switch (specialType)
|
||||
{
|
||||
case 0:
|
||||
return ParticipantManagement::WmsTypeClass_def::None;
|
||||
case 1:
|
||||
return ParticipantManagement::WmsTypeClass_def::Building;
|
||||
case 2:
|
||||
return ParticipantManagement::WmsTypeClass_def::Vehicle;
|
||||
case 3:
|
||||
return ParticipantManagement::WmsTypeClass_def::Human;
|
||||
case 4:
|
||||
return ParticipantManagement::WmsTypeClass_def::TargetVehicle;
|
||||
case 5:
|
||||
return ParticipantManagement::WmsTypeClass_def::TargetHuman;
|
||||
case 6:
|
||||
return ParticipantManagement::WmsTypeClass_def::Airborne;
|
||||
case 7:
|
||||
return ParticipantManagement::WmsTypeClass_def::VehicleMarker;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
return ParticipantManagement::WmsTypeClass_def::None;
|
||||
}
|
||||
|
||||
ParticipantManagement::TypeClass IWMS2ECC_Impl::convertTypeClass(int typeClass)
|
||||
{
|
||||
switch (typeClass)
|
||||
{
|
||||
case 1:
|
||||
return ParticipantManagement::TypeClass_def::Unit;
|
||||
case 2: // WeaponSystem
|
||||
return ParticipantManagement::TypeClass_def::VehicleWithGear;
|
||||
case 3: // Vehicle Light
|
||||
case 4: // Vehicle Armored
|
||||
return ParticipantManagement::TypeClass_def::GroundVehicle;
|
||||
case 5:
|
||||
return ParticipantManagement::TypeClass_def::Human;
|
||||
case 6: // OCSoldier
|
||||
case 7: // OCVehicle
|
||||
return ParticipantManagement::TypeClass_def::SupportEntity;
|
||||
case 8:
|
||||
return ParticipantManagement::TypeClass_def::Aircraft;
|
||||
case 10:
|
||||
return ParticipantManagement::TypeClass_def::SupportUnit;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
return ParticipantManagement::TypeClass_def::Unit;
|
||||
|
||||
}
|
||||
|
||||
int IWMS2ECC_Impl::convert(ParticipantManagement::TypeClass typeClass)
|
||||
{
|
||||
switch (typeClass.underlying())
|
||||
{
|
||||
case ParticipantManagement::TypeClass_def::Unknown:
|
||||
return 0; // Unknown
|
||||
case ParticipantManagement::TypeClass_def::Unit:
|
||||
return 1; // Unit
|
||||
case ParticipantManagement::TypeClass_def::Human:
|
||||
return 5; // Soldier
|
||||
case ParticipantManagement::TypeClass_def::VehicleWithGear:
|
||||
case ParticipantManagement::TypeClass_def::WeaponSystem:
|
||||
return 2; // WeaponSystem
|
||||
case ParticipantManagement::TypeClass_def::GroundVehicle:
|
||||
return 3; // Vehicle light
|
||||
case ParticipantManagement::TypeClass_def::SupportUnit:
|
||||
return 10; // OCUnit
|
||||
case ParticipantManagement::TypeClass_def::SupportEntity:
|
||||
return 7; // OCVehicle
|
||||
case ParticipantManagement::TypeClass_def::Aircraft:
|
||||
return 8; // Aircraft
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
return 1; // Unit, Vessel
|
||||
}
|
||||
|
||||
|
||||
bool IWMS2ECC_Impl::setEquipmentType(const EquipmentType &et)
|
||||
{
|
||||
std::vector<ParticipantManagement::EquipmentType> vEquipTypes;
|
||||
const ParticipantManagement::EquipmentType &etData = convert(et);
|
||||
vEquipTypes.push_back(etData);
|
||||
|
||||
return m_exercisesHandler->modifyEquipmentTypes(vEquipTypes);
|
||||
}
|
||||
|
||||
bool IWMS2ECC_Impl::setEquipmentTypes(const equipTypeMap &map)
|
||||
{
|
||||
INFO_LOG(m_logger) << "IN setEquipmentTypes: equipMap.size: " << map.size();
|
||||
|
||||
std::vector<ParticipantManagement::EquipmentType> vEquipTypes;
|
||||
vEquipTypes.reserve(map.size());
|
||||
for (const IWMS2ECC::EquipmentType &et : map)
|
||||
vEquipTypes.push_back(convert(et));
|
||||
|
||||
return m_exercisesHandler->modifyEquipmentTypes(vEquipTypes);
|
||||
}
|
||||
|
||||
IWMS2ECC::PlayerAssignState IWMS2ECC_Impl::convert(const ParticipantManagement::ParticipantAssignState &state)
|
||||
{
|
||||
switch (state.underlying())
|
||||
{
|
||||
case ParticipantManagement::ParticipantAssignState_def::NotAssigned:
|
||||
return IWMS2ECC::NOT_ASSIGNED;
|
||||
case ParticipantManagement::ParticipantAssignState_def::AssignedWms:
|
||||
return IWMS2ECC::ASSIGNED;
|
||||
case ParticipantManagement::ParticipantAssignState_def::HandoutWms:
|
||||
return IWMS2ECC::HANDOUT_WMS;
|
||||
case ParticipantManagement::ParticipantAssignState_def::HandoutExcon:
|
||||
return IWMS2ECC::HANDOUT_EXCON;
|
||||
case ParticipantManagement::ParticipantAssignState_def::ExconWmsOverruled:
|
||||
return IWMS2ECC::HANDOUT_EXCON_OVERRULED_WMS;
|
||||
}
|
||||
|
||||
Q_ASSERT(false);
|
||||
return IWMS2ECC::UNDEFINED;
|
||||
}
|
||||
|
||||
ParticipantManagement::ParticipantAssignState IWMS2ECC_Impl::convert(const IWMS2ECC::PlayerAssignState &state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case IWMS2ECC::UNDEFINED:
|
||||
return ParticipantManagement::ParticipantAssignState_def::NotAssigned;
|
||||
case IWMS2ECC::NOT_ASSIGNED:
|
||||
return ParticipantManagement::ParticipantAssignState_def::NotAssigned;
|
||||
case IWMS2ECC::ASSIGNED:
|
||||
return ParticipantManagement::ParticipantAssignState_def::AssignedWms;
|
||||
case IWMS2ECC::HANDOUT_WMS:
|
||||
return ParticipantManagement::ParticipantAssignState_def::HandoutWms;
|
||||
case IWMS2ECC::HANDOUT_EXCON:
|
||||
return ParticipantManagement::ParticipantAssignState_def::HandoutExcon;
|
||||
case IWMS2ECC::HANDOUT_EXCON_OVERRULED_WMS:
|
||||
return ParticipantManagement::ParticipantAssignState_def::ExconWmsOverruled;
|
||||
}
|
||||
|
||||
Q_ASSERT(false);
|
||||
return ParticipantManagement::ParticipantAssignState_def::NotAssigned;
|
||||
}
|
||||
|
||||
IWMS2ECC::RegisterReturnValue IWMS2ECC_Impl::convert(const ParticipantManagement::RegisterReturnValue retValue)
|
||||
{
|
||||
switch (retValue.underlying())
|
||||
{
|
||||
case ParticipantManagement::RegisterReturnValue_def::AssignmentIncorrect:
|
||||
return IWMS2ECC::AssignmentIncorrect;
|
||||
case ParticipantManagement::RegisterReturnValue_def::PlayerDeleted:
|
||||
return IWMS2ECC::PlayerDeleted;
|
||||
case ParticipantManagement::RegisterReturnValue_def::PlayerNotFound:
|
||||
return IWMS2ECC::PlayerNotFound;
|
||||
case ParticipantManagement::RegisterReturnValue_def::RegistrationFailed:
|
||||
return IWMS2ECC::RegistrationFailed;
|
||||
case ParticipantManagement::RegisterReturnValue_def::RegistrationOk:
|
||||
return IWMS2ECC::RegistrationOk;
|
||||
case ParticipantManagement::RegisterReturnValue_def::EquipNoAlreadyAssigned:
|
||||
return IWMS2ECC::EquipNoAlreadyAssigned;
|
||||
}
|
||||
|
||||
Q_ASSERT(false);
|
||||
return IWMS2ECC::RegistrationFailed;
|
||||
}
|
||||
|
||||
} // Namespace WarehouseManagement
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Interface zwischen WMS und ECC (Implementation)
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <WMS_Interface/IWMS2ECC.h>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <ParticipantManagement/ppm.hpp>
|
||||
#include <ExerciseManagement/exm.hpp>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
class ExercisesHandler;
|
||||
class IWMS2ECC_Impl : public QObject, IWMS2ECC
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit IWMS2ECC_Impl(const std::shared_ptr<ExercisesHandler> &exercisesHandler);
|
||||
|
||||
// reimplemented functions
|
||||
|
||||
RegisterReturnValue registerPlayer(int playerId, int equipNo, const PlayerAssignState &playerAssignState, const QString &alias,
|
||||
const QString &info, int exerciseId) override;
|
||||
|
||||
IWMS2ECC::UnregisterReturnValue unregister(int equipNo, int exerciseId) override;
|
||||
PlayerInfo getPlayerInfo(int playerId, int exerciseId) override;
|
||||
|
||||
IWMS2ECC::exerciseMap getExercises() const override;
|
||||
IWMS2ECC::Exercise getActualExercise() const override;
|
||||
|
||||
// QMap<EquipId,Amount>
|
||||
QMap<int, int> getEquipRequirements(int exerciseId) const override;
|
||||
|
||||
QMap<int, PlayerInfo> getAllPlayers(int exerciseId) const override;
|
||||
QMap<int, PlayerInfo> getAllVehicles(int exerciseId) const override;
|
||||
|
||||
int getPlayerId(int equipNo, int exerciseId) const override;
|
||||
int getEquipNo(int playerId, int exerciseId) const override;
|
||||
|
||||
int getTypeClassId(int equipTypeId) const override;
|
||||
|
||||
bool setEquipmentTypes(const IWMS2ECC::equipTypeMap &map);
|
||||
bool setEquipmentType(const IWMS2ECC::EquipmentType &et);
|
||||
|
||||
IWMS2ECC::PlayerInfo convert(const ParticipantManagement::Participant &part, int exerciseId, const QMap<int, ParticipantManagement::Participant> &allParticipants = {}) const;
|
||||
static IWMS2ECC::Exercise convert(const ExerciseManagement::Exercise &ex);
|
||||
static ParticipantManagement::ParticipantAssignState convert(const IWMS2ECC::PlayerAssignState &state);
|
||||
|
||||
Q_SIGNALS:
|
||||
void registrationReturnValue(int exerciseId, qint32 participantId, IWMS2ECC::RegisterReturnValue retValue);
|
||||
|
||||
protected:
|
||||
QMap<int, IWMS2ECC::PlayerInfo> getAllParticipants(int exerciseId) const;
|
||||
|
||||
QByteArray getSymbol(int symbolId, int exerciseId, const QColor &color, int role) const;
|
||||
|
||||
// Convert enums (PlayerAssignState (Wms) & ParticipantAssignState (ExconPlayer)
|
||||
static IWMS2ECC::PlayerAssignState convert(const ParticipantManagement::ParticipantAssignState &state);
|
||||
|
||||
ParticipantManagement::EquipmentType convert(const IWMS2ECC::EquipmentType &et);
|
||||
IWMS2ECC::EquipmentType convert(const ParticipantManagement::EquipmentType &et);
|
||||
IWMS2ECC::RegisterReturnValue convert(const ParticipantManagement::RegisterReturnValue retValue);
|
||||
|
||||
static ParticipantManagement::WmsTypeClass convert(int specialType);
|
||||
static int convert(ParticipantManagement::TypeClass typeClass);
|
||||
static ParticipantManagement::TypeClass convertTypeClass(int typeClass);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onRegistrationReturnValue(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue);
|
||||
|
||||
private:
|
||||
const std::shared_ptr<ExercisesHandler> m_exercisesHandler;
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
} // Namespace WarehouseManagement
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
log4j.reset=true
|
||||
log4j.rootLogger=WARN, file
|
||||
|
||||
# Service: WarehouseManagement
|
||||
###########################################################
|
||||
|
||||
#log4j.logger.WMS.main=WARN
|
||||
#log4j.logger.WMS.MainHandler=INFO
|
||||
#log4j.logger.WMS.DdsHandler=INFO
|
||||
#log4j.logger.WMS.DdsHandlerExercise=INFO
|
||||
#log4j.logger.WMS.ExercisesHandler=INFO
|
||||
#log4j.logger.WMS.ExerciseParticipantHandler=INFO
|
||||
#log4j.logger.WMS.Wms2Ecc=DEBUG
|
||||
#log4j.logger.WMS.Ecc2Wms=DEBUG
|
||||
#log4j.logger.WMS.Server=DEBUG
|
||||
#log4j.logger.WMS.XmlRpcServer=DEBUG
|
||||
|
||||
# File
|
||||
###########################################################
|
||||
log4j.appender.file=Lts::RollingFileAppender
|
||||
log4j.appender.file.MaxFileSize=1MB
|
||||
log4j.appender.file.MaxBackupIndex=9
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d %-5p %c |#| %m (%.50F:%L) %n
|
||||
|
||||
|
||||
# Appnd_Console
|
||||
###########################################################
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern= %d %p %c %c{1} - %m (%-.30F:%L) %n
|
||||
|
||||
|
||||
# Appnd_Syslog
|
||||
###########################################################
|
||||
log4j.appender.syslog=org.apache.log4j.SyslogAppender
|
||||
log4j.appender.syslog.Threshold=ERROR
|
||||
log4j.appender.syslog.SysLogHost=localhost
|
||||
log4j.appender.syslog.Facility=LOCAL7
|
||||
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.syslog.layout.ConversionPattern= %-4r %-5p %c %x - %m
|
||||
log4j.appender.syslog.LevelRangeFilter.AcceptOnMatch=true
|
||||
log4j.appender.syslog.LevelRangeFilter.LevelMin=INFO
|
||||
log4j.appender.syslog.LevelRangeFilter.LevelMax=FATAL
|
||||
|
||||
|
||||
###########################################################
|
||||
###########################################################
|
||||
###########################################################
|
||||
# 1) Available Levels in LOG4CXX Version 0.10.0:
|
||||
# WMSCE,
|
||||
# DEBUG,
|
||||
# INFO,
|
||||
# WARN,
|
||||
# ERROR
|
||||
# FATAL
|
||||
#
|
||||
# d = date/time
|
||||
# p = priority (Level)
|
||||
# c = category/channel
|
||||
# m = message
|
||||
# F = file
|
||||
# L = line
|
||||
# n = platform dependent line separator character or characters.
|
||||
# ....
|
||||
#
|
||||
# Examples for console:
|
||||
# a)
|
||||
# %d %p %c #%m# (%.50F:%L)%n
|
||||
# date/time
|
||||
# priority
|
||||
# category/channel
|
||||
# #message#
|
||||
# (Maximal 50Character des Filename von rechts:Line)
|
||||
# line separator
|
||||
#
|
||||
# b)
|
||||
# %d (%.15F:%L) %-5p %c |#| %m%n
|
||||
# date/time
|
||||
# (Maximal 15Character des Filename von rechts:Line)
|
||||
# priority, Right pad with spaces if the priority name is less than 5 characters long.
|
||||
# category/channel
|
||||
# message
|
||||
# line separator
|
||||
#
|
||||
# Examples for files:
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Building Config - logging facility
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-09-05
|
||||
*/
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
|
||||
LOGGER_T getLogger(const char *name)
|
||||
{
|
||||
static const char ns[] = "WMS.";
|
||||
std::string loggerName;
|
||||
const size_t len = strlen(name);
|
||||
loggerName.reserve(sizeof(ns) + len);
|
||||
loggerName.append(ns, sizeof(ns) - 1);
|
||||
loggerName.append(name, len);
|
||||
|
||||
try
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
|
||||
getNGLLogger(loggerName);
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace WarehouseManagement
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Logging for TetraRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
using LOGGER_T = NGL::INGLLogger&;
|
||||
|
||||
LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
} // namespace WarehouseManagement
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* main for TetraRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
#include <memory>
|
||||
#include "main_handler.h"
|
||||
#include "logger.h"
|
||||
#include "settings.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
|
||||
int iRet = -1;
|
||||
LtsCommandLineParser::LtsCommandLineParser options;
|
||||
if (!options.init())
|
||||
return iRet;
|
||||
app.createLogger("WMS", options.exerciseId());
|
||||
WarehouseManagement::Settings::setIniFile(options.iniFile());
|
||||
|
||||
{
|
||||
std::unique_ptr<WarehouseManagement::MainHandler> mainHandler(new WarehouseManagement::MainHandler);
|
||||
if (mainHandler->init(options.domainId()))
|
||||
{
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
iRet = app.exec();
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
}
|
||||
}
|
||||
|
||||
return iRet;
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* MainHandler for TetraRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
#include "main_handler.h"
|
||||
#include <DDS/Core/pacemaker.h>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
|
||||
MainHandler::MainHandler()
|
||||
: QObject()
|
||||
, m_logger(getLogger("MainHandler"))
|
||||
{}
|
||||
|
||||
MainHandler::~MainHandler()
|
||||
{
|
||||
delete m_dataManager;
|
||||
m_wms2ecc = nullptr;
|
||||
m_exercisesHandler = nullptr;
|
||||
m_ddsHandler = nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool MainHandler::init(int domainId)
|
||||
{
|
||||
// initialize DDS
|
||||
m_ddsHandler = std::make_shared<DdsHandler>(domainId);
|
||||
if (!m_ddsHandler->init())
|
||||
return false;
|
||||
|
||||
m_exercisesHandler = std::make_shared<ExercisesHandler>(m_ddsHandler);
|
||||
if (!m_exercisesHandler->init())
|
||||
return false;
|
||||
|
||||
m_wms2ecc = std::make_shared<IWMS2ECC_Impl>(m_exercisesHandler);
|
||||
|
||||
m_dataManager = new DataManager(m_wms2ecc, m_ddsHandler, m_exercisesHandler);
|
||||
m_dataManager->init();
|
||||
|
||||
connect(m_exercisesHandler.get(), &ExercisesHandler::participantChanged, m_dataManager,
|
||||
&DataManager::onParticipantChanged);
|
||||
connect(m_exercisesHandler.get(), &ExercisesHandler::exerciseChanged, m_dataManager,
|
||||
&DataManager::onExerciseChanged);
|
||||
connect(m_exercisesHandler.get(), &ExercisesHandler::registrationReturnValue, m_dataManager,
|
||||
&DataManager::onRegistrationReturnValue);
|
||||
|
||||
m_ddsHandler->pacemaker()->setNewState(Core::RunningState::inner_enum::Running);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace WarehouseManagement
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* MainHandler for TetraRadio
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "dds_handler.h"
|
||||
#include "exercises_handler.h"
|
||||
#include "interface_wms2ecc_impl.h"
|
||||
#include "data_manager.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include <QObject>
|
||||
|
||||
|
||||
#include <LtsWebSocket/client_connection.h>
|
||||
#include <LtsWebSocket/client_message_factory.h>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
|
||||
class MainHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainHandler();
|
||||
~MainHandler();
|
||||
|
||||
bool init(int domainId);
|
||||
|
||||
private:
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler;
|
||||
std::shared_ptr<ExercisesHandler> m_exercisesHandler;
|
||||
std::shared_ptr<IWMS2ECC_Impl> m_wms2ecc;
|
||||
DataManager* m_dataManager = nullptr;
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
} // namespace WarehouseManagement
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Settings for GuezNasat
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
#include <nglsettings/nglsettings_settings.h>
|
||||
#include <ngltools/ngltools_filesystem.h>
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
class NGLSettingsClass : public NGL::Settings
|
||||
{
|
||||
public:
|
||||
NGLSettingsClass()
|
||||
: NGL::Settings(s_iniFile.isEmpty() ? NGL::findProjectConfigFile() : s_iniFile)
|
||||
{}
|
||||
static void setIniFile(const QString &fn)
|
||||
{
|
||||
s_iniFile = fn;
|
||||
}
|
||||
static QString s_iniFile;
|
||||
};
|
||||
QString NGLSettingsClass::s_iniFile;
|
||||
Q_GLOBAL_STATIC(NGLSettingsClass, s)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
NGL::Settings *Settings::settings()
|
||||
{
|
||||
return s();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Settings::setIniFile(const QString &ini)
|
||||
{
|
||||
NGLSettingsClass::setIniFile(ini);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QString Settings::wmsServerName()
|
||||
{
|
||||
QString defaultWmsServer = QStringLiteral("localhost");
|
||||
#ifndef GUEZ_MODE
|
||||
defaultWmsServer = QStringLiteral("ECCORSV05");
|
||||
#endif
|
||||
return s()->settings()->value(QStringLiteral("WarehouseManagement/WmsServer"), defaultWmsServer).toString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
} // namespace WarehouseManagement
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Settings for GuezNasat
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <QPointF>
|
||||
#include <QString>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class Settings;
|
||||
}
|
||||
|
||||
namespace WarehouseManagement
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
void setIniFile(const QString &ini);
|
||||
NGL::Settings *settings();
|
||||
QString wmsServerName();
|
||||
}
|
||||
|
||||
} // namespace WarehouseManagement
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<service namespace="WarehouseManagement" procNames="WarehouseManagement" abbreviation="WMS" exerciseDependency="Global" groups="Core" prio="3">
|
||||
<rcs>
|
||||
<Id Id="$Id: ea_export_script.txt 28914 2016-08-23 12:08:05Z ehrlicher $"/>
|
||||
<HeadURL HeadURL="$HeadURL: svn://slssvn/TDS/branches/product/devel/trunk/Lts/Common/CodeGen/ea_export_script.txt $"/>
|
||||
<Author Author="$Author: ehrlicher $"/>
|
||||
</rcs>
|
||||
<tables/>
|
||||
<dbServiceStructs/>
|
||||
<topicTypes>
|
||||
<topicType name="dummyStruct">
|
||||
<column name="id" idlType="long"/>
|
||||
</topicType>
|
||||
</topicTypes>
|
||||
<functionTopics/>
|
||||
<enumerations>
|
||||
<enumeration name="dummyEnum">
|
||||
<attribute key="unknown" value=""/>
|
||||
</enumeration>
|
||||
</enumerations>
|
||||
</service>
|
||||
Reference in new issue
Block a user