From e2299d7e420bf07da8a2bf6d20f1d7857c23e379 Mon Sep 17 00:00:00 2001 From: Markus Ehrnsperger <> Date: Mon, 4 Dec 2023 20:23:59 +0100 Subject: [PATCH] remove tChannelID args --- epg_events.cpp | 155 +++++++++++++++--------------------- epg_events.h | 114 +++++++++++--------------- epgsearch.cpp | 10 +-- ffmpeg.cpp | 1 - pages/channels_widget.ecpp | 33 ++------ pages/edit_searchtimer.ecpp | 25 ++---- pages/edit_timer.ecpp | 22 +---- pages/multischedule.ecpp | 8 -- pages/pageelems.ecpp | 6 -- pages/playlist.ecpp | 14 +--- pages/schedule.ecpp | 41 +--------- pages/searchepg.ecpp | 10 ++- pages/stream.ecpp | 10 +-- pages/switch_channel.ecpp | 3 +- pages/whats_on.ecpp | 16 ---- recman.cpp | 34 ++++---- recman.h | 4 +- stringhelpers.h | 70 ++++++++++++++-- timers.cpp | 7 +- tntconfig.cpp | 1 - tools.h | 9 +-- 21 files changed, 230 insertions(+), 363 deletions(-) diff --git a/epg_events.cpp b/epg_events.cpp index 59fdd1b2..5f0ea386 100644 --- a/epg_events.cpp +++ b/epg_events.cpp @@ -1,4 +1,3 @@ - #include "epg_events.h" #include "tools.h" @@ -27,19 +26,16 @@ namespace vdrlive * ------------------------------------------------------------------------- */ - EpgInfo::EpgInfo(const std::string& id, const std::string& caption) : + EpgInfo::EpgInfo(cSv id, cSv caption): m_eventId(id), m_caption(caption) - { - } + { } - EpgInfo::~EpgInfo() - { - } + EpgInfo::~EpgInfo() { } - const std::string EpgInfo::ChannelName() const + cSv EpgInfo::ChannelName() const { const cChannel* channel = Channel(); - return channel ? channel->Name() : ""; + return channel ? channel->Name() : cSv(); } const std::string EpgInfo::CurrentTime(const char* format) const @@ -75,15 +71,12 @@ namespace vdrlive * ------------------------------------------------------------------------- */ - EpgEvent::EpgEvent(const std::string& id, const cEvent* event, const char* channelName) : + EpgEvent::EpgEvent(cSv id, const cEvent* event, const char* channelName) : EpgInfo(id, channelName), m_event(event) - { - } + { } - EpgEvent::~EpgEvent() - { - } + EpgEvent::~EpgEvent() { } /* * ------------------------------------------------------------------------- @@ -91,29 +84,26 @@ namespace vdrlive * ------------------------------------------------------------------------- */ - EpgString::EpgString(const std::string& id, const std::string& caption, const std::string& info) : + EpgString::EpgString(cSv id, cSv caption, cSv info) : EpgInfo(id, caption), m_info(info) - { - } + { } - EpgString::~EpgString() - { - } + EpgString::~EpgString() { } - const std::string EpgString::Title() const + cSv EpgString::Title() const { return m_info; } - const std::string EpgString::ShortDescr() const + cSv EpgString::ShortDescr() const { - return ""; + return cSv(); } - const std::string EpgString::LongDescr() const + cSv EpgString::LongDescr() const { - return ""; + return cSv(); } time_t EpgString::GetStartTime() const @@ -132,61 +122,60 @@ namespace vdrlive * ------------------------------------------------------------------------- */ - EpgRecording::EpgRecording(const std::string& recid, const cRecording* recording, const char* caption) : - EpgInfo(recid, (caption != 0) ? caption : ""), + EpgRecording::EpgRecording(cSv recid, const cRecording* recording, const char* caption) : + EpgInfo(recid, caption), m_recording(recording), m_ownCaption(caption != 0), m_checkedArchived(false), m_archived() - { - } + { } EpgRecording::~EpgRecording() { m_recording = 0; } - const std::string EpgRecording::Caption() const + cSv EpgRecording::Caption() const { if (m_ownCaption) { return EpgInfo::Caption(); } if (!m_recording) { - return ""; + return cSv(); } return Name(); } - const std::string EpgRecording::Title() const + cSv EpgRecording::Title() const { if (!m_recording) { - return ""; + return cSv(); } const cRecordingInfo* info = m_recording->Info(); return (info && info->Title()) ? info->Title() : Name(); } - const std::string EpgRecording::ShortDescr() const + cSv EpgRecording::ShortDescr() const { const cRecordingInfo* info = m_recording ? m_recording->Info() : 0; - return (info && info->ShortText()) ? info->ShortText() : ""; + return (info && info->ShortText()) ? info->ShortText() : cSv(); } - const std::string EpgRecording::LongDescr() const + cSv EpgRecording::LongDescr() const { const cRecordingInfo* info = m_recording ? m_recording->Info() : 0; - return (info && info->Description()) ? info->Description() : ""; + return (info && info->Description()) ? info->Description() : cSv(); } - const std::string EpgRecording::ChannelName() const + cSv EpgRecording::ChannelName() const { const cRecordingInfo* info = m_recording ? m_recording->Info() : 0; - return info && info->ChannelName() ? info->ChannelName(): ""; + return info && info->ChannelName() ? info->ChannelName(): cSv(); } - const std::string EpgRecording::Archived() const + cSv EpgRecording::Archived() const { if (!m_checkedArchived && m_recording) { m_archived = RecordingsManager::GetArchiveDescr(m_recording); @@ -195,7 +184,7 @@ namespace vdrlive return m_archived; } - const std::string EpgRecording::FileName() const + cSv EpgRecording::FileName() const { return m_recording->FileName(); } @@ -246,9 +235,9 @@ namespace vdrlive return -1; } - const std::string EpgRecording::Name() const + cSv EpgRecording::Name() const { - std::string name(m_recording->Name()); + cSv name(m_recording->Name()); size_t index = name.find_last_of('~'); if (index != std::string::npos) { name = name.substr(index+1); @@ -262,15 +251,12 @@ namespace vdrlive * ------------------------------------------------------------------------- */ - EmptyEvent::EmptyEvent(std::string const &id, tChannelID const &channelID, const char* channelName) : + EmptyEvent::EmptyEvent(cSv id, tChannelID const &channelID, const char* channelName) : EpgInfo(id, channelName), m_channelID(channelID) - { - } + { } - EmptyEvent::~EmptyEvent() - { - } + EmptyEvent::~EmptyEvent() { } /* * ------------------------------------------------------------------------- @@ -280,90 +266,80 @@ namespace vdrlive namespace EpgEvents { std::string EncodeDomId(tChannelID const &chanId, tEventID const &eId) { - std::string channelId(chanId.ToString()); std::string eventId("event_"); - channelId = vdrlive::EncodeDomId(channelId, ".-", "pm"); - - eventId += channelId; + eventId += vdrlive::EncodeDomId(cToSvChannel(chanId), ".-", "pm"); eventId += '_'; eventId += cSv(cToSvInt(eId)); return eventId; } - void DecodeDomId(std::string const &epgid, tChannelID& channelId, tEventID& eventId) + void DecodeDomId(cSv epgid, tChannelID& channelId, tEventID& eventId) { - std::string const eventStr("event_"); + cSv eventStr("event_"); size_t delimPos = epgid.find_last_of('_'); - std::string cIdStr = epgid.substr(eventStr.length(), delimPos - eventStr.length()); - - cIdStr = vdrlive::DecodeDomId(cIdStr, "mp", "-."); + cSv cIdStr_enc = epgid.substr(eventStr.length(), delimPos - eventStr.length()); - std::string const eIdStr = epgid.substr(delimPos+1); + std::string cIdStr = vdrlive::DecodeDomId(cIdStr_enc, "mp", "-."); + cSv eIdStr = epgid.substr(delimPos+1); channelId = tChannelID::FromString(cIdStr.c_str()); eventId = parse_int(eIdStr); } - EpgInfoPtr CreateEpgInfo(std::string const &epgid, cSchedules const *schedules) + EpgInfoPtr CreateEpgInfo(cSv epgid, cSchedules const *schedules) { - std::string const errorInfo(tr("Epg error")); - tEventID eventId = tEventID(); tChannelID channelId = tChannelID(); DecodeDomId(epgid, channelId, eventId); -#if VDRVERSNUM >= 20301 LOCK_CHANNELS_READ; cChannel const *channel = Channels->GetByChannelID(channelId); -#else - cChannel const *channel = Channels.GetByChannelID(channelId); -#endif if (!channel) { - return CreateEpgInfo(epgid, errorInfo, tr("Wrong channel id")); + return CreateEpgInfo(epgid, tr("Epg error"), tr("Wrong channel id")); } cSchedule const *schedule = schedules->GetSchedule(channel); if (!schedule) { - return CreateEpgInfo(epgid, errorInfo, tr("Channel has no schedule")); + return CreateEpgInfo(epgid, tr("Epg error"), tr("Channel has no schedule")); } cEvent const *event = schedule->GetEvent(eventId); if (!event) { - return CreateEpgInfo(epgid, errorInfo, tr("Wrong event id")); + return CreateEpgInfo(epgid, tr("Epg error"), tr("Wrong event id")); } - return CreateEpgInfo(channel, event, epgid.c_str()); + return CreateEpgInfo(channel, event, epgid); } - EpgInfoPtr CreateEpgInfo(cChannel const *chan, cEvent const *event, char const *idOverride) + EpgInfoPtr CreateEpgInfo(cChannel const *chan, cEvent const *event, cSv idOverride) { assert(chan); if (event) { - std::string domId(idOverride ? idOverride : EncodeDomId(chan->GetChannelID(), event->EventID())); - return EpgInfoPtr(new EpgEvent(domId, event, chan->Name())); + if (idOverride.empty()) return std::make_shared(EncodeDomId(chan->GetChannelID(), event->EventID()), event, chan->Name()); + return std::make_shared(idOverride, event, chan->Name()); } if (LiveSetup().GetShowChannelsWithoutEPG()) { - std::string domId(idOverride ? idOverride : EncodeDomId(chan->GetChannelID(), 0)); - return EpgInfoPtr(new EmptyEvent(domId, chan->GetChannelID(), chan->Name())); + std::string domId(!idOverride.empty() ? idOverride : EncodeDomId(chan->GetChannelID(), 0)); + return std::make_shared(domId, chan->GetChannelID(), chan->Name()); } return EpgInfoPtr(); } - EpgInfoPtr CreateEpgInfo(std::string const &recid, cRecording const *recording, char const *caption) + EpgInfoPtr CreateEpgInfo(cSv recid, cRecording const *recording, char const *caption) { - return EpgInfoPtr(new EpgRecording(recid, recording, caption)); + return std::make_shared(recid, recording, caption); } - EpgInfoPtr CreateEpgInfo(std::string const &id, std::string const &caption, std::string const &info) + EpgInfoPtr CreateEpgInfo(cSv id, cSv caption, cSv info) { - return EpgInfoPtr(new EpgString(id, caption, info)); + return std::make_shared(id, caption, info); } - bool ScanForEpgImages(std::string const & imageId, std::string const & wildcard, std::list & images) + bool ScanForEpgImages(cSv imageId, cSv wildcard, std::list & images) { bool found = false; - const std::string filemask(LiveSetup().GetEpgImageDir() + "/" + imageId + wildcard); + const std::string filemask = concat(LiveSetup().GetEpgImageDir(), "/", imageId, wildcard); glob_t globbuf; globbuf.gl_offs = 0; if (!LiveSetup().GetEpgImageDir().empty() && glob(filemask.c_str(), GLOB_DOOFFS, NULL, &globbuf) == 0) { @@ -378,20 +354,19 @@ namespace vdrlive return found; } - bool ScanForRecImages(std::string const & imageId, std::string const & recfolder , std::list & images) + bool ScanForRecImages(cSv imageId, cSv recfolder , std::list & images) { bool found = false; const std::string filetypes[] = {"png", "jpg", "PNG", "JPG"}; int size = sizeof(filetypes)/sizeof(filetypes[0]); if (recfolder.empty()) { - // dsyslog( "live: ScanForRecImages: recFolder empty for %s", imageId.c_str()); return found; } for (int j = 0; j < size; j++) { - const std::string filemask(recfolder + "/*." + filetypes[j]); + const std::string filemask = concat(recfolder, "/*.", filetypes[j]); glob_t globbuf; globbuf.gl_offs = 0; if (glob(filemask.c_str(), GLOB_DOOFFS, NULL, &globbuf) == 0) { @@ -404,7 +379,7 @@ namespace vdrlive // create a temporary symlink of the image in /tmp const std::string imagename(imagefile.substr(delimPos+1)); - const std::string tmpfile("/tmp/" + imageId + "_" + imagename); + const std::string tmpfile = concat("/tmp/", imageId, "_", imagename); char cmdBuff[500]; sprintf(cmdBuff,"ln -s \"%s\" \"%s\"",imagefile.c_str(),tmpfile.c_str()); @@ -436,10 +411,10 @@ namespace vdrlive return false; } - std::list EpgImages(std::string const &epgid) + std::list EpgImages(cSv epgid) { size_t delimPos = epgid.find_last_of('_'); - std::string imageId = epgid.substr(delimPos+1); + cSv imageId = epgid.substr(delimPos+1); std::list images; @@ -478,10 +453,10 @@ namespace vdrlive return images; } - std::list RecImages(std::string const &epgid, std::string const &recfolder) + std::list RecImages(cSv epgid, cSv recfolder) { size_t delimPos = epgid.find_last_of('_'); - std::string imageId = epgid.substr(delimPos+1); + cSv imageId = epgid.substr(delimPos+1); std::list images; // Scan for all images in recording directory diff --git a/epg_events.h b/epg_events.h index 8941fc18..04065661 100644 --- a/epg_events.h +++ b/epg_events.h @@ -29,43 +29,43 @@ namespace vdrlive namespace EpgEvents { std::string EncodeDomId(tChannelID const &chanId, tEventID const &eventId); - void DecodeDomId(std::string const &epgid, tChannelID &chanId, tEventID &eventId); + void DecodeDomId(cSv epgid, tChannelID &chanId, tEventID &eventId); /** * Allocate and initalize an epgEvent instance with the * passed channel and event information. * Never call this function with a NULL chan pointer */ - EpgInfoPtr CreateEpgInfo(cChannel const *chan, cEvent const *event, char const *idOverride = 0); + EpgInfoPtr CreateEpgInfo(cChannel const *chan, cEvent const *event, cSv idOverride = cSv()); /** * This is the inverse creator for epgInfos to the creator above. */ - EpgInfoPtr CreateEpgInfo(std::string const &epgid, cSchedules const *schedules); + EpgInfoPtr CreateEpgInfo(cSv epgid, cSchedules const *schedules); /** * Allocate and initalize an epgEvent instance with the * passed recording information. */ - EpgInfoPtr CreateEpgInfo(std::string const &recid, cRecording const *recording, char const *caption = 0); + EpgInfoPtr CreateEpgInfo(cSv recid, cRecording const *recording, char const *caption = 0); /** * Allocate and initalize an epgEvent instance with the * passed string informations */ - EpgInfoPtr CreateEpgInfo(std::string const &id, std::string const &caption, std::string const &info); + EpgInfoPtr CreateEpgInfo(cSv id, cSv caption, cSv info); /** * Return a list of EpgImage paths for a given epgid. */ - bool PosterTvscraper(cTvMedia &media, const cEvent *event, const cRecording *recording); - std::list EpgImages(std::string const &epgid); + bool PosterTvscraper(cTvMedia &media, const cEvent *event, const cRecording *recording); + std::list EpgImages(cSv epgid); /** * Return a list of RecImages in the given folder. */ - std::list RecImages(std::string const &epgid, std::string const &recfolder); + std::list RecImages(cSv epgid, cSv recfolder); /** * Calculate the duration. A duration can be zero or @@ -88,30 +88,27 @@ namespace vdrlive class EpgInfo { - protected: - EpgInfo(std::string const &id, - std::string const &caption); - public: + EpgInfo(cSv id, cSv caption); virtual ~EpgInfo(); - virtual std::string const Id() const { return m_eventId; } + virtual cSv Id() const { return m_eventId; } - virtual std::string const Caption() const { return m_caption; } + virtual cSv Caption() const { return m_caption; } - virtual std::string const Title() const = 0; + virtual cSv Title() const = 0; - virtual std::string const ShortDescr() const = 0; + virtual cSv ShortDescr() const = 0; - virtual std::string const LongDescr() const = 0; + virtual cSv LongDescr() const = 0; virtual cChannel const * Channel() const { return 0; } - virtual std::string const ChannelName() const; + virtual cSv ChannelName() const; - virtual std::string const Archived() const { return ""; } + virtual cSv Archived() const { return cSv(); } - virtual std::string const FileName() const { return ""; } + virtual cSv FileName() const { return cSv(); } virtual std::string const StartTime(const char* format) const; @@ -138,27 +135,23 @@ namespace vdrlive class EpgString : public EpgInfo { - friend EpgInfoPtr EpgEvents::CreateEpgInfo(std::string const &, std::string const &, std::string const &); - - protected: - EpgString(std::string const &id, - std::string const &caption, - std::string const &info); + friend EpgInfoPtr EpgEvents::CreateEpgInfo(cSv, cSv, cSv); public: + EpgString(cSv id, cSv caption, cSv info); virtual ~EpgString(); - virtual std::string const Title() const; + virtual cSv Title() const; - virtual std::string const ShortDescr() const; + virtual cSv ShortDescr() const; - virtual std::string const LongDescr() const; + virtual cSv LongDescr() const; virtual time_t GetStartTime() const; virtual time_t GetEndTime() const; - virtual std::string const FileName() const { return ""; } + virtual cSv FileName() const { return cSv(); } private: const std::string m_info; @@ -168,33 +161,25 @@ namespace vdrlive class EpgEvent : public EpgInfo { - friend EpgInfoPtr EpgEvents::CreateEpgInfo(cChannel const *, cEvent const *, char const *); - - protected: - EpgEvent(std::string const &id, - cEvent const *event, - char const *channelName); + friend EpgInfoPtr EpgEvents::CreateEpgInfo(cChannel const *, cEvent const *, cSv); public: + EpgEvent(cSv id, cEvent const *event, char const *channelName); virtual ~EpgEvent(); - virtual std::string const Title() const { return std::string(m_event->Title() ? m_event->Title() : ""); } + virtual cSv Title() const { return m_event->Title(); } - virtual std::string const ShortDescr() const { return std::string(m_event->ShortText() ? m_event->ShortText() : ""); } + virtual cSv ShortDescr() const { return m_event->ShortText(); } - virtual std::string const LongDescr() const { return std::string(m_event->Description() ? m_event->Description() : ""); } + virtual cSv LongDescr() const { return m_event->Description(); } virtual time_t GetStartTime() const { return m_event->StartTime(); } virtual time_t GetEndTime() const { return m_event->EndTime(); } -#if VDRVERSNUM >= 20301 virtual cChannel const * Channel() const { LOCK_CHANNELS_READ; return Channels->GetByChannelID(m_event->ChannelID());} -#else - virtual cChannel const * Channel() const { return Channels.GetByChannelID(m_event->ChannelID());} -#endif - virtual std::string const FileName() const { return ""; } + virtual cSv FileName() const { return cSv(); } virtual cEvent const *Event() const { return m_event; } private: @@ -205,31 +190,25 @@ namespace vdrlive class EmptyEvent : public EpgInfo { - friend EpgInfoPtr EpgEvents::CreateEpgInfo(cChannel const *, cEvent const *, char const *); - - protected: - EmptyEvent(std::string const &id, tChannelID const &channelID, const char* channelName); + friend EpgInfoPtr EpgEvents::CreateEpgInfo(cChannel const *, cEvent const *, cSv); public: + EmptyEvent(cSv id, tChannelID const &channelID, const char* channelName); virtual ~EmptyEvent(); - virtual std::string const Title() const { return tr("No EPG information available"); } + virtual cSv Title() const { return tr("No EPG information available"); } - virtual std::string const ShortDescr() const { return ""; } + virtual cSv ShortDescr() const { return cSv(); } - virtual std::string const LongDescr() const { return ""; } + virtual cSv LongDescr() const { return cSv(); } virtual time_t GetStartTime() const { return 0; } virtual time_t GetEndTime() const { return 0; } -#if VDRVERSNUM >= 20301 virtual cChannel const * Channel() const { LOCK_CHANNELS_READ; return Channels->GetByChannelID(m_channelID);} -#else - virtual cChannel const * Channel() const { return Channels.GetByChannelID(m_channelID);} -#endif - virtual std::string const FileName() const { return ""; } + virtual cSv FileName() const { return cSv(); } private: tChannelID m_channelID; @@ -239,31 +218,28 @@ namespace vdrlive class EpgRecording : public EpgInfo { - friend EpgInfoPtr EpgEvents::CreateEpgInfo(std::string const &, cRecording const *, char const *); + friend EpgInfoPtr EpgEvents::CreateEpgInfo(cSv, cRecording const *, const char *); protected: - EpgRecording(std::string const &recid, - cRecording const *recording, - char const *caption); - - const std::string Name() const; + cSv Name() const; public: + EpgRecording(cSv recid, cRecording const *recording, char const *caption); virtual ~EpgRecording(); - virtual std::string const Caption() const; + virtual cSv Caption() const; - virtual std::string const Title() const; + virtual cSv Title() const; - virtual std::string const ShortDescr() const; + virtual cSv ShortDescr() const; - virtual std::string const LongDescr() const; + virtual cSv LongDescr() const; - virtual std::string const ChannelName() const; + virtual cSv ChannelName() const; - virtual std::string const Archived() const; + virtual cSv Archived() const; - virtual std::string const FileName() const; + virtual cSv FileName() const; virtual time_t GetStartTime() const; diff --git a/epgsearch.cpp b/epgsearch.cpp index 13fa57d1..844b92b0 100644 --- a/epgsearch.cpp +++ b/epgsearch.cpp @@ -285,7 +285,7 @@ void SearchTimer::ParseChannel( std::string const& data ) void SearchTimer::ParseChannelIDs( std::string const& data ) { std::vector parts = StringSplit( data, '|' ); - m_channelMin = lexical_cast( parts[ 0 ] ); + m_channelMin = tChannelID::FromString( parts[ 0 ].c_str() ); LOCK_CHANNELS_READ; cChannel const* channel = Channels->GetByChannelID( m_channelMin ); @@ -295,13 +295,9 @@ void SearchTimer::ParseChannelIDs( std::string const& data ) if ( parts.size() < 2 ) return; - m_channelMax = lexical_cast( parts[ 1 ] ); + m_channelMax = tChannelID::FromString( parts[ 1 ].c_str() ); -#if VDRVERSNUM >= 20301 channel = Channels->GetByChannelID( m_channelMax ); -#else - channel = Channels.GetByChannelID( m_channelMax ); -#endif if ( channel != 0 ) m_channels += std::string( " - " ) + channel->Name(); } @@ -553,7 +549,7 @@ SearchResult::SearchResult( std::string const& data ) case 4: m_description = StringReplace( *part, "|", ":" ); break; case 5: m_starttime = parse_int( *part ); break; case 6: m_stoptime = parse_int( *part ); break; - case 7: m_channel = lexical_cast( *part ); break; + case 7: m_channel = tChannelID::FromString( part->c_str() ); break; case 8: m_timerstart = parse_int( *part ); break; case 9: m_timerstop = parse_int( *part ); break; case 10: m_file = *part; break; diff --git a/ffmpeg.cpp b/ffmpeg.cpp index 7971e2b4..b6c6b94f 100644 --- a/ffmpeg.cpp +++ b/ffmpeg.cpp @@ -1,4 +1,3 @@ - #include "ffmpeg.h" #include "setup.h" diff --git a/pages/channels_widget.ecpp b/pages/channels_widget.ecpp index 6161fc59..1d36c1cf 100644 --- a/pages/channels_widget.ecpp +++ b/pages/channels_widget.ecpp @@ -1,13 +1,8 @@ <%pre> - #include #include #include -#if VDRVERSNUM < 20300 -#include // ReadLock -#endif - using namespace vdrlive; @@ -20,28 +15,16 @@ using namespace vdrlive; <%session scope="global"> bool logged_in(false); -<{ -if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); -}> +% if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); +> -%#if VDRVERSNUM >= 20301 -% for ( cChannel *listChannel = (cChannel *)Channels->First(); listChannel; listChannel = (cChannel *)Channels->Next( listChannel ) ) { -%#else -% for ( cChannel *listChannel = Channels.First(); listChannel; listChannel = Channels.Next( listChannel ) ) { -%#endif -% if ( listChannel->GroupSep() || *listChannel->Name() == '\0' ) -% continue; -% -% std::string listChannelId = *listChannel->GetChannelID().ToString(); - + % } diff --git a/pages/edit_searchtimer.ecpp b/pages/edit_searchtimer.ecpp index 6a662964..17310499 100644 --- a/pages/edit_searchtimer.ecpp +++ b/pages/edit_searchtimer.ecpp @@ -24,10 +24,8 @@ using namespace vdrlive; bool usedescr = false; int usechannel = SearchTimer::NoChannel; - tChannelID channelfrom; // used with Tntnet20 - std::string channelfrom_string = ""; // used with Tntnet30 - tChannelID channelto; // used with Tntnet20 - std::string channelto_string = ""; // used with Tntnet30 + std::string channelfrom_string = ""; + std::string channelto_string = ""; std::string changrpsel = ""; bool usetime = false; @@ -105,10 +103,8 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); bool testmode = !test.empty(); editsearchtimer = NULL; -#if TNTVERSION >= 30000 - channelfrom = channelfrom.FromString(channelfrom_string.c_str()); // Tntnet30: get struct channel from parameter string - channelto = channelto.FromString(channelto_string.c_str()); // Tntnet30: get struct channel from parameter string -#endif + tChannelID channelfrom = tChannelID::FromString(channelfrom_string.c_str()); + tChannelID channelto = tChannelID::FromString(channelto_string.c_str()); if ( request.getMethod() == "POST") { SearchTimer searchtimer; @@ -611,20 +607,11 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); -<%cpp> -#if TNTVERSION >= 30000 - std::string namefrom = "channelfrom_string"; // Tntnet30 does not work with parameter type tChannelID - std::string nameto = "channelto_string"; // Tntnet30 does not work with parameter type tChannelID -#else - std::string namefrom = "channelfrom"; - std::string nameto = "channelto"; -#endif - - + - +
<$ tr("from channel" ) $>:
<& channels_widget name=(namefrom) channelid=(true) selected=(channelfrom) &><& channels_widget name=("channelfrom_string") channelid=(true) selected=(channelfrom) &>
<$ tr("to channel" ) $>:
<& channels_widget name=(nameto) channelid=(true) selected=(channelto) &><& channels_widget name=("channelto_string") channelid=(true) selected=(channelto)&>
diff --git a/pages/edit_timer.ecpp b/pages/edit_timer.ecpp index 21e622bb..c00c1526 100644 --- a/pages/edit_timer.ecpp +++ b/pages/edit_timer.ecpp @@ -21,8 +21,7 @@ using namespace vdrlive; std::string epgid; std::string async; // form parameters - tChannelID channel; // used with Tntnet20 - std::string channel_string = ""; // used with Tntnet30 + std::string channel_string = ""; int active = 1; std::string title = ""; std::string remoteServerName = ""; @@ -52,9 +51,7 @@ const cTimer* timer; <%include>page_init.eh <%cpp> -#if TNTVERSION >= 30000 - channel = channel.FromString(channel_string.c_str()); // Tntnet30: get struct channel from parameter string -#endif + tChannelID channel = tChannelID::FromString(channel_string.c_str()); if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); if (!cUser::CurrentUserHasRightTo(UR_EDITTIMERS)) @@ -127,16 +124,10 @@ const cTimer* timer; EpgEvents::DecodeDomId(epgid, channelid, eventid); if ( channelid.Valid() && eventid != 0 ) { cSchedule const* schedule; -#if VDRVERSNUM >= 20301 { LOCK_SCHEDULES_READ; schedule = Schedules->GetSchedule( channelid ); } -#else - cSchedulesLock schedLock; - cSchedules const* schedules = cSchedules::Schedules( schedLock ); - schedule = schedules->GetSchedule( channelid ); -#endif const cEvent *event = schedule->GetEvent( eventid ); if (event) eventTimer.reset( new cTimer( event ) ); else { @@ -235,14 +226,7 @@ const cTimer* timer;
<$ trVDR("Channel") $>:
-<%cpp> -#if TNTVERSION >= 30000 - std::string name = "channel_string"; // Tntnet30 does not work with parameter type tChannelID -#else - std::string name = "channel"; -#endif - -
<& channels_widget name=(name) channelid=(true) selected=(channel) &>
+
<& channels_widget name=("channel_string") channelid=(true) selected=(channel) &>
diff --git a/pages/multischedule.ecpp b/pages/multischedule.ecpp index 6a97f23b..858c8dcf 100644 --- a/pages/multischedule.ecpp +++ b/pages/multischedule.ecpp @@ -350,14 +350,10 @@ std::vector times_start; int chan = channel_groups_numbers[ channel ][ j ]; cChannel* Channel; -#if VDRVERSNUM >= 20301 { LOCK_CHANNELS_READ; Channel = (cChannel *)Channels->GetByNumber( chan ); } -#else - Channel = Channels.GetByNumber( chan ); -#endif if ( ! Channel ) continue; if ( Channel->GroupSep() || !Channel->Name() || !*Channel->Name() ) @@ -366,14 +362,10 @@ std::vector times_start; channel_IDs[ j ] = Channel->GetChannelID(); cSchedule const* Schedule; -#if VDRVERSNUM >= 20301 { LOCK_SCHEDULES_READ; Schedule = Schedules->GetSchedule( Channel ); } -#else - Schedule = schedules->GetSchedule( Channel ); -#endif if ( ! Schedule ) { // insert dummy event for the entire channel if no EPG data diff --git a/pages/pageelems.ecpp b/pages/pageelems.ecpp index d675be66..974ad408 100644 --- a/pages/pageelems.ecpp +++ b/pages/pageelems.ecpp @@ -379,15 +379,9 @@ if (LiveSetup().GetUseStreamdev() && LiveFeatures(). <%cpp> if (LiveSetup().GetUseStreamdev() && LiveFeatures().Loaded()) { -#if TNTVERSION >= 30000 " alt="" <& tooltip.hint text=(tr("Stream this channel into media player.")) &> /> <%cpp> -#else - -" alt="" <& tooltip.hint text=(tr("Stream this channel into media player.")) &> /> -<%cpp> -#endif } diff --git a/pages/playlist.ecpp b/pages/playlist.ecpp index d617bb37..63faaf5b 100644 --- a/pages/playlist.ecpp +++ b/pages/playlist.ecpp @@ -8,7 +8,6 @@ using namespace vdrlive; <%args> - tChannelID channel; std::string channel_str; std::string recid; @@ -20,9 +19,7 @@ using namespace vdrlive; <%include>page_init.eh <%cpp> -#if TNTVERSION >= 30000 - channel = channel.FromString(channel_str.c_str()); // Tntnet30: get struct channel from parameter string -#endif + tChannelID channel = tChannelID::FromString(channel_str.c_str()); if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); if (!cUser::CurrentUserHasRightTo(UR_STARTREPLAY)) @@ -31,17 +28,8 @@ using namespace vdrlive; // the availabilty of Channel signals that we will do live tv streaming. Channel = 0; if (recid.empty()) { -#if VDRVERSNUM >= 20301 LOCK_CHANNELS_READ; Channel = (cChannel *)Channels->GetByChannelID(channel); -#else - ReadLock channelsLock(Channels); - - if (!channelsLock) { - throw HtmlError(tr("Couldn't aquire access to channels, please try again later.")); - } - Channel = Channels.GetByChannelID(channel); -#endif if (Channel == 0) { throw HtmlError( tr("Couldn't find channel or no channels available. Maybe you mistyped your request?") ); } diff --git a/pages/schedule.ecpp b/pages/schedule.ecpp index 81301303..540b90aa 100644 --- a/pages/schedule.ecpp +++ b/pages/schedule.ecpp @@ -39,18 +39,7 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); bool display_pictures = !(LiveSetup().GetTvscraperImageDir().empty()); -#if VDRVERSNUM < 20301 - cSchedulesLock schedulesLock; - cSchedules const* schedules = cSchedules::Schedules( schedulesLock ); - - ReadLock channelsLock( Channels ); - if ( !channelsLock ) - throw HtmlError( tr("Couldn't aquire access to channels, please try again later.") ); -#endif - - // cChannel* Channel; (see %request above) { -#if VDRVERSNUM >= 20301 LOCK_CHANNELS_READ; if ( channel > 0 ) Channel = (cChannel *)Channels->GetByNumber( channel ); @@ -64,31 +53,13 @@ bool display_pictures = !(LiveSetup().GetTvscraperImageDir().empty()); prev = cString::sprintf("href=\"schedule.html?channel=%i\"", Channel->Number() - 1); if (Channel->Number() < Channels->MaxNumber()) next = cString::sprintf("href=\"schedule.html?channel=%i\"", Channel->Number() + 1); -#else - if ( channel > 0 ) - Channel = Channels.GetByNumber( channel ); - else if (cDevice::CurrentChannel()) - Channel = Channels.GetByNumber(cDevice::CurrentChannel()); - else - Channel = Channels.Get( Channels.GetNextNormal( -1 ) ); - if ( Channel == 0 ) - throw HtmlError( tr("Couldn't find channel or no channels available. Maybe you mistyped your request?") ); - if (Channel->Number() > 1) - prev = cString::sprintf("href=\"schedule.html?channel=%i\"", Channel->Number() - 1); - if (Channel->Number() < Channels.MaxNumber()) - next = cString::sprintf("href=\"schedule.html?channel=%i\"", Channel->Number() + 1); -#endif } cSchedule const* Schedule; -#if VDRVERSNUM >= 20301 { LOCK_SCHEDULES_READ; Schedule = Schedules->GetSchedule( (const cChannel *)Channel ); } -#else - Schedule = schedules->GetSchedule( Channel ); -#endif <& pageelems.doc_type &> @@ -142,11 +113,7 @@ bool display_pictures = !(LiveSetup().GetTvscraperImageDir().empty()); RecordingsItemRecPtr recItem; bool recItemFound; cLargeString epg_item("epg_item", 1000); -#if VDRVERSNUM >= 20301 for (const cEvent *Event = (cEvent *)Schedule->Events()->First(); Event; Event = (cEvent *)Schedule->Events()->Next(Event)) { -#else - for (const cEvent *Event = Schedule->Events()->First(); Event; Event = Schedule->Events()->Next(Event)) { -#endif if (Event->EndTime() <= now && Event != PresentEvent) continue; epg_item.clear(); @@ -156,11 +123,7 @@ bool display_pictures = !(LiveSetup().GetTvscraperImageDir().empty()); bool lastEventCurrentDay = false; { -#if VDRVERSNUM >= 20301 cEvent* NextEvent = (cEvent *)Schedule->Events()->Next(Event); -#else - cEvent* NextEvent = Schedule->Events()->Next(Event); -#endif if (!NextEvent) { lastEventCurrentDay = true; } @@ -215,8 +178,8 @@ if(recItemFound) { <%def channel_selection>
- - <& channels_widget name=("channel") selected=(Channel ? *Channel->GetChannelID().ToString() : "") onchange=("document.forms.channels.submit()") &> + + <& channels_widget name=("channel") selected=(Channel ? cSv(cToSvChannel(Channel->GetChannelID())) : cSv() ) onchange=("document.forms.channels.submit()") &> % if (cDevice::PrimaryDevice() && cDevice::PrimaryDevice()->HasDecoder() ) { <& pageelems.ajax_action_href action="switch_channel" tip=(tr("Switch to this channel.")) param=(Channel->GetChannelID()) image="zap.png" alt="" &> % } diff --git a/pages/searchepg.ecpp b/pages/searchepg.ecpp index 443ea55d..ca13977d 100644 --- a/pages/searchepg.ecpp +++ b/pages/searchepg.ecpp @@ -20,8 +20,8 @@ using namespace vdrlive; bool usesubtitle = false; bool usedescr = false; int usechannel = SearchTimer::NoChannel; - tChannelID channelfrom; - tChannelID channelto; + std::string channelfrom_string; + std::string channelto_string; std::string changrpsel = ""; bool usetime = false; std::string start_h = "00"; @@ -64,6 +64,8 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); #define CHECKIF(x) reply.out() << ( (x) ? "checked=\"checked\"" : "" ); searchtimer = 0; + tChannelID channelfrom = tChannelID::FromString(channelfrom_string.c_str()); + tChannelID channelto = tChannelID::FromString(channelto_string.c_str()); if ( request.getMethod() == "POST") { SearchTimer searchtimer; @@ -362,11 +364,11 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); - + - +
<$ tr("from channel" ) $>:<& channels_widget name=("channelfrom") channelid=(true) selected=(channelfrom) &><& channels_widget name=("channelfrom_string") channelid=(true) selected=(channelfrom) &>
<$ tr("to channel" ) $>:<& channels_widget name=("channelto") channelid=(true) selected=(channelto) &><& channels_widget name=("channelto_string") channelid=(true) selected=(channelto) &>
diff --git a/pages/stream.ecpp b/pages/stream.ecpp index 4d48d77f..94a1ad00 100644 --- a/pages/stream.ecpp +++ b/pages/stream.ecpp @@ -22,8 +22,7 @@ using namespace vdrlive; <%include>page_init.eh <%cpp> - tChannelID channelid; - channelid = channelid.FromString(channelid_str.c_str()); + tChannelID channelid = channelid.FromString(channelid_str.c_str()); if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); pageTitle = trVDR("Stream"); @@ -110,14 +109,7 @@ using namespace vdrlive; dsyslog("vdrlive::stream: generating EPG info"); const cSchedule *Schedule = NULL; { -#if VDRVERSNUM >= 20301 - LOCK_SCHEDULES_READ; -#else - cSchedulesLock schedulesLock; - const cSchedules* Schedules = cSchedules::Schedules(schedulesLock); -#endif - Schedule = Schedules->GetSchedule(Channel); } const cEvent *Event = NULL; diff --git a/pages/switch_channel.ecpp b/pages/switch_channel.ecpp index 7ea6847c..fc95e657 100644 --- a/pages/switch_channel.ecpp +++ b/pages/switch_channel.ecpp @@ -13,8 +13,7 @@ using namespace vdrlive; std::string async; <%cpp> - tChannelID paramID; - paramID = paramID.FromString(param.c_str()); + tChannelID paramID = tChannelID::FromString(param.c_str()); bool ajaxReq = !async.empty() && (parse_int(async) != 0); std::string referrer; diff --git a/pages/whats_on.ecpp b/pages/whats_on.ecpp index 89c39816..d1c7bafa 100644 --- a/pages/whats_on.ecpp +++ b/pages/whats_on.ecpp @@ -121,31 +121,15 @@ if (type == "now") { // collect the broadcasts if (type != "favs") { -#if VDRVERSNUM >= 20301 LOCK_CHANNELS_READ; { -#else - ReadLock channelsLock( Channels ); - if (channelsLock) { -#endif -#if VDRVERSNUM >= 20301 for (cChannel *Channel = (cChannel *)Channels->First(); Channel && Channel->Number() <= LiveSetup().GetLastChannel(); Channel = (cChannel *)Channels->Next(Channel)) { -#else - for (cChannel *Channel = Channels.First(); Channel && Channel->Number() <= LiveSetup().GetLastChannel(); Channel = Channels.Next(Channel)) { -#endif if (Channel->GroupSep()) { continue; } const cSchedule *Schedule; { -#if VDRVERSNUM >= 20301 - LOCK_SCHEDULES_READ; -#else - cSchedulesLock schedulesLock; - const cSchedules* Schedules = cSchedules::Schedules(schedulesLock); -#endif - Schedule = Schedules->GetSchedule(Channel); } if (!Schedule) { diff --git a/recman.cpp b/recman.cpp index 5d689974..304af6ca 100644 --- a/recman.cpp +++ b/recman.cpp @@ -262,7 +262,7 @@ namespace vdrlive { m_recTree.reset(); } if (stateChanged || !m_recTree) { - m_recTree = std::shared_ptr(new RecordingsTree(recMan)); + m_recTree = std::shared_ptr(new RecordingsTree(recMan)); } if (!m_recTree) { esyslog("live: creation of recordings tree failed!"); @@ -422,7 +422,7 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vectorempty() ) return false; // there are no recordings // find all recordings with equal name - RecordingsItemRecPtr dummy (new RecordingsItemDummy(event, scraperVideo)); + RecordingsItemRecPtr dummy = std::make_shared(event, scraperVideo); const auto equalName = std::equal_range(RecItems->begin(), RecItems->end(), dummy, RecordingsItemPtrCompare::ByDuplicatesName); if (equalName.first == equalName.second) return false; // there is no recording with this name @@ -489,25 +489,25 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), dirName); if (iter != m_subdirs.end() && !(dirName < *iter) ) return *iter; - RecordingsItemDirPtr recPtr (new RecordingsItemDir(dirName, Level() + 1)); - m_subdirs.insert(iter, recPtr); - return recPtr; + RecordingsItemDirPtr dirPtr = std::make_shared(dirName, Level() + 1); + m_subdirs.insert(iter, dirPtr); + return dirPtr; } RecordingsItemDirPtr RecordingsItemDir::addDirCollectionIfNotExists(int collectionId, const RecordingsItemRecPtr &rPtr) { std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), collectionId); if (iter != m_subdirs.end() && !(collectionId < *iter) ) return *iter; - RecordingsItemDirPtr recPtr2 (new RecordingsItemDirCollection(Level() + 1, rPtr)); - m_subdirs.insert(iter, recPtr2); - return recPtr2; + RecordingsItemDirPtr dirPtr2 = std::make_shared(Level() + 1, rPtr); + m_subdirs.insert(iter, dirPtr2); + return dirPtr2; } RecordingsItemDirPtr RecordingsItemDir::addDirSeasonIfNotExists(int seasonNumber, const RecordingsItemRecPtr &rPtr) { std::vector::iterator iter = std::lower_bound(m_subdirs.begin(), m_subdirs.end(), seasonNumber); if (iter != m_subdirs.end() && !(seasonNumber < *iter) ) return *iter; - RecordingsItemDirPtr recPtr2 (new RecordingsItemDirSeason(Level() + 1, rPtr)); - m_subdirs.insert(iter, recPtr2); - return recPtr2; + RecordingsItemDirPtr dirPtr2 = std::make_shared(Level() + 1, rPtr); + m_subdirs.insert(iter, dirPtr2); + return dirPtr2; } const std::vector *RecordingsItemDir::getRecordings(eSortOrder sortOrder) @@ -995,7 +995,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im */ RecordingsTree::RecordingsTree(RecordingsManagerPtr recMan) : m_maxLevel(0), - m_root(new RecordingsItemDir("", 0)) + m_root(std::make_shared("", 0)) { // esyslog("live: DH: ****** RecordingsTree::RecordingsTree() ********"); cMeasureTime timeRecs, timeIdentify, timeOverview, timeImage, timeDurationDeviation, timeNumTsFiles, timeItemRec; @@ -1005,8 +1005,8 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im m_creation_timestamp = time(0); cGetScraperVideo getScraperVideo; bool scraperDataAvailable = getScraperVideo.call(LiveSetup().GetPluginScraper()); - RecordingsItemDirPtr recPtrTvShows (new RecordingsItemDir(tr("TV shows"), 1)); - RecordingsItemDirPtr recPtrMovieCollections (new RecordingsItemDir(tr("Movie collections"), 1)); + RecordingsItemDirPtr recPtrTvShows = std::make_shared(tr("TV shows"), 1); + RecordingsItemDirPtr recPtrMovieCollections = std::make_shared(tr("Movie collections"), 1); // create "base" folders m_allRecordings.clear(); if (scraperDataAvailable) { @@ -1015,7 +1015,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im m_root->m_subdirs.push_back(recPtrTvShows); recPtrMovieCollections->m_s_season_number = 2; m_root->m_subdirs.push_back(recPtrMovieCollections); - RecordingsItemDirPtr recPtrOthers (new RecordingsItemDir(tr("File system view"), 1)); + RecordingsItemDirPtr recPtrOthers = std::make_shared(tr("File system view"), 1); recPtrOthers->m_s_season_number = 3; m_rootFileSystem = recPtrOthers; m_root->m_subdirs.push_back(recPtrOthers); @@ -1044,7 +1044,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im else { cSv recName = name.substr(index, name.length() - index); timeRecs.start(); - RecordingsItemRecPtr recPtr (new RecordingsItemRec(recName, recording, &timeIdentify, &timeOverview, &timeImage, &timeDurationDeviation, &timeNumTsFiles, &timeItemRec)); + RecordingsItemRecPtr recPtr = std::make_shared(recName, recording, &timeIdentify, &timeOverview, &timeImage, &timeDurationDeviation, &timeNumTsFiles, &timeItemRec); timeRecs.stop(); dir->m_entries.push_back(recPtr); m_allRecordings.push_back(recPtr); @@ -1141,7 +1141,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im return r; } else { - RecordingsManagerPtr n(new RecordingsManager); + RecordingsManagerPtr n(new RecordingsManager); RecordingsManager::m_recMan = n; return n; } diff --git a/recman.h b/recman.h index 563f9cfc..68bc4598 100644 --- a/recman.h +++ b/recman.h @@ -174,11 +174,9 @@ namespace vdrlive { { friend class RecordingsTree; - protected: - RecordingsItemDir(cSv name, int level); - public: virtual ~RecordingsItemDir(); + RecordingsItemDir(cSv name, int level); cSv Name() const { return m_name; } int Level() const { return m_level; } diff --git a/stringhelpers.h b/stringhelpers.h index b212febd..9ed19fc4 100644 --- a/stringhelpers.h +++ b/stringhelpers.h @@ -771,19 +771,35 @@ class cToSvInt_sik: public cSv { class cToSv { public: cToSv() {} +// not intended for copy +// you can copy the cSv of this class (from operator cSv() ) cToSv(const cToSv&) = delete; cToSv &operator= (const cToSv &) = delete; virtual ~cToSv() {} virtual operator cSv() const = 0; }; +inline std::ostream& operator<<(std::ostream& os, cToSv const& sv ) +{ + return os << cSv(sv); +} + class cToSvInt: public cToSv { public: // T must be an integer type, like long, unsigned, ... template cToSvInt(T i): m_result(ns_concat::addCharsIbe(m_buffer + 20, i)) {} - cToSvInt(const cToSvInt&) = delete; - cToSvInt &operator= (const cToSvInt &) = delete; operator cSv() const { return cSv(m_result, m_buffer + 20 - m_result); } + cToSvInt &setw(size_t desired_width, char fill_char = '0') { + char *new_m_result = m_buffer + 20 - std::min((int)desired_width, 20); + if (m_result <= new_m_result) return *this; // requested width alread there + if (*m_result == '-') { + *new_m_result = '-'; + memset(new_m_result + 1, fill_char, m_result - new_m_result); + } else + memset(new_m_result, fill_char, m_result - new_m_result); + m_result = new_m_result; + return *this; + } private: char m_buffer[20]; // unsigned int 64: max. 20. (18446744073709551615) signed int64: max. 19 (+ sign) char *m_result; @@ -795,8 +811,6 @@ class cToSvHex: public cToSv { template cToSvHex(T value) { addCharsHex(m_buffer, N, value); } - cToSvHex(const cToSvHex&) = delete; - cToSvHex &operator= (const cToSvHex &) = delete; operator cSv() const { return cSv(m_buffer, N); } protected: cToSvHex() { } @@ -857,7 +871,8 @@ class cToSvFile: public cToSv { cToSvFile(const cToSvFile&) = delete; cToSvFile &operator= (const cToSvFile &) = delete; operator cSv() const { return m_result; } - char *data() { return m_s; } // returns 0 in case of an empty file + char *data() { return m_s; } // Retunrs zero if file is empty! Is zero terminated + const char *c_str() { return m_s?m_s:""; } // Is zero terminated bool exists() const { return m_exists; } ~cToSvFile() { std::free(m_s); } private: @@ -941,11 +956,56 @@ class cToSvFormated: public cToSv { std::free(m_huge_buffer); } operator cSv() const { return m_result; } + const char *c_str() const { return m_result.data(); } private: char m_buffer[256]; char *m_huge_buffer = nullptr; cSv m_result; }; +/* + * channel helper functions (for vdr tChannelID) + * +*/ +// #include + +// ========================================================= +// some performance improvemnt, to get string presentation for channel +// you can also use channelID.ToString() +// in struct tChannelID { (in vdr): +// static tChannelID FromString(const char *s); +// cString ToString(void) const; +// ========================================================= + +class cToSvChannelSource: public cToSv { + public: + cToSvChannelSource(int Code) { + int st_Mask = 0xFF000000; + char *q = m_buffer; + *q++ = (Code & st_Mask) >> 24; + if (int n = cSource::Position(Code)) { + q += snprintf(q, 14, "%u.%u", abs(n) / 10, abs(n) % 10); // can't simply use "%g" here since the silly 'locale' messes up the decimal point + *q++ = (n < 0) ? 'W' : 'E'; + } + *q = 0; + } + operator cSv() const { return cSv(m_buffer); } + const char *c_str() const { return m_buffer; } + private: + char m_buffer[16]; // 1 + "%u.%u", sec. %u: 1 digit + 1 zero terminator +}; +class cToSvChannel: public cToSvFormated { + public: + cToSvChannel(const tChannelID &channelID): + cToSvFormated(channelID.Rid() ? "%s-%d-%d-%d-%d" : "%s-%d-%d-%d", + cToSvChannelSource(channelID.Source()).c_str(), + channelID.Nid(), channelID.Tid(), channelID.Sid(), channelID.Rid() ) + {} +}; + +inline void stringAppend(std::string &str, const tChannelID &channelID) { + str.append(cToSvChannel(channelID)); +} + // __attribute__ ((format (printf, 2, 3))) can not be used, but should work starting with gcc 13.1 template void stringAppendFormated(std::string &str, const char *fmt, Args&&... args) { diff --git a/timers.cpp b/timers.cpp index 39110ba5..9321bbb6 100644 --- a/timers.cpp +++ b/timers.cpp @@ -23,7 +23,7 @@ namespace vdrlive { std::string SortedTimers::GetTimerId( cTimer const& timer ) { std::stringstream builder; - builder << timer.Channel()->GetChannelID() << ":" << timer.WeekDays() << ":" + builder << cSv(cToSvChannel(timer.Channel()->GetChannelID())) << ":" << timer.WeekDays() << ":" << timer.Day() << ":" << timer.Start() << ":" << timer.Stop(); return builder.str(); } @@ -166,7 +166,7 @@ namespace vdrlive { std::stringstream builder; builder << flags << ":" - << channel << ":" + << cSv(cToSvChannel(channel)) << ":" << ( weekdays != "-------" ? weekdays : "" ) << ( weekdays == "-------" || day.empty() ? "" : "@" ) << day << ":" << start << ":" @@ -187,9 +187,10 @@ namespace vdrlive { dsyslog("live: UpdateTimer() remote '%s'", remote); dsyslog("live: UpdateTimer() oldRemote '%s'", oldRemote); dsyslog("live: UpdateTimer() channel '%s'", *(channel.ToString())); + dsyslog("live: UpdateTimer() channel '%s'", cToSvChannel(channel).c_str() ); dsyslog("live: UpdateTimer() builder '%s'", builder.str().c_str()); - timerStruct timerData = { .id = timerId, .remote=remote, .oldRemote=oldRemote, .builder=builder.str() }; + timerStruct timerData = { .id = timerId, .remote=remote, .oldRemote=oldRemote, .builder=builder.str() }; // dsyslog("live: SV: in UpdateTimer"); m_updateTimers.push_back( timerData ); diff --git a/tntconfig.cpp b/tntconfig.cpp index e0f34783..6bae393e 100644 --- a/tntconfig.cpp +++ b/tntconfig.cpp @@ -1,4 +1,3 @@ - #include "tntconfig.h" #include "i18n.h" diff --git a/tools.h b/tools.h index f2c028a0..a547a128 100644 --- a/tools.h +++ b/tools.h @@ -29,7 +29,8 @@ std::istream& operator>>( std::istream& is, tChannelID& ret ); inline std::ostream& operator<<( std::ostream& os, tChannelID const& id ) { - return os << *id.ToString(); +// return os << *id.ToString(); + return os << cToSvChannel(id); } @@ -98,8 +99,6 @@ template public: cToSvXxHash32(XXH32_hash_t value): cToSvHex<8>::cToSvHex(value) {} cToSvXxHash32(cSv str): cToSvHex<8>::cToSvHex(XXH32(str.data(), str.length(), 20)) {} - cToSvXxHash32(const cToSvXxHash32&) = delete; - cToSvXxHash32 &operator= (const cToSvXxHash32 &) = delete; }; XXH64_hash_t parse_hex_64(cSv str); @@ -107,16 +106,12 @@ template public: cToSvXxHash64(XXH64_hash_t value): cToSvHex<16>::cToSvHex(value) {} cToSvXxHash64(cSv str): cToSvHex<16>::cToSvHex(XXH3_64bits(str.data(), str.length() )) {} - cToSvXxHash64(const cToSvXxHash64&) = delete; - cToSvXxHash64 &operator= (const cToSvXxHash64 &) = delete; }; XXH128_hash_t parse_hex_128(cSv str); class cToSvXxHash128: public cToSvHex<32> { public: cToSvXxHash128(XXH128_hash_t value): cToSvHex<32>::cToSvHex() { setb(value); } cToSvXxHash128(cSv str): cToSvHex<32>::cToSvHex() { setb(XXH3_128bits(str.data(), str.length() )); } - cToSvXxHash128(const cToSvXxHash128&) = delete; - cToSvXxHash128 &operator= (const cToSvXxHash128 &) = delete; private: void setb(XXH128_hash_t value) { addCharsHex(m_buffer, 16, value.high64);