/** * Handler for all exercise objects * $Id$ * $HeadURL$ * $Author$ * Created by Hanna E. Rathje, SLSE, 2015-09-03 */ #include "handler_effect_show_actor_relocation.h" #include "handler_tab_data.h" #include "handler_ppm_data.h" #include "object_effect_show_actor_relocation.h" #include "esm_db.h" #include "initialization.h" #include #include namespace EffectShowManagement { //============================================================================= HandlerEffectShowActorRelocation::HandlerEffectShowActorRelocation(Initialization *mainHandler, QObject *parent) : QObject(parent) , EffectShowActorRelocationModifyRequestHandler(mainHandler->dds()->fts()) , EffectShowActorRelocationRemoveRequestHandler(mainHandler->dds()->fts()) , m_mainHandler(mainHandler) , m_logger(getLogger("HandlerEffectShowActorRelocation")) {} //============================================================================= HandlerEffectShowActorRelocation::~HandlerEffectShowActorRelocation() { qDeleteAll(m_effectShowActorRelocationObjMap); } //============================================================================= bool HandlerEffectShowActorRelocation::init() { bool bRet = true; // create EffectShowActorRelocations objects auto cbActor = [this, &bRet](const Database::EsmEffectShowActorRelocation &data) { ObjectEffectShowActorRelocation *ifs(new ObjectEffectShowActorRelocation(m_mainHandler)); Core::FunctionReplyObject ret = ifs->createObject(data); if (ret.error()) { delete ifs; ERROR_LOG(m_logger) << ret(); bRet = false; return; } m_effectShowActorRelocationObjMap.insert(ifs->getId(), ifs); }; if (!m_mainHandler->db()->select(cbActor) || !bRet) { ERROR_LOG(m_logger) << "Error reading data from database!"; return false; } DEBUG_LOG(m_logger) << "m_effectShowActorRelocationObjMap.size() = " << m_effectShowActorRelocationObjMap.size(); return true; } //============================================================================= void HandlerEffectShowActorRelocation::relocationOrderConfirmationReceived(const ConvertFromTab::OrderConfirmation_t &orderConfirmation) { DEBUG_LOG(m_logger) << "relocationOrderConfirmationReceived()"; ObjectEffectShowActorRelocation *ifs = m_effectShowActorRelocationObjMap.value(orderConfirmation.orderId); if (ifs == nullptr) { WARNING_LOG(m_logger) << "Error receiving effect show relocation ID not known."; return; } // add confirmation data auto data = ifs->getData(); data.orderConfirmation = orderConfirmation.confirmation.underlying(); data.answertText = orderConfirmation.answerText; ifs->updateObject(data); } //----------------------------------------------------------------------------- void HandlerEffectShowActorRelocation::onEffectShowActorRelocationModifyRequest( const rti::core::SampleIdentity &cookie, const EffectShowActorRelocation &request) { DEBUG_LOG(m_logger) << "onEffectShowActorRelocationModifyRequest: " << request.id(); auto ret = request.id() > 0 ? effectShowActorRelocationModifyRequest(request) : effectShowActorRelocationCreateRequest(request); if (ret.error()) WARNING_LOG(m_logger) << ret(); m_mainHandler->dds()->fts()->effectShowActorRelocationModifyReply(cookie, ret); } //----------------------------------------------------------------------------- Core::FunctionReplyObject HandlerEffectShowActorRelocation::effectShowActorRelocationCreateRequest(const EffectShowActorRelocation &request) { ObjectEffectShowActorRelocation *ifs(new ObjectEffectShowActorRelocation(m_mainHandler)); Core::FunctionReplyObject ret = ifs->createObject(ObjectEffectShowActorRelocation::ddsToDb(request)); if (ret.error()) delete ifs; else { m_effectShowActorRelocationObjMap.insert(ifs->getId(), ifs); // trigger relocation telegram to effect show actor int participantId = ifs->getIdEffectShowActor(); int equipmentNumber = m_mainHandler->handlerPpmData()->getEquipmentNumber(participantId); m_mainHandler->handlerTabData()->relocationOrder(equipmentNumber, participantId, ifs->getRelocationOrder()); DEBUG_LOG(m_logger) << "effectShowActorRelocationCreateRequest() - insert"; } return ret; } //----------------------------------------------------------------------------- Core::FunctionReplyObject HandlerEffectShowActorRelocation::effectShowActorRelocationModifyRequest(const EffectShowActorRelocation &request) { ObjectEffectShowActorRelocation *ifs = m_effectShowActorRelocationObjMap.value(request.id()); if (ifs == nullptr) return Core::FunctionReplyObject(request.id(), tr_lts("dds", "EffectShowActorRelocation with id %1 not found")).arg(request.id()); return ifs->updateObject(ObjectEffectShowActorRelocation::ddsToDb(request)); } //----------------------------------------------------------------------------- void HandlerEffectShowActorRelocation::onEffectShowActorRelocationRemoveRequest(const rti::core::SampleIdentity &cookie, const Core::RemoveElementRequest &request) { DEBUG_LOG(m_logger) << "onEffectShowActorRelocationRemoveRequest: " << request.id(); Core::FunctionReplyObject ret; ObjectEffectShowActorRelocation *ifs = m_effectShowActorRelocationObjMap.value(request.id()); if (!ifs) { ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "'%1' with id %2 not found")).arg(QStringLiteral("HandlerEffectShowActorRelocation")).arg(request.id());; m_mainHandler->dds()->fts()->effectShowActorRelocationRemoveReply(cookie, ret); return; } EffectShowActorRelocation ddsData; ddsData.id(request.id()); if (m_mainHandler->dds()->topicLockMaster()->isLocked(ddsData, m_mainHandler->exerciseId())) { ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "EffectShowActorRelocation '%1' is used by another user!")).arg(ifs->getId()); m_mainHandler->dds()->fts()->effectShowActorRelocationRemoveReply(cookie, ret); return; } ret = ifs->removeObject(); if (ret.error()) ERROR_LOG(m_logger) << LOGFUNCTION << ret(); else { // trigger relocation telegram to effect show actor int participantId = ifs->getIdEffectShowActor(); int equipmentNumber = m_mainHandler->handlerPpmData()->getEquipmentNumber(participantId); m_mainHandler->handlerTabData()->retractOrder(equipmentNumber, participantId, ifs->getRetractOrder()); // remove from map delete ifs; m_effectShowActorRelocationObjMap.remove(request.id()); } m_mainHandler->dds()->fts()->effectShowActorRelocationRemoveReply(cookie, ret); } //----------------------------------------------------------------------------- } // Namespace EffectShowManagement