26 m_sortedDpList(nullptr),
34 m_xmitInProgress(false),
35 m_currXmitRecord(nullptr),
59 this->m_memSize =
DP_MAX_FILES * (
sizeof(DpStateEntry) +
sizeof(DpSortedList));
62 this->m_memPtr = allocator.
allocate(memId, this->m_memSize, notUsed);
67 (this->m_memSize >= (
sizeof(DpSortedList) +
sizeof(DpStateEntry))) and
68 (this->m_memPtr !=
nullptr)
71 this->m_numDpSlots = this->m_memSize / (
sizeof(DpSortedList) +
sizeof(DpStateEntry));
74 this->m_dpList =
static_cast<DpStateEntry*
>(this->m_memPtr);
76 this->m_sortedDpList =
reinterpret_cast<DpSortedList*
>(&this->m_dpList[this->m_numDpSlots]);
77 for (
FwSizeType slot = 0; slot < this->m_numDpSlots; slot++) {
79 (void)
new(&this->m_dpList[slot]) DpStateEntry();
80 this->m_dpList[slot].entry =
false;
81 this->m_dpList[slot].dir = -1;
83 this->m_sortedDpList[slot].recPtr =
nullptr;
84 this->m_sortedDpList[slot].sent =
false;
90 this->m_numDpSlots = 0;
94 for (
FwSizeType dir = 0; dir < numDirs; dir++) {
95 this->m_directories[dir] = directories[dir];
97 this->m_numDirectories = numDirs;
100 this->m_allocator = &allocator;
101 this->m_allocatorId = memId;
102 this->m_initialized =
true;
108 if (not this->checkInit()) {
113 if (this->m_xmitInProgress) {
129 for (
FwSizeType dir = 0; dir < this->m_numDirectories; dir++) {
133 U32 pendingFiles = 0;
134 U64 pendingDpBytes = 0;
140 this->m_directories[dir],
145 status = dpDir.
readDirectory(this->m_fileList, (this->m_numDpSlots - totalFiles), filesRead);
149 this->m_directories[dir],
157 filesRead <= this->m_numDpSlots - totalFiles,
165 this->m_directories[dir].toChar(),
166 this->m_fileList[file].toChar()
188 stat = dpFile.
read(dpBuff, size);
217 entry.record.setid(container.
getId());
219 entry.record.setstate(container.
getState());
222 entry.record.setsize(
static_cast<U64>(fileSize));
226 this->m_dpList[this->m_numDpRecords] = entry;
229 if (not this->insertEntry(this->m_dpList[this->m_numDpRecords])) {
236 pendingDpBytes += entry.record.getsize();
240 if (this->m_numDpRecords > this->m_numDpSlots) {
247 totalFiles += filesRead;
250 this->m_directories[dir],
251 static_cast<U32
>(totalFiles),
258 if (totalFiles == this->m_numDpSlots) {
269 bool DpCatalog::insertEntry(DpStateEntry& entry) {
272 this->m_sortedDpList[this->m_numDpRecords].recPtr = &entry;
273 this->m_sortedDpList[this->m_numDpRecords].sent =
false;
274 this->m_numDpRecords++;
280 void DpCatalog::deleteEntry(DpStateEntry& entry) {
284 void DpCatalog::sendNextEntry() {
290 for (
FwSizeType record = 0; record < this->m_numDpRecords; record++) {
291 if (not this->m_sortedDpList[record].sent) {
293 if (this->m_sortedDpList[record].recPtr !=
nullptr) {
295 this->m_currXmitRecord = &this->m_sortedDpList[record];
298 this->m_directories[this->m_sortedDpList[record].recPtr->dir].toChar(),
299 this->m_sortedDpList[record].recPtr->record.getid(),
300 this->m_sortedDpList[record].recPtr->record.gettSec(),
301 this->m_sortedDpList[record].recPtr->record.gettSub()
304 this->m_currXmitFileName,
305 static_cast<U32
>(this->m_sortedDpList[record].recPtr->record.getsize()),
306 this->m_sortedDpList[record].recPtr->record.getpriority()
308 this->
fileOut_out(0, this->m_currXmitFileName, this->m_currXmitFileName, 0, 0);
309 this->m_xmitBytes += this->m_sortedDpList[record].recPtr->record.getsize();
314 this->m_sortedDpList[record].sent =
true;
320 this->m_xmitInProgress =
false;
321 this->m_xmitBytes = 0;
322 this->m_currXmitRecord =
nullptr;
324 if (this->m_xmitCmdWait) {
325 this->m_xmitCmdWait =
false;
331 bool DpCatalog::checkInit() {
332 if (not this->m_initialized) {
336 else if (0 == this->m_numDpSlots) {
348 if ((this->m_allocator !=
nullptr) and (this->m_memPtr !=
nullptr)) {
349 this->m_allocator->
deallocate(this->m_allocatorId, this->m_memPtr);
365 if (this->m_currXmitRecord) {
366 this->m_currXmitRecord->sent =
true;
370 this->sendNextEntry();
388 BUILD_CATALOG_cmdHandler(
398 START_XMIT_CATALOG_cmdHandler(
409 this->m_xmitCmdWait =
false;
410 this->m_xmitOpCode = 0;
411 this->m_xmitCmdSeq = 0;
414 this->m_xmitCmdWait =
true;
415 this->m_xmitOpCode = opCode;
416 this->m_xmitCmdSeq = cmdSeq;
423 this->m_xmitBytes = 0;
424 this->sendNextEntry();
431 STOP_XMIT_CATALOG_cmdHandler(
441 CLEAR_CATALOG_cmdHandler(
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
PlatformUIntType NATIVE_UINT_TYPE
constexpr const char * DP_FILENAME_FORMAT
PlatformAssertArgType FwAssertArgType
PlatformUIntType FwNativeUIntType
PlatformSignedSizeType FwSignedSizeType
PlatformSizeType FwSizeType
PlatformIndexType FwIndexType
C++-compatible configuration header for fprime configuration.
Enum representing a command response.
@ EXECUTION_ERROR
Command had execution error.
@ OK
Command successfully executed.
A data product Container.
Fw::Time getTimeTag() const
static constexpr FwSizeType MIN_PACKET_SIZE
FwDpPriorityType getPriority() const
Fw::DpState getState() const
Get the product state.
Fw::SerializeStatus deserializeHeader()
void setBuffer(const Buffer &buffer)
Set the packet buffer.
@ UNTRANSMITTED
The untransmitted state.
virtual void deallocate(const NATIVE_UINT_TYPE identifier, void *ptr)=0
Deallocate memory.
virtual void * allocate(const NATIVE_UINT_TYPE identifier, NATIVE_UINT_TYPE &size, bool &recoverable)=0
Allocate memory.
void format(const CHAR *formatString,...)
write formatted string to buffer
const char * toChar() const
Wait or don't wait for something.
Status open(const char *path, OpenMode mode) override
Open or create a directory.
Status readDirectory(Fw::String filenameArray[], const FwSizeType arraySize, FwSizeType &filenameCount)
Read the contents of the directory and store filenames in filenameArray of size arraySize.
@ OP_OK
Operation was successful.
Status read(U8 *buffer, FwSignedSizeType &size)
read data from this file into supplied buffer bounded by size
void close() override
close the file, if not opened then do nothing
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
@ BAD_SIZE
Invalid size parameter.
@ OP_OK
Operation was successful.
@ OPEN_READ
Open file for reading.
static Status getFileSize(const char *path, FwSignedSizeType &size)
Get the size of the file (in bytes) at the specified path.
@ OP_OK
Operation was successful.
Auto-generated base for DpCatalog component.
Svc::SendFileResponse fileOut_out(FwIndexType portNum, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName, U32 offset, U32 length)
Invoke output port fileOut.
void log_WARNING_LO_DpXmitInProgress()
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
void log_WARNING_HI_FileOpenError(const Fw::StringBase &loc, I32 stat)
void log_ACTIVITY_HI_ProcessingDirectoryComplete(const Fw::StringBase &loc, U32 total, U32 pending, U64 pending_bytes)
void log_ACTIVITY_LO_SendingProduct(const Fw::StringBase &file, U32 bytes, U32 prio)
void log_WARNING_HI_DirectoryOpenError(const Fw::StringBase &loc, I32 stat)
void log_ACTIVITY_LO_ProcessingFile(const Fw::StringBase &file)
void log_ACTIVITY_LO_ProcessingDirectory(const Fw::StringBase &directory)
void log_ACTIVITY_HI_CatalogBuildComplete()
void log_WARNING_HI_DpInsertError(Svc::DpRecord dp)
void log_WARNING_HI_ComponentNotInitialized()
void log_WARNING_HI_FileReadError(const Fw::StringBase &file, I32 stat)
void log_WARNING_HI_ComponentNoMemory()
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
void log_WARNING_HI_FileSizeError(const Fw::StringBase &file, I32 stat)
void log_WARNING_HI_CatalogFull(const Fw::StringBase &dir)
void log_WARNING_HI_DpCatalogFull(Svc::DpRecord dp)
void log_WARNING_HI_FileHdrDesError(const Fw::StringBase &file, I32 stat)
void log_ACTIVITY_HI_CatalogXmitCompleted(U64 bytes)
void log_ACTIVITY_LO_ProductComplete(const Fw::StringBase &file)
void configure(Fw::FileNameString directories[DP_MAX_DIRECTORIES], FwSizeType numDirs, NATIVE_UINT_TYPE memId, Fw::MemAllocator &allocator)
Configure the DpCatalog.
DpCatalog(const char *const compName)
DpCatalog constructor.
~DpCatalog()
DpCatalog destructor.
Send file response struct.
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
static const FwSizeType DP_MAX_FILES
static const FwSizeType DP_MAX_DIRECTORIES