diff options
| author | etobi <git@e-tobi.net> | 2009-10-25 21:47:44 +0100 |
|---|---|---|
| committer | etobi <git@e-tobi.net> | 2009-10-25 22:04:41 +0100 |
| commit | 1bc46ff520d87425c3a119a8e6ac998194e48d48 (patch) | |
| tree | dbe69ca7fa58516283814a368e60dd336a867b24 | |
| parent | 6bf565287bd718a72b8d862cae4d41797ca82fdc (diff) | |
| download | vdr-plugin-osdteletext-1bc46ff520d87425c3a119a8e6ac998194e48d48.tar.gz vdr-plugin-osdteletext-1bc46ff520d87425c3a119a8e6ac998194e48d48.tar.bz2 | |
Made Storage injected into using classes instead of refering to a static
instance (References #177)
Patch provided by Andreas Brachold
| -rw-r--r-- | menu.c | 28 | ||||
| -rw-r--r-- | menu.h | 3 | ||||
| -rw-r--r-- | osdteletext.c | 32 | ||||
| -rw-r--r-- | txtrecv.c | 73 | ||||
| -rw-r--r-- | txtrecv.h | 18 |
5 files changed, 77 insertions, 77 deletions
@@ -43,7 +43,8 @@ int TeletextBrowser::currentChannelNumber=0; TeletextBrowser* TeletextBrowser::self=0; -TeletextBrowser::TeletextBrowser(cTxtStatus *txtSt) { +TeletextBrowser::TeletextBrowser(cTxtStatus *txtSt,Storage *s) { + storage = s; cursorPos=0; pageFound=true; selectingChannel=false; @@ -524,11 +525,10 @@ bool TeletextBrowser::CheckPage() { StorageHandle fd; - Storage *s=Storage::instance(); - if (!(fd=s->openForReading(PageID(channel, currentPage, currentSubPage), false)) ) + if (!(fd=storage->openForReading(PageID(channel, currentPage, currentSubPage), false)) ) return false; - s->close(fd); + storage->close(fd); return true; } @@ -574,22 +574,21 @@ bool TeletextBrowser::DecodePage() { unsigned char cache[40*24+12]; StorageHandle fd; // Take a look if there is a xxx-00 page - Storage *s=Storage::instance(); if (currentSubPage==0) { - if ( !(fd=s->openForReading(PageID(channel, currentPage,currentSubPage), false)) ) { + if ( !(fd=storage->openForReading(PageID(channel, currentPage,currentSubPage), false)) ) { // There is no subpage 0 so look if there is subpage 1 currentSubPage++; // Generate file string } else { // yes file exists - s->close(fd); + storage->close(fd); } } - if ( (fd=s->openForReading(PageID(channel, currentPage, currentSubPage), true)) ) + if ( (fd=storage->openForReading(PageID(channel, currentPage, currentSubPage), true)) ) { - s->read(cache,sizeof cache,fd); // Read full page data - s->close(fd); + storage->read(cache,sizeof cache,fd); // Read full page data + storage->close(fd); Display::HoldFlush(); Display::ClearMessage(); @@ -621,12 +620,11 @@ int TeletextBrowser::PageCheckSum() { CheckFirstSubPage(currentSubPage); - Storage *s=Storage::instance(); - if ((fd=s->openForReading(PageID(channel, currentPage, currentSubPage), false)) ) { + if ((fd=storage->openForReading(PageID(channel, currentPage, currentSubPage), false)) ) { uchar cache[960]; - s->read(cache, 12, fd); //skip - s->read(cache, sizeof(cache), fd); - s->close(fd); + storage->read(cache, 12, fd); //skip + storage->read(cache, sizeof(cache), fd); + storage->close(fd); memset(cache+12, 0, 8); //it seems that there the clock is transmitted, ignore changes for (uint i=0;i<sizeof(cache); i++) retSum+=cache[i]; @@ -24,7 +24,7 @@ extern int Stretch; class TeletextBrowser : public cOsdObject { public: - TeletextBrowser(cTxtStatus *txtSt); + TeletextBrowser(cTxtStatus *txtSt,Storage *s); ~TeletextBrowser(); void Show(void); static void ChannelSwitched(int ChannelNumber); @@ -67,6 +67,7 @@ protected: static tChannelID channel; static int currentChannelNumber; static TeletextBrowser* self; + Storage *storage; private: void ChangeBackground(); }; diff --git a/osdteletext.c b/osdteletext.c index ec6e65a..2f24611 100644 --- a/osdteletext.c +++ b/osdteletext.c @@ -35,7 +35,10 @@ private: cTxtStatus *txtStatus; bool startReceiver; bool storeTopText; + Storage *storage; + int maxStorage; void initTexts(); + Storage::StorageSystem storageSystem; public: cPluginTeletextosd(void); virtual ~cPluginTeletextosd(); @@ -104,6 +107,8 @@ cPluginTeletextosd::cPluginTeletextosd(void) // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT! txtStatus=0; startReceiver=true; + storage = NULL; + maxStorage=-1; } cPluginTeletextosd::~cPluginTeletextosd() @@ -111,7 +116,10 @@ cPluginTeletextosd::~cPluginTeletextosd() // Clean up after yourself! if (txtStatus) delete txtStatus; - Storage::instance()->cleanUp(); + if(storage) { + storage->cleanUp(); + delete storage; + } } const char *cPluginTeletextosd::CommandLineHelp(void) @@ -144,16 +152,15 @@ bool cPluginTeletextosd::ProcessArgs(int argc, char *argv[]) }; int c; - int maxStorage=-1; while ((c = getopt_long(argc, argv, "s:d:n:t", long_options, NULL)) != -1) { switch (c) { case 's': if (!optarg) break; if (strcasecmp(optarg, "legacy")==0) - Storage::setSystem(Storage::StorageSystemLegacy); + storageSystem = Storage::StorageSystemLegacy; else if (strcasecmp(optarg, "packed")==0) - Storage::setSystem(Storage::StorageSystemPacked); + storageSystem = Storage::StorageSystemPacked; break; case 'd': Storage::setRootDir(optarg); break; @@ -166,10 +173,6 @@ bool cPluginTeletextosd::ProcessArgs(int argc, char *argv[]) break; } } - //do this here because the option -s to change the storage system might be given - // after -n, and then -s would have no effect - if (maxStorage>=0) - Storage::instance()->setMaxStorage(maxStorage); return true; } @@ -178,10 +181,17 @@ bool cPluginTeletextosd::Start(void) // Start any background activities the plugin shall perform. //Clean any files which might be remaining from the last session, //perhaps due to a crash they have not been deleted. - Storage::instance()->init(); + storage = Storage::CreateInstance(storageSystem); + if(storage) { + if (maxStorage>=0) + storage->setMaxStorage(maxStorage); + storage->init(); + } else { + return false; + } initTexts(); if (startReceiver) - txtStatus=new cTxtStatus(storeTopText); + txtStatus=new cTxtStatus(storeTopText, storage); if (ttSetup.OSDheight<=100) ttSetup.OSDheight=Setup.OSDHeight; if (ttSetup.OSDwidth<=100) ttSetup.OSDwidth=Setup.OSDWidth; @@ -232,7 +242,7 @@ const char *cPluginTeletextosd::MainMenuEntry(void) cOsdObject *cPluginTeletextosd::MainMenuAction(void) { // Perform the action when selected from the main VDR menu. - return new TeletextBrowser(txtStatus); + return new TeletextBrowser(txtStatus,storage); } cMenuSetupPage *cPluginTeletextosd::SetupMenu(void) @@ -100,36 +100,24 @@ int Storage::cleanSubDir(const char *dir) { return bytesDeleted; } -Storage *Storage::s_self = 0; -Storage::StorageSystem Storage::system = Storage::StorageSystemPacked; +int Storage::storageOption = -1; Storage::Storage() { - s_self=this; byteCount=0; - storageOption=-1; failedFreeSpace=false; } Storage::~Storage() { } -void Storage::setSystem(StorageSystem s) { - system=s; -} - -Storage *Storage::instance() { - if (!s_self) { - switch (system) { - case StorageSystemLegacy: - s_self=new LegacyStorage(); - break; - case StorageSystemPacked: - default: - s_self=new PackedStorage(); - break; - } - } - return s_self; +Storage *Storage::CreateInstance(StorageSystem system) { + switch (system) { + case StorageSystemLegacy: + return new LegacyStorage(); + case StorageSystemPacked: + default: + return new PackedStorage(); + } } void Storage::setMaxStorage(int maxMB) { @@ -457,8 +445,8 @@ StorageHandle PackedStorage::openForReading(PageID page, bool countAsAccess) { -cTelePage::cTelePage(PageID t_page, uchar t_flags, uchar t_lang,int t_mag) - : mag(t_mag), flags(t_flags), lang(t_lang), page(t_page) +cTelePage::cTelePage(PageID t_page, uchar t_flags, uchar t_lang,int t_mag, Storage *s) + : mag(t_mag), flags(t_flags), lang(t_lang), page(t_page), storage(s) { memset(pagebuf,' ',26*40); } @@ -473,20 +461,19 @@ void cTelePage::SetLine(int line, uchar *myptr) void cTelePage::save() { - Storage *s=Storage::instance(); unsigned char buf; StorageHandle fd; - if ( (fd=s->openForWriting(page)) ) { - s->write("VTXV4",5,fd); - buf=0x01; s->write(&buf,1,fd); - buf=mag; s->write(&buf,1,fd); - buf=page.page; s->write(&buf,1,fd); - buf=flags; s->write(&buf,1,fd); - buf=lang; s->write(&buf,1,fd); - buf=0x00; s->write(&buf,1,fd); - buf=0x00; s->write(&buf,1,fd); - s->write(pagebuf,24*40,fd); - s->close(fd); + if ( (fd=storage->openForWriting(page)) ) { + storage->write("VTXV4",5,fd); + buf=0x01; storage->write(&buf,1,fd); + buf=mag; storage->write(&buf,1,fd); + buf=page.page; storage->write(&buf,1,fd); + buf=flags; storage->write(&buf,1,fd); + buf=lang; storage->write(&buf,1,fd); + buf=0x00; storage->write(&buf,1,fd); + buf=0x00; storage->write(&buf,1,fd); + storage->write(pagebuf,24*40,fd); + storage->close(fd); } } @@ -495,8 +482,8 @@ bool cTelePage::IsTopTextPage() return (page.page & 0xFF) <= 0x99 && (page.page & 0x0F) <= 0x9; } -cTxtStatus::cTxtStatus(bool storeTopText) - :storeTopText(storeTopText) +cTxtStatus::cTxtStatus(bool storeTopText, Storage* storage) + :storeTopText(storeTopText), storage(storage) { receiver = NULL; currentLiveChannel = tChannelID::InvalidID; @@ -536,7 +523,7 @@ void cTxtStatus::ChannelSwitch(const cDevice *Device, int ChannelNumber) int TPid = newLiveChannel->Tpid(); if (TPid) { - receiver = new cTxtReceiver(TPid, currentLiveChannel, storeTopText); + receiver = new cTxtReceiver(TPid, currentLiveChannel, storeTopText, storage); cDevice::ActualDevice()->AttachReceiver(receiver); } @@ -544,11 +531,12 @@ void cTxtStatus::ChannelSwitch(const cDevice *Device, int ChannelNumber) } -cTxtReceiver::cTxtReceiver(int TPid, tChannelID chan, bool storeTopText) +cTxtReceiver::cTxtReceiver(int TPid, tChannelID chan, bool storeTopText, Storage* storage) : cReceiver(chan, -1, TPid), cThread("osdteletext-receiver"), TxtPage(0), storeTopText(storeTopText), buffer((188+60)*75) { - Storage::instance()->prepareDirectory(ChannelID()); + storage->prepareDirectory(ChannelID()); + // 10 ms timeout on getting TS frames buffer.SetTimeouts(0, 10); } @@ -560,6 +548,9 @@ cTxtReceiver::~cTxtReceiver() Activate(false); buffer.Clear(); delete TxtPage; + if(storage) { + delete storage; + } } void cTxtReceiver::Stop() @@ -705,7 +696,7 @@ void cTxtReceiver::DecodeTXT(uchar* TXT_buf) pgno = mag8 * 256 + b1; subno = (b2 + b3 * 256) & 0x3f7f; // Sub Page Number - TxtPage = new cTelePage(PageID(ChannelID(), pgno, subno), flags, lang, mag); + TxtPage = new cTelePage(PageID(ChannelID(), pgno, subno), flags, lang, mag, storage); TxtPage->SetLine((int)line,(uchar *)ptr); break; } @@ -55,17 +55,16 @@ public: virtual ~Storage(); enum StorageSystem { StorageSystemLegacy, StorageSystemPacked }; //must be called before the first call to instance() - static void setSystem(StorageSystem system); void setMaxStorage(int maxMB=-1); - static Storage *instance(); + static Storage *CreateInstance(StorageSystem system); //must be called before operation starts. Set all options (RootDir, maxStorage) before. void init(); virtual void cleanUp() = 0; virtual void getFilename(char *buffer, int bufLength, PageID page); - void prepareDirectory(tChannelID chan); + virtual void prepareDirectory(tChannelID chan); virtual StorageHandle openForWriting(PageID page) = 0; virtual StorageHandle openForReading(PageID page, bool countAsAccess) = 0; @@ -79,15 +78,13 @@ protected: int cleanSubDir(const char *dir); int doCleanUp(); virtual int actualFileSize(int netFileSize) { return netFileSize; } - static Storage *s_self; void freeSpace(); bool exists(const char* file); long byteCount; cString currentDir; private: - static StorageSystem system; - int storageOption; + static int storageOption; bool failedFreeSpace; }; @@ -143,8 +140,9 @@ class cTelePage { unsigned char lang; PageID page; unsigned char pagebuf[27*40]; + Storage* storage; public: - cTelePage(PageID page, uchar flags, uchar lang, int mag); + cTelePage(PageID page, uchar flags, uchar lang, int mag, Storage *s); ~cTelePage(); void SetLine(int, uchar*); void save(); @@ -166,13 +164,14 @@ private: cTelePage *TxtPage; void SaveAndDeleteTxtPage(); bool storeTopText; + Storage *storage; protected: virtual void Activate(bool On); virtual void Receive(uchar *Data, int Length); virtual void Action(); cRingTxtFrames buffer; public: - cTxtReceiver(int TPid, tChannelID chan, bool storeTopText); + cTxtReceiver(int TPid, tChannelID chan, bool storeTopText, Storage* storage); virtual ~cTxtReceiver(); virtual void Stop(); }; @@ -182,10 +181,11 @@ private: cTxtReceiver *receiver; tChannelID currentLiveChannel; bool storeTopText; + Storage* storage; protected: virtual void ChannelSwitch(const cDevice *Device, int ChannelNumber); public: - cTxtStatus(bool storeTopText); + cTxtStatus(bool storeTopText, Storage* storage); ~cTxtStatus(); }; |
