From 7d0569d8e9010d67c9443e329ee6fa7f95b7fa39 Mon Sep 17 00:00:00 2001 From: ZXGuesser Date: Fri, 29 Sep 2017 13:46:55 +0100 Subject: [PATCH] Get rid of Mag so that everything is using PacketMag instead. 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. --- Makefile | 4 ++-- filemonitor.cpp | 38 +++++++++++++++++++++++++++++++++++--- mag.cpp | 1 + newfor.h | 1 - packetmag.cpp | 13 ++++++------- packetmag.h | 10 ++++++++++ pagelist.cpp | 36 +++++++++++++++++++++++++++--------- pagelist.h | 10 +++++++--- service.cpp | 10 +++++----- service.h | 1 - specialpages.cpp | 4 +--- 11 files changed, 94 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 448ab1e..ca99f7c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/filemonitor.cpp b/filemonitor.cpp index 44d5423..cc642d2 100644 --- a/filemonitor.cpp +++ b/filemonitor.cpp @@ -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 @@ -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; diff --git a/mag.cpp b/mag.cpp index 1677f6b..f0e60b1 100644 --- a/mag.cpp +++ b/mag.cpp @@ -1,4 +1,5 @@ /// @todo THIS MODULE WILL BE REDUNDANT AUG 2017 +// Nothing using this as of 2017-09-27 #include "mag.h" diff --git a/newfor.h b/newfor.h index bb57eca..322efc1 100644 --- a/newfor.h +++ b/newfor.h @@ -9,7 +9,6 @@ //@todo Update these to the VBIT2 equivalents //#include "buffer.h" -//#include "mag.h" //#include "hamm.h" diff --git a/packetmag.cpp b/packetmag.cpp index 5e2ded1..a5a1a7e 100644 --- a/packetmag.cpp +++ b/packetmag.cpp @@ -25,7 +25,6 @@ PacketMag::PacketMag(uint8_t mag, std::list* 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; @@ -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 { @@ -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); } } @@ -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; @@ -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 diff --git a/packetmag.h b/packetmag.h index a070ac0..3aa0541 100644 --- a/packetmag.h +++ b/packetmag.h @@ -22,10 +22,20 @@ class PacketMag : public PacketSource /** Default destructor */ virtual ~PacketMag(); + /** Access _pageSet + * \return The current value of _pageSet + */ + std::list* 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); diff --git a/pagelist.cpp b/pagelist.cpp index 67482ff..399005f 100644 --- a/pagelist.cpp +++ b/pagelist.cpp @@ -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 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* p=m->Get_pageSet(); for (std::list::const_iterator it=p->begin();it!=p->end();++it) { @@ -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::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 diff --git a/pagelist.h b/pagelist.h index 6bdb468..b703df7 100644 --- a/pagelist.h +++ b/pagelist.h @@ -10,7 +10,7 @@ #include "configure.h" #include "ttxpagestream.h" -#include "mag.h" +#include "packetmag.h" namespace ttx { @@ -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 * @param filename The filename of the page we are looking for. @@ -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 @@ -96,7 +100,7 @@ class PageList private: Configure* _configure; // The configuration object std::list _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 diff --git a/service.cpp b/service.cpp index 36225d7..4734970 100644 --- a/service.cpp +++ b/service.cpp @@ -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* 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)); @@ -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? @@ -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. diff --git a/service.h b/service.h index c7968bb..99f0ba0 100644 --- a/service.h +++ b/service.h @@ -10,7 +10,6 @@ #include "configure.h" #include "pagelist.h" #include "packet.h" -// #include "mag.h" // @todo THIS WILL BE REDUNDANT #include #include #include diff --git a/specialpages.cpp b/specialpages.cpp index a13fb43..2216541 100644 --- a/specialpages.cpp +++ b/specialpages.cpp @@ -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()