fsfw/datapoollocal/LocalPoolObjectBase.cpp

127 lines
3.7 KiB
C++
Raw Normal View History

2021-01-12 19:41:47 +01:00
#include "LocalDataPoolManager.h"
2020-12-03 13:00:04 +01:00
#include "LocalPoolObjectBase.h"
2021-01-12 19:41:47 +01:00
#include "HasLocalDpIFUserAttorney.h"
2020-12-03 13:00:04 +01:00
2021-01-11 22:33:58 +01:00
LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, HasLocalDataPoolIF* hkOwner,
DataSetIF* dataSet, pool_rwm_t setReadWriteMode):
localPoolId(poolId), readWriteMode(setReadWriteMode) {
2021-01-11 22:46:40 +01:00
if(poolId == PoolVariableIF::NO_PARAMETER) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-11 22:46:40 +01:00
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
<< "which is the NO_PARAMETER value!" << std::endl;
#endif
2021-01-11 22:46:40 +01:00
}
if(hkOwner == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-11 22:46:40 +01:00
sif::error << "LocalPoolVar<T>::LocalPoolVar: The supplied pool "
<< "owner is a invalid!" << std::endl;
#endif
2021-01-11 22:46:40 +01:00
return;
}
2021-01-12 14:08:51 +01:00
AccessPoolManagerIF* poolManAccessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
hkManager = poolManAccessor->getHkManagerHandle();
2021-01-12 19:41:47 +01:00
2021-01-11 22:46:40 +01:00
if (dataSet != nullptr) {
dataSet->registerVariable(this);
}
2020-12-03 13:00:04 +01:00
}
2021-01-11 22:33:58 +01:00
LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, DataSetIF *dataSet,
pool_rwm_t setReadWriteMode):
2021-01-11 22:46:40 +01:00
localPoolId(poolId), readWriteMode(setReadWriteMode) {
if(poolId == PoolVariableIF::NO_PARAMETER) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-11 22:46:40 +01:00
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
<< "which is the NO_PARAMETER value!" << std::endl;
#endif
2021-01-11 22:46:40 +01:00
}
HasLocalDataPoolIF* hkOwner =
objectManager->get<HasLocalDataPoolIF>(poolOwner);
if(hkOwner == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-11 22:46:40 +01:00
sif::error << "LocalPoolVariable: The supplied pool owner did not "
<< "implement the correct interface"
<< " HasLocalDataPoolIF!" << std::endl;
#endif
2021-01-11 22:46:40 +01:00
return;
}
2021-01-12 14:08:51 +01:00
//hkManager = hkOwner->getHkManagerHandle();
AccessPoolManagerIF* poolManAccessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
//hkManager = HasLocalDpIFUserAttorney::getHkManagerHandle(hkOwner);
hkManager = poolManAccessor->getHkManagerHandle();
2021-01-11 22:46:40 +01:00
if(dataSet != nullptr) {
dataSet->registerVariable(this);
}
2020-12-03 13:00:04 +01:00
}
pool_rwm_t LocalPoolObjectBase::getReadWriteMode() const {
2021-01-11 22:46:40 +01:00
return readWriteMode;
2020-12-03 13:00:04 +01:00
}
bool LocalPoolObjectBase::isValid() const {
2021-01-11 22:46:40 +01:00
return valid;
2020-12-03 13:00:04 +01:00
}
void LocalPoolObjectBase::setValid(bool valid) {
2021-01-11 22:46:40 +01:00
this->valid = valid;
2020-12-03 13:00:04 +01:00
}
lp_id_t LocalPoolObjectBase::getDataPoolId() const {
2021-01-11 22:46:40 +01:00
return localPoolId;
2020-12-03 13:00:04 +01:00
}
void LocalPoolObjectBase::setDataPoolId(lp_id_t poolId) {
2021-01-11 22:46:40 +01:00
this->localPoolId = poolId;
2020-12-03 13:00:04 +01:00
}
void LocalPoolObjectBase::setChanged(bool changed) {
2021-01-11 22:46:40 +01:00
this->changed = changed;
2020-12-03 13:00:04 +01:00
}
bool LocalPoolObjectBase::hasChanged() const {
2021-01-11 22:46:40 +01:00
return changed;
2020-12-03 13:00:04 +01:00
}
void LocalPoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) {
this->readWriteMode = newReadWriteMode;
}
2021-01-07 20:23:23 +01:00
void LocalPoolObjectBase::reportReadCommitError(const char* variableType,
ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId) {
#if FSFW_DISABLE_PRINTOUT == 0
const char* type = nullptr;
if(read) {
type = "read";
}
else {
type = "commit";
}
const char* errMsg = nullptr;
if(error == HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND) {
errMsg = "Pool entry not found";
}
else if(error == HasLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT) {
errMsg = "Pool entry type conflict";
}
else if(error == PoolVariableIF::INVALID_READ_WRITE_MODE) {
errMsg = "Pool variable wrong read-write mode";
}
else if(error == PoolVariableIF::INVALID_POOL_ENTRY) {
errMsg = "Pool entry invalid";
}
else {
errMsg = "Unknown error code";
}
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-11 22:33:58 +01:00
sif::warning << variableType << ": " << type << " call | " << errMsg << " | Owner: 0x"
<< std::hex << std::setw(8) << std::setfill('0') << objectId << std::dec
<< " LPID: " << lpId << std::endl;
2021-01-07 20:23:23 +01:00
#else
sif::printWarning("%s: %s call | %s | Owner: 0x%08x LPID: %lu\n",
variableType, type, errMsg, objectId, lpId);
2021-01-07 20:23:23 +01:00
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
}