From b71ccf8dd8274b6dc00dcec74e412bad25c812cd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 Nov 2020 15:28:55 +0100 Subject: [PATCH] some refactoring --- datapoollocal/LocalDataPoolManager.cpp | 234 +++++++++++++------------ datapoollocal/LocalDataPoolManager.h | 7 + 2 files changed, 133 insertions(+), 108 deletions(-) diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index d89f597e4..65a40298b 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -101,120 +101,15 @@ ReturnValue_t LocalDataPoolManager::performHkOperation() { break; } case(ReportingType::UPDATE_HK): { - if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { - // Update packets shall only be generated from datasets. - continue; - } - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( - receiver.dataId.sid); - if(dataSet->hasChanged()) { - // prepare and send update notification - ReturnValue_t result = generateHousekeepingPacket( - receiver.dataId.sid, dataSet, true); - if(result != HasReturnvaluesIF::RETURN_OK) { - status = result; - } - } - handleChangeResetLogic(receiver.dataType, receiver.dataId, - dataSet); + handleHkUpdate(receiver, status); break; } case(ReportingType::UPDATE_NOTIFICATION): { - MarkChangedIF* toReset = nullptr; - if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { - LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( - receiver.dataId.localPoolId); - if(poolObj == nullptr) { - continue; - } - if(poolObj->hasChanged()) { - // prepare and send update notification. - CommandMessage notification; - HousekeepingMessage::setUpdateNotificationVariableCommand( - ¬ification, receiver.dataId.localPoolId); - ReturnValue_t result = hkQueue->sendMessage( - receiver.destinationQueue, ¬ification); - if(result != HasReturnvaluesIF::RETURN_OK) { - status = result; - } - toReset = poolObj; - } - - } - else { - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( - receiver.dataId.sid); - if(dataSet == nullptr) { - continue; - } - if(dataSet->hasChanged()) { - // prepare and send update notification - CommandMessage notification; - HousekeepingMessage::setUpdateNotificationSetCommand( - ¬ification, receiver.dataId.sid); - ReturnValue_t result = hkQueue->sendMessage( - receiver.destinationQueue, ¬ification); - if(result != HasReturnvaluesIF::RETURN_OK) { - status = result; - } - toReset = dataSet; - } - } - if(toReset != nullptr) { - handleChangeResetLogic(receiver.dataType, - receiver.dataId, toReset); - } + handleNotificationUpdate(receiver, status); break; } case(ReportingType::UPDATE_SNAPSHOT): { - MarkChangedIF* toReset = nullptr; - // check whether data has changed and send messages in case it has. - if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { - LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( - receiver.dataId.localPoolId); - if(poolObj == nullptr) { - continue; - } - if(poolObj->hasChanged()) { - // prepare and send update snapshot. - CommandMessage notification; - // todo: serialize into store with timestamp. - store_address_t storeId; - HousekeepingMessage::setUpdateSnapshotSetCommand( - ¬ification, receiver.dataId.sid, storeId); - ReturnValue_t result = hkQueue->sendMessage( - receiver.destinationQueue, ¬ification); - if(result != HasReturnvaluesIF::RETURN_OK) { - status = result; - } - toReset = poolObj; - } - } - else { - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( - receiver.dataId.sid); - if(dataSet == nullptr) { - continue; - } - if(dataSet->hasChanged()) { - // prepare and send update snapshot. - CommandMessage notification; - // todo: serialize into store with timestamp. - store_address_t storeId; - HousekeepingMessage::setUpdateSnapshotVariableCommand( - ¬ification, receiver.dataId.localPoolId, storeId); - ReturnValue_t result = hkQueue->sendMessage( - receiver.destinationQueue, ¬ification); - if(result != HasReturnvaluesIF::RETURN_OK) { - status = result; - } - toReset = dataSet; - } - } - if(toReset != nullptr) { - handleChangeResetLogic(receiver.dataType, - receiver.dataId, toReset); - } + handleNotificationSnapshot(receiver, status); break; } default: @@ -226,6 +121,129 @@ ReturnValue_t LocalDataPoolManager::performHkOperation() { return status; } +ReturnValue_t LocalDataPoolManager::handleHkUpdate(HkReceiver& receiver, + ReturnValue_t& status) { + if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { + // Update packets shall only be generated from datasets. + return HasReturnvaluesIF::RETURN_FAILED; + } + LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( + receiver.dataId.sid); + if(dataSet->hasChanged()) { + // prepare and send update notification + ReturnValue_t result = generateHousekeepingPacket( + receiver.dataId.sid, dataSet, true); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + } + handleChangeResetLogic(receiver.dataType, receiver.dataId, + dataSet); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t LocalDataPoolManager::handleNotificationUpdate( + HkReceiver& receiver, ReturnValue_t& status) { + MarkChangedIF* toReset = nullptr; + if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { + LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( + receiver.dataId.localPoolId); + if(poolObj == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + if(poolObj->hasChanged()) { + // prepare and send update notification. + CommandMessage notification; + HousekeepingMessage::setUpdateNotificationVariableCommand( + ¬ification, receiver.dataId.localPoolId); + ReturnValue_t result = hkQueue->sendMessage( + receiver.destinationQueue, ¬ification); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + toReset = poolObj; + } + + } + else { + LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( + receiver.dataId.sid); + if(dataSet == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + if(dataSet->hasChanged()) { + // prepare and send update notification + CommandMessage notification; + HousekeepingMessage::setUpdateNotificationSetCommand( + ¬ification, receiver.dataId.sid); + ReturnValue_t result = hkQueue->sendMessage( + receiver.destinationQueue, ¬ification); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + toReset = dataSet; + } + } + if(toReset != nullptr) { + handleChangeResetLogic(receiver.dataType, + receiver.dataId, toReset); + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( + HkReceiver& receiver, ReturnValue_t& status) { + MarkChangedIF* toReset = nullptr; + // check whether data has changed and send messages in case it has. + if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { + LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( + receiver.dataId.localPoolId); + if(poolObj == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + if(poolObj->hasChanged()) { + // prepare and send update snapshot. + CommandMessage notification; + // todo: serialize into store with timestamp. + store_address_t storeId; + HousekeepingMessage::setUpdateSnapshotSetCommand( + ¬ification, receiver.dataId.sid, storeId); + ReturnValue_t result = hkQueue->sendMessage( + receiver.destinationQueue, ¬ification); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + toReset = poolObj; + } + } + else { + LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( + receiver.dataId.sid); + if(dataSet == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + if(dataSet->hasChanged()) { + // prepare and send update snapshot. + CommandMessage notification; + // todo: serialize into store with timestamp. + store_address_t storeId; + HousekeepingMessage::setUpdateSnapshotVariableCommand( + ¬ification, receiver.dataId.localPoolId, storeId); + ReturnValue_t result = hkQueue->sendMessage( + receiver.destinationQueue, ¬ification); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + toReset = dataSet; + } + } + if(toReset != nullptr) { + handleChangeResetLogic(receiver.dataType, + receiver.dataId, toReset); + } + return HasReturnvaluesIF::RETURN_OK; +} + void LocalDataPoolManager::handleChangeResetLogic( DataType type, DataId dataId, MarkChangedIF* toReset) { if(hkUpdateResetList == nullptr) { diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index afe827605..a5cd0f98c 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -350,6 +350,13 @@ private: void handleChangeResetLogic(DataType type, DataId dataId, MarkChangedIF* toReset); void resetHkUpdateResetHelper(); + + ReturnValue_t handleHkUpdate(HkReceiver& hkReceiver, + ReturnValue_t& status); + ReturnValue_t handleNotificationUpdate(HkReceiver& hkReceiver, + ReturnValue_t& status); + ReturnValue_t handleNotificationSnapshot(HkReceiver& hkReceiver, + ReturnValue_t& status); };