diff --git a/TCPClient.cpp b/TCPClient.cpp index d022726..c8dfb7a 100644 --- a/TCPClient.cpp +++ b/TCPClient.cpp @@ -269,8 +269,6 @@ void TCPClient::addChar(char ch, char* response) static int mode=MODENORMAL; static int charCount=0; // Used to accumulate Newfor - std::stringstream ss; - response[0]=0; switch (mode) { @@ -320,6 +318,7 @@ void TCPClient::addChar(char ch, char* response) else { // Got a complete non-newfor command + std::stringstream ss; ss << "[TCPClient::addChar] finished cmd='" << strlen(_cmd) << "\n"; std::cerr << ss.str(); if (strlen(_cmd)) // Avoid this being called twice by \n\r combinations diff --git a/carousel.cpp b/carousel.cpp index 22a0516..680dcd6 100644 --- a/carousel.cpp +++ b/carousel.cpp @@ -30,13 +30,12 @@ TTXPageStream* Carousel::nextCarousel() TTXPageStream* p; if (_carouselList.size()==0) return NULL; - std::stringstream ss; - for (std::list::iterator it=_carouselList.begin();it!=_carouselList.end();++it) { p=*it; if (p->GetStatusFlag()==TTXPageStream::MARKED && p->GetCarouselFlag()) // only remove it once { + std::stringstream ss; ss << "[Carousel::nextCarousel] Deleted " << p->GetSourcePage() << "\n"; std::cerr << ss.str(); @@ -47,6 +46,7 @@ TTXPageStream* Carousel::nextCarousel() } else if ((!(p->IsCarousel())) || (p->Special())) { + std::stringstream ss; ss << "[Carousel::nextCarousel] no longer a carousel " << std::hex << p->GetPageNumber() << "\n"; std::cerr << ss.str(); diff --git a/configure.cpp b/configure.cpp index e62c5bc..b891d13 100644 --- a/configure.cpp +++ b/configure.cpp @@ -4,11 +4,11 @@ using namespace ttx; -int Configure::DirExists(char *path) +int Configure::DirExists(std::string *path) { struct stat info; - if(stat(path, &info ) != 0) + if(stat(path->c_str(), &info ) != 0) return 0; else if(info.st_mode & S_IFDIR) return 1; @@ -26,12 +26,12 @@ Configure::Configure(int argc, char** argv) : _serviceStatusString(20, ' '), _subtitleRepeats(1) { - std::stringstream ss; - strncpy(_configFile,CONFIGFILE,MAXPATH-1); -#ifdef _WIN32 - strncpy(_pageDir,"./pages",MAXPATH-1); // a relative path as a sensible default + _configFile = CONFIGFILE; + +#ifdef RASPBIAN + _pageDir = "/home/pi/teletext"; #else - strcpy(_pageDir,"/home/pi/teletext"); + _pageDir = "./pages"; // a relative path as a sensible default #endif // This is where the default header template is defined. _headerTemplate = "VBIT2 %%# %%a %d %%b" "\x03" "%H:%M:%S"; @@ -41,7 +41,7 @@ Configure::Configure(int argc, char** argv) : _commandPortEnabled = false; _reverseBits = false; - _debug = false; + _debugLevel = 0; _rowAdaptive = false; _linesPerField = 16; // default to 16 lines per field @@ -56,34 +56,63 @@ Configure::Configure(int argc, char** argv) : //Scan the command line for overriding the pages file. if (argc>1) { - for (int i=1;i -1 && l < MAXDEBUGLEVEL) + { + _debugLevel = (int)l; + + std::stringstream ss; + ss << "[Configure::Configure] debugging enabled at level " << _debugLevel << "\n"; + std::cerr << ss.str(); + } + else + { + std::cerr << "[Configure::Configure] invalid debug level argument\n"; + exit(EXIT_FAILURE); + } + } + else + { + std::cerr << "[Configure::Configure] --debug requires an argument\n"; + exit(EXIT_FAILURE); + } } } } - if (!DirExists(_pageDir)) + if (!DirExists(&_pageDir)) { + std::stringstream ss; ss << "[Configure::Configure] " << _pageDir << " does not exist or is not a directory\n"; std::cerr << ss.str(); exit(EXIT_FAILURE); } - - // TODO: allow overriding config file from command line + // TODO: allow overriding config file from command line + std::stringstream ss; ss << "[Configure::Configure] Pages directory is " << _pageDir << "\n"; ss << "[Configure::Configure] Config file is " << _configFile << "\n"; std::cerr << ss.str(); @@ -105,8 +134,6 @@ Configure::~Configure() int Configure::LoadConfigFile(std::string filename) { std::ifstream filein(filename.c_str()); // Open the file - - std::stringstream ss; std::vector::iterator iter; // these are all the valid strings for config lines @@ -114,6 +141,7 @@ int Configure::LoadConfigFile(std::string filename) if (filein.is_open()) { + std::stringstream ss; ss << "[Configure::LoadConfigFile] opened " << filename << "\n"; std::cerr << ss.str(); @@ -385,6 +413,7 @@ int Configure::LoadConfigFile(std::string filename) } if (error) { + std::stringstream ss; ss << "[Configure::LoadConfigFile] invalid config line: " << line << "\n"; std::cerr << ss.str(); } diff --git a/configure.h b/configure.h index ecc2312..550f610 100644 --- a/configure.h +++ b/configure.h @@ -19,7 +19,8 @@ #include "ttxline.h" #define CONFIGFILE "vbit.conf" // default config file name -#define MAXPATH 132 + +#define MAXDEBUGLEVEL 3 namespace ttx @@ -33,7 +34,7 @@ class Configure Configure(int argc=0, char** argv=NULL); ~Configure(); - inline char* GetPageDirectory(){return _pageDir;}; + inline std::string GetPageDirectory(){return _pageDir;}; std::string GetHeaderTemplate(){return _headerTemplate;} bool GetRowAdaptive(){return _rowAdaptive;} @@ -48,7 +49,7 @@ class Configure bool GetCommandPortEnabled(){return _commandPortEnabled;} uint16_t GetLinesPerField(){return _linesPerField;} bool GetReverseFlag(){return _reverseBits;} - bool GetDebugFlag(){return _debug;} + int GetDebugLevel(){return _debugLevel;} int GetMagazinePriority(uint8_t mag){return _magazinePriority[mag];} /* these don't really belong in configure, but it's the only place that everything can access */ @@ -56,7 +57,7 @@ class Configure time_t GetMasterClock(){return _masterClock;} private: - int DirExists(char *path); + int DirExists(std::string *path); int LoadConfigFile(std::string filename); @@ -78,12 +79,12 @@ class Configure uint16_t _CountryNetworkIdentificationCode; std::string _serviceStatusString; /// 20 characters - char _configFile[MAXPATH]; /// Configuration file name --config - char _pageDir[MAXPATH]; /// Configuration file name --dir + std::string _configFile; /// Configuration file name --config + std::string _pageDir; /// Configuration file name --dir uint8_t _subtitleRepeats; /// Number of times a subtitle repeats (typically 1 or 2). bool _commandPortEnabled; bool _reverseBits; - bool _debug; + int _debugLevel; time_t _masterClock; }; diff --git a/filemonitor.cpp b/filemonitor.cpp index 8693a4a..1c67c4a 100644 --- a/filemonitor.cpp +++ b/filemonitor.cpp @@ -77,8 +77,6 @@ int FileMonitor::readDirectory(std::string path) struct dirent *dirp; struct stat attrib; - std::stringstream ss; - DIR *dp; // Open the directory @@ -107,6 +105,7 @@ int FileMonitor::readDirectory(std::string path) { if (readDirectory(name)) // recurse into directory { + std::stringstream ss; ss << "Error(" << errno << ") recursing into " << name << "\n"; std::cerr << ss.str(); } @@ -140,6 +139,7 @@ int FileMonitor::readDirectory(std::string path) // page was not 'special' but now is, add to SpecialPages list q->SetSpecialFlag(true); _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(q); + std::stringstream ss; ss << "[FileMonitor::run] page was normal, is now special " << std::hex << q->GetPageNumber() << "\n"; std::cerr << ss.str(); // page will be removed from NormalPages list by the service thread @@ -150,6 +150,7 @@ int FileMonitor::readDirectory(std::string path) // page was 'special' but now isn't, add to NormalPages list _pageList->GetMagazines()[mag]->GetNormalPages()->addPage(q); q->SetNormalFlag(true); + std::stringstream ss; ss << "[FileMonitor::run] page was special, is now normal " << std::hex << q->GetPageNumber() << "\n"; std::cerr << ss.str(); } @@ -160,6 +161,7 @@ int FileMonitor::readDirectory(std::string path) q->SetCarouselFlag(true); q->StepNextSubpage(); // ensure we're pointing at a subpage _pageList->GetMagazines()[mag]->GetCarousel()->addPage(q); + std::stringstream ss; ss << "[FileMonitor::run] page is now a carousel " << std::hex << q->GetPageNumber() << "\n"; std::cerr << ss.str(); } @@ -181,6 +183,7 @@ int FileMonitor::readDirectory(std::string path) } else { + std::stringstream ss; ss << "[FileMonitor::run] Adding a new page " << dirp->d_name << "\n"; std::cerr << ss.str(); // A new file. Create the page object and add it to the page list. @@ -228,12 +231,14 @@ int FileMonitor::readDirectory(std::string path) } else { + std::stringstream ss; ss << "[FileMonitor::run] Failed to add" << dirp->d_name << "\n"; // should never happen std::cerr << ss.str(); } } else { + std::stringstream ss; ss << "[FileMonitor::run] Failed to load" << dirp->d_name << "\n"; std::cerr << ss.str(); } diff --git a/normalpages.cpp b/normalpages.cpp index fdf7e18..59b238d 100644 --- a/normalpages.cpp +++ b/normalpages.cpp @@ -23,7 +23,6 @@ void NormalPages::addPage(TTXPageStream* p) TTXPageStream* NormalPages::NextPage() { - std::stringstream ss; if (_page == nullptr) { if (_needSorting) @@ -53,6 +52,7 @@ TTXPageStream* NormalPages::NextPage() if (_page->GetStatusFlag()==TTXPageStream::MARKED && _page->GetNormalFlag()) // only remove it once { + std::stringstream ss; ss << "[NormalPages::NextPage] Deleted " << _page->GetSourcePage() << "\n"; std::cerr << ss.str(); _iter = _NormalPagesList.erase(_iter); @@ -65,6 +65,7 @@ TTXPageStream* NormalPages::NextPage() if (_page->Special()) { + std::stringstream ss; ss << "[NormalPages::NextPage] page became Special" << std::hex << _page->GetPageNumber() << "\n"; std::cerr << ss.str(); _iter = _NormalPagesList.erase(_iter); diff --git a/packetDebug.cpp b/packetDebug.cpp index be889ac..3d68a13 100644 --- a/packetDebug.cpp +++ b/packetDebug.cpp @@ -52,7 +52,7 @@ bool PacketDebug::IsReady(bool force) (void)force; // silence error about unused parameter bool result=false; - if (_configure->GetDebugFlag()) + if (_configure->GetDebugLevel()) { if (GetEvent(EVENT_FIELD)) { diff --git a/pagelist.cpp b/pagelist.cpp index 55401af..6d5796a 100644 --- a/pagelist.cpp +++ b/pagelist.cpp @@ -191,13 +191,13 @@ int PageList::Match(char* pageNumber) for (std::list::iterator p=_pageList[mag].begin();p!=_pageList[mag].end();++p) { TTXPageStream* ptr; - std::stringstream ss; char s[6]; char* ps=s; bool match=true; for (ptr=&(*p);ptr!=nullptr;ptr=(TTXPageStream*)ptr->Getm_SubPage()) // For all the subpages in a carousel { // Convert the page number into a string so we can compare it + std::stringstream ss; ss << std::hex << std::uppercase << std::setw(5) << ptr->GetPageNumber(); strcpy(ps,ss.str().c_str()); // std::cerr << "[PageList::FindPage] matching " << ps << std::endl; diff --git a/ttxpage.cpp b/ttxpage.cpp index 84e554a..fd600d3 100644 --- a/ttxpage.cpp +++ b/ttxpage.cpp @@ -118,7 +118,6 @@ bool TTXPage::m_LoadTTI(std::string filename) int lines=0; // Open the file std::ifstream filein(filename.c_str()); - std::stringstream ss; TTXPage* p=this; p->m_Init(); // reset page char * ptr; @@ -263,7 +262,9 @@ bool TTXPage::m_LoadTTI(std::string filename) { std::getline(filein, line); if (line.length()<3) - ss << "invalid page function/coding " << line << "\n"; + { + // invalid page function/coding + } else { SetPageFunctionInt(std::strtol(line.substr(0,1).c_str(), &ptr, 16)); @@ -273,7 +274,7 @@ bool TTXPage::m_LoadTTI(std::string filename) } default: { - ss << "Command not understood " << line << "\n"; + // line not understood } } // switch } // if matched command @@ -281,7 +282,6 @@ bool TTXPage::m_LoadTTI(std::string filename) } // seek command if (!found) std::getline(filein, line); } - std::cerr << ss.str(); filein.close(); // Not sure that we need to close it p->Setm_SubPage(nullptr); TTXPage::pageChanged=false; @@ -505,9 +505,9 @@ int TTXPage::GetLanguage() void TTXPage::SetPageNumber(int page) { - std::stringstream ss; if ((page<0x10000) || (page>0x8ff99)) { + std::stringstream ss; ss << "[TTXPage::SetPageNumber] Page number is out of range: " << std::hex << page << std::endl; std::cerr << ss.str(); page = 0x8FF00; diff --git a/updatedpages.cpp b/updatedpages.cpp index d53dbb3..88683e2 100644 --- a/updatedpages.cpp +++ b/updatedpages.cpp @@ -21,8 +21,6 @@ void UpdatedPages::addPage(TTXPageStream* p) TTXPageStream* UpdatedPages::NextPage() { - std::stringstream ss; - if (_page == nullptr) { _iter=_UpdatedPagesList.begin(); @@ -45,7 +43,8 @@ TTXPageStream* UpdatedPages::NextPage() /* remove pointers from this list if the pages are marked for deletion */ if (_page->GetStatusFlag()==TTXPageStream::MARKED && _page->GetUpdatedFlag()) // only remove it once { - ss << "[UpdatedPages::NextPage] Deleted " << _page->GetSourcePage() << std::endl; + std::stringstream ss; + ss << "[UpdatedPages::NextPage] Deleted " << _page->GetSourcePage() << "\n"; std::cerr << ss.str(); _iter = _UpdatedPagesList.erase(_iter); _page->SetUpdatedFlag(false);