17 static_assert(std::numeric_limits<FwSizeType>::max() >= PRMDB_NUM_DB_ENTRIES,
18 "PRMDB_NUM_DB_ENTRIES must fit within range of FwSizeType");
26 WorkingBuffer() :
Fw::LinearBufferBase(m_buff, sizeof(m_buff)) {}
31 static_assert(
sizeof(m_buff) >=
sizeof(U32),
"Size of parameter buffer storage must be >= sizeof(U32)");
39 this->m_activeDb = &this->m_dbStore1;
40 this->m_stagingDb = &this->m_dbStore2;
50 this->m_fileName = file;
55 this->m_sandboxDir = directory;
60 if (this->m_sandboxDir.
length() > 0) {
87 auto success = this->m_activeDb->
find(
id, val);
115 }
else if (update_status ==
NO_SLOTS) {
122 void PrmDbImpl::pingIn_handler(
FwIndexType portNum, U32 key) {
127 void PrmDbImpl::PRM_SAVE_FILE_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
138 this->applySandbox(paramFile);
150 U32 crcInitial = 0xFFFFFFFF;
155 stat = paramFile.write(buff.getBuffAddr(), writeSize, Os::File::WaitType::WAIT);
171 for (
const auto& entry : *db) {
173 static const U8 delim = PRMDB_ENTRY_DELIMITER;
180 U32 recordSize =
static_cast<U32
>(
sizeof(
FwPrmIdType) + entry.getValue().getSize());
184 serStat = buff.serializeFrom(recordSize);
199 serStat = buff.serializeFrom(entry.getKey());
210 if (!this->writeSaveFileChunk(paramFile, entry.getValue().getBuffAddr(), entry.getValue().getSize(),
212 opCode, cmdSeq, crc)) {
224 stat = paramFile.position(currPosInParamFile);
232 stat = paramFile.seek(0, Os::File::SeekType::ABSOLUTE);
241 crcFinal = ~crcFinal;
242 serStat = buff.serializeFrom(crcFinal);
245 writeSize =
static_cast<FwSizeType>(buff.getSize());
247 stat = paramFile.write(buff.getBuffAddr(), writeSize, Os::File::WaitType::WAIT);
255 stat = paramFile.seek(static_cast<FwSignedSizeType>(currPosInParamFile), Os::File::SeekType::ABSOLUTE);
283 if (writeSize != size) {
289 if (data !=
nullptr && writeSize != 0) {
290 crc.
update(data, writeSize);
295 void PrmDbImpl::PRM_LOAD_FILE_cmdHandler(
FwOpcodeType opCode,
298 const PrmDb_Merge& merge) {
307 if (fileName.
length() == 0) {
330 if (success == PrmLoadStatus::SUCCESS) {
342 void PrmDbImpl::PRM_COMMIT_STAGED_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
352 PrmDbStore* temp = this->m_activeDb;
353 this->m_activeDb = this->m_stagingDb;
355 this->m_stagingDb = temp;
378 this->applySandbox(paramFile);
392 stat = paramFile.
read(buff.getBuffAddr(), readSize);
398 if (readSize !=
sizeof(fileCrc)) {
407 serStat = buff.deserializeTo(fileCrc);
410 U32 crc = 0xFFFFFFFF;
419 if (fileCrc != crc) {
425 stat = paramFile.
seek(
sizeof(fileCrc), Os::File::SeekType::ABSOLUTE);
432 U32 recordNumTotal = 0;
433 U32 recordNumAdded = 0;
434 U32 recordNumUpdated = 0;
435 U32 recordNumDropped = 0;
437 for (
FwSizeType entry = 0; entry < PRMDB_NUM_DB_ENTRIES; entry++) {
439 readSize =
static_cast<FwSizeType>(
sizeof(delimiter));
455 if (
sizeof(delimiter) != readSize) {
457 static_cast<I32>(readSize));
461 if (PRMDB_ENTRY_DELIMITER != delimiter) {
470 readSize =
sizeof(recordSize);
472 fStat = paramFile.
read(buff.getBuffAddr(), readSize, Os::File::WaitType::WAIT);
477 if (
sizeof(recordSize) != readSize) {
479 static_cast<I32>(readSize));
483 Fw::SerializeStatus desStat = buff.setBuffLen(static_cast<Fw::Serializable::SizeType>(readSize));
489 desStat = buff.deserializeTo(recordSize);
496 static_cast<I32>(recordSize));
504 fStat = paramFile.
read(buff.getBuffAddr(), readSize, Os::File::WaitType::WAIT);
509 if (
sizeof(parameterId) != static_cast<FwSizeType>(readSize)) {
511 static_cast<I32>(readSize));
516 desStat = buff.setBuffLen(static_cast<Fw::Serializable::SizeType>(readSize));
522 desStat = buff.deserializeTo(parameterId);
527 readSize = recordSize -
sizeof(parameterId);
528 desStat = tmpParamBuffer.
setBuffLen(static_cast<Fw::Serializable::SizeType>(readSize));
537 if (static_cast<U32>(readSize) != recordSize -
sizeof(parameterId)) {
539 static_cast<I32>(readSize));
544 PrmUpdateType updateStatus = updateAddPrmImpl(parameterId, tmpParamBuffer, dbType);
559 if (recordNumDropped > 0) {
564 return PrmLoadStatus::SUCCESS;
568 auto* db = getDbPtr(prmDbType);
574 auto prevSize = db->getSize();
575 switch (db->insert(
id, val)) {
580 if (prevSize < db->getSize()) {
584 static_cast<FwAssertArgType>(db->getSize()));
600 void PrmDbImpl::clearDb(
PrmDbType prmDbType) {
601 getDbPtr(prmDbType)->
clear();
605 *getDbPtr(dest) = *getDbPtr(src);
609 PrmDbImpl::PrmDbStore* PrmDbImpl::getDbPtr(
PrmDbType dbType) {
void update(const void *const data, const FwSizeType len)
Serialization/Deserialization operation was successful.
Parameter already in database, updated parameter.
void configure(const char *allowedDirectory)
Configure the allowed sandbox directory.
State of parameter DB file load operations.
FwIdType FwOpcodeType
The type of a command opcode.
void pingOut_out(FwIndexType portNum, U32 key) const
Invoke output port pingOut.
PlatformSizeType FwSizeType
void log_WARNING_LO_PrmDbFileLoadInvalidAction(const Svc::PrmDb_PrmDbFileLoadState ¤tState, const Svc::PrmDb_PrmLoadAction &attemptedAction) const
void configureSandbox(const char *directory)
PrmDb sandbox configure method.
void log_ACTIVITY_HI_PrmIdUpdated(FwPrmIdType Id) const
Os::FileInterface::Status calculateCrc(U32 &crc)
Calculate CRC32 of the entire file.
void readParamFile()
PrmDb file read function.
Os::FileInterface::Status seek(FwSignedSizeType offset, Os::FileInterface::SeekType seekType)
Seek file pointer.
StringTemplate< FW_FIXED_LENGTH_STRING_SIZE > String
FwIdType FwPrmIdType
The type of a parameter identifier.
void log_WARNING_HI_PrmFileReadError(const Svc::PrmDb_PrmReadError &stage, I32 record, I32 error) const
void log_ACTIVITY_HI_PrmFileSaveComplete(U32 records) const
void log_WARNING_HI_PrmFileWriteError(const Svc::PrmDb_PrmWriteError &stage, I32 record, I32 error) const
A wrapper around Os::File that restricts file access to an allowed directory.
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
Overwrite file when it exists and creation was requested.
PrmDbImpl(const char *name)
PrmDb constructor.
PrmDb_PrmDbType PrmDbType
Parameter added to database.
void log_ACTIVITY_HI_PrmFileLoadComplete(const Fw::StringBase &databaseString, U32 recordsTotal, U32 recordsAdded, U32 recordsUpdated) const
SerializeStatus
forward declaration for string
virtual void lock()
Lock the guarded mutex.
Os::FileInterface::Status open(const char *path, Os::FileInterface::Mode mode, Os::FileInterface::OverwriteType overwrite=Os::FileInterface::NO_OVERWRITE)
Open a file, validating the path against the sandbox directory.
void log_ACTIVITY_HI_PrmDbCommitComplete() const
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
void clear() override
Clear the map.
virtual void unLock()
Unlock the guarded mutex.
void log_ACTIVITY_HI_PrmIdAdded(FwPrmIdType Id) const
A generic interface for creating and comparing hash values.
void log_ACTIVITY_HI_PrmDbCopyAllComplete(const Fw::StringBase &databaseStringSrc, const Fw::StringBase &databaseStringDest) const
const char * toChar() const
Convert to a C-style char*.
void configure(const char *file)
PrmDb configure method.
Os::FileInterface::Status write(const U8 *buffer, FwSizeType &size, Os::FileInterface::WaitType wait)
Write data to the file.
Command successfully executed.
uint8_t U8
8-bit unsigned integer
void log_WARNING_HI_PrmDbFull(FwPrmIdType Id) const
SerializeStatus setBuffLen(Serializable::SizeType length) override
Set buffer length manually.
Auto-generated base for PrmDb component.
Command had execution error.
void log_WARNING_LO_PrmIdNotFound(FwPrmIdType Id)
Operation was successful.
Os::FileInterface::Status read(U8 *buffer, FwSizeType &size, Os::FileInterface::WaitType wait)
Read data from the file.
Success find(const K &key, V &value) const override
PlatformIndexType FwIndexType
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
Command failed validation.
RateGroupDivider component implementation.
virtual SizeType length() const
Get the length of the string.
Enum representing parameter validity.
Implementation of malloc based allocator.
No slots available to add new parameter.
void finalize(HashBuffer &buffer) const
virtual ~PrmDbImpl()
PrmDb destructor.
Component for managing parameters.
void log_WARNING_HI_PrmFileBadCrc(U32 readCrc, U32 compCrc) const
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
void log_WARNING_HI_PrmDbFileLoadFailed() const