improve structure
All checks were successful
EIVE/eive-obsw/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2023-11-15 15:27:12 +01:00
parent f0536a9d77
commit 457acc3bdb
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 57 additions and 39 deletions

View File

@ -137,53 +137,68 @@ ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore,
if (cmdMessage.getMessageType() == messagetypes::TM_STORE) { if (cmdMessage.getMessageType() == messagetypes::TM_STORE) {
Command_t cmd = cmdMessage.getCommand(); Command_t cmd = cmdMessage.getCommand();
if (cmd == TmStoreMessage::DELETE_STORE_CONTENT_TIME) { if (cmd == TmStoreMessage::DELETE_STORE_CONTENT_TIME) {
Clock::getClock_timeval(&currentTv); result = handleDeletionCmd(ipcStore, cmdMessage);
store_address_t storeId = TmStoreMessage::getStoreId(&cmdMessage);
auto accessor = ipcStore.getData(storeId);
size_t size = accessor.second.size();
if (size < 4) {
return returnvalue::FAILED;
}
const uint8_t* data = accessor.second.data();
uint32_t deleteUpToUnixSeconds = 0;
if (size == 4) {
SerializeAdapter::deSerialize(&deleteUpToUnixSeconds, &data, &size,
SerializeIF::Endianness::NETWORK);
deleteUpTo(deleteUpToUnixSeconds);
} else if (size == 8) {
uint32_t deleteFromUnixSeconds = 0;
SerializeAdapter::deSerialize(&deleteFromUnixSeconds, &data, &size,
SerializeIF::Endianness::NETWORK);
SerializeAdapter::deSerialize(&deleteUpToUnixSeconds, &data, &size,
SerializeIF::Endianness::NETWORK);
deleteFromUpTo(deleteFromUnixSeconds, deleteUpToUnixSeconds);
}
execCmd = cmd; execCmd = cmd;
} else if (cmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) { } else if (cmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) {
Clock::getClock_timeval(&currentTv); result = handleDumpCmd(ipcStore, cmdMessage);
store_address_t storeId = TmStoreMessage::getStoreId(&cmdMessage);
auto accessor = ipcStore.getData(storeId);
if (accessor.second.size() < 8) {
return returnvalue::FAILED;
}
uint32_t dumpFromUnixSeconds = 0;
uint32_t dumpUntilUnixSeconds = 0;
size_t size = 8;
SerializeAdapter::deSerialize(&dumpFromUnixSeconds, accessor.second.data(), &size,
SerializeIF::Endianness::NETWORK);
SerializeAdapter::deSerialize(&dumpUntilUnixSeconds, accessor.second.data() + 4, &size,
SerializeIF::Endianness::NETWORK);
result = startDumpFromUpTo(dumpFromUnixSeconds, dumpUntilUnixSeconds);
if (result == BUSY_DUMPING) {
triggerEvent(persTmStore::BUSY_DUMPING_EVENT);
return result;
}
execCmd = cmd; execCmd = cmd;
} }
} }
return result; return result;
} }
ReturnValue_t PersistentTmStore::handleDeletionCmd(StorageManagerIF& ipcStore,
CommandMessage& cmdMessage) {
Clock::getClock_timeval(&currentTv);
store_address_t storeId = TmStoreMessage::getStoreId(&cmdMessage);
auto accessor = ipcStore.getData(storeId);
size_t size = accessor.second.size();
if (size < 4) {
return returnvalue::FAILED;
}
const uint8_t* data = accessor.second.data();
uint32_t deleteUpToUnixSeconds = 0;
if (size == 4) {
SerializeAdapter::deSerialize(&deleteUpToUnixSeconds, &data, &size,
SerializeIF::Endianness::NETWORK);
deleteUpTo(deleteUpToUnixSeconds);
} else if (size == 8) {
uint32_t deleteFromUnixSeconds = 0;
SerializeAdapter::deSerialize(&deleteFromUnixSeconds, &data, &size,
SerializeIF::Endianness::NETWORK);
SerializeAdapter::deSerialize(&deleteUpToUnixSeconds, &data, &size,
SerializeIF::Endianness::NETWORK);
deleteFromUpTo(deleteFromUnixSeconds, deleteUpToUnixSeconds);
} else {
sif::warning << "PersistentTmStore: Unknown deletion time specification" << std::endl;
return returnvalue::FAILED;
}
return returnvalue::OK;
}
ReturnValue_t PersistentTmStore::handleDumpCmd(StorageManagerIF& ipcStore,
CommandMessage& cmdMessage) {
Clock::getClock_timeval(&currentTv);
store_address_t storeId = TmStoreMessage::getStoreId(&cmdMessage);
auto accessor = ipcStore.getData(storeId);
if (accessor.second.size() < 8) {
return returnvalue::FAILED;
}
uint32_t dumpFromUnixSeconds = 0;
uint32_t dumpUntilUnixSeconds = 0;
size_t size = 8;
SerializeAdapter::deSerialize(&dumpFromUnixSeconds, accessor.second.data(), &size,
SerializeIF::Endianness::NETWORK);
SerializeAdapter::deSerialize(&dumpUntilUnixSeconds, accessor.second.data() + 4, &size,
SerializeIF::Endianness::NETWORK);
ReturnValue_t result = startDumpFromUpTo(dumpFromUnixSeconds, dumpUntilUnixSeconds);
if (result == BUSY_DUMPING) {
triggerEvent(persTmStore::BUSY_DUMPING_EVENT);
return result;
}
return returnvalue::OK;
}
ReturnValue_t PersistentTmStore::startDumpFrom(uint32_t fromUnixSeconds) { ReturnValue_t PersistentTmStore::startDumpFrom(uint32_t fromUnixSeconds) {
return startDumpFromUpTo(fromUnixSeconds, currentTv.tv_sec); return startDumpFromUpTo(fromUnixSeconds, currentTv.tv_sec);
} }

View File

@ -14,6 +14,7 @@
#include "eive/eventSubsystemIds.h" #include "eive/eventSubsystemIds.h"
#include "eive/resultClassIds.h" #include "eive/resultClassIds.h"
#include "fsfw/ipc/CommandMessage.h"
enum class RolloverInterval { MINUTELY, HOURLY, DAILY }; enum class RolloverInterval { MINUTELY, HOURLY, DAILY };
@ -146,6 +147,8 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
std::optional<uint8_t> extractSuffix(const std::string& pathStr); std::optional<uint8_t> extractSuffix(const std::string& pathStr);
bool updateBaseDir(); bool updateBaseDir();
ReturnValue_t assignAndOrCreateMostRecentFile(); ReturnValue_t assignAndOrCreateMostRecentFile();
ReturnValue_t handleDeletionCmd(StorageManagerIF& ipcStore, CommandMessage& cmdMessage);
ReturnValue_t handleDumpCmd(StorageManagerIF& ipcStore, CommandMessage& cmdMessage);
}; };
#endif /* MISSION_TMTC_TMSTOREBACKEND_H_ */ #endif /* MISSION_TMTC_TMSTOREBACKEND_H_ */