From f1292f1034fccb01ea1cfde57d7a52d5e5454476 Mon Sep 17 00:00:00 2001 From: ZXGuesser Date: Sat, 4 Aug 2018 02:39:56 +0100 Subject: [PATCH] deleting pages of all types now works Do iterators need resetting in DeleteOldPages? --- carousel.cpp | 9 ++++- filemonitor.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++----- normalpages.cpp | 12 +++++++ packetmag.cpp | 35 ++++++------------ pagelist.cpp | 16 ++++++--- specialpages.cpp | 12 +++++++ ttxpagestream.h | 3 +- 7 files changed, 142 insertions(+), 39 deletions(-) diff --git a/carousel.cpp b/carousel.cpp index 5bb4d60..3cff09e 100644 --- a/carousel.cpp +++ b/carousel.cpp @@ -39,7 +39,14 @@ TTXPageStream* Carousel::nextCarousel() for (std::list::iterator it=_carouselList.begin();it!=_carouselList.end();++it) { p=*it; - + if (p->GetStatusFlag()==TTXPageStream::MARKED) + { + std::cerr << "[Carousel::nextCarousel] Deleted " << p->GetSourcePage() << std::endl; + p->SetState(TTXPageStream::GONE); + _carouselList.remove(p); + return nullptr; + } + if (p->Expired()) { // std::cerr << "[Carousel::nextCarousel] page " << std::hex << p->GetPageNumber() << std::dec << " cycle time=" << p->GetCycleTime() << std::endl; diff --git a/filemonitor.cpp b/filemonitor.cpp index dcbe3e3..286d744 100644 --- a/filemonitor.cpp +++ b/filemonitor.cpp @@ -114,20 +114,98 @@ void FileMonitor::run() p->IncrementUpdateCount(); p->GetPageCount(); // renumber the subpages int mag=(p->GetPageNumber() >> 16) & 0x7; - if (p->IsCarousel() && !(p->GetCarouselFlag()) && !(p->Special())) + + if (p->GetSpecialFlag()) { - // page has become a carousel so add it to its mag's carousel list + // Page was 'special' + p->SetSpecialFlag(p->Special()); p->SetCarouselFlag(p->IsCarousel()); - _pageList->GetMagazines()[mag]->GetCarousel()->addPage(p); - std::cerr << "[FileMonitor::run] page is now a carousel " << std::hex << p->GetPageNumber() << std::endl; + if (!(p->Special())) + { + // Page is longer 'special' + // TODO: remove from SpecialPages list + _pageList->GetMagazines()[mag]->GetSpecialPages()->deletePage(p); + + if (p->IsCarousel()) + { + // Page is a 'carousel', add to Carousel list + _pageList->GetMagazines()[mag]->GetCarousel()->addPage(p); + std::cerr << "[FileMonitor::run] page was special, is now a carousel " << std::hex << p->GetPageNumber() << std::endl; + } + else + { + // Page is 'normal', add to NormalPages list + _pageList->GetMagazines()[mag]->GetNormalPages()->addPage(p); + std::cerr << "[FileMonitor::run] page was special, is now normal " << std::hex << p->GetPageNumber() << std::endl; + } + } + else + { + // no change + std::cerr << "[FileMonitor::run] page remains special " << std::hex << p->GetPageNumber() << std::endl; + } } - if (p->Special() && !(p->GetSpecialFlag())) + else if (p->GetCarouselFlag()) { - // page has become special so add it to its mag's special pages list + // Page was 'carousel' p->SetSpecialFlag(p->Special()); - _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(p); - std::cerr << "[FileMonitor::run] page is now special " << std::hex << p->GetPageNumber() << std::endl; + p->SetCarouselFlag(p->IsCarousel()); + if (!(p->IsCarousel()) || p->Special()) + { + // Page is no longer a 'carousel' + // TODO: remove from Carousel list + _pageList->GetMagazines()[mag]->GetCarousel()->deletePage(p); + + if (p->Special()) + { + // Page is 'special', add to SpecialPages list + _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(p); + std::cerr << "[FileMonitor::run] page was carousel, is now special " << std::hex << p->GetPageNumber() << std::endl; + } + else + { + // Page is 'normal', add to NormalPages list + _pageList->GetMagazines()[mag]->GetNormalPages()->addPage(p); + std::cerr << "[FileMonitor::run] page was carousel, is now normal " << std::hex << p->GetPageNumber() << std::endl; + } + } + else + { + // no change + std::cerr << "[FileMonitor::run] page remains a carousel " << std::hex << p->GetPageNumber() << std::endl; + } } + else + { + // Page was 'normal' + p->SetSpecialFlag(p->Special()); + p->SetCarouselFlag(p->IsCarousel()); + if (p->Special() || p->IsCarousel()) + { + // Page is no longer 'normal' + // TODO: remove from NormalPages list + _pageList->GetMagazines()[mag]->GetNormalPages()->deletePage(p); + + if (p->Special()) + { + // Page is 'special', add to SpecialPages list + _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(p); + std::cerr << "[FileMonitor::run] page was normal, is now special " << std::hex << p->GetPageNumber() << std::endl; + } + else if (p->IsCarousel()) + { + // Page is a 'carousel', add to Carousel list + _pageList->GetMagazines()[mag]->GetCarousel()->addPage(p); + std::cerr << "[FileMonitor::run] page was normal, is now a carousel " << std::hex << p->GetPageNumber() << std::endl; + } + } + else + { + // no change + std::cerr << "[FileMonitor::run] page remains normal " << std::hex << p->GetPageNumber() << std::endl; + } + } + if (_pageList->CheckForPacket29(p)) { std::cerr << "[FileMonitor::run] found packet 29" << std::endl; diff --git a/normalpages.cpp b/normalpages.cpp index 3fcd521..161d57a 100644 --- a/normalpages.cpp +++ b/normalpages.cpp @@ -42,6 +42,18 @@ TTXPageStream* NormalPages::NextPage() _page = nullptr; } + if (_page) + { + if (_page->GetStatusFlag()==TTXPageStream::MARKED) + { + std::cerr << "[NormalPages::NextPage] Deleted " << _page->GetSourcePage() << std::endl; + _page->SetState(TTXPageStream::GONE); + _NormalPagesList.remove(_page); + ResetIter(); + return nullptr; + } + } + return _page; } diff --git a/packetmag.cpp b/packetmag.cpp index b0ffc11..33981fc 100644 --- a/packetmag.cpp +++ b/packetmag.cpp @@ -139,34 +139,19 @@ Packet* PacketMag::GetPacket(Packet* p) { //_outp("c"); } - else // No carousel? Take the next page in the main sequence + else // No carousel? Take the next normal page { _page=_normalPages->NextPage(); - if (_page == nullptr){ - // couldn't get a page to send so sent a time filling header - p->Header(_magNumber,0xFF,0x3F7F,0x8010); - p->HeaderText(_configure->GetHeaderTemplate()); // Placeholder 32 characters. This gets replaced later - ClearEvent(EVENT_FIELD); // This will suspend all packets until the next field. - return p; - } - else if (_page->GetStatusFlag()==TTXPageStream::MARKED) - { - // If it is marked for deletion, then remove it. - // never delete anything until we sort out the deleting from carousel issue - //_pageSet->remove(*(_it++)); - _page=nullptr; - } - else if (_page->IsCarousel()) // Don't let carousel pages into the main page sequence - { - // Page is a carousel, this shouldn't happen - _page=nullptr; // clear everything for now so that we keep running - } - else if (_page->Special()) - { - // Page is special, this shouldn't happen - _page=nullptr; - } } + + if (_page == nullptr){ + // couldn't get a page to send so sent a time filling header + p->Header(_magNumber,0xFF,0x3F7F,0x8010); + p->HeaderText(_configure->GetHeaderTemplate()); // Placeholder 32 characters. This gets replaced later + ClearEvent(EVENT_FIELD); // This will suspend all packets until the next field. + return p; + } + _thisRow=0; if (_page->GetCarouselFlag()){ diff --git a/pagelist.cpp b/pagelist.cpp index a55ec36..c0036da 100644 --- a/pagelist.cpp +++ b/pagelist.cpp @@ -406,9 +406,9 @@ void PageList::DeleteOldPages() { TTXPageStream* ptr; ptr=&(*p); - if (ptr->GetStatusFlag()==TTXPageStream::NOTFOUND) + if (ptr->GetStatusFlag()==TTXPageStream::GONE) { - if (((ptr->GetPageNumber() >> 8) & 0xFF) == 0xFF) + if (((ptr->GetPageNumber() >> 8) & 0xFF) == 0xFF) { // page mFF - make sure packet 29 is removed _magPacket29[mag][0] = nullptr; @@ -416,8 +416,16 @@ void PageList::DeleteOldPages() _magPacket29[mag][2] = nullptr; _mag[mag]->SetPacket29(_magPacket29[mag]); } - - // std::cerr << "[PageList::DeleteOldPages] Marked for Delete " << ptr->GetSourcePage() << std::endl; + + std::cerr << "[PageList::DeleteOldPages] Deleted " << ptr->GetSourcePage() << std::endl; + // page has been removed from lists + _pageList[mag].remove(*p); + p--; + // TODO: reset iterators ? + } + else if (ptr->GetStatusFlag()==TTXPageStream::NOTFOUND) + { + std::cerr << "[PageList::DeleteOldPages] Marked for Delete " << ptr->GetSourcePage() << std::endl; // Pages marked here get deleted in the Service thread ptr->SetState(TTXPageStream::MARKED); } diff --git a/specialpages.cpp b/specialpages.cpp index e45a4b3..2ca2e01 100644 --- a/specialpages.cpp +++ b/specialpages.cpp @@ -55,6 +55,18 @@ TTXPageStream* SpecialPages::NextPage() _page->StepNextSubpageNoLoop(); // ensure we don't point at a null subpage } + if (_page) + { + if (_page->GetStatusFlag()==TTXPageStream::MARKED) + { + std::cerr << "[SpecialPages::NextPage] Deleted " << _page->GetSourcePage() << std::endl; + _page->SetState(TTXPageStream::GONE); + _specialPagesList.remove(_page); + ResetIter(); + return nullptr; + } + } + return _page; } diff --git a/ttxpagestream.h b/ttxpagestream.h index caa4b85..5bd1fdc 100644 --- a/ttxpagestream.h +++ b/ttxpagestream.h @@ -23,7 +23,8 @@ class TTXPageStream : public TTXPage NEW, // Just created NOTFOUND, // Not found yet FOUND, // Matched on drive - MARKED + MARKED, // To be deleted + GONE // Safe to delete }; /** Default constructor. Don't call this */