fprime/Svc/CmdSequencer/Sequence.cpp
Ian Brault 2b65cc83cf
Add new Fw::ConstStringBase type for strings backed by immutable string literals (#4269)
* Add new Fw::StringBase type StaticString for strings backed my immutable literals

* Spellcheck fix

* Add disclaimer comment about use of StaticString

* Refactor the StringBase interface into an immutable ConstStringBase abstract base class and the now mutable StringBase class

* Rename StaticString to ConstExternalString and inherit from ConstStringBase

* Fix typo

* Change references from StringBase to ConstStringBase where applicable

* Updates following review meeting: add missing deserialize function and add new error status, move length function implementation into ConstStringBase so it is not pure virtual

* Clang format fix

* Additional clang-format fixes

* Fix the copy-assignment operator for StringBase not being correctly evaluated

* Clang format fix

* Explicitly delete the Serializable assignment operator and provide a skeleton implementation for RawTimeInterface to appease the compiler

* Revert "Explicitly delete the Serializable assignment operator and provide a skeleton implementation for RawTimeInterface to appease the compiler"

This reverts commit 086d7bcd3ca9c4f6e553d7fc34d0d126a69a165b.

* Move ConstStringBase to separate hpp/cpp files, plus other pull request feedback

* Clang format fix

* Update length implementation for ConstStringBase and ConstExternalString

* Improved asserts in ConstExternalString constructor

Co-authored-by: Rob Bocchino <bocchino@icloud.com>

* Fixed ConstStringBase length implementation

Co-authored-by: Rob Bocchino <bocchino@icloud.com>

* Clang format fix

* Add some UTs for ConstExternalString, fix non-overridden interfaces, and fix ConstStringBase::maxLength asserting for zero capacity strings

* Spell-check fix for ConstExternalString UTs

* Revise length implementation in ConstStringBase

If the capacity is zero, return zero

* Format

---------

Co-authored-by: Ian Brault <ian.r.brault@jpl.nasa.gov>
Co-authored-by: Rob Bocchino <bocchino@icloud.com>
Co-authored-by: Rob Bocchino <bocchino@jpl.nasa.gov>
Co-authored-by: M Starch <LeStarch@googlemail.com>
2025-11-07 09:50:05 -08:00

83 lines
3.1 KiB
C++

// ======================================================================
// \title Sequence.cpp
// \author Bocchino/Canham
// \brief Implementation file for CmdSequencer::Sequence
//
// Copyright (C) 2009-2018 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
// ======================================================================
#include <Fw/Types/Assert.hpp>
#include <Svc/CmdSequencer/CmdSequencerImpl.hpp>
namespace Svc {
CmdSequencerComponentImpl::Sequence ::Sequence(CmdSequencerComponentImpl& component)
: m_component(component), m_events(*this), m_allocatorId(0) {}
CmdSequencerComponentImpl::Sequence ::~Sequence() {}
CmdSequencerComponentImpl::Sequence::Header ::Header()
: m_fileSize(0), m_numRecords(0), m_timeBase(TimeBase::TB_DONT_CARE), m_timeContext(FW_CONTEXT_DONT_CARE) {}
bool CmdSequencerComponentImpl::Sequence::Header ::validateTime(CmdSequencerComponentImpl& component) {
Fw::Time validTime = component.getTime();
Events& events = component.m_sequence->m_events;
// Time base
const TimeBase validTimeBase = validTime.getTimeBase();
if ((this->m_timeBase != validTimeBase) and (this->m_timeBase != TimeBase::TB_DONT_CARE)) {
events.timeBaseMismatch(validTimeBase, this->m_timeBase);
return false;
}
// Time context
const FwTimeContextStoreType validContext = validTime.getContext();
if ((this->m_timeContext != validContext) and (this->m_timeContext != FW_CONTEXT_DONT_CARE)) {
events.timeContextMismatch(validContext, this->m_timeContext);
return false;
}
// Canonicalize time
this->m_timeBase = validTimeBase;
this->m_timeContext = validContext;
return true;
}
void CmdSequencerComponentImpl::Sequence ::allocateBuffer(FwEnumStoreType identifier,
Fw::MemAllocator& allocator,
FwSizeType bytes) {
// has to be at least as big as a header
FW_ASSERT(bytes >= Sequence::Header::SERIALIZED_SIZE);
bool recoverable;
this->m_allocatorId = identifier;
this->m_buffer.setExtBuffer(static_cast<U8*>(allocator.allocate(identifier, bytes, recoverable)), bytes);
}
void CmdSequencerComponentImpl::Sequence ::deallocateBuffer(Fw::MemAllocator& allocator) {
allocator.deallocate(this->m_allocatorId, this->m_buffer.getBuffAddr());
this->m_buffer.clear();
}
const CmdSequencerComponentImpl::Sequence::Header& CmdSequencerComponentImpl::Sequence ::getHeader() const {
return this->m_header;
}
void CmdSequencerComponentImpl::Sequence ::setFileName(const Fw::ConstStringBase& fileName) {
this->m_fileName = fileName;
this->m_logFileName = fileName;
this->m_stringFileName = fileName;
}
Fw::CmdStringArg& CmdSequencerComponentImpl::Sequence ::getFileName() {
return this->m_fileName;
}
Fw::LogStringArg& CmdSequencerComponentImpl::Sequence ::getLogFileName() {
return this->m_logFileName;
}
Fw::String& CmdSequencerComponentImpl::Sequence ::getStringFileName() {
return this->m_stringFileName;
}
} // namespace Svc