F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
DpCatalog.cpp
Go to the documentation of this file.
1 // ======================================================================
2 
3 // \title DpCatalog.cpp
4 // \author tcanham
5 // \brief cpp file for DpCatalog component implementation class
6 // ======================================================================
7 
9 #include "Fw/Dp/DpContainer.hpp"
10 #include "Fw/FPrimeBasicTypes.hpp"
11 
12 #include <new> // placement new
13 #include "Fw/Types/StringUtils.hpp"
14 #include "Os/File.hpp"
15 #include "Os/FileSystem.hpp"
16 #include "Utils/Hash/Hash.hpp"
17 
18 namespace Svc {
19 static_assert(DP_MAX_DIRECTORIES > 0, "Configuration DP_MAX_DIRECTORIES must be positive");
20 static_assert(DP_MAX_FILES > 0, "Configuration DP_MAX_FILES must be positive");
21 // ----------------------------------------------------------------------
22 // Component construction and destruction
23 // ----------------------------------------------------------------------
24 
25 DpCatalog ::DpCatalog(const char* const compName) : DpCatalogComponentBase(compName) {
26  // Members are default-initialized via in-class initializers in the header.
27 }
28 
30  Fw::FileNameString& stateFile,
31  FwEnumStoreType memId,
32  Fw::MemAllocator& allocator) {
33  const FwSizeType numDirs = directories.getSize();
34  // Do some assertion checks
35  FW_ASSERT(numDirs <= DP_MAX_DIRECTORIES, static_cast<FwAssertArgType>(numDirs));
36 
37  this->m_stateFile = stateFile;
38 
39  // Request memory for state file data storage.
40  // RedBlackTreeSet storage is allocated as a member variable, so we only need
41  // to allocate memory for the state file tracking array.
42  static const FwSizeType slotSize = sizeof(DpDstateFileEntry);
43  this->m_memSize = DP_MAX_FILES * slotSize;
44  bool notUsed; // we don't need to recover the catalog.
45  // request memory. this->m_memSize will be modified if there is less than we requested
46  this->m_memPtr = allocator.allocate(memId, this->m_memSize, notUsed);
47 
48  // Initialize if there is enough room for at least one record and memory was allocated
49  if ((this->m_memSize >= slotSize) and (this->m_memPtr != nullptr)) {
50  // set the number of available record slots based on how much memory we actually got,
51  // never exceeding the DP_MAX_FILES working arrays even if the allocator returned more
52  // memory than was requested
53  const FwSizeType allocatedSlots = this->m_memSize / slotSize;
54  this->m_numDpSlots = (allocatedSlots < DP_MAX_FILES) ? allocatedSlots : DP_MAX_FILES;
55  // Initialize the catalog
56  this->resetCatalog();
57  // assign pointer for the state file storage
58  this->m_stateFileData = static_cast<DpDstateFileEntry*>(this->m_memPtr);
59  } else {
60  // if we don't have enough memory, set the number of records
61  // to zero for later detection
62  this->m_numDpSlots = 0;
63  }
64 
65  // assign directory names
66  for (FwSizeType dir = 0; dir < numDirs; dir++) {
67  this->m_directories[dir] = directories[dir];
68  }
69  this->m_numDirectories = numDirs;
70 
71  // store allocator
72  this->m_allocator = &allocator;
73  this->m_allocatorId = memId;
74  this->m_initialized = true;
75 }
76 
78  FwSizeType numDirs,
79  Fw::FileNameString& stateFile,
80  FwEnumStoreType memId,
81  Fw::MemAllocator& allocator) {
82  FW_ASSERT(numDirs <= DP_MAX_DIRECTORIES, static_cast<FwAssertArgType>(numDirs));
83  const Fw::ExternalArray<Fw::FileNameString> directoryArray(directories, numDirs);
84  this->configure(directoryArray, stateFile, memId, allocator);
85 }
86 
87 void DpCatalog::resetCatalog() {
88  // Clear the catalog
89  this->m_dpCatalog.clear();
90  // Clear transmission state
91  this->m_hasCurrentXmit = false;
92  // Reset counters
93  this->m_pendingFiles = 0;
94  this->m_pendingDpBytes = 0;
95  // Mark the catalog as un-built
96  this->m_catalogBuilt = false;
97 }
98 
99 void DpCatalog::resetStateFileData() {
100  // clear state file data
101  for (FwSizeType slot = 0; slot < this->m_numDpSlots; slot++) {
102  this->m_stateFileData[slot].used = false;
103  this->m_stateFileData[slot].visited = false;
104  (void)new (&this->m_stateFileData[slot].entry.record) DpRecord();
105  }
106  this->m_stateFileEntries = 0;
107 }
108 
109 Fw::CmdResponse DpCatalog::loadStateFile() {
110  FW_ASSERT(this->m_stateFileData != nullptr);
111 
112  // Make sure that a file was specified
113  if (this->m_stateFile.length() == 0) {
115  return Fw::CmdResponse::OK;
116  }
117 
118  // buffer for reading entries
119 
120  BYTE buffer[sizeof(FwIndexType) + DpRecord::SERIALIZED_SIZE];
121  Fw::ExternalSerializeBuffer entryBuffer(buffer, sizeof(buffer));
122 
123  // open the state file
124  Os::File stateFile;
125  Os::File::Status stat = stateFile.open(this->m_stateFile.toChar(), Os::File::OPEN_READ);
126  if (stat == Os::File::DOESNT_EXIST) {
127  // A missing state file is expected on first boot and is not an error
128  this->log_WARNING_LO_NoStateFile(this->m_stateFile);
129  return Fw::CmdResponse::OK;
130  }
131  if (stat != Os::File::OP_OK) {
132  this->log_WARNING_HI_StateFileOpenError(this->m_stateFile, stat);
134  }
135 
136  FwSizeType fileSize = 0;
137  stat = stateFile.size(fileSize);
138  if (stat != Os::File::OP_OK) {
139  this->log_WARNING_HI_StateFileReadError(this->m_stateFile, stat, 0);
140  stateFile.close();
142  }
143 
144  FwSizeType fileLoc = 0;
145  this->m_stateFileEntries = 0;
147 
148  // A product may have several records (a priority change, then its completion); the last one
149  // read wins, so the walk is bounded by the record count rather than the slot count
150  const FwSizeType maxRecords = fileSize / static_cast<FwSizeType>(sizeof(buffer)) + 1;
151  for (FwSizeType record = 0; record < maxRecords; record++) {
152  FwSizeType size = static_cast<FwSizeType>(sizeof(buffer));
153  // read the directory index
154  stat = stateFile.read(buffer, size);
155  if (stat != Os::File::OP_OK) {
156  this->log_WARNING_HI_StateFileReadError(this->m_stateFile, stat, static_cast<I32>(fileLoc));
157  stateFile.close();
159  }
160 
161  if (0 == size) {
162  // no more entries
163  break;
164  }
165 
166  // check to see if the full entry was read. If not,
167  // abandon it and finish. We can at least operate on
168  // the entries that were read.
169  if (size != sizeof(buffer)) {
170  this->log_WARNING_HI_StateFileTruncated(this->m_stateFile, static_cast<I32>(fileLoc),
171  static_cast<I32>(size));
172  stateFile.close();
173  return Fw::CmdResponse::OK;
174  }
175 
176  // reset the buffer for deserializing the entry
177  Fw::SerializeStatus serStat = entryBuffer.setBuffLen(static_cast<Fw::Serializable::SizeType>(size));
178  // should always fit
179  FW_ASSERT(Fw::FW_SERIALIZE_OK == serStat, serStat);
180  entryBuffer.resetDeser();
181 
182  // deserialization after this point should always work, since
183  // the source buffer was specifically sized to hold the data
184 
185  // Deserialize the file directory index. If an error occurs processing the file,
186  // generate event and return EXECUTION_ERROR.
187  DpStateEntry fileEntry{};
188  Fw::SerializeStatus status = entryBuffer.deserializeTo(fileEntry.dir);
189  if (status != Fw::FW_SERIALIZE_OK) {
190  this->log_WARNING_HI_FileCorruptedDataError(this->m_stateFile, static_cast<I32>(status));
191  stateFile.close();
193  }
194  status = entryBuffer.deserializeTo(fileEntry.record);
195  if (status != Fw::FW_SERIALIZE_OK) {
196  this->log_WARNING_HI_FileCorruptedDataError(this->m_stateFile, static_cast<I32>(status));
197  stateFile.close();
199  }
200 
201  // A record whose directory is not configured (the directory list changed, or the file is corrupt) names a
202  // file this configuration cannot locate. Skip it so that every loaded record has a valid directory index
203  if ((fileEntry.dir < 0) || (fileEntry.dir >= static_cast<FwIndexType>(this->m_numDirectories))) {
204  this->log_WARNING_HI_StateFileDirectoryInvalid(this->m_stateFile, static_cast<I32>(fileLoc), fileEntry.dir);
205  fileLoc += size;
206  continue;
207  }
208 
209  const FwSizeType slot = this->findStateFileSlot(fileEntry);
210  if (slot == this->m_stateFileEntries) {
211  if (this->m_stateFileEntries >= this->m_numDpSlots) {
212  // no slot for another product; later records for products that have a slot still apply
213  fileLoc += size;
214  continue;
215  }
216  this->m_stateFileEntries++;
217  }
218  this->m_stateFileData[slot].entry = fileEntry;
219  this->m_stateFileData[slot].used = true;
220  this->m_stateFileData[slot].visited = false;
221 
222  // increment the file location
223  fileLoc += size;
224  }
225  stateFile.close();
226  return Fw::CmdResponse::OK;
227 }
228 
229 void DpCatalog::getFileState(DpStateEntry& entry) {
230  FW_ASSERT(this->m_stateFileData != nullptr);
231  const FwSizeType line = this->findStateFileSlot(entry);
232  if (line < this->m_stateFileEntries) {
233  // a recorded priority differs from the file header only if SET_DP_PRIORITY changed it
234  entry.record.set_priority(this->m_stateFileData[line].entry.record.get_priority());
235  // update the transmitted state
236  entry.record.set_state(this->m_stateFileData[line].entry.record.get_state());
237  entry.record.set_blocks(this->m_stateFileData[line].entry.record.get_blocks());
238  // mark it as visited for later pruning if necessary
239  this->m_stateFileData[line].visited = true;
240  }
241 }
242 
243 FwSizeType DpCatalog::findStateFileSlot(const DpStateEntry& entry) const {
244  FW_ASSERT(this->m_stateFileData != nullptr);
245  for (FwSizeType line = 0; line < this->m_stateFileEntries; line++) {
246  if (this->m_stateFileData[line].entry.isSameProduct(entry)) {
247  return line;
248  }
249  }
250  return this->m_stateFileEntries;
251 }
252 
253 FwSizeType DpCatalog::findStateFileSlotByIdentity(FwDpIdType id, U32 tSec, U32 tSub) const {
254  FW_ASSERT(this->m_stateFileData != nullptr);
255  for (FwSizeType line = 0; line < this->m_stateFileEntries; line++) {
256  if (this->m_stateFileData[line].entry.hasIdentity(id, tSec, tSub)) {
257  return line;
258  }
259  }
260  return this->m_stateFileEntries;
261 }
262 
263 DpCatalog_StateFileUpdateStatus DpCatalog::updateStateFileData(const DpStateEntry& entry) {
264  FwSizeType slot = this->findStateFileSlot(entry);
265  if (slot == this->m_stateFileEntries) {
266  // outside a catalog build, a slot not visited by the last build is for a file that is gone
267  for (FwSizeType line = 0; line < this->m_stateFileEntries; line++) {
268  if (not this->m_stateFileData[line].visited) {
269  slot = line;
270  break;
271  }
272  }
273  }
274  if (slot == this->m_stateFileEntries) {
275  if (this->m_stateFileEntries >= this->m_numDpSlots) {
276  // only worth reporting when the state is kept in a state file
277  if (this->m_stateFile.length() > 0) {
278  this->log_WARNING_HI_StateFileFull(entry.record.get_id(), entry.record.get_tSec(),
279  entry.record.get_tSub());
280  }
282  }
283  this->m_stateFileEntries++;
284  }
285  this->m_stateFileData[slot].entry = entry;
286  this->m_stateFileData[slot].used = true;
287  this->m_stateFileData[slot].visited = true;
289 }
290 
291 DpCatalog_StateFileWriteStatus DpCatalog::pruneAndWriteStateFile() {
292  FW_ASSERT(this->m_stateFileData != nullptr);
293 
294  // There is a chance that a data product file can disappear after
295  // the state file is written from the last catalog build and transmit.
296  // This function will walk the state file data and write back only
297  // the entries that were visited during the last catalog build. This will
298  // remove any entries that are no longer valid.
299 
300  // open the state file
301  Os::File stateFile;
302  // we open it as a new file so we don't accumulate invalid entries
303  Os::File::Status stat =
304  stateFile.open(this->m_stateFile.toChar(), Os::File::OPEN_CREATE, Os::FileInterface::OVERWRITE);
305 
306  if (stat != Os::File::OP_OK) {
307  this->log_WARNING_HI_StateFileOpenError(this->m_stateFile, stat);
309  }
310 
311  // buffer for writing entries
312  BYTE buffer[sizeof(FwIndexType) + DpRecord::SERIALIZED_SIZE];
313  Fw::ExternalSerializeBuffer entryBuffer(buffer, sizeof(buffer));
314 
315  // write entries to the state file
316  for (FwSizeType entry = 0; entry < this->m_numDpSlots; entry++) {
317  // only write entries that were used
318  if ((this->m_stateFileData[entry].used) and (this->m_stateFileData[entry].visited)) {
319  // reset the buffer for serializing the entry
320  entryBuffer.resetSer();
321  // serialize the file directory index
322  Fw::SerializeStatus serStat = entryBuffer.serializeFrom(this->m_stateFileData[entry].entry.dir);
323  // Should always fit
324  FW_ASSERT(Fw::FW_SERIALIZE_OK == serStat, serStat);
325  serStat = entryBuffer.serializeFrom(this->m_stateFileData[entry].entry.record);
326  // Should always fit
327  FW_ASSERT(Fw::FW_SERIALIZE_OK == serStat, serStat);
328  // write the entry
329  FwSizeType size = entryBuffer.getSize();
330  // Protect against overflow
331  stat = stateFile.write(buffer, size);
332  if (stat != Os::File::OP_OK) {
333  this->log_WARNING_HI_StateFileWriteError(this->m_stateFile, stat);
334  stateFile.close();
336  }
337  }
338  }
339 
340  // close the state file
341  stateFile.close();
343 }
344 
345 void DpCatalog::appendFileState(const DpStateEntry& entry) {
346  FW_ASSERT(this->m_stateFileData != nullptr);
347  FW_ASSERT(entry.dir < static_cast<FwIndexType>(this->m_numDirectories), static_cast<FwAssertArgType>(entry.dir),
348  static_cast<FwAssertArgType>(this->m_numDirectories));
349 
350  // We will append state to the existing state file
351  // TODO: Have to handle case where state file has partially transmitted
352  // state already
353 
354  // open the state file
355  Os::File stateFile;
356  // we open it as a new file so we don't accumulate invalid entries
357  Os::File::Status stat = stateFile.open(this->m_stateFile.toChar(), Os::File::OPEN_APPEND);
358  if (stat != Os::File::OP_OK) {
359  this->log_WARNING_HI_StateFileOpenError(this->m_stateFile, stat);
360  return;
361  }
362 
363  // buffer for writing entries
364  BYTE buffer[sizeof(FwIndexType) + DpRecord::SERIALIZED_SIZE];
365  Fw::ExternalSerializeBuffer entryBuffer(buffer, sizeof(buffer));
366  // reset the buffer for serializing the entry
367  entryBuffer.resetSer();
368  // serialize the file directory index
369  Fw::SerializeStatus serStat = entryBuffer.serializeFrom(entry.dir);
370  // should fit
371  FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK, serStat);
372  serStat = entryBuffer.serializeFrom(entry.record);
373  // should fit
374  FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK, serStat);
375  // write the entry
376  FwSizeType size = entryBuffer.getSize();
377  stat = stateFile.write(buffer, size);
378  if (stat != Os::File::OP_OK) {
379  stateFile.close();
380  this->log_WARNING_HI_StateFileWriteError(this->m_stateFile, stat);
381  return;
382  }
383 
384  // close the state file
385  stateFile.close();
386 }
387 
388 Fw::CmdResponse DpCatalog::doCatalogBuild() {
389  // check initialization
390  if (not this->checkInit()) {
392  }
393 
394  // check that initialization got memory
395  if (0 == this->m_numDpSlots) {
398  }
399 
400  // make sure a downlink is not in progress
401  if (this->m_xmitInProgress) {
404  }
405 
406  // reset state file data
407  this->resetStateFileData();
408 
409  // load state data from file; proceeding on a failed load would later
410  // overwrite the state file and destroy the transmit state it records
411  Fw::CmdResponse response = this->loadStateFile();
412  if (response != Fw::CmdResponse::OK) {
413  this->resetStateFileData();
414  return response;
415  }
416 
417  // reset catalog
418  this->resetCatalog();
419 
420  // fill the catalog with DP files
421  response = this->fillBinaryTree();
422  if (response != Fw::CmdResponse::OK) {
423  // clean up the catalog
424  this->resetCatalog();
425  this->resetStateFileData();
426  return response;
427  }
428 
429  // prune and rewrite the state file. A failure is reported by event; the file then holds the records
430  // written before the failure (or the previous contents if it could not be opened), and the build
431  // still completes from the catalog in memory
432  (void)this->pruneAndWriteStateFile();
433 
435 
436  // Flag so addToCat knows it is good to go
437  this->m_catalogBuilt = true;
438 
439  return Fw::CmdResponse::OK;
440 }
441 
442 Fw::CmdResponse DpCatalog::fillBinaryTree() {
443  // keep cumulative number of files
444  FwSizeType totalFiles = 0;
445 
446  // get file listings from file system
447  // double bounds to appease static analysis
448  for (FwSizeType dir = 0; dir < this->m_numDirectories && dir < static_cast<FwSizeType>(DP_MAX_DIRECTORIES); dir++) {
449  // read in each directory and keep track of total
450  this->log_ACTIVITY_LO_ProcessingDirectory(this->m_directories[dir]);
451  FwSizeType filesProcessed = 0;
452 
454  Os::Directory::Status status = dpDir.open(this->m_directories[dir].toChar(), Os::Directory::OpenMode::READ);
455  if (status != Os::Directory::OP_OK) {
456  this->log_WARNING_HI_DirectoryOpenError(this->m_directories[dir], status);
458  }
459 
460  // bound the read loop by the number of entries in the directory
461  FwSizeType fileCount = 0;
462  status = dpDir.getFileCount(fileCount);
463  if (status != Os::Directory::OP_OK) {
464  this->log_WARNING_HI_DirectoryOpenError(this->m_directories[dir], status);
466  }
467 
468  // read entries one at a time so non-DP files do not consume catalog slots
469  Fw::String fileName;
470  for (FwSizeType entry = 0; entry < fileCount; entry++) {
471  status = dpDir.read(fileName);
472  if (status == Os::Directory::NO_MORE_FILES) {
473  break;
474  }
475  if (status != Os::Directory::OP_OK) {
476  this->log_WARNING_HI_DirectoryOpenError(this->m_directories[dir], status);
478  }
479 
480  // only consider files with the DP extension
481  const FwSizeType fileNameLength = fileName.length();
482  const FwSizeType dpExtLength = Fw::StringUtils::string_length(DP_EXT, sizeof(DP_EXT));
483  const FwSignedSizeType loc =
484  Fw::StringUtils::substring_find_last(fileName.toChar(), fileNameLength, DP_EXT, dpExtLength);
485 
486  // Only accept files whose final suffix is the data product extension
487  if ((-1 == loc) || (static_cast<FwSizeType>(loc) + dpExtLength != fileNameLength)) {
488  continue;
489  }
490 
491  // stop if there is no free catalog slot for this DP file
492  if ((totalFiles + filesProcessed) == this->m_numDpSlots) {
493  break;
494  }
495 
496  Fw::String fullFile;
497  Fw::FormatStatus formatStatus =
498  fullFile.format("%s/%s", this->m_directories[dir].toChar(), fileName.toChar());
499  if (formatStatus != Fw::FormatStatus::SUCCESS) {
500  this->log_WARNING_HI_FileNameFormatError(fileName,
501  static_cast<Fw::StringFormatStatus::T>(formatStatus));
502  continue;
503  }
504 
505  const ProcessFileStatus ret = processFile(fullFile, dir);
506  if (ret == ProcessFileStatus::QUIT) {
507  break;
508  }
509 
510  if (ret == ProcessFileStatus::SUCCESS) {
511  filesProcessed++;
512  }
513 
514  } // end for each file in a directory
515 
516  totalFiles += filesProcessed;
517 
518  this->log_ACTIVITY_HI_ProcessingDirectoryComplete(this->m_directories[dir], static_cast<U32>(totalFiles),
519  this->m_pendingFiles, this->m_pendingDpBytes);
520 
521  // check to see if catalog is full
522  // that means generated products exceed the catalog size
523  if (totalFiles == this->m_numDpSlots) {
524  this->log_WARNING_HI_CatalogFull(this->m_directories[dir]);
525  break;
526  }
527  } // end for each directory
528 
529  return Fw::CmdResponse::OK;
530 
531 } // end fillBinaryTree()
532 
533 FwSizeType DpCatalog::determineDirectory(const Fw::String& fullFile) {
534  FW_ASSERT(this->m_numDirectories <= DP_MAX_DIRECTORIES, static_cast<FwAssertArgType>(this->m_numDirectories));
535  // Grab the directory string (up until the final slash)
536  // Could be found directly w/ a dirname func or regex
538  fullFile.toChar(), fullFile.length(), DIRECTORY_DELIMITER,
540 
541  // Seems like the logic works so long as the path styles match (i.e. relative vs absolute)
542  // Full path resolution might be a worthwhile add
543 
544  // No directory delimiter found; return DP_MAX_DIRECTORIES to signal failure
545  if (-1 == loc) {
546  return DP_MAX_DIRECTORIES;
547  }
548 
549  for (FwSizeType dir = 0; dir < this->m_numDirectories; dir++) {
550  const Fw::FileNameString& dir_string = this->m_directories[dir];
551 
552  // Compare both strings up to location of final slash
553  // StringUtils::substring_find will return zero if both paths agree
554  // memory safe since both are fixed width strings
555  // and loc is before the fixed width
556  if ((dir_string.length() == static_cast<FwSizeType>(loc)) &&
557  (Fw::StringUtils::substring_find(dir_string.toChar(), dir_string.length(), fullFile.toChar(),
558  static_cast<FwSizeType>(loc)) == 0)) {
559  return dir;
560  }
561  }
562 
563  // No directory matched
564  return DP_MAX_DIRECTORIES;
565 }
566 
567 DpCatalog::ProcessFileStatus DpCatalog::processFile(const Fw::String& fullFile, FwSizeType dir) {
568  FW_ASSERT(dir < static_cast<FwSizeType>(DP_MAX_DIRECTORIES), static_cast<FwAssertArgType>(dir));
569  // file class instance for processing files
570  Os::File dpFile;
571 
572  // Working buffer for DP headers
573  U8 dpBuff[Fw::DpContainer::MIN_PACKET_SIZE]; // Header buffer
574  Fw::Buffer hdrBuff(dpBuff, sizeof(dpBuff)); // buffer for container header decoding
575  Fw::DpContainer container; // container object for extracting header fields
576 
577  this->log_ACTIVITY_LO_ProcessingFile(fullFile);
578 
579  // get file size
580  FwSizeType fileSize = 0;
581  Os::FileSystem::Status sizeStat = Os::FileSystem::getFileSize(fullFile.toChar(), fileSize);
582  if (sizeStat != Os::FileSystem::OP_OK) {
583  this->log_WARNING_HI_FileSizeError(fullFile, sizeStat);
584  return ProcessFileStatus::FAILED;
585  }
586 
587  if (fileSize < Fw::DpContainer::MIN_PACKET_SIZE) {
589  return ProcessFileStatus::FAILED;
590  }
591 
592  Os::File::Status stat = dpFile.open(fullFile.toChar(), Os::File::OPEN_READ);
593  if (stat != Os::File::OP_OK) {
594  this->log_WARNING_HI_FileOpenError(fullFile, stat);
595  return ProcessFileStatus::FAILED;
596  }
597 
598  // Read DP header and header hash
600 
601  stat = dpFile.read(dpBuff, size);
602  if (stat != Os::File::OP_OK) {
603  this->log_WARNING_HI_FileReadError(fullFile, stat);
604  dpFile.close();
605  return ProcessFileStatus::FAILED;
606  }
607 
608  // if full header and hashes aren't read, something's wrong with the file, so skip
609  if (size != Fw::DpContainer::MIN_PACKET_SIZE) {
611  dpFile.close();
612  return ProcessFileStatus::FAILED;
613  }
614 
615  // if all is well, don't need the file any more
616  dpFile.close();
617 
618  // give buffer to container instance
619  container.setBuffer(hdrBuff);
620 
621  // make sure the header metadata matches its stored hash before trusting it
622  Utils::HashBuffer storedHash;
623  Utils::HashBuffer computedHash;
624  Fw::Success::T hashStatus = container.checkHeaderHash(storedHash, computedHash);
625  if (hashStatus != Fw::Success::SUCCESS) {
626  this->log_WARNING_HI_FileHdrError(fullFile, DpHdrField::CRC, computedHash.asBigEndianU32(),
627  storedHash.asBigEndianU32());
628  return ProcessFileStatus::FAILED;
629  }
630 
631  // reset header deserialization in the container
632  Fw::SerializeStatus desStat = container.deserializeHeader();
633  if (desStat != Fw::FW_SERIALIZE_OK) {
634  this->log_WARNING_HI_FileHdrDesError(fullFile, desStat);
635  return ProcessFileStatus::FAILED;
636  }
637 
638  const FwSizeType dataSize = container.getDataSize();
639  const FwSizeType expectedDataSize = fileSize - Fw::DpContainer::MIN_PACKET_SIZE;
640  if (dataSize != expectedDataSize) {
642  return ProcessFileStatus::FAILED;
643  }
644 
645  Fw::FileNameString canonicalFileName;
646  Fw::FormatStatus canonicalFormatStatus =
647  canonicalFileName.format(DP_FILENAME_FORMAT, this->m_directories[dir].toChar(), container.getId(),
648  container.getTimeTag().getSeconds(), container.getTimeTag().getUSeconds());
649  if (canonicalFormatStatus != Fw::FormatStatus::SUCCESS) {
650  this->log_WARNING_HI_FileNameFormatError(fullFile,
651  static_cast<Fw::StringFormatStatus::T>(canonicalFormatStatus));
652  return ProcessFileStatus::FAILED;
653  }
654  if (canonicalFileName != fullFile) {
655  this->log_WARNING_HI_InvalidFileName(fullFile, canonicalFileName);
656  return ProcessFileStatus::FAILED;
657  }
658 
659  // add entry to catalog.
660  DpStateEntry entry{};
661  entry.dir = static_cast<FwIndexType>(dir);
662  entry.record.set_id(container.getId());
663  entry.record.set_priority(container.getPriority());
664  entry.record.set_state(container.getState());
665  entry.record.set_tSec(container.getTimeTag().getSeconds());
666  entry.record.set_tSub(container.getTimeTag().getUSeconds());
667  entry.record.set_size(static_cast<U64>(fileSize));
668 
669  // check the state file to see if there is transmit state
670  this->getFileState(entry);
671 
672  // skip a file the state file records as already transmitted
673  if (entry.record.get_state() == Fw::DpState::TRANSMITTED) {
674  this->log_ACTIVITY_HI_DpFileSkipped(fullFile);
675  return ProcessFileStatus::FAILED;
676  }
677 
678  // a duplicate insert updates the tree in place; skip it so pending counters are not double-counted.
679  // The sort key includes the priority, which SET_DP_PRIORITY may have changed since the file was
680  // added, so a file already in the catalog is recognized by its stable identity, not by the key
681  DpStateEntry existing{};
682  if (this->findEntryByIdentity(entry, existing) == DpCatalog_EntryLookupStatus::FOUND) {
683  this->log_DIAGNOSTIC_DpDuplicate(entry.record);
684  return ProcessFileStatus::FAILED;
685  }
686 
687  // make sure there is a free slot before inserting, so a full catalog is reported as such
688  // and the entry is not left in the tree uncounted
689  if (this->m_dpCatalog.getSize() >= this->m_numDpSlots) {
690  this->log_WARNING_HI_DpCatalogFull(entry.record);
691  return ProcessFileStatus::QUIT;
692  }
693 
694  // insert into the sorted catalog. A free slot was verified above, so a failure here is a tree
695  // error, not a full catalog
696  bool inserted = this->insertEntry(entry);
697  if (!inserted) {
698  this->log_WARNING_HI_DpInsertError(entry.record);
699  return ProcessFileStatus::QUIT;
700  }
701 
702  // increment our counters
703  this->m_pendingFiles++;
704  this->m_pendingDpBytes += entry.record.get_size();
705 
706  this->log_ACTIVITY_HI_DpFileAdded(canonicalFileName);
707 
708  // No need to track iterator state - begin() always gives us the highest priority entry
709  // and we remove entries as we transmit them
710 
711  return ProcessFileStatus::SUCCESS;
712 }
713 
714 // ----------------------------------------------------------------------
715 // DpStateEntry Comparison Ops
716 // ----------------------------------------------------------------------
717 I8 DpCatalog::DpStateEntry::compareEntries(const DpStateEntry& left, const DpStateEntry& right) {
718  // check priority. Lower is higher priority
719  if (left.record.get_priority() < right.record.get_priority()) {
720  return -1;
721  } else if (left.record.get_priority() > right.record.get_priority()) {
722  return 1;
723  }
724 
725  // check time. Older is higher priority
726  else if (left.record.get_tSec() < right.record.get_tSec()) {
727  return -1;
728  } else if (left.record.get_tSec() > right.record.get_tSec()) {
729  return 1;
730  }
731 
732  // check subsecond time. Older is higher priority
733  else if (left.record.get_tSub() < right.record.get_tSub()) {
734  return -1;
735  } else if (left.record.get_tSub() > right.record.get_tSub()) {
736  return 1;
737  }
738 
739  // check ID. Lower is higher priority
740  else if (left.record.get_id() < right.record.get_id()) {
741  return -1;
742  } else if (left.record.get_id() > right.record.get_id()) {
743  return 1;
744  }
745 
746  // check directory. A file of the same name in two configured directories is two products, and the
747  // key includes the directory so that a priority change can never move one onto the other's key
748  else if (left.dir < right.dir) {
749  return -1;
750  } else if (left.dir > right.dir) {
751  return 1;
752  }
753 
754  // all fields equal: the same product
755  else {
756  return 0;
757  }
758 }
759 
760 bool DpCatalog::DpStateEntry::hasIdentity(FwDpIdType id, U32 tSec, U32 tSub) const {
761  return (this->record.get_id() == id) && (this->record.get_tSec() == tSec) && (this->record.get_tSub() == tSub);
762 }
763 
764 bool DpCatalog::DpStateEntry::isSameProduct(const DpStateEntry& other) const {
765  return (this->dir == other.dir) &&
766  this->hasIdentity(other.record.get_id(), other.record.get_tSec(), other.record.get_tSub());
767 }
768 
769 bool DpCatalog::DpStateEntry::operator==(const DpStateEntry& other) const {
770  return compareEntries(*this, other) == 0;
771 }
772 bool DpCatalog::DpStateEntry::operator!=(const DpStateEntry& other) const {
773  return compareEntries(*this, other) != 0;
774 }
775 
776 bool DpCatalog::DpStateEntry::operator>(const DpStateEntry& other) const {
777  return compareEntries(*this, other) > 0;
778 }
779 bool DpCatalog::DpStateEntry::operator<(const DpStateEntry& other) const {
780  return compareEntries(*this, other) < 0;
781 }
782 
783 bool DpCatalog::insertEntry(DpStateEntry& entry) {
784  // Insert into the RedBlackTreeSet
785  // The tree maintains sorting by priority, time, ID, and directory via DpStateEntry comparison operators
786  Fw::Success status = this->m_dpCatalog.insert(entry);
787  return (status == Fw::Success::SUCCESS);
788 }
789 
790 void DpCatalog::sendNextEntry() {
791  // Use xmit flag to break upon STOP_XMIT_CATALOG
792  if (this->m_xmitInProgress != true) {
793  return;
794  }
795  // A send is still in flight (START_XMIT_CATALOG after a STOP, before the file completed): its
796  // fileDone resumes the walk, so do not re-send the entry that is still in the catalog (#5777)
797  if (this->m_hasCurrentXmit) {
798  return;
799  }
800 
801  // Look for the next entry to send
802  DpStateEntry entry;
803  if (!this->findNextEntry(entry)) {
804  // if no entry found, we are done
805  this->m_xmitInProgress = false;
806  this->log_ACTIVITY_HI_CatalogXmitCompleted(this->m_xmitBytes);
807  this->dispatchWaitedResponse(Fw::CmdResponse::OK);
808  return;
809  }
810 
811  // Save current entry for fileDone_handler
812  this->m_currentXmitEntry = entry;
813  this->m_hasCurrentXmit = true;
814 
815  // Build file name based on the found entry
816  Fw::FormatStatus formatStatus =
817  this->m_currXmitFileName.format(DP_FILENAME_FORMAT, this->m_directories[entry.dir].toChar(),
818  entry.record.get_id(), entry.record.get_tSec(), entry.record.get_tSub());
819  if (formatStatus != Fw::FormatStatus::SUCCESS) {
820  this->log_WARNING_HI_FileNameFormatError(this->m_currXmitFileName,
821  static_cast<Fw::StringFormatStatus::T>(formatStatus));
822  // No send is in flight, so no fileDone will arrive: abort the transmit
823  // rather than leaving it wedged in progress
824  this->abortXmit(Fw::CmdResponse::EXECUTION_ERROR);
825  return;
826  }
827  this->log_ACTIVITY_LO_SendingProduct(this->m_currXmitFileName, static_cast<U32>(entry.record.get_size()),
828  entry.record.get_priority());
829  Svc::SendFileResponse resp = this->fileOut_out(0, this->m_currXmitFileName, this->m_currXmitFileName, 0, 0);
830  if (resp.get_status() != Svc::SendFileStatus::STATUS_OK) {
831  this->log_WARNING_HI_DpFileSendError(this->m_currXmitFileName, resp.get_status());
832  // A rejected send produces no fileDone callback: abort the transmit
833  // rather than leaving it wedged in progress
834  this->abortXmit(Fw::CmdResponse::EXECUTION_ERROR);
835  return;
836  }
837  // FileDownlink echoes this context in fileDone; it identifies this send (#5777)
838  this->m_currXmitContext = resp.get_context();
839 } // end sendNextEntry()
840 
841 static_assert(sizeof(FwDpPriorityType) <= sizeof(U32),
842  "DpRecord stores priority as U32; a wider FwDpPriorityType would be truncated in the catalog");
843 
844 bool DpCatalog::findNextEntry(DpStateEntry& entry) {
845  // Entries are ordered by ascending priority value (begin() returns the most urgent) and are removed
846  // as they are transmitted, so the next entry to send is the first one at or after m_xmitStartPriority.
847  // Entries before the range are skipped (not removed) so a later START_XMIT_CATALOG can still send
848  // them; once an entry past m_xmitEndPriority is reached nothing further can be in range.
849  const FwSizeType size = this->m_dpCatalog.getSize();
850  typename Fw::RedBlackTreeSet<DpStateEntry, DP_MAX_FILES>::ConstIterator iter = this->m_dpCatalog.begin();
851  // index gives the walk a fixed upper bound (catalog size); the iterator check is the real end condition
852  for (FwSizeType index = 0; (index < size) && (iter != this->m_dpCatalog.end()); index++, ++iter) {
853  const FwDpPriorityType priority = (*iter).record.get_priority();
854  if (priority < this->m_xmitStartPriority) {
855  continue;
856  }
857  if (priority > this->m_xmitEndPriority) {
858  break;
859  }
860  entry = *iter;
861  return true;
862  }
863 
864  return false;
865 }
866 
867 bool DpCatalog::checkInit() {
868  if (not this->m_initialized) {
870  return false;
871  } else if (0 == this->m_numDpSlots) {
873  return false;
874  }
875 
876  return true;
877 }
878 
880  // only try to deallocate if both pointers are non-zero
881  // it's a way to more gracefully shut down if there are missing
882  // pointers
883  if ((this->m_allocator != nullptr) and (this->m_memPtr != nullptr)) {
884  this->m_allocator->deallocate(this->m_allocatorId, this->m_memPtr);
885  }
886 }
887 
888 // ----------------------------------------------------------------------
889 // Handler implementations for user-defined typed input ports
890 // ----------------------------------------------------------------------
891 
892 void DpCatalog ::fileDone_handler(FwIndexType portNum, const Svc::SendFileResponse& resp) {
893  // Accept only the fileDone for the send in flight (matching FileDownlink context); anything
894  // else is a late callback from an abandoned send (#5777) and must not touch the current transmit
895  if (!this->m_hasCurrentXmit || resp.get_context() != this->m_currXmitContext) {
897  return;
898  }
899 
900  // check file status
902  this->log_WARNING_HI_DpFileXmitError(this->m_currXmitFileName, resp.get_status());
903  this->abortXmit(Fw::CmdResponse::EXECUTION_ERROR);
904  return;
905  }
906 
907  // Reduce pending
908  this->m_pendingDpBytes -= this->m_currentXmitEntry.record.get_size();
909  this->m_pendingFiles--;
910  // Log File Complete & pending
911  this->log_ACTIVITY_LO_ProductComplete(this->m_currXmitFileName, this->m_pendingFiles, this->m_pendingDpBytes);
912 
913  // mark the entry as transmitted
914  this->m_currentXmitEntry.record.set_state(Fw::DpState::TRANSMITTED);
915  // update the transmitted state in the state file data, so a later rewrite of the state file
916  // keeps it (a full table is reported by the update), and in the state file
917  (void)this->updateStateFileData(this->m_currentXmitEntry);
918  this->appendFileState(this->m_currentXmitEntry);
919  // add the size
920  this->m_xmitBytes += this->m_currentXmitEntry.record.get_size();
921 
922  // Remove from catalog. The entry is located by its stable identity rather than by the copy kept
923  // for the send, whose sort key may be stale if the priority changed during the send.
924  // Not ground-reachable: the set is emptied only by resetCatalog, which also clears m_hasCurrentXmit (checked
925  // above), and DELETE_DP refuses the product in flight (doDeleteDp)
926  DpStateEntry catalogEntry{};
927  const DpCatalog_EntryLookupStatus found = this->findEntryByIdentity(this->m_currentXmitEntry, catalogEntry);
928  FW_ASSERT(found == DpCatalog_EntryLookupStatus::FOUND, static_cast<FwAssertArgType>(found.e));
929  // catalogEntry is a copy of a set element, so its key is present
930  const Fw::Success status = this->m_dpCatalog.remove(catalogEntry);
931  FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(status));
932 
933  this->m_hasCurrentXmit = false;
934 
935  // send the next entry, if it exists
936  this->sendNextEntry();
937 }
938 
939 void DpCatalog ::pingIn_handler(FwIndexType portNum, U32 key) {
940  // return code for health ping
941  this->pingOut_out(0, key);
942 }
943 
944 void DpCatalog ::addToCat_handler(FwIndexType portNum,
945  const Fw::StringBase& fileName,
946  FwDpPriorityType priority,
947  FwSizeType size) {
948  // check initialization
949  if (not this->checkInit()) {
950  return;
951  }
952 
953  // check that initialization got memory
954  if (0 == this->m_numDpSlots) {
956  return;
957  }
958 
959  // Check the catalog has been built
960  if (not this->m_catalogBuilt) {
961  this->log_ACTIVITY_HI_NotLoaded(fileName);
962  return;
963  }
964 
965  // Both of these are grabbed from the header
966  (void)priority;
967  (void)size;
968 
969  // Since this is a runtime addition
970  // Check if file is in one of our directories
971  FwSizeType dir = this->determineDirectory(fileName);
972 
973  // Not in one of our directories; skip this file
974  if (dir == DP_MAX_DIRECTORIES) {
975  this->log_WARNING_HI_DirectoryNotManaged(fileName);
976  return;
977  }
978 
979  const ProcessFileStatus ret = processFile(fileName, dir);
980 
981  if (ret == ProcessFileStatus::SUCCESS) {
982  this->resumeIfRemainActive();
983  // The state file is not rewritten here: a newly written product has no transmit state to
984  // record, and pruneAndWriteStateFile() would discard the TRANSMITTED records appended by
985  // fileDone since the catalog was built.
986  }
987 }
988 
989 void DpCatalog ::resumeIfRemainActive() {
990  // If the transmission already finished (or was stopped), resume only if m_remainActive and findNextEntry sees a
991  // pending entry (the new product or one left behind) inside the active priority range. Probing first
992  // avoids the CatalogXmitCompleted that sendNextEntry would report for an empty range.
993  // Otherwise, the fileDone of the file in flight invokes sendNextEntry, which finds the right file,
994  // or the product is transmitted by the next transmit command
995  if (!this->m_xmitInProgress && this->m_remainActive) {
996  DpStateEntry nextEntry{};
997  if (this->findNextEntry(nextEntry)) {
998  this->m_xmitInProgress = true;
999  this->sendNextEntry();
1000  }
1001  }
1002 }
1003 
1004 // ----------------------------------------------------------------------
1005 // Handler implementations for commands
1006 // ----------------------------------------------------------------------
1007 
1008 void DpCatalog ::BUILD_CATALOG_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
1009  // invoke helper
1010  this->cmdResponse_out(opCode, cmdSeq, this->doCatalogBuild());
1011 }
1012 
1013 void DpCatalog ::START_XMIT_CATALOG_cmdHandler(FwOpcodeType opCode,
1014  U32 cmdSeq,
1015  const Fw::Wait& wait,
1016  bool remainActive) {
1017  this->startXmitCmd(opCode, cmdSeq, wait, remainActive, 0, std::numeric_limits<FwDpPriorityType>::max());
1018 }
1019 
1020 void DpCatalog ::START_XMIT_CATALOG_WITH_PRIORITY_cmdHandler(FwOpcodeType opCode,
1021  U32 cmdSeq,
1022  const Fw::Wait& wait,
1023  bool remainActive,
1024  FwDpPriorityType startPriority,
1025  FwDpPriorityType endPriority) {
1026  this->startXmitCmd(opCode, cmdSeq, wait, remainActive, startPriority, endPriority);
1027 }
1028 
1029 void DpCatalog::startXmitCmd(FwOpcodeType opCode,
1030  U32 cmdSeq,
1031  const Fw::Wait& wait,
1032  bool remainActive,
1033  FwDpPriorityType startPriority,
1034  FwDpPriorityType endPriority) {
1035  if (startPriority > endPriority) {
1036  this->log_WARNING_LO_XmitPriorityRangeInvalid(startPriority, endPriority);
1037  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR);
1038  return;
1039  }
1040  this->m_remainActive = remainActive;
1041 
1042  // Arm the waited response before starting: an empty catalog completes the
1043  // transmit inside doCatalogXmit and must still answer a waited command
1044  if (Fw::Wait::WAIT == wait) {
1045  this->m_xmitCmdWait = true;
1046  this->m_xmitOpCode = opCode;
1047  this->m_xmitCmdSeq = cmdSeq;
1048  }
1049 
1050  Fw::CmdResponse resp = this->doCatalogXmit(startPriority, endPriority);
1051  FW_ASSERT(resp.isValid(), static_cast<FwAssertArgType>(resp.e));
1052 
1053  if (resp != Fw::CmdResponse::OK) {
1054  this->m_xmitCmdWait = false;
1055  this->m_xmitOpCode = 0;
1056  this->m_xmitCmdSeq = 0;
1057  this->cmdResponse_out(opCode, cmdSeq, resp);
1058  } else if (Fw::Wait::NO_WAIT == wait) {
1059  this->cmdResponse_out(opCode, cmdSeq, resp);
1060  }
1061 }
1062 
1063 Fw::CmdResponse DpCatalog::doCatalogXmit(FwDpPriorityType startPriority, FwDpPriorityType endPriority) {
1064  FW_ASSERT(startPriority <= endPriority, static_cast<FwAssertArgType>(startPriority),
1065  static_cast<FwAssertArgType>(endPriority));
1066  // check initialization
1067  if (not this->checkInit()) {
1069  }
1070 
1071  // check that initialization got memory
1072  if (0 == this->m_numDpSlots) {
1073  this->log_WARNING_HI_NoDpMemory();
1075  }
1076 
1077  // make sure a downlink is not in progress
1078  if (this->m_xmitInProgress) {
1081  }
1082 
1083  // Check the catalog has been built
1084  if (not this->m_catalogBuilt) {
1087  }
1088 
1089  // start transmission; a START that resumes a send left in flight by STOP keeps the
1090  // session's byte tally, so CatalogXmitCompleted reports the whole session
1091  if (!this->m_hasCurrentXmit) {
1092  this->m_xmitBytes = 0;
1093  }
1094  this->m_xmitStartPriority = startPriority;
1095  this->m_xmitEndPriority = endPriority;
1096  this->log_ACTIVITY_HI_CatalogXmitRangeStarted(startPriority, endPriority);
1097  this->m_xmitInProgress = true;
1098  // Step 3b - search for and send first entry
1099  this->sendNextEntry();
1100  return Fw::CmdResponse::OK;
1101 }
1102 
1103 void DpCatalog ::STOP_XMIT_CATALOG_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
1104  if (not this->m_xmitInProgress) {
1106  // benign error, so don't fail the command
1107  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
1108  } else {
1109  this->log_ACTIVITY_HI_CatalogXmitStopped(this->m_xmitBytes);
1110  // Disarm xmitInProgress so sendNextEntry stops; keep hasCurrentXmit so the
1111  // in-flight file's fileDone is still recorded (the context check rejects any other)
1112  this->m_xmitInProgress = false;
1113  // Respond to original cmd to start xmit
1114  // (if we haven't already)
1115  this->dispatchWaitedResponse(Fw::CmdResponse::OK);
1116 
1117  // Respond to this command
1118  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
1119  }
1120 }
1121 
1122 void DpCatalog ::CLEAR_CATALOG_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
1123  // Dropping the send in flight closes the transmit session here, as STOP does, so a waited
1124  // START_XMIT_CATALOG is answered now and the next BUILD/START is not refused as in progress
1125  if (this->m_xmitInProgress) {
1126  this->abortXmit(Fw::CmdResponse::EXECUTION_ERROR);
1127  }
1128  this->log_ACTIVITY_HI_CatalogCleared(this->m_pendingFiles, this->m_pendingDpBytes);
1129  this->resetCatalog();
1130  this->resetStateFileData();
1131 
1132  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
1133 }
1134 
1135 void DpCatalog ::dispatchWaitedResponse(Fw::CmdResponse response) {
1136  if (this->m_xmitCmdWait) {
1137  this->cmdResponse_out(this->m_xmitOpCode, this->m_xmitCmdSeq, response);
1138 
1139  // Prevent a Duplicate Cmd Response
1140  this->m_xmitCmdWait = false;
1141  this->m_xmitOpCode = 0;
1142  this->m_xmitCmdSeq = 0;
1143  }
1144 }
1145 
1146 void DpCatalog ::abortXmit(Fw::CmdResponse response) {
1147  this->m_hasCurrentXmit = false;
1148  this->m_xmitInProgress = false;
1149  this->dispatchWaitedResponse(response);
1150 }
1151 
1152 void DpCatalog ::SET_DP_PRIORITY_cmdHandler(FwOpcodeType opCode,
1153  U32 cmdSeq,
1154  FwDpIdType id,
1155  U32 tSec,
1156  U32 tSub,
1157  FwDpPriorityType priority) {
1158  if (not this->checkInit()) {
1159  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
1160  return;
1161  }
1162 
1163  DpStateEntry entry{};
1164  if (this->findProductEntry(id, tSec, tSub, entry) == DpCatalog_EntryLookupStatus::NOT_FOUND) {
1165  this->log_WARNING_HI_DpNotFound(id, tSec, tSub);
1166  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
1167  return;
1168  }
1169 
1170  const DpCatalog_PriorityChangeStatus status = this->setDpPriority(entry, priority);
1171  this->cmdResponse_out(opCode, cmdSeq,
1174 }
1175 
1176 DpCatalog_PriorityChangeStatus DpCatalog ::setDpPriority(DpStateEntry& entry, FwDpPriorityType priority) {
1177  const FwDpIdType id = entry.record.get_id();
1178  const U32 tSec = entry.record.get_tSec();
1179  const U32 tSub = entry.record.get_tSub();
1180  const FwDpPriorityType oldPriority = entry.record.get_priority();
1181  if (priority == oldPriority) {
1182  this->log_ACTIVITY_HI_DpPriorityUnchanged(id, tSec, tSub, priority);
1184  }
1185 
1186  // Priority is part of the sort key, so the entry is re-linked by removing and re-inserting it.
1187  // Only this entry moves, and every send restarts the walk at begin(), so a transmit in
1188  // progress follows the new order from its next send
1189  // entry is a copy of a set element, so its key is present
1190  Fw::Success status = this->m_dpCatalog.remove(entry);
1191  FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(status));
1192  entry.record.set_priority(priority);
1193  // the removal freed a node, and the key (which includes the full product identity) is held by no
1194  // other entry, so the insert cannot fail or collide
1195  status = this->m_dpCatalog.insert(entry);
1196  FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(status));
1197  // The send in flight is not affected; its copy is kept current so that the record written on
1198  // completion carries the priority the product had (fileDone finds the catalog entry by identity)
1199  if (this->m_hasCurrentXmit && this->m_currentXmitEntry.isSameProduct(entry)) {
1200  this->m_currentXmitEntry.record.set_priority(priority);
1201  }
1202  this->log_ACTIVITY_HI_DpPrioritySet(id, tSec, tSub, oldPriority, priority);
1203 
1204  // Record the new priority with the product's state, as completion does, so that a rewrite of the
1205  // state file keeps it across a rebuild or restart. Nothing else depends on this record: a runtime
1206  // addToCat recognizes the product by identity, not by priority (processFile)
1207  const DpCatalog_StateFileUpdateStatus updateStatus = this->updateStateFileData(entry);
1208  if (this->m_stateFile.length() == 0) {
1210  }
1211  if (updateStatus == DpCatalog_StateFileUpdateStatus::FULL) {
1213  }
1214  const DpCatalog_StateFileWriteStatus writeStatus = this->pruneAndWriteStateFile();
1217 }
1218 
1219 void DpCatalog ::DELETE_DP_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, FwDpIdType id, U32 tSec, U32 tSub) {
1220  this->cmdResponse_out(opCode, cmdSeq, this->doDeleteDp(id, tSec, tSub));
1221 }
1222 
1223 Fw::CmdResponse DpCatalog ::doDeleteDp(FwDpIdType id, U32 tSec, U32 tSub) {
1224  if (not this->checkInit()) {
1226  }
1227  // The file in flight is never preempted (3.6.4): removing it would break the send and its fileDone
1228  if (this->m_hasCurrentXmit && this->m_currentXmitEntry.hasIdentity(id, tSec, tSub)) {
1229  this->log_WARNING_HI_DpInFlight(id, tSec, tSub);
1231  }
1232 
1233  // A pending product has a catalog entry; a transmitted one is known only by its state file record
1234  DpStateEntry entry{};
1235  const bool inCatalog = (this->findProductEntry(id, tSec, tSub, entry) == DpCatalog_EntryLookupStatus::FOUND);
1236  FwSizeType slot = this->m_stateFileEntries;
1237  if (inCatalog) {
1238  slot = this->findStateFileSlot(entry);
1239  } else {
1240  slot = this->findStateFileSlotByIdentity(id, tSec, tSub);
1241  if (slot != this->m_stateFileEntries) {
1242  entry = this->m_stateFileData[slot].entry;
1243  }
1244  }
1245  const bool inStateFile = (slot != this->m_stateFileEntries);
1246  if (not inCatalog && not inStateFile) {
1247  this->log_WARNING_HI_DpNotFound(id, tSec, tSub);
1249  }
1250  // Catalog entries and loaded state file records only hold configured directory indices (3.6.5)
1251  FW_ASSERT((entry.dir >= 0) && (entry.dir < static_cast<FwIndexType>(this->m_numDirectories)),
1252  static_cast<FwAssertArgType>(entry.dir), static_cast<FwAssertArgType>(this->m_numDirectories));
1253 
1254  Fw::FileNameString fileName;
1255  const Fw::FormatStatus formatStatus =
1256  fileName.format(DP_FILENAME_FORMAT, this->m_directories[entry.dir].toChar(), entry.record.get_id(),
1257  entry.record.get_tSec(), entry.record.get_tSub());
1258  if (formatStatus != Fw::FormatStatus::SUCCESS) {
1259  this->log_WARNING_HI_FileNameFormatError(fileName, static_cast<Fw::StringFormatStatus::T>(formatStatus));
1261  }
1262 
1263  // The file goes first so that a failure leaves the catalog and state file describing what is on disk.
1264  // A file already gone is a stale reference that the delete cleans up
1265  const Os::FileSystem::Status removeStatus = Os::FileSystem::removeFile(fileName.toChar());
1266  if ((removeStatus != Os::FileSystem::OP_OK) && (removeStatus != Os::FileSystem::DOESNT_EXIST)) {
1267  this->log_WARNING_HI_DpFileRemoveError(fileName, static_cast<I32>(removeStatus));
1269  }
1270 
1271  if (inCatalog) {
1272  // entry is a copy of a set element, so its key is present
1273  const Fw::Success status = this->m_dpCatalog.remove(entry);
1274  FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(status));
1275  this->m_pendingDpBytes -= entry.record.get_size();
1276  this->m_pendingFiles--;
1277  }
1278  if (inStateFile) {
1279  // drop the slot by moving the last one into it; the slots in use stay contiguous
1280  this->m_stateFileEntries--;
1281  this->m_stateFileData[slot] = this->m_stateFileData[this->m_stateFileEntries];
1282  this->m_stateFileData[this->m_stateFileEntries].used = false;
1283  this->m_stateFileData[this->m_stateFileEntries].visited = false;
1284  }
1285  this->log_ACTIVITY_HI_DpDeleted(fileName, entry.record.get_state());
1286 
1287  // Rewrite the state file without the record so that a rebuild or restart does not resurrect it. A
1288  // failure is reported by the rewrite; the product is gone from disk and memory regardless
1289  if (inStateFile && (this->m_stateFile.length() > 0)) {
1290  const DpCatalog_StateFileWriteStatus writeStatus = this->pruneAndWriteStateFile();
1291  if (writeStatus != DpCatalog_StateFileWriteStatus::WRITTEN) {
1293  }
1294  }
1295  return Fw::CmdResponse::OK;
1296 }
1297 
1298 void DpCatalog ::RETRANSMIT_DP_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, FwDpIdType id, U32 tSec, U32 tSub) {
1299  this->cmdResponse_out(opCode, cmdSeq, this->doRetransmitDp(id, tSec, tSub));
1300 }
1301 
1302 Fw::CmdResponse DpCatalog ::doRetransmitDp(FwDpIdType id, U32 tSec, U32 tSub) {
1303  if (not this->checkInit()) {
1305  }
1306  // processFile needs the state file data of the last build to recognize the product's record
1307  if (not this->m_catalogBuilt) {
1310  }
1311  // The product in flight is still cataloged (3.6.4); report it as in flight rather than pending
1312  if (this->m_hasCurrentXmit && this->m_currentXmitEntry.hasIdentity(id, tSec, tSub)) {
1315  }
1316  DpStateEntry pendingEntry{};
1317  if (this->findProductEntry(id, tSec, tSub, pendingEntry) == DpCatalog_EntryLookupStatus::FOUND) {
1320  }
1321 
1322  // A transmitted product has no catalog entry, so its file is located by its canonical name in the managed
1323  // directories; the first directory holding the file is used, as the other commands use the first match
1324  Fw::String fullFile;
1326  for (FwSizeType index = 0;
1327  (index < this->m_numDirectories) && (index < static_cast<FwSizeType>(DP_MAX_DIRECTORIES)); index++) {
1328  Fw::String candidate;
1329  const Fw::FormatStatus formatStatus =
1330  candidate.format(DP_FILENAME_FORMAT, this->m_directories[index].toChar(), id, tSec, tSub);
1331  if (formatStatus != Fw::FormatStatus::SUCCESS) {
1332  // a directory too long for the name is skipped; the file may still be in a shorter one
1333  this->log_WARNING_LO_DpRetransmitNameError(this->m_directories[index],
1334  static_cast<Fw::StringFormatStatus::T>(formatStatus));
1335  continue;
1336  }
1337  if (Os::FileSystem::exists(candidate.toChar())) {
1338  fullFile = candidate;
1339  dir = index;
1340  break;
1341  }
1342  }
1343  if (dir == static_cast<FwSizeType>(DP_MAX_DIRECTORIES)) {
1346  }
1347 
1348  // The identity key of the product: its directory, id and time tag (priority and state are not compared)
1349  DpStateEntry product{};
1350  product.dir = static_cast<FwIndexType>(dir);
1351  product.record.set_id(id);
1352  product.record.set_tSec(tSec);
1353  product.record.set_tSub(tSub);
1354  // processFile applies the product's state file record through getFileState, which looks the slot up by the same
1355  // key: a record reading TRANSMITTED would make it skip the file, and a recorded priority would replace the header
1356  // priority. Drop the record (the last slot moves into its place, as DELETE_DP does) so the product is cataloged
1357  // from its header alone, and put it back if the file cannot be cataloged
1358  const FwSizeType slot = this->findStateFileSlot(product);
1359  const bool hadRecord = (slot != this->m_stateFileEntries);
1360  DpDstateFileEntry savedSlot{};
1361  DpDstateFileEntry savedLast{};
1362  if (hadRecord) {
1363  savedSlot = this->m_stateFileData[slot];
1364  savedLast = this->m_stateFileData[this->m_stateFileEntries - 1];
1365  this->m_stateFileEntries--;
1366  this->m_stateFileData[slot] = this->m_stateFileData[this->m_stateFileEntries];
1367  this->m_stateFileData[this->m_stateFileEntries].used = false;
1368  this->m_stateFileData[this->m_stateFileEntries].visited = false;
1369  }
1370  const ProcessFileStatus ret = this->processFile(fullFile, dir);
1371  if (ret != ProcessFileStatus::SUCCESS) {
1372  if (hadRecord) {
1373  this->m_stateFileData[this->m_stateFileEntries] = savedLast;
1374  this->m_stateFileData[slot] = savedSlot;
1375  this->m_stateFileEntries++;
1376  }
1379  }
1380  // Not ground-reachable: processFile succeeded only if the file's canonical name, built from its header id and
1381  // time tag, equals fullFile, which was built from the command's id and time tag in the same directory, so the
1382  // entry it inserted has exactly this identity and nothing has touched the set since
1383  DpStateEntry catalogEntry{};
1384  const DpCatalog_EntryLookupStatus found = this->findEntryByIdentity(product, catalogEntry);
1385  FW_ASSERT(found == DpCatalog_EntryLookupStatus::FOUND, static_cast<FwAssertArgType>(found.e));
1386  this->log_ACTIVITY_HI_DpRetransmitScheduled(fullFile, catalogEntry.record.get_priority());
1387 
1388  // Record the product UNTRANSMITTED at its header priority, as a completion records it, so that the state file
1389  // data holds the reset; a product that had a record always gets one (its slot was just freed), a product without
1390  // one may find the data full (StateFileFull, 3.6.8). Then rewrite the state file so that a rebuild after a
1391  // restart catalogs the product instead of skipping it, whether its TRANSMITTED record held a slot or was appended
1392  // without one. A write failure is reported by the rewrite and fails the command, as for DELETE_DP; the product
1393  // stays rescheduled in memory
1394  (void)this->updateStateFileData(catalogEntry);
1396  if (this->m_stateFile.length() > 0) {
1397  const DpCatalog_StateFileWriteStatus writeStatus = this->pruneAndWriteStateFile();
1398  if (writeStatus != DpCatalog_StateFileWriteStatus::WRITTEN) {
1400  }
1401  }
1402  // From here on the product is scheduled as a runtime insert is (3.6.7)
1403  this->resumeIfRemainActive();
1404  return response;
1405 }
1406 
1407 DpCatalog_EntryLookupStatus DpCatalog ::findEntryByIdentity(const DpStateEntry& product, DpStateEntry& entry) const {
1408  // The sort key includes the priority, which SET_DP_PRIORITY changes, so the lookup is by the
1409  // identity fields alone; the walk is bounded by the catalog capacity
1411  iter != this->m_dpCatalog.end(); ++iter) {
1412  if ((*iter).isSameProduct(product)) {
1413  entry = *iter;
1415  }
1416  }
1418 }
1419 
1420 DpCatalog_EntryLookupStatus DpCatalog ::findProductEntry(FwDpIdType id, U32 tSec, U32 tSub, DpStateEntry& entry) const {
1421  // The command names the product by id and time tag. The sort key includes the priority, which the
1422  // command changes, so the lookup is a walk by the identity fields, bounded by the catalog capacity
1424  iter != this->m_dpCatalog.end(); ++iter) {
1425  if ((*iter).hasIdentity(id, tSec, tSub)) {
1426  entry = *iter;
1428  }
1429  }
1431 }
1432 
1433 } // namespace Svc
Serialization/Deserialization operation was successful.
A data product Container.
Definition: DpContainer.hpp:26
void pingOut_out(FwIndexType portNum, U32 key) const
Invoke output port pingOut.
FwDpPriorityType getPriority() const
virtual void * allocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t))=0
void log_WARNING_HI_StateFileTruncated(const Fw::StringBase &file, I32 offset, I32 size) const
Log event StateFileTruncated.
FwIdType FwOpcodeType
The type of a command opcode.
void log_WARNING_HI_StateFileFull(FwDpIdType id, U32 tSec, U32 tSub) const
void log_WARNING_HI_DirectoryOpenError(const Fw::StringBase &loc, I32 stat) const
void log_WARNING_HI_DpRetransmitError(FwDpIdType id, U32 tSec, U32 tSub, const Svc::DpCatalog_RetransmitRejectReason &reason) const
Representing success.
void log_WARNING_LO_XmitPriorityRangeInvalid(FwDpPriorityType startPriority, FwDpPriorityType endPriority) const
PlatformSizeType FwSizeType
void log_WARNING_HI_DpFileXmitError(const Fw::StringBase &file, const Svc::SendFileStatus &stat)
Log event DpFileXmitError.
U32 FwDpPriorityType
The type of a data product priority.
void log_ACTIVITY_HI_NotLoaded(const Fw::StringBase &file) const
Log event NotLoaded.
I32 FwEnumStoreType
Auto-generated base for DpCatalog component.
FwSignedSizeType substring_find(const CHAR *source_string, FwSizeType source_size, const CHAR *sub_string, FwSizeType sub_size)
find the first occurrence of a substring
Definition: StringUtils.cpp:43
void log_WARNING_HI_FileNameFormatError(const Fw::StringBase &file, const Fw::StringFormatStatus &status)
Wait or don&#39;t wait for something.
Definition: WaitEnumAc.hpp:18
void log_WARNING_HI_DpInsertError(const Svc::DpRecord &dp)
static constexpr FwSizeType MIN_PACKET_SIZE
Definition: DpContainer.hpp:65
static const FwIndexType DP_MAX_DIRECTORIES
void log_WARNING_HI_StateFileDirectoryInvalid_ThrottleClear()
Reset throttle value for StateFileDirectoryInvalid.
The priority was changed and, if a state file is configured, recorded in it (DpPrioritySet reported) ...
Svc::SendFileResponse fileOut_out(FwIndexType portNum, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName, U32 offset, U32 length) const
Invoke output port fileOut.
int8_t I8
8-bit signed integer
Definition: BasicTypes.h:51
ConstIterator begin() const override
Status size(FwSizeType &size_result) override
get size of currently open file
Definition: File.cpp:111
Svc::SendFileStatus::T get_status() const
Get member status.
void configure(const Fw::ExternalArray< Fw::FileNameString > &directories, Fw::FileNameString &stateFile, FwEnumStoreType memId, Fw::MemAllocator &allocator)
Configure the DpCatalog.
Definition: DpCatalog.cpp:29
No entry with the identity is in the catalog.
enum T e
The raw enum value.
Overwrite file when it exists and creation was requested.
Definition: File.hpp:60
PlatformSignedSizeType FwSignedSizeType
The data product is pending in the catalog and will be transmitted.
void log_ACTIVITY_HI_CatalogCleared(U32 pending, U64 pending_bytes) const
static bool exists(const char *path)
Return true if the path exists, false otherwise.
Definition: FileSystem.cpp:148
void log_WARNING_HI_StateFileOpenError(const Fw::StringBase &file, I32 stat) const
Log event StateFileOpenError.
Enum representing a command response.
#define DIRECTORY_DELIMITER
Definition: DpCatalog.hpp:28
void log_ACTIVITY_HI_DpFileAdded(const Fw::StringBase &file) const
void log_WARNING_HI_DpFileRemoveError(const Fw::StringBase &file, I32 stat) const
The state file could not be opened (StateFileOpenError reported)
void setBuffer(const Buffer &buffer)
Set the packet buffer.
bool isValid() const
Check raw enum value for validity.
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
SerializeStatus
forward declaration for string
U32 get_context() const
Get member context.
void log_WARNING_HI_FileCorruptedDataError(const Fw::StringBase &file, I32 stat) const
void log_WARNING_HI_FileOpenError(const Fw::StringBase &loc, I32 stat)
void log_ACTIVITY_LO_ProductComplete(const Fw::StringBase &file, U32 pending, U64 pending_bytes) const
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
Definition: File.cpp:50
void log_WARNING_HI_NoDpMemory() const
Log event NoDpMemory.
void log_WARNING_HI_FileSizeError(const Fw::StringBase &file, I32 stat)
The transmitted state.
The size of the serial representation.
void log_WARNING_HI_FileReadError(const Fw::StringBase &file, I32 stat)
void clear() override
Clear the set.
Open file for appending.
Definition: File.hpp:37
void log_ACTIVITY_HI_DpFileSkipped(const Fw::StringBase &file) const
void log_ACTIVITY_HI_DpRetransmitScheduled(const Fw::StringBase &file, FwDpPriorityType priority) const
void log_ACTIVITY_LO_ProcessingDirectory(const Fw::StringBase &directory) const
void log_WARNING_HI_DpNotFound(FwDpIdType id, U32 tSec, U32 tSub) const
void log_DIAGNOSTIC_DpDuplicate(const Svc::DpRecord &dp)
File doesn&#39;t exist (for read)
Definition: File.hpp:43
void log_ACTIVITY_HI_ProcessingDirectoryComplete(const Fw::StringBase &loc, U32 total, U32 pending, U64 pending_bytes) const
void log_ACTIVITY_LO_SendingProduct(const Fw::StringBase &file, U32 bytes, U32 prio) const
void log_WARNING_LO_NoStateFileSpecified() const
Log event NoStateFileSpecified.
External serialize buffer with no copy semantics.
void log_WARNING_HI_DpInFlight(FwDpIdType id, U32 tSec, U32 tSub) const
void log_WARNING_LO_NoStateFile(const Fw::StringBase &file) const
Log event NoStateFile.
T
The raw enum type.
A record could not be written (StateFileWriteError reported)
U32 getSeconds() const
Definition: Time.cpp:128
constexpr const char * DP_FILENAME_FORMAT
Definition: DpCfg.hpp:21
Fw::Time getTimeTag() const
The entry already had the priority (DpPriorityUnchanged reported)
FwSizeType getSize() const override
void log_ACTIVITY_HI_DpPriorityUnchanged(FwDpIdType id, U32 tSec, U32 tSub, FwDpPriorityType priority) const
An entry with the identity is in the catalog.
void close() override
close the file, if not opened then do nothing
Definition: File.cpp:97
Status write(const U8 *buffer, FwSizeType &size)
write data to this file from the supplied buffer bounded by size
Definition: File.cpp:213
Directory stream has no more files.
Definition: Directory.hpp:27
void log_WARNING_LO_XmitNotActive() const
Log event XmitNotActive.
const char * toChar() const
Convert to a C-style char*.
void log_ACTIVITY_HI_CatalogXmitCompleted(U64 bytes) const
void log_WARNING_HI_DpFileSendError(const Fw::StringBase &file, const Svc::SendFileStatus &stat)
Log event DpFileSendError.
void log_ACTIVITY_LO_ProcessingFile(const Fw::StringBase &file) const
static const FwIndexType DP_MAX_FILES
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:58
FwSizeType getSize() const
Command successfully executed.
void log_WARNING_HI_FileHdrError(const Fw::StringBase &file, const Svc::DpHdrField &field, U32 exp, U32 act)
void log_ACTIVITY_HI_CatalogXmitStopped(U64 bytes) const
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
DpCatalog(const char *const compName)
DpCatalog constructor.
Definition: DpCatalog.cpp:25
Directory class.
Definition: Directory.hpp:116
static Status getFileSize(const char *path, FwSizeType &size)
Get the size of the file (in bytes) at the specified path.
Definition: FileSystem.cpp:227
void log_WARNING_HI_StateFileDirectoryInvalid(const Fw::StringBase &file, I32 offset, FwIndexType dirIndex)
FwSignedSizeType substring_find_last(const CHAR *source_string, FwSizeType source_size, const CHAR *sub_string, FwSizeType sub_size)
find the last occurrence of a substring
Definition: StringUtils.cpp:85
Status read(U8 *buffer, FwSizeType &size)
read data from this file into supplied buffer bounded by size
Definition: File.cpp:194
Success remove(const T &element) override
Command had execution error.
FwIdType FwDpIdType
The type of a data product identifier.
void log_WARNING_HI_StateFileReadError(const Fw::StringBase &file, I32 stat, I32 offset) const
Log event StateFileReadError.
Fw::DpState getState() const
Get the product state.
void log_ACTIVITY_HI_DpDeleted(const Fw::StringBase &file, const Fw::DpState &state) const
void log_WARNING_HI_DirectoryNotManaged(const Fw::StringBase &file) const
Memory Allocation base class.
void log_WARNING_LO_DpRetransmitNameError(const Fw::StringBase &dir, const Fw::StringFormatStatus &status) const
void log_WARNING_HI_CatalogFull(const Fw::StringBase &dir)
Operation was successful.
Definition: File.hpp:42
No file of the data product exists in a managed directory.
The entry was recorded in its own slot or a reused stale slot.
U32 getUSeconds() const
Definition: Time.cpp:132
void log_WARNING_HI_XmitUnbuiltCatalog() const
Log event XmitUnbuiltCatalog.
PlatformIndexType FwIndexType
void log_WARNING_HI_FileHdrDesError(const Fw::StringBase &file, I32 stat)
Operation was successful.
Definition: Directory.hpp:22
void log_ACTIVITY_HI_CatalogXmitRangeStarted(FwDpPriorityType startPriority, FwDpPriorityType endPriority) const
Open file for reading.
Definition: File.hpp:33
Send file response struct.
U32 asBigEndianU32() const
Convert bytes 0 through 3 of the hash data to a big-Endian U32 value.
void log_WARNING_LO_StaleFileDone(U32 context, const Svc::SendFileStatus &status)
#define DP_EXT
Definition: DpCfg.hpp:20
A container class for holding a hash buffer.
Definition: HashBuffer.hpp:26
Success::T checkHeaderHash(Utils::HashBuffer &storedHash, Utils::HashBuffer &computedHash) const
Check the header hash.
Success insert(const T &element) override
Command failed validation.
RateGroupDivider component implementation.
ConstIterator end() const override
virtual SizeType length() const
Get the length of the string.
U8 BYTE
byte type
Definition: BasicTypes.h:57
The priority was changed but could not be recorded in the configured state file (error reported) ...
Fw::SerializeStatus deserializeHeader()
Definition: DpContainer.cpp:38
Operation was successful.
Definition: FileSystem.hpp:24
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
Invalid size parameter.
Definition: File.hpp:46
Wait for something.
Definition: WaitEnumAc.hpp:34
FwDpIdType getId() const
FwSizeType getDataSize() const
Don&#39;t wait for something.
Definition: WaitEnumAc.hpp:36
void log_ACTIVITY_HI_DpPrioritySet(FwDpIdType id, U32 tSec, U32 tSub, FwDpPriorityType oldPriority, FwDpPriorityType newPriority) const
void log_WARNING_HI_InvalidFileName(const Fw::StringBase &file, const Fw::StringBase &expected)
The data product file could not be cataloged (see the preceding file event)
#define FW_ASSERT(...)
Definition: Assert.hpp:14
static Status removeFile(const char *path)
Remove a file at the specified path.
Definition: FileSystem.cpp:87
Success/Failure.
void log_WARNING_HI_DpCatalogFull(const Svc::DpRecord &dp)
void log_WARNING_HI_StateFileWriteError(const Fw::StringBase &file, I32 stat) const
Log event StateFileWriteError.
Path doesn&#39;t exist.
Definition: FileSystem.hpp:32
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
FwSizeType string_length(const CHAR *source, FwSizeType buffer_size)
get the length of the source string
Definition: StringUtils.cpp:32
FormatStatus
status of string format calls
Definition: format.hpp:18
Open file for writing and truncates file if it exists, ie same flags as creat()
Definition: File.hpp:34