Skip to content

Commit

Permalink
deleting pages of all types now works
Browse files Browse the repository at this point in the history
Do iterators need resetting in DeleteOldPages?
  • Loading branch information
ZXGuesser committed Aug 4, 2018
1 parent 688c1c2 commit f1292f1
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 39 deletions.
9 changes: 8 additions & 1 deletion carousel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ TTXPageStream* Carousel::nextCarousel()
for (std::list<TTXPageStream*>::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;
Expand Down
94 changes: 86 additions & 8 deletions filemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions normalpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
35 changes: 10 additions & 25 deletions packetmag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()){
Expand Down
16 changes: 12 additions & 4 deletions pagelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,18 +406,26 @@ 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;
_magPacket29[mag][1] = nullptr;
_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);
}
Expand Down
12 changes: 12 additions & 0 deletions specialpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion ttxpagestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit f1292f1

Please sign in to comment.