2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/storagemanager/ConstStorageAccessor.h"
|
2020-09-29 14:35:05 +02:00
|
|
|
|
2021-01-03 14:33:17 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/globalfunctions/arrayprinter.h"
|
|
|
|
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
|
|
|
|
#include "fsfw/storagemanager/StorageManagerIF.h"
|
|
|
|
|
|
|
|
ConstStorageAccessor::ConstStorageAccessor(store_address_t storeId) : storeId(storeId) {}
|
2020-09-29 14:35:05 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ConstStorageAccessor::ConstStorageAccessor(store_address_t storeId, StorageManagerIF* store)
|
|
|
|
: storeId(storeId), store(store) {
|
|
|
|
internalState = AccessState::ASSIGNED;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstStorageAccessor::~ConstStorageAccessor() {
|
2022-02-02 10:29:30 +01:00
|
|
|
if (deleteData and store != nullptr) {
|
|
|
|
store->deleteData(storeId);
|
|
|
|
}
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other)
|
|
|
|
: constDataPointer(other.constDataPointer),
|
|
|
|
storeId(other.storeId),
|
|
|
|
size_(other.size_),
|
|
|
|
store(other.store),
|
|
|
|
deleteData(other.deleteData),
|
|
|
|
internalState(other.internalState) {
|
|
|
|
// This prevent premature deletion
|
|
|
|
other.store = nullptr;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ConstStorageAccessor& ConstStorageAccessor::operator=(ConstStorageAccessor&& other) {
|
|
|
|
constDataPointer = other.constDataPointer;
|
|
|
|
storeId = other.storeId;
|
|
|
|
store = other.store;
|
|
|
|
size_ = other.size_;
|
|
|
|
deleteData = other.deleteData;
|
|
|
|
this->store = other.store;
|
|
|
|
// This prevents premature deletion
|
|
|
|
other.store = nullptr;
|
|
|
|
return *this;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
const uint8_t* ConstStorageAccessor::data() const { return constDataPointer; }
|
2020-09-29 14:35:05 +02:00
|
|
|
|
|
|
|
size_t ConstStorageAccessor::size() const {
|
2022-02-02 10:29:30 +01:00
|
|
|
if (internalState == AccessState::UNINIT) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::warning << "StorageAccessor: Not initialized!" << std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
return size_;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t ConstStorageAccessor::getDataCopy(uint8_t* pointer, size_t maxSize) {
|
|
|
|
if (internalState == AccessState::UNINIT) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::warning << "StorageAccessor: Not initialized!" << std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
if (size_ > maxSize) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::error << "StorageAccessor: Supplied buffer not large enough" << std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
std::copy(constDataPointer, constDataPointer + size_, pointer);
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
void ConstStorageAccessor::release() { deleteData = false; }
|
2020-09-29 14:35:05 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
store_address_t ConstStorageAccessor::getId() const { return storeId; }
|
2020-09-29 14:35:05 +02:00
|
|
|
|
|
|
|
void ConstStorageAccessor::print() const {
|
2022-02-02 10:29:30 +01:00
|
|
|
if (internalState == AccessState::UNINIT or constDataPointer == nullptr) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::warning << "StorageAccessor: Not initialized!" << std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2022-02-02 10:29:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
arrayprinter::print(constDataPointer, size_);
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConstStorageAccessor::assignStore(StorageManagerIF* store) {
|
2022-02-02 10:29:30 +01:00
|
|
|
internalState = AccessState::ASSIGNED;
|
|
|
|
this->store = store;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|