Check object existence before adding it to the PST

Currently, adding new objects/components to the FixedSlotSequence PST is
not being checked, meaning that it is possible to add NULL objects here
without any warning. This causes NULL-pointer errors when non-existent
components are added, which can be hard to debug.

To solve this, add a check for the object existence before adding it to
PST and emit an error message.

Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
This commit is contained in:
Maximilian Luz 2019-12-19 16:09:50 +01:00 committed by Robin.Mueller
parent fa6cbe7e0c
commit d17146d847
2 changed files with 10 additions and 0 deletions

View File

@ -57,6 +57,11 @@ ReturnValue_t FixedTimeslotTask::startTask() {
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
uint32_t slotTimeMs, int8_t executionStep) {
if (!objectManager->get<ExecutableObjectIF>(componentId)) {
error << "Component " << std::hex << componentId << " not found, not adding it to pst" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
pst.addSlot(componentId, slotTimeMs, executionStep, this);
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -40,6 +40,11 @@ uint32_t FixedTimeslotTask::getPeriodMs() const {
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
uint32_t slotTimeMs, int8_t executionStep) {
if (!objectManager->get<ExecutableObjectIF>(componentId)) {
error << "Component " << std::hex << componentId << " not found, not adding it to pst" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
pst.addSlot(componentId, slotTimeMs, executionStep, this);
return HasReturnvaluesIF::RETURN_OK;
}