fsfw/src/fsfw/action/TemplateAction.h

30 lines
965 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
2023-07-03 10:09:47 +02:00
template <class owner_class, class action_type, class ActionEnum>
2022-06-29 23:36:45 +02:00
class TemplateAction : public Action {
public:
#ifdef FSFW_INTROSPECTION
2023-07-03 10:09:47 +02:00
TemplateAction(owner_class *myOwner, ActionEnum id) : Action(), myOwner(myOwner) {
2022-06-29 23:36:45 +02:00
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
2023-07-03 10:09:47 +02:00
TemplateAction(owner_class *myOwner, ActionEnum id) : Action((uint32_t)id), myOwner(myOwner) {
2022-06-29 23:36:45 +02:00
myOwner->getActionHelper()->registerAction(this);
}
#endif
2023-07-03 10:09:47 +02:00
ReturnValue_t handle() override { return myOwner->handleAction(dynamic_cast<action_type *>(this)); }
2022-06-29 23:36:45 +02:00
private:
2023-07-03 10:09:47 +02:00
owner_class *myOwner;
2022-09-08 11:41:32 +02:00
};