2020-05-17 22:20:54 +02:00
|
|
|
#ifndef GLOBALPOOLVARIABLE_TPP_
|
|
|
|
#define GLOBALPOOLVARIABLE_TPP_
|
2020-05-17 01:17:11 +02:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline GlobPoolVar<T>::GlobPoolVar(uint32_t set_id,
|
|
|
|
DataSetIF* dataSet, ReadWriteMode_t setReadWriteMode):
|
|
|
|
dataPoolId(set_id), valid(PoolVariableIF::INVALID),
|
|
|
|
readWriteMode(setReadWriteMode)
|
|
|
|
{
|
|
|
|
if (dataSet != nullptr) {
|
|
|
|
dataSet->registerVariable(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 20:33:57 +02:00
|
|
|
template<typename T>
|
|
|
|
inline ReturnValue_t GlobPoolVar<T>::read(uint32_t lockTimeout) {
|
|
|
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = readWithoutLock();
|
|
|
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
|
|
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline ReturnValue_t GlobPoolVar<T>::commit(uint32_t lockTimeout) {
|
|
|
|
ReturnValue_t result = glob::dataPool.lockDataPool(lockTimeout);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = commitWithoutLock();
|
|
|
|
ReturnValue_t unlockResult = glob::dataPool.unlockDataPool();
|
|
|
|
if(unlockResult != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::error << "GlobPoolVar::read: Could not unlock global data pool"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-17 01:17:11 +02:00
|
|
|
template <class T>
|
2020-06-05 20:33:57 +02:00
|
|
|
inline ReturnValue_t GlobPoolVar<T>::readWithoutLock() {
|
2020-05-17 13:37:50 +02:00
|
|
|
PoolEntry<T>* read_out = glob::dataPool.getData<T>(dataPoolId, 1);
|
2020-05-17 01:17:11 +02:00
|
|
|
if (read_out != NULL) {
|
|
|
|
valid = read_out->valid;
|
|
|
|
value = *(read_out->address);
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
} else {
|
|
|
|
value = 0;
|
|
|
|
valid = false;
|
|
|
|
sif::error << "PoolVariable: read of DP Variable 0x" << std::hex
|
|
|
|
<< dataPoolId << std::dec << " failed." << std::endl;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-06-05 20:33:57 +02:00
|
|
|
inline ReturnValue_t GlobPoolVar<T>::commitWithoutLock() {
|
2020-05-17 13:37:50 +02:00
|
|
|
PoolEntry<T>* write_back = glob::dataPool.getData<T>(dataPoolId, 1);
|
2020-05-17 01:17:11 +02:00
|
|
|
if ((write_back != NULL) && (readWriteMode != VAR_READ)) {
|
|
|
|
write_back->valid = valid;
|
|
|
|
*(write_back->address) = value;
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
} else {
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline GlobPoolVar<T>::GlobPoolVar():
|
|
|
|
dataPoolId(PoolVariableIF::NO_PARAMETER),
|
|
|
|
valid(PoolVariableIF::INVALID),
|
|
|
|
readWriteMode(VAR_READ), value(0) {}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline GlobPoolVar<T>::GlobPoolVar(const GlobPoolVar& rhs) :
|
|
|
|
dataPoolId(rhs.dataPoolId), valid(rhs.valid), readWriteMode(
|
|
|
|
rhs.readWriteMode), value(rhs.value) {}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline pool_rwm_t GlobPoolVar<T>::getReadWriteMode() const {
|
|
|
|
return readWriteMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline uint32_t GlobPoolVar<T>::getDataPoolId() const {
|
|
|
|
return dataPoolId;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline void GlobPoolVar<T>::setDataPoolId(uint32_t poolId) {
|
|
|
|
dataPoolId = poolId;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline bool GlobPoolVar<T>::isValid() const {
|
|
|
|
if (valid)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline uint8_t GlobPoolVar<T>::getValid() {
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-06-05 20:33:57 +02:00
|
|
|
inline void GlobPoolVar<T>::setValid(bool valid) {
|
2020-05-17 01:17:11 +02:00
|
|
|
this->valid = valid;
|
|
|
|
}
|
2020-05-17 22:20:54 +02:00
|
|
|
|
|
|
|
#endif
|