Skip to content

Commit 2ecf839

Browse files
committed
Only Reset DpCat Traversal Stack if addition is higher priority
1 parent 834a17a commit 2ecf839

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

Svc/DpCatalog/DpCatalog.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ int DpCatalog::processFile(Fw::String fullFile, FwSizeType dir = DP_MAX_DIRECTOR
476476
Fw::StringUtils::string_length(DIRECTORY_DELIMITER, sizeof(DIRECTORY_DELIMITER)));
477477

478478
// TODO: What happens w/ relative paths and root dir files
479+
// Seems like the logic works so long as the path styles match
479480
if (-1 == loc) {
480481
this->log_WARNING_HI_DirectoryNotManaged(fullFile);
481482
return 0;
@@ -485,7 +486,7 @@ int DpCatalog::processFile(Fw::String fullFile, FwSizeType dir = DP_MAX_DIRECTOR
485486
const char* const dir_string = this->m_directories[dir].toChar();
486487

487488
// Compare both strings up to location of final slash
488-
// memsafe since both are fixed width strings
489+
// memory safe since both are fixed width strings
489490
// and loc is before the fixed width
490491
if (strncmp(dir_string, fullFile.toChar(), static_cast<FwSizeType>(loc)) == 0) {
491492
break;
@@ -581,9 +582,29 @@ int DpCatalog::processFile(Fw::String fullFile, FwSizeType dir = DP_MAX_DIRECTOR
581582

582583
this->log_ACTIVITY_HI_DpFileAdded(addedFileName);
583584

585+
// Compute relative priority to current xmit if we are
586+
if (this->m_xmitInProgress && this->m_currentXmitNode != nullptr) {
587+
return 16 + this->compareNodes(entry, this->m_currentXmitNode->entry);
588+
}
589+
584590
return 1;
585591
}
586592

593+
int DpCatalog::compareNodes(DpStateEntry& left, DpStateEntry& right) {
594+
// check priority. Lower is higher priority
595+
if (left.record.get_priority() == right.record.get_priority()) {
596+
// check time. Older is higher priority
597+
if (left.record.get_tSec() == right.record.get_tSec()) {
598+
// check ID. Lower is higher priority
599+
return left.record.get_id() < right.record.get_id();
600+
} else { // if seconds are not equal. Older is higher priority
601+
return left.record.get_tSec() < right.record.get_tSec();
602+
}
603+
} else { // if priority is not equal. Lower is higher priority.
604+
return left.record.get_priority() < right.record.get_priority();
605+
} // end checking for left/right insertion
606+
}
607+
587608
bool DpCatalog::insertEntry(DpStateEntry& entry) {
588609
// the tree is filled in the following priority order:
589610
// 1. DP priority - lower number is higher priority
@@ -865,17 +886,22 @@ void DpCatalog ::addToCat_handler(FwIndexType portNum,
865886
(void)priority;
866887
(void)size;
867888

889+
// ret > 0 := success
890+
// ret > 16 := higher priority addition
868891
int ret = processFile(fileName);
869892

870893
if (ret > 0) {
871-
// TODO: Handle adding a node to a catalog that has
894+
// Handle adding a node to a catalog that has
872895
// already moved past the inserted node's priority
873-
// Lazy solution is to re-init the current tx-node to the root of the b-tree
874-
// This wipes the traversal stack
875-
this->resetTreeStack();
896+
// Lazy solution is to wipe the traversal stack
897+
// Only wipe traversal if the new node is higher priority than current xmit
898+
if (ret >= 16) {
899+
this->resetTreeStack();
900+
}
876901

877902
// If we already finished, sendNext only if remainingActive
878903
if (!this->m_xmitInProgress && this->m_remainActive) {
904+
this->resetTreeStack();
879905
this->m_xmitInProgress = true;
880906
this->sendNextEntry();
881907
}

Svc/DpCatalog/DpCatalog.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ class DpCatalog final : public DpCatalogComponentBase {
151151
/// @return -1 for quit, 0 for failure but continue, 1 for success
152152
int processFile(Fw::String fullFile, FwSizeType dir);
153153

154+
/// @brief insert an entry into the sorted list; if it exists, update the metadata
155+
/// @param left an entry to compare
156+
/// @param right other entry to compare
157+
/// @return 1 if left is higher priority, 0 if equal, and -1 if right is higher priority
158+
int compareNodes(DpStateEntry& left, DpStateEntry& right);
159+
154160
/// @brief insert an entry into the sorted list; if it exists, update the metadata
155161
/// @param entry new entry
156162
/// @return failed if couldn't find a slot FIXME: Should we just assert? We should never run out.
@@ -260,8 +266,8 @@ class DpCatalog final : public DpCatalogComponentBase {
260266
U32 m_pendingFiles; //!< Pending Files to Transmit
261267
U64 m_pendingDpBytes; //!< Pending Bytes to Transmit
262268

263-
bool m_remainActive; //!< Does the DpCat resume transmission when a runtime Dp is received after the full catalog
264-
//!< is sent
269+
bool m_remainActive; //!< Does the DpCat resume transmission when a runtime Dp is received after the full
270+
//!< catalog is sent
265271
};
266272

267273
} // namespace Svc

0 commit comments

Comments
 (0)