Skip to content

Commit

Permalink
Get rid of Mag so that everything is using PacketMag instead.
Browse files Browse the repository at this point in the history
get access to mags through pageList to add pages to specialpages and carousel lists when the pagelist is first loaded, and when a page is added or changed by the filemonitor so that they go live as immediately.
  • Loading branch information
ZXGuesser committed Sep 29, 2017
1 parent 3872ae4 commit 7d0569d
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ LIBS += -lwsock32
endif

#Set any dependent files (e.g. header files) so that if they are edited they cause a re-compile (e.g. "main.h my_sub_functions.h some_definitions_file.h"), or leave blank
DEPS = vbit2.h service.h configure.h pagelist.h ttxpage.h packet.h tables.h mag.h ttxpagestream.h ttxline.h carousel.h filemonitor.h command.h TCPClient.h newfor.h hamm-tables.h packetsource.h packetmag.h packet830.h packetsubtitle.h ttxcodes.h specialpages.h
DEPS = vbit2.h service.h configure.h pagelist.h ttxpage.h packet.h tables.h ttxpagestream.h ttxline.h carousel.h filemonitor.h command.h TCPClient.h newfor.h hamm-tables.h packetsource.h packetmag.h packet830.h packetsubtitle.h ttxcodes.h specialpages.h

OBJ = vbit2.o service.o configure.o pagelist.o ttxpage.o packet.o tables.o mag.o ttxpagestream.o ttxline.o carousel.o filemonitor.o command.o TCPClient.o newfor.o packetsource.o packetmag.o packet830.o packetsubtitle.o specialpages.o
OBJ = vbit2.o service.o configure.o pagelist.o ttxpage.o packet.o tables.o ttxpagestream.o ttxline.o carousel.o filemonitor.o command.o TCPClient.o newfor.o packetsource.o packetmag.o packet830.o packetsubtitle.o specialpages.o

#Below here doesn't need to change
#Compile each object file
Expand Down
38 changes: 35 additions & 3 deletions filemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,29 @@ void FileMonitor::run()

if (attrib.st_mtime!=p->GetModifiedTime()) // File exists. Has it changed?
{
std::cerr << "File has been modified" << dirp->d_name << std::endl;
std::cerr << "[FileMonitor::run] File has been modified " << dirp->d_name << std::endl;
// We just load the new page and update the modified time
// This isn't good enough.
// We need a mutex or semaphore to lock out this page while we do that
// lock
p->LoadPage(name); // What if this fails? We can see the bool. What to do ?
p->GetPageCount(); // renumber the subpages
if (p->IsCarousel() && !(p->GetCarouselFlag()))
{
// page has become a carousel so add it to its mag's carousel list
p->SetCarouselFlag(p->IsCarousel());
int mag=(p->GetPageNumber() >> 16) & 0x7;
_pageList->GetMagazines()[mag]->GetCarousel()->addPage(p);
std::cerr << "[FileMonitor::run] page is now a carousel " << std::hex << p->GetPageNumber() << std::endl;
}
if (p->Special() && !(p->GetSpecialFlag()))
{
// page has become special so add it to its mag's special pages list
p->SetSpecialFlag(p->Special());
int mag=(p->GetPageNumber() >> 16) & 0x7;
_pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(p);
std::cerr << "[FileMonitor::run] page is now special " << std::hex << p->GetPageNumber() << std::endl;
}
p->SetModifiedTime(attrib.st_mtime);
// unlock

Expand All @@ -120,11 +137,26 @@ void FileMonitor::run()
}
else
{
std::cerr << "[FileMonitor::run] " << " Adding a new page" << dirp->d_name << std::endl;
std::cerr << "[FileMonitor::run] Adding a new page " << dirp->d_name << std::endl;
// A new file. Create the page object and add it to the page list.
if ((p=new TTXPageStream(name)))
{
_pageList->AddPage(p);
p->SetSpecialFlag(p->Special());
p->SetCarouselFlag(p->IsCarousel());
p->GetPageCount(); // renumber the subpages
_pageList->AddPage(p);
if (p->GetCarouselFlag())
{
int mag=(p->GetPageNumber() >> 16) & 0x7;
_pageList->GetMagazines()[mag]->GetCarousel()->addPage(p);
std::cerr << "[FileMonitor::run] new page is a carousel " << std::hex << p->GetPageNumber() << std::endl;
}
if (p->GetSpecialFlag())
{
int mag=(p->GetPageNumber() >> 16) & 0x7;
_pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(p);
std::cerr << "[FileMonitor::run] new page is special " << std::hex << p->GetPageNumber() << std::endl;
}
}
else
std::cerr << "[FileMonitor::run] Failed to load" << dirp->d_name << std::endl;
Expand Down
1 change: 1 addition & 0 deletions mag.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// @todo THIS MODULE WILL BE REDUNDANT AUG 2017
// Nothing using this as of 2017-09-27

#include "mag.h"

Expand Down
1 change: 0 additions & 1 deletion newfor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

//@todo Update these to the VBIT2 equivalents
//#include "buffer.h"
//#include "mag.h"
//#include "hamm.h"


Expand Down
13 changes: 6 additions & 7 deletions packetmag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ PacketMag::PacketMag(uint8_t mag, std::list<TTXPageStream>* pageSet, ttx::Config
}
if (_pageSet->size()>0)
{
//std::cerr << "[Mag::Mag] enters. page size=" << _pageSet->size() << std::endl;
_it=_pageSet->begin();
//_it->DebugDump();
_page=&*_it;
Expand Down Expand Up @@ -151,7 +150,7 @@ Packet* PacketMag::GetPacket(Packet* p)
{
//_outp("c");
_page->StepNextSubpage();
//std::cerr << "[Mag::GetPacket] Header thisSubcode=" << std::hex << _page->GetCarouselPage()->GetSubCode() << std::endl;
//std::cerr << "[PacketMag::GetPacket] Header thisSubcode=" << std::hex << _page->GetCarouselPage()->GetSubCode() << std::endl;
}
else // No carousel? Take the next page in the main sequence
{
Expand Down Expand Up @@ -228,15 +227,15 @@ Packet* PacketMag::GetPacket(Packet* p)
}
}

// the function of a page changes
// the page has stopped being special, or become special without getting its flag set
if (_page->Special() != _page->GetSpecialFlag()){
_page->SetSpecialFlag(_page->Special());
if (_page->Special()){
//std::cerr << "page became special " << std::hex << _page->GetPageNumber() << std::endl;
std::cerr << "[PacketMag::GetPacket] page became special " << std::hex << _page->GetPageNumber() << std::endl;
_specialPages->addPage(_page);
return nullptr;
} else {
//std::cerr << "page became normal " << std::hex << _page->GetPageNumber() << std::endl;
std::cerr << "[PacketMag::GetPacket] page became normal " << std::hex << _page->GetPageNumber() << std::endl;
_specialPages->deletePage(_page);
}
}
Expand Down Expand Up @@ -345,7 +344,7 @@ Packet* PacketMag::GetPacket(Packet* p)
val.replace(1,1,1,(triplet & 0x3F) | 0x40);
val.replace(2,1,1,((triplet & 0xFC0) >> 6) | 0x40);
val.replace(3,1,1,((triplet & 0x3F000) >> 12) | 0x40);
//std::cerr << "[Mag::GetPacket] region:" << std::hex << region << " nos:" << std::hex << NOS << " triplet:" << std::hex << triplet << std::endl;
//std::cerr << "[PacketMag::GetPacket] region:" << std::hex << region << " nos:" << std::hex << NOS << " triplet:" << std::hex << triplet << std::endl;
p->SetRow(_magNumber, 28, val, CODING_13_TRIPLETS);
_lastTxt=_page->GetTxRow(26); // Get _lastTxt ready for packet 26 processing
_state=PACKETSTATE_PACKET26;
Expand Down Expand Up @@ -412,7 +411,7 @@ Packet* PacketMag::GetPacket(Packet* p)
//_outp("J");
if (_lastTxt->IsBlank() && (_configure->GetRowAdaptive() || _page->GetPageFunction() != LOP)) // If a row is empty then skip it if row adaptive mode on, or not a level 1 page
{
// std::cerr << "[Mag::GetPacket] Empty row" << std::hex << _page->GetPageNumber() << std::dec << std::endl;
// std::cerr << "[PacketMag::GetPacket] Empty row" << std::hex << _page->GetPageNumber() << std::dec << std::endl;
return nullptr;
}
else
Expand Down
10 changes: 10 additions & 0 deletions packetmag.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ class PacketMag : public PacketSource
/** Default destructor */
virtual ~PacketMag();

/** Access _pageSet
* \return The current value of _pageSet
*/
std::list<TTXPageStream>* Get_pageSet() { return _pageSet; }

SpecialPages* GetSpecialPages() { return _specialPages; }
Carousel* GetCarousel() { return _carousel; }

/** Get the next packet
* @return The next packet OR if IsReady() would return false then a filler packet
*/
Packet* GetPacket(Packet* p) override;

void SetPriority(uint8_t priority) { _priority = priority; }

bool IsReady(bool force=false);

Expand Down
36 changes: 27 additions & 9 deletions pagelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,15 @@ int PageList::LoadPageList(std::string filepath)
// How many files did we accept?
for (int i=0;i<8;i++)
{
//std::cerr << "Page list count[" << i << "]=" << _pageList[i].size() << std::endl;
// Initialise a magazine streamer with a page list
/*
std::list<TTXPageStream> pageSet;
pageSet=_pageList[i];
_mag[i]=new vbit::Mag(pageSet);
*/
_mag[i]=new vbit::Mag(i, &_pageList[i], _configure);
_mag[i]=new vbit::PacketMag(i, &_pageList[i], _configure, 9); // this creates the eight PacketMags that Service will use. Priority will be set in Service later
}

AddSpecialPagesAndCarousels(); // add any special pages that were loaded in

// Just for testing
if (1) for (int i=0;i<8;i++)
{
vbit::Mag* m=_mag[i];
vbit::PacketMag* m=_mag[i];
std::list<TTXPageStream>* p=m->Get_pageSet();
for (std::list<TTXPageStream>::const_iterator it=p->begin();it!=p->end();++it)
{
Expand Down Expand Up @@ -363,6 +359,28 @@ void PageList::DeleteOldPages()
}
}

void PageList::AddSpecialPagesAndCarousels()
{
// moves any special pages and carousels into the magazine's _specialPages and _carousels lists immediately so that it doesn't have to wait for the page to next be transmitted
for (int mag=0;mag<8;mag++)
{
for (std::list<TTXPageStream>::iterator p=_pageList[mag].begin();p!=_pageList[mag].end();++p)
{
TTXPageStream* ptr;
ptr=&(*p);
if (ptr->IsCarousel() && !(ptr->GetCarouselFlag()))
{
ptr->SetCarouselFlag(ptr->IsCarousel());
_mag[mag]->GetCarousel()->addPage(ptr);
}
if (ptr->Special() && !(ptr->GetSpecialFlag()))
{
ptr->SetSpecialFlag(true);
_mag[mag]->GetSpecialPages()->addPage(ptr);
}
}
}
}

/* Want this to happen in the Service thread.
// Not the best idea, to check for deletes here
Expand Down
10 changes: 7 additions & 3 deletions pagelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "configure.h"
#include "ttxpagestream.h"
#include "mag.h"
#include "packetmag.h"

namespace ttx
{
Expand All @@ -33,7 +33,7 @@ class PageList
*/
int LoadPageList(std::string filepath);

vbit::Mag **GetMagazines(){vbit::Mag **p=_mag;return p;};
vbit::PacketMag **GetMagazines(){vbit::PacketMag **p=_mag;return p;};

/** Return the page object that was loaded from <filename>
* @param filename The filename of the page we are looking for.
Expand Down Expand Up @@ -66,6 +66,10 @@ class PageList
/** Delete all pages that no longer exist
*/
void DeleteOldPages();

/** Get special pages into a list in magazine
*/
void AddSpecialPagesAndCarousels();

/** \brief Iterate through all pages
* \return Returns the next page or nullptr if we are at the end
Expand Down Expand Up @@ -96,7 +100,7 @@ class PageList
private:
Configure* _configure; // The configuration object
std::list<TTXPageStream> _pageList[8]; /// The list of Pages in this service. One list per magazine
vbit::Mag* _mag[8];
vbit::PacketMag* _mag[8];

// iterators through selected pages. (use the same iterator for D command and MD, L etc.)
uint8_t _iterMag; /// Magazine number for the iterator
Expand Down
10 changes: 5 additions & 5 deletions service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ Service::Service(Configure *configure, PageList *pageList) :
// @todo Put priority into config and add commands to allow updates.
uint8_t priority[8]={9,3,3,6,3,3,5,6}; // 1=High priority,9=low. Note: priority[0] is mag 8

vbit::Mag **magList=_pageList->GetMagazines();
vbit::PacketMag **magList=_pageList->GetMagazines();
// Register all the packet sources
for (uint8_t mag=0;mag<8;mag++)
{
vbit::Mag* m=magList[mag];
std::list<TTXPageStream>* p=m->Get_pageSet();
_register(new PacketMag(mag,p,_configure,priority[mag]));
vbit::PacketMag* m=magList[mag];
m->SetPriority(priority[mag]); // set the mags to the desired priorities
_register(m); // use the PacketMags created in pageList rather than duplicating them
}
// Add packet sources for subtitles, databroadcast and packet 830
_register(_subtitle=new PacketSubtitle(_configure));
Expand Down Expand Up @@ -144,7 +144,6 @@ void Service::_updateEvents()
if (_fieldCounter>=50)
{
_fieldCounter=0;
seconds++;
// std::cerr << "Seconds=" << seconds << std::endl;
// Could implement a seconds counter here if we needed it
if (seconds%10==0){ // how often do we want to trigger sending special packets?
Expand All @@ -154,6 +153,7 @@ void Service::_updateEvents()
(*iterator)->SetEvent(EVENT_PACKET_29);
}
}
seconds++;
// if (seconds>30) exit(0); // JUST FOR DEBUGGING!!!! Must remove
}
// New field, so set the FIELD event in all the sources.
Expand Down
1 change: 0 additions & 1 deletion service.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "configure.h"
#include "pagelist.h"
#include "packet.h"
// #include "mag.h" // @todo THIS WILL BE REDUNDANT
#include <packetsource.h>
#include <packetmag.h>
#include <packet830.h>
Expand Down
4 changes: 1 addition & 3 deletions specialpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ void SpecialPages::addPage(TTXPageStream* p)

void SpecialPages::deletePage(TTXPageStream* p)
{
if (*_iter == p)
_iter--; // if iterator is pointing at this page wind it back
_specialPagesList.remove(p);
_page = nullptr;
ResetIter();
}

TTXPageStream* SpecialPages::NextPage()
Expand Down

0 comments on commit 7d0569d

Please sign in to comment.