diff --git a/action/ActionHelper.cpp b/action/ActionHelper.cpp index ef9f06a9..19a84d82 100644 --- a/action/ActionHelper.cpp +++ b/action/ActionHelper.cpp @@ -1,9 +1,9 @@ #include #include #include + ActionHelper::ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue) : - owner(setOwner), queueToUse(useThisQueue), ipcStore( - NULL) { + owner(setOwner), queueToUse(useThisQueue), ipcStore(nullptr) { } ActionHelper::~ActionHelper() { @@ -22,10 +22,12 @@ ReturnValue_t ActionHelper::handleActionMessage(CommandMessage* command) { ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) { ipcStore = objectManager->get(objects::IPC_STORE); - if (ipcStore == NULL) { + if (ipcStore == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - setQueueToUse(queueToUse_); + if(queueToUse_ != nullptr) { + setQueueToUse(queueToUse_); + } return HasReturnvaluesIF::RETURN_OK; } diff --git a/action/ActionHelper.h b/action/ActionHelper.h index 6ba6dd89..3d8351d6 100644 --- a/action/ActionHelper.h +++ b/action/ActionHelper.h @@ -38,7 +38,7 @@ public: * @param queueToUse_ Pointer to the messageQueue to be used * @return Returns RETURN_OK if successful */ - ReturnValue_t initialize(MessageQueueIF* queueToUse_); + ReturnValue_t initialize(MessageQueueIF* queueToUse_ = nullptr); /** * Function to be called from the owner to send a step message. Success or failure will be determined by the result value. * diff --git a/container/FIFO.h b/container/FIFO.h index 889d2ade..f70c78b0 100644 --- a/container/FIFO.h +++ b/container/FIFO.h @@ -70,13 +70,8 @@ public: } ReturnValue_t pop() { - if(empty()) { - return EMPTY; - } else { - readIndex = next(readIndex); - --currentSize; - return HasReturnvaluesIF::RETURN_OK; - } + T value; + return this->retrieve(&value); } static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS; diff --git a/devicehandlers/FixedSlotSequence.cpp b/devicehandlers/FixedSlotSequence.cpp index 466d846f..8974510e 100644 --- a/devicehandlers/FixedSlotSequence.cpp +++ b/devicehandlers/FixedSlotSequence.cpp @@ -90,14 +90,8 @@ uint32_t FixedSlotSequence::getLengthMs() const { ReturnValue_t FixedSlotSequence::checkSequence() const { if(slotList.empty()) { sif::error << "Fixed Slot Sequence: Slot list is empty!" << std::endl; - // does check sequence have to be const? - // if I want to check a class, I need the ability to set - // internal class states. - //isEmpty = true; - std::exit(0); + return HasReturnvaluesIF::RETURN_FAILED; } - // Iterate through slotList and check successful creation. - // Checks if timing is ok (must be ascending) and if all handlers were found. auto slotIt = slotList.begin(); uint32_t count = 0; uint32_t time = 0; diff --git a/devicehandlers/FixedSlotSequence.h b/devicehandlers/FixedSlotSequence.h index 1d872c84..dd9636c1 100644 --- a/devicehandlers/FixedSlotSequence.h +++ b/devicehandlers/FixedSlotSequence.h @@ -12,14 +12,19 @@ using SlotListIter = std::multiset::iterator; /** * @brief This class is the representation of a Polling Sequence Table in software. + * @details + * The FixedSlotSequence object maintains the dynamic execution of + * device handler objects. * - * @details The FixedSlotSequence object maintains the dynamic execution of device handler objects. - * The main idea is to create a list of device handlers, to announce all handlers to the - * polling sequence and to maintain a list of polling slot objects. This slot list represents the - * Polling Sequence Table in software. Each polling slot contains information to indicate when and - * which device handler shall be executed within a given polling period. - * The sequence is then executed by iterating through this slot list. - * Handlers are invoking by calling a certain function stored in the handler list. + * The main idea is to create a list of device handlers, to announce all + * handlers to thepolling sequence and to maintain a list of + * polling slot objects. This slot list represents the Polling Sequence Table + * in software. + * + * Each polling slot contains information to indicate when and + * which device handler shall be executed within a given polling period. + * The sequence is then executed by iterating through this slot list. + * Handlers are invoking by calling a certain function stored in the handler list. */ class FixedSlotSequence { public: @@ -112,7 +117,13 @@ public: */ SlotListIter current; - virtual ReturnValue_t checkSequence() const; + /** + * Iterate through slotList and check successful creation. + * Checks if timing is ok (must be ascending) and if all handlers were found. + * @return + */ + ReturnValue_t checkSequence() const; + protected: /** diff --git a/objectmanager/ObjectManagerIF.h b/objectmanager/ObjectManagerIF.h index 1d7674c6..3a23e339 100644 --- a/objectmanager/ObjectManagerIF.h +++ b/objectmanager/ObjectManagerIF.h @@ -12,6 +12,7 @@ #include #include #include +#include /** * @brief This class provides an interface to the global object manager. @@ -24,9 +25,12 @@ */ class ObjectManagerIF : public HasReturnvaluesIF { public: - static const uint8_t INTERFACE_ID = CLASS_ID::OBJECT_MANAGER_IF; - static const ReturnValue_t INSERTION_FAILED = MAKE_RETURN_CODE( 1 ); - static const ReturnValue_t NOT_FOUND = MAKE_RETURN_CODE( 2 ); + static constexpr uint8_t INTERFACE_ID = CLASS_ID::OBJECT_MANAGER_IF; + static constexpr ReturnValue_t INSERTION_FAILED = MAKE_RETURN_CODE( 1 ); + static constexpr ReturnValue_t NOT_FOUND = MAKE_RETURN_CODE( 2 ); + static constexpr ReturnValue_t CHILD_INIT_FAILED = MAKE_RETURN_CODE( 3 ); + static constexpr ReturnValue_t INTERNAL_ERR_REPORTER_UNINIT = MAKE_RETURN_CODE( 4 ); + protected: /** * @brief This method is used to hide the template-based get call from @@ -79,16 +83,21 @@ public: }; -/*Documentation can be found in the class method declaration above.*/ -template -T* ObjectManagerIF::get( object_id_t id ) { - SystemObjectIF* temp = this->getSystemObject(id); - return dynamic_cast(temp); -} - /** * @brief This is the forward declaration of the global objectManager instance. */ extern ObjectManagerIF *objectManager; +/*Documentation can be found in the class method declaration above.*/ +template +T* ObjectManagerIF::get( object_id_t id ) { + if(objectManager == nullptr) { + sif::error << "ObjectManagerIF: Global object manager has not " + "been initialized yet!" << std::endl; + std::exit(0); + } + SystemObjectIF* temp = this->getSystemObject(id); + return dynamic_cast(temp); +} + #endif /* OBJECTMANAGERIF_H_ */ diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index aed66349..d1c3fe3a 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -57,10 +57,10 @@ ReturnValue_t FixedTimeslotTask::startTask() { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { - if (objectManager->get(componentId) != NULL) { + if (objectManager->get(componentId) != nullptr) { if(slotTimeMs == 0) { - // TODO: FreeRTOS throws errors for zero values. - // maybe there is a better solution than this. + // FreeRTOS throws a sanity error for zero values, so we set + // the time to one millisecond. slotTimeMs = 1; } pst.addSlot(componentId, slotTimeMs, executionStep, this); diff --git a/osal/linux/FixedTimeslotTask.cpp b/osal/linux/FixedTimeslotTask.cpp index 04ceb4e6..098753a7 100644 --- a/osal/linux/FixedTimeslotTask.cpp +++ b/osal/linux/FixedTimeslotTask.cpp @@ -42,14 +42,14 @@ uint32_t FixedTimeslotTask::getPeriodMs() const { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { - if (!objectManager->get(componentId)) { - sif::error << "Component " << std::hex << componentId - << " not found, not adding it to pst" << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; + if (objectManager->get(componentId) != nullptr) { + pst.addSlot(componentId, slotTimeMs, executionStep, this); + return HasReturnvaluesIF::RETURN_OK; } - pst.addSlot(componentId, slotTimeMs, executionStep, this); - return HasReturnvaluesIF::RETURN_OK; + sif::error << "Component " << std::hex << componentId << + " not found, not adding it to pst" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; } ReturnValue_t FixedTimeslotTask::checkSequence() const { diff --git a/osal/rtems/PollingTask.cpp b/osal/rtems/PollingTask.cpp index c2dc629b..6b0c0fbd 100644 --- a/osal/rtems/PollingTask.cpp +++ b/osal/rtems/PollingTask.cpp @@ -66,10 +66,16 @@ ReturnValue_t PollingTask::startTask() { } } -ReturnValue_t PollingTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, - int8_t executionStep) { - pst.addSlot(componentId, slotTimeMs, executionStep, this); - return HasReturnvaluesIF::RETURN_OK; +ReturnValue_t PollingTask::addSlot(object_id_t componentId, + uint32_t slotTimeMs, int8_t executionStep) { + if (objectManager->get(componentId) != nullptr) { + pst.addSlot(componentId, slotTimeMs, executionStep, this); + return HasReturnvaluesIF::RETURN_OK; + } + + sif::error << "Component " << std::hex << componentId << + " not found, not adding it to pst" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; } uint32_t PollingTask::getPeriodMs() const { diff --git a/returnvalues/HasReturnvaluesIF.h b/returnvalues/HasReturnvaluesIF.h index d84fc757..9bbaf601 100644 --- a/returnvalues/HasReturnvaluesIF.h +++ b/returnvalues/HasReturnvaluesIF.h @@ -13,9 +13,7 @@ class HasReturnvaluesIF { public: static const ReturnValue_t RETURN_OK = 0; static const ReturnValue_t RETURN_FAILED = 0xFFFF; - virtual ~HasReturnvaluesIF() { - } - + virtual ~HasReturnvaluesIF() {} }; #endif /* HASRETURNVALUESIF_H_ */ diff --git a/storagemanager/LocalPool.tpp b/storagemanager/LocalPool.tpp index 5cead166..c46e1a8d 100644 --- a/storagemanager/LocalPool.tpp +++ b/storagemanager/LocalPool.tpp @@ -242,8 +242,8 @@ inline ReturnValue_t LocalPool::initialize() { } internalErrorReporter = objectManager->get( objects::INTERNAL_ERROR_REPORTER); - if (internalErrorReporter == NULL){ - return RETURN_FAILED; + if (internalErrorReporter == nullptr){ + return ObjectManagerIF::INTERNAL_ERR_REPORTER_UNINIT; } //Check if any pool size is large than the maximum allowed. @@ -251,7 +251,7 @@ inline ReturnValue_t LocalPool::initialize() { if (element_sizes[count] >= STORAGE_FREE) { sif::error << "LocalPool::initialize: Pool is too large! " "Max. allowed size is: " << (STORAGE_FREE - 1) << std::endl; - return RETURN_FAILED; + return StorageManagerIF::POOL_TOO_LARGE; } } return RETURN_OK; diff --git a/storagemanager/StorageManagerIF.h b/storagemanager/StorageManagerIF.h index d85fe86f..d1f9cde5 100644 --- a/storagemanager/StorageManagerIF.h +++ b/storagemanager/StorageManagerIF.h @@ -71,6 +71,7 @@ public: static const ReturnValue_t ILLEGAL_STORAGE_ID = MAKE_RETURN_CODE(3); //!< This return code indicates that data was requested with an illegal storage ID. static const ReturnValue_t DATA_DOES_NOT_EXIST = MAKE_RETURN_CODE(4); //!< This return code indicates that the requested ID was valid, but no data is stored there. static const ReturnValue_t ILLEGAL_ADDRESS = MAKE_RETURN_CODE(5); + static const ReturnValue_t POOL_TOO_LARGE = MAKE_RETURN_CODE(6); //!< Pool size too large on initialization. static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::OBSW; static const Event GET_DATA_FAILED = MAKE_EVENT(0, SEVERITY::LOW);