Skip to content

Commit

Permalink
Generate time filling headers if there are no pages to be transmitted…
Browse files Browse the repository at this point in the history
… (happens if there are only carousel or special pages in a magazine)

Also prevent special pages from getting into carousels
  • Loading branch information
ZXGuesser committed Jan 15, 2018
1 parent cd6b2d7 commit 8b74f6e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 40 deletions.
2 changes: 1 addition & 1 deletion filemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void FileMonitor::run()
p->LoadPage(name); // What if this fails? We can see the bool. What to do ?
p->GetPageCount(); // renumber the subpages
int mag=(p->GetPageNumber() >> 16) & 0x7;
if (p->IsCarousel() && !(p->GetCarouselFlag()))
if (p->IsCarousel() && !(p->GetCarouselFlag()) && !(p->Special()))
{
// page has become a carousel so add it to its mag's carousel list
p->SetCarouselFlag(p->IsCarousel());
Expand Down
99 changes: 61 additions & 38 deletions packetmag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ Packet* PacketMag::GetPacket(Packet* p)
ClearEvent(EVENT_SPECIAL_PAGES);
return nullptr;
}
} else {
}
else if (GetEvent(EVENT_FIELD))
{
_page=_carousel->nextCarousel(); // The next carousel page (if there is one)

// But before that, do some housekeeping
Expand All @@ -149,43 +151,64 @@ Packet* PacketMag::GetPacket(Packet* p)
if (_page) // Carousel? Step to the next subpage
{
//_outp("c");

}
else // No carousel? Take the next page in the main sequence
{
if (_it==_pageSet->end())
{
std::cerr << "This can not happen (we can't get the next page?)" << std::endl;
exit(0);
}
++_it;
if (_it==_pageSet->end())
{
_it=_pageSet->begin();
}
// Get pointer to the page we are sending
// todo: Find a way to skip carousels without going into an infinite loop
_page=&*_it;
// If it is marked for deletion, then remove it.
if (_page->GetStatusFlag()==TTXPageStream::MARKED)
{
// ensure pages are removed from carousel and special lists so that we don't try to access them after deletion
if (_page->IsCarousel())
_carousel->deletePage(_page);
if (_page->Special())
_specialPages->deletePage(_page);

_pageSet->remove(*(_it++));
if (_page->Special() && _page->GetSpecialFlag()){
// don't let special pages into normal sequence as carousels
std::cerr << "special page got into carousel this should not happen" << std::endl;
_carousel->deletePage(_page);
_page=nullptr;
return nullptr;
// Stays in HEADER mode so that we run this again
}
if (_page->IsCarousel() && _page->GetCarouselFlag()) // Don't let registered carousel pages into the main page sequence
}
else // No carousel? Take the next page in the main sequence
{
bool loopBreaker = false;
do
{
// Page is a carousel - it should be in the carousel list but will also still be in the pageSet
_page=nullptr; // clear everything for now so that we keep running
return nullptr;
if (_it==_pageSet->end())
{
std::cerr << "This can not happen (we can't get the next page?)" << std::endl;
exit(0);
}
++_it;
if (_it==_pageSet->end())
{
_it=_pageSet->begin();
if (loopBreaker)
{
// we have looped through entire page list and not found any non-carousel or non-special pages to transmit, 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;
}
loopBreaker = true;
}
// Get pointer to the page we are sending
// todo: Find a way to skip carousels without going into an infinite loop
_page=&*_it;
// If it is marked for deletion, then remove it.
if (_page->GetStatusFlag()==TTXPageStream::MARKED)
{
// ensure pages are removed from carousel and special lists so that we don't try to access them after deletion
if (_page->IsCarousel())
_carousel->deletePage(_page);
if (_page->Special())
_specialPages->deletePage(_page);

_pageSet->remove(*(_it++));
_page=nullptr;
// Stays in HEADER mode so that we run this again
}
if (_page->IsCarousel() && _page->GetCarouselFlag()) // Don't let registered carousel pages into the main page sequence
{
// Page is a carousel - it should be in the carousel list but will also still be in the pageSet
_page=nullptr; // clear everything for now so that we keep running
} else if (_page->Special() && _page->GetSpecialFlag()){
// don't let special pages into normal sequence
_page=nullptr;
}
}
while (_page == nullptr);
}
_thisRow=0;

Expand All @@ -206,11 +229,6 @@ Packet* PacketMag::GetPacket(Packet* p)
}
}

if (_page->Special() && _page->GetSpecialFlag()){
// don't let special pages into normal sequence
return nullptr;
}

// for a non carousel page GetCarouselPage() just returns the page itself
_page->StepNextSubpage();
thisSubcode=_page->GetCarouselPage()->GetSubCode();
Expand All @@ -224,6 +242,11 @@ Packet* PacketMag::GetPacket(Packet* p)
_status|=PAGESTATUS_C8_UPDATE;
}
}
else
{
// there is nothing we can transmit
return nullptr;
}

// the page has stopped being special, or become special without getting its flag set
if (_page->Special() != _page->GetSpecialFlag()){
Expand Down
2 changes: 1 addition & 1 deletion pagelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void PageList::AddSpecialPagesAndCarousels()
{
TTXPageStream* ptr;
ptr=&(*p);
if (ptr->IsCarousel() && !(ptr->GetCarouselFlag()))
if (ptr->IsCarousel() && !(ptr->GetCarouselFlag()) && !(ptr->Special()))
{
ptr->SetCarouselFlag(ptr->IsCarousel());
_mag[mag]->GetCarousel()->addPage(ptr);
Expand Down

0 comments on commit 8b74f6e

Please sign in to comment.