improved custom checker API

- More clang-tidy improvements
This commit is contained in:
Robin Müller 2022-05-30 11:09:37 +02:00 committed by Gitea
parent 689fb378d8
commit 4542f31c40
4 changed files with 21 additions and 17 deletions

View File

@ -74,8 +74,10 @@ ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
[[noreturn]] void FixedTimeslotTask::taskFunctionality() { void FixedTimeslotTask::taskFunctionality() {
pollingSeqTable.intializeSequenceAfterTaskCreation(); ReturnValue_t result = pollingSeqTable.intializeSequenceAfterTaskCreation();
// Ignore returnvalue for now
static_cast<void>(result);
// A local iterator for the Polling Sequence Table is created to // A local iterator for the Polling Sequence Table is created to
// find the start time for the first entry. // find the start time for the first entry.

View File

@ -93,7 +93,7 @@ class FixedTimeslotTask : public FixedTimeslotTaskBase {
* the checkAndRestartPeriod system call blocks the task until the next * the checkAndRestartPeriod system call blocks the task until the next
* period. On missing the deadline, the deadlineMissedFunction is executed. * period. On missing the deadline, the deadlineMissedFunction is executed.
*/ */
[[noreturn]] void taskFunctionality(); void taskFunctionality();
static bool delayForInterval(chron_ms* previousWakeTimeMs, chron_ms interval); static bool delayForInterval(chron_ms* previousWakeTimeMs, chron_ms interval);
}; };

View File

@ -29,7 +29,7 @@ void FixedSlotSequence::executeAndAdvance() {
uint32_t FixedSlotSequence::getIntervalToNextSlotMs() { uint32_t FixedSlotSequence::getIntervalToNextSlotMs() {
uint32_t oldTime; uint32_t oldTime;
SlotListIter slotListIter = current; auto slotListIter = current;
// Get the pollingTimeMs of the current slot object. // Get the pollingTimeMs of the current slot object.
oldTime = slotListIter->pollingTimeMs; oldTime = slotListIter->pollingTimeMs;
// Advance to the next object. // Advance to the next object.
@ -51,7 +51,7 @@ uint32_t FixedSlotSequence::getIntervalToNextSlotMs() {
uint32_t FixedSlotSequence::getIntervalToPreviousSlotMs() { uint32_t FixedSlotSequence::getIntervalToPreviousSlotMs() {
uint32_t currentTime; uint32_t currentTime;
SlotListIter slotListIter = current; auto slotListIter = current;
// Get the pollingTimeMs of the current slot object. // Get the pollingTimeMs of the current slot object.
currentTime = slotListIter->pollingTimeMs; currentTime = slotListIter->pollingTimeMs;
@ -67,7 +67,7 @@ uint32_t FixedSlotSequence::getIntervalToPreviousSlotMs() {
bool FixedSlotSequence::slotFollowsImmediately() { bool FixedSlotSequence::slotFollowsImmediately() {
uint32_t currentTime = current->pollingTimeMs; uint32_t currentTime = current->pollingTimeMs;
SlotListIter fixedSequenceIter = this->current; auto fixedSequenceIter = this->current;
// Get the pollingTimeMs of the current slot object. // Get the pollingTimeMs of the current slot object.
if (fixedSequenceIter == slotList.begin()) return false; if (fixedSequenceIter == slotList.begin()) return false;
fixedSequenceIter--; fixedSequenceIter--;
@ -96,8 +96,8 @@ ReturnValue_t FixedSlotSequence::checkSequence() const {
return FixedTimeslotTaskIF::SLOT_LIST_EMPTY; return FixedTimeslotTaskIF::SLOT_LIST_EMPTY;
} }
if (customCheckFunction != nullptr) { if (customChecker != nullptr) {
ReturnValue_t result = customCheckFunction(slotList); ReturnValue_t result = customChecker(slotList, customCheckArgs);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
// Continue for now but print error output. // Continue for now but print error output.
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
@ -161,8 +161,9 @@ ReturnValue_t FixedSlotSequence::intializeSequenceAfterTaskCreation() const {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void FixedSlotSequence::addCustomCheck(ReturnValue_t (*customCheckFunction)(const SlotList&)) { void FixedSlotSequence::addCustomCheck(CustomCheckFunc customChecker_, void* checkerArgs_) {
this->customCheckFunction = customCheckFunction; customChecker = customChecker_;
customCheckArgs = checkerArgs_;
} }
bool FixedSlotSequence::isEmpty() const { return slotList.empty(); } bool FixedSlotSequence::isEmpty() const { return slotList.empty(); }

View File

@ -30,7 +30,7 @@ class FixedSlotSequence {
public: public:
using SlotList = std::multiset<FixedSequenceSlot>; using SlotList = std::multiset<FixedSequenceSlot>;
using SlotListIter = std::multiset<FixedSequenceSlot>::iterator; using SlotListIter = std::multiset<FixedSequenceSlot>::iterator;
using CustomCheckFunc = ReturnValue_t (*)(const SlotList&, void* args);
/** /**
* @brief The constructor of the FixedSlotSequence object. * @brief The constructor of the FixedSlotSequence object.
* @param setLength The period length, expressed in ms. * @param setLength The period length, expressed in ms.
@ -106,7 +106,7 @@ class FixedSlotSequence {
/** /**
* @brief This method returns the length of this FixedSlotSequence instance. * @brief This method returns the length of this FixedSlotSequence instance.
*/ */
uint32_t getLengthMs() const; [[nodiscard]] uint32_t getLengthMs() const;
/** /**
* @brief The method to execute the device handler entered in the current * @brief The method to execute the device handler entered in the current
@ -137,7 +137,7 @@ class FixedSlotSequence {
* @return * @return
* - SLOT_LIST_EMPTY if the slot list is empty * - SLOT_LIST_EMPTY if the slot list is empty
*/ */
ReturnValue_t checkSequence() const; [[nodiscard]] ReturnValue_t checkSequence() const;
/** /**
* @brief A custom check can be injected for the respective slot list. * @brief A custom check can be injected for the respective slot list.
@ -149,7 +149,7 @@ class FixedSlotSequence {
* @param customCheckFunction * @param customCheckFunction
* *
*/ */
void addCustomCheck(ReturnValue_t (*customCheckFunction)(const SlotList&)); void addCustomCheck(CustomCheckFunc func, void* userArgs);
/** /**
* @brief Perform any initialization steps required after the executing * @brief Perform any initialization steps required after the executing
@ -157,9 +157,9 @@ class FixedSlotSequence {
* executing task! * executing task!
* @return * @return
*/ */
ReturnValue_t intializeSequenceAfterTaskCreation() const; [[nodiscard]] ReturnValue_t intializeSequenceAfterTaskCreation() const;
bool isEmpty() const; [[nodiscard]] bool isEmpty() const;
protected: protected:
/** /**
@ -175,7 +175,8 @@ class FixedSlotSequence {
*/ */
SlotList slotList; SlotList slotList;
ReturnValue_t (*customCheckFunction)(const SlotList&) = nullptr; CustomCheckFunc customChecker = nullptr;
void* customCheckArgs = nullptr;
uint32_t lengthMs; uint32_t lengthMs;
}; };