fsfw/src/fsfw/action/TemplateAction.h

30 lines
931 B
C
Raw Normal View History

2022-06-29 23:36:45 +02:00
#pragma once
#include "Action.h"
2022-08-19 13:27:26 +02:00
#include "fsfw/serviceinterface/ServiceInterface.h"
2022-06-29 23:36:45 +02:00
template <class owner, class action, class ActionEnum>
class TemplateAction : public Action {
public:
#ifdef FSFW_INTROSPECTION
TemplateAction(owner *myOwner, ActionEnum id) : Action(), myOwner(myOwner) {
Action::setEnum(&id);
2022-09-08 11:41:32 +02:00
if (myOwner->getActionHelper() == nullptr) {
2022-08-19 13:27:26 +02:00
sif::error
<< "TemplateAction::TemplateAction: Action instances need to be created (ie located) after the actionHelper instance."
<< "Program will segfault now..." << std::endl;
}
2022-06-29 23:36:45 +02:00
myOwner->getActionHelper()->registerAction(this);
}
#else
2022-08-19 13:27:26 +02:00
TemplateAction(owner *myOwner, ActionEnum id) : Action((uint32_t)id), myOwner(myOwner) {
2022-06-29 23:36:45 +02:00
myOwner->getActionHelper()->registerAction(this);
}
#endif
ReturnValue_t handle() override { return myOwner->handleAction(dynamic_cast<action *>(this)); }
private:
owner *myOwner;
2022-09-08 11:41:32 +02:00
};