From e34664d26575abd17bc001bee296f1703101b276 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Fri, 19 Aug 2022 13:27:26 +0200 Subject: [PATCH] Adding error message to a coding error --- src/fsfw/action/ActionHelper.cpp | 4 +++- src/fsfw/action/ActionHelper.h | 6 ++++++ src/fsfw/action/TemplateAction.h | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/fsfw/action/ActionHelper.cpp b/src/fsfw/action/ActionHelper.cpp index 8c68ea63..9ad7b6be 100644 --- a/src/fsfw/action/ActionHelper.cpp +++ b/src/fsfw/action/ActionHelper.cpp @@ -57,7 +57,9 @@ void ActionHelper::finish(bool success, MessageQueueId_t reportTo, ActionId_t co void ActionHelper::setQueueToUse(MessageQueueIF* queue) { queueToUse = queue; } -#include +MessageQueueIF const * ActionHelper::getQueue() const { + return queueToUse; +} void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, store_address_t dataAddress) { diff --git a/src/fsfw/action/ActionHelper.h b/src/fsfw/action/ActionHelper.h index cdda7040..8e646ea6 100644 --- a/src/fsfw/action/ActionHelper.h +++ b/src/fsfw/action/ActionHelper.h @@ -100,6 +100,12 @@ class ActionHelper { */ void setQueueToUse(MessageQueueIF* queue); + /** + * Needed so templateAction can check if actionHelper was + * contructed already to aid in debuggig a nasty coding error. + */ + MessageQueueIF const * getQueue() const; + void registerAction(Action* action); std::map const* getActionMap(); diff --git a/src/fsfw/action/TemplateAction.h b/src/fsfw/action/TemplateAction.h index 8b83379e..f9eeccf3 100644 --- a/src/fsfw/action/TemplateAction.h +++ b/src/fsfw/action/TemplateAction.h @@ -1,6 +1,7 @@ #pragma once #include "Action.h" +#include "fsfw/serviceinterface/ServiceInterface.h" template class TemplateAction : public Action { @@ -8,10 +9,15 @@ class TemplateAction : public Action { #ifdef FSFW_INTROSPECTION TemplateAction(owner *myOwner, ActionEnum id) : Action(), myOwner(myOwner) { Action::setEnum(&id); + if (myOwner->getActionHelper()->getQueue() == nullptr) { + sif::error + << "TemplateAction::TemplateAction: Action instances need to be created (ie located) after the actionHelper instance." + << "Program will segfault now..." << std::endl; + } myOwner->getActionHelper()->registerAction(this); } #else - TemplateAction(owner *myOwner, ActionEnum id) : Action((uint32_t) id), myOwner(myOwner) { + TemplateAction(owner *myOwner, ActionEnum id) : Action((uint32_t)id), myOwner(myOwner) { myOwner->getActionHelper()->registerAction(this); } #endif