@@ -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+
587608bool 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 }
0 commit comments