2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/storagemanager/StorageAccessor.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/serviceinterface/ServiceInterface.h"
|
|
|
|
#include "fsfw/storagemanager/StorageManagerIF.h"
|
2020-09-29 14:35:05 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
StorageAccessor::StorageAccessor(store_address_t storeId) : ConstStorageAccessor(storeId) {}
|
|
|
|
|
|
|
|
StorageAccessor::StorageAccessor(store_address_t storeId, StorageManagerIF* store)
|
|
|
|
: ConstStorageAccessor(storeId, store) {}
|
2020-09-29 14:35:05 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) {
|
|
|
|
// Call the parent move assignment and also assign own member.
|
|
|
|
dataPointer = other.dataPointer;
|
2022-06-20 15:15:33 +02:00
|
|
|
ConstStorageAccessor::operator=(std::move(other));
|
2022-02-02 10:29:30 +01:00
|
|
|
return *this;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call the parent move ctor and also transfer own member.
|
2022-02-02 10:29:30 +01:00
|
|
|
StorageAccessor::StorageAccessor(StorageAccessor&& other)
|
|
|
|
: ConstStorageAccessor(std::move(other)), dataPointer(other.dataPointer) {}
|
2020-09-29 14:35:05 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t StorageAccessor::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-08-15 20:28:16 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
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-08-15 20:28:16 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
std::copy(dataPointer, dataPointer + size_, pointer);
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::OK;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* StorageAccessor::data() {
|
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 dataPointer;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t StorageAccessor::write(uint8_t* data, size_t size, uint16_t offset) {
|
|
|
|
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-08-15 20:28:16 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
if (offset + size > size_) {
|
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: Data too large for pool "
|
|
|
|
"entry!"
|
|
|
|
<< std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
std::copy(data, data + size, dataPointer + offset);
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::OK;
|
2020-09-29 14:35:05 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
void StorageAccessor::assignConstPointer() { constDataPointer = dataPointer; }
|