From b220116f77e782dd3cfb317a2152fbb9099699f1 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 29 Jan 2015 15:22:00 +0000 Subject: [PATCH] Update the ProgramInfoUpdater to use recordedid Uses recordeid instead of chanid/starttime. The change affects the following events: RECORDING_LIST_CHANGE (ADD|DELETE) - but not UPDATE UPDATE_FILE_SIZE UPDATE_MASTER_PROG_INFO - renamed to UPDATE_MASTER_REC_INFO Bumps protocol version from 83 to 84 --- mythtv/bindings/perl/MythTV.pm | 2 +- mythtv/bindings/php/MythBackend.php | 4 +- mythtv/html/tv/js/recordings.js | 14 +++-- mythtv/libs/libmyth/programinfo.cpp | 19 ++++--- mythtv/libs/libmyth/programinfoupdater.cpp | 32 ++++------- mythtv/libs/libmyth/programinfoupdater.h | 28 +++------ mythtv/libs/libmythbase/mythversion.h | 4 +- mythtv/libs/libmythtv/recordinginfo.cpp | 4 +- mythtv/programs/mythbackend/mainserver.cpp | 18 +++--- mythtv/programs/mythfrontend/playbackbox.cpp | 60 +++++++++----------- mythtv/programs/mythfrontend/playbackbox.h | 5 +- 11 files changed, 82 insertions(+), 108 deletions(-) diff --git a/mythtv/bindings/perl/MythTV.pm b/mythtv/bindings/perl/MythTV.pm index 277fe4e05bf..2878f2cc791 100644 --- a/mythtv/bindings/perl/MythTV.pm +++ b/mythtv/bindings/perl/MythTV.pm @@ -108,7 +108,7 @@ package MythTV; # versions of the form "58a". This will get used if protocol versions are # changed on a fixes branch ongoing. our $PROTO_VERSION = "83"; - our $PROTO_TOKEN = "BreakingGlass"; + our $PROTO_TOKEN = "CanaryCoalmine"; # currentDatabaseVersion is defined in libmythtv in # mythtv/libs/libmythtv/dbcheck.cpp and should be the current MythTV core diff --git a/mythtv/bindings/php/MythBackend.php b/mythtv/bindings/php/MythBackend.php index 23068898d29..6bdaa941905 100644 --- a/mythtv/bindings/php/MythBackend.php +++ b/mythtv/bindings/php/MythBackend.php @@ -11,8 +11,8 @@ class MythBackend { // MYTH_PROTO_VERSION is defined in libmyth in mythtv/libs/libmyth/mythcontext.h // and should be the current MythTV protocol version. - static $protocol_version = '83'; - static $protocol_token = 'BreakingGlass'; + static $protocol_version = '84'; + static $protocol_token = 'CanaryCoalmine'; // The character string used by the backend to separate records static $backend_separator = '[]:[]'; diff --git a/mythtv/html/tv/js/recordings.js b/mythtv/html/tv/js/recordings.js index ff35446ba1b..73f86280b88 100644 --- a/mythtv/html/tv/js/recordings.js +++ b/mythtv/html/tv/js/recordings.js @@ -136,7 +136,7 @@ var MythRecordings = new function() { { wsClient = new parent.WebSocketEventClient(); wsClient.eventReceiver = function(event) { HandleMythEvent(event) }; - wsClient.filters = ["MASTER_UPDATE_PROG_INFO", "RECORDING_LIST_CHANGE", + wsClient.filters = ["MASTER_UPDATE_REC_INFO", "RECORDING_LIST_CHANGE", "UPDATE_FILE_SIZE"]; parent.globalWSHandler.AddListener(wsClient); }; @@ -165,17 +165,19 @@ var MythRecordings = new function() { return; // TODO: Add some information to the event so we can decide whether // the current page needs reloading. - if (tokens[0] == "MASTER_UPDATE_PROG_INFO") + if (tokens[0] == "MASTER_UPDATE_REC_INFO") { - if (tokens.length < 3) + if (tokens.length < 2) return; - var chanId = tokens[1]; - var startTime = tokens[2]; + var recordedId = tokens[1]; } else if (tokens[0] == "RECORDING_LIST_CHANGE") { - if (tokens.length < 4) + if (tokens.length < 3) return; + var type = tokens[1]; + var recordedId = tokens[2]; + } }; }; diff --git a/mythtv/libs/libmyth/programinfo.cpp b/mythtv/libs/libmyth/programinfo.cpp index 5f7e52ede4d..a893f1304ba 100644 --- a/mythtv/libs/libmyth/programinfo.cpp +++ b/mythtv/libs/libmyth/programinfo.cpp @@ -2599,6 +2599,8 @@ void ProgramInfo::SaveBookmark(uint64_t frame) SaveMarkupMap(bookmarkmap); } + set_flag(programflags, FL_BOOKMARK, is_valid); + if (IsRecording()) { MSqlQuery query(MSqlQuery::InitCon()); @@ -2615,26 +2617,24 @@ void ProgramInfo::SaveBookmark(uint64_t frame) if (!query.exec()) MythDB::DBError("bookmark flag update", query); - } - set_flag(programflags, FL_BOOKMARK, is_valid); - - SendUpdateEvent(); + SendUpdateEvent(); + } } void ProgramInfo::SendUpdateEvent(void) { - updater->insert(chanid, recstartts, kPIUpdate); + updater->insert(recordedid, kPIUpdate); } void ProgramInfo::SendAddedEvent(void) const { - updater->insert(chanid, recstartts, kPIAdd); + updater->insert(recordedid, kPIAdd); } void ProgramInfo::SendDeletedEvent(void) const { - updater->insert(chanid, recstartts, kPIDelete); + updater->insert(recordedid, kPIDelete); } /** \brief Queries Latest bookmark timestamp from the database. @@ -2813,6 +2813,8 @@ void ProgramInfo::SaveWatched(bool watched) MythDB::DBError("Set watched flag", query); else UpdateLastDelete(watched); + + SendUpdateEvent(); } else if (IsVideoFile()) { @@ -2839,7 +2841,6 @@ void ProgramInfo::SaveWatched(bool watched) } set_flag(programflags, FL_WATCHED, watched); - SendUpdateEvent(); } /** \brief Queries "recorded" table for its "editing" field @@ -5790,7 +5791,7 @@ void ProgramInfo::SaveFilesize(uint64_t fsize) if (!query.exec()) MythDB::DBError("File size update", query); - updater->insert(chanid, recstartts, kPIUpdateFileSize, fsize); + updater->insert(recordedid, kPIUpdateFileSize, fsize); } uint64_t ProgramInfo::GetFilesize(void) const diff --git a/mythtv/libs/libmyth/programinfoupdater.cpp b/mythtv/libs/libmyth/programinfoupdater.cpp index b7d2d862b64..c13ba03a279 100644 --- a/mythtv/libs/libmyth/programinfoupdater.cpp +++ b/mythtv/libs/libmyth/programinfoupdater.cpp @@ -8,31 +8,24 @@ using std::vector; -uint qHash(const PIKey &k) -{ - return qHash(k.chanid) ^ qHash(k.recstartts.toTime_t()); -} - void ProgramInfoUpdater::insert( - uint chanid, const QDateTime &recstartts, - PIAction action, uint64_t filesize) + uint recordedid, PIAction action, uint64_t filesize) { QMutexLocker locker(&lock); if (kPIUpdate == action || kPIUpdateFileSize == action) { - PIKey key = PIKey(chanid, recstartts); - QHash::iterator it = needsUpdate.find(key); + QHash::iterator it = needsUpdate.find(recordedid); // If there is no action in the set we can insert // If it is the same type of action we can overwrite, // If it the new action is a full update we can overwrite if (it == needsUpdate.end()) - needsUpdate.insert(key, PIKeyData(action, filesize)); + needsUpdate.insert(recordedid, PIKeyData(action, filesize)); else if (((*it).action == action) || (kPIUpdate == action)) (*it) = PIKeyData(action, filesize); } else { - needsAddDelete.push_back(PIKeyAction(chanid, recstartts, action)); + needsAddDelete.push_back(PIKeyAction(recordedid, action)); } // Start a new run() if one isn't already running.. @@ -68,9 +61,8 @@ void ProgramInfoUpdater::run(void) continue; QString type = (kPIAdd == (*ita).action) ? "ADD" : "DELETE"; - QString msg = QString("RECORDING_LIST_CHANGE %1 %2 %3") - .arg(type).arg((*ita).chanid) - .arg((*ita).recstartts.toString(Qt::ISODate)); + QString msg = QString("RECORDING_LIST_CHANGE %1 %2") + .arg(type).arg((*ita).recordedid); workDone = true; gCoreContext->SendMessage(msg); @@ -79,23 +71,21 @@ void ProgramInfoUpdater::run(void) // Send updates in any old order, we just need // one per updated ProgramInfo. - QHash::iterator itu = needsUpdate.begin(); + QHash::iterator itu = needsUpdate.begin(); for (; itu != needsUpdate.end(); ++itu) { QString msg; if (kPIUpdateFileSize == (*itu).action) { - msg = QString("UPDATE_FILE_SIZE %1 %2 %3") - .arg(itu.key().chanid) - .arg(itu.key().recstartts.toString(Qt::ISODate)) + msg = QString("UPDATE_FILE_SIZE %1 %2") + .arg(itu.key()) .arg((*itu).filesize); } else { - msg = QString("MASTER_UPDATE_PROG_INFO %1 %2") - .arg(itu.key().chanid) - .arg(itu.key().recstartts.toString(Qt::ISODate)); + msg = QString("MASTER_UPDATE_REC_INFO %1") + .arg(itu.key()); } workDone = true; diff --git a/mythtv/libs/libmyth/programinfoupdater.h b/mythtv/libs/libmyth/programinfoupdater.h index 70f63be810d..3c9ef25ad25 100644 --- a/mythtv/libs/libmyth/programinfoupdater.h +++ b/mythtv/libs/libmyth/programinfoupdater.h @@ -24,30 +24,20 @@ typedef enum PIAction { kPIUpdateFileSize, } PIAction; -class MPUBLIC PIKey +class MPUBLIC PIKeyAction { public: - PIKey(uint c, const QDateTime &r) : chanid(c), recstartts(r) {} + PIKeyAction(uint recordedid, PIAction a) : + recordedid(recordedid), action(a) { } - uint chanid; - QDateTime recstartts; + uint recordedid; + PIAction action; - bool operator==(const PIKey &other) const + bool operator==(const PIKeyAction &other) const { - return (chanid == other.chanid && - recstartts == other.recstartts); + return (recordedid == other.recordedid); } }; -uint qHash(const PIKey &k); - -class MPUBLIC PIKeyAction : public PIKey -{ - public: - PIKeyAction(uint c, const QDateTime &r, PIAction a) : - PIKey(c, r), action(a) { } - - PIAction action; -}; class MPUBLIC PIKeyData { @@ -62,7 +52,7 @@ class MPUBLIC ProgramInfoUpdater : public QRunnable public: ProgramInfoUpdater() : isRunning(false) { setAutoDelete(false); } - void insert(uint chanid, const QDateTime &recstartts, + void insert(uint recordedid, PIAction action, uint64_t filesize = 0ULL); void run(void); @@ -71,7 +61,7 @@ class MPUBLIC ProgramInfoUpdater : public QRunnable QWaitCondition moreWork; bool isRunning; std::vector needsAddDelete; - QHash needsUpdate; + QHash needsUpdate; }; #endif // _PROGRAM_INFO_UPDATER_H_ diff --git a/mythtv/libs/libmythbase/mythversion.h b/mythtv/libs/libmythbase/mythversion.h index 01fd8f9caa8..87ceec17b4a 100644 --- a/mythtv/libs/libmythbase/mythversion.h +++ b/mythtv/libs/libmythbase/mythversion.h @@ -39,8 +39,8 @@ * http://www.mythtv.org/wiki/Category:Myth_Protocol_Commands * http://www.mythtv.org/wiki/Category:Myth_Protocol */ -#define MYTH_PROTO_VERSION "83" -#define MYTH_PROTO_TOKEN "BreakingGlass" +#define MYTH_PROTO_VERSION "84" +#define MYTH_PROTO_TOKEN "CanaryCoalmine" /** \brief Increment this whenever the MythTV core database schema changes. * diff --git a/mythtv/libs/libmythtv/recordinginfo.cpp b/mythtv/libs/libmythtv/recordinginfo.cpp index 17eaf0e6b92..2dfea3a88ef 100644 --- a/mythtv/libs/libmythtv/recordinginfo.cpp +++ b/mythtv/libs/libmythtv/recordinginfo.cpp @@ -1618,7 +1618,7 @@ void RecordingInfo::SaveFilesize(uint64_t fsize) GetRecordingFile()->m_fileSize = fsize; GetRecordingFile()->Save(); // Ideally this would be called just the once when all metadata is gathered - updater->insert(chanid, recstartts, kPIUpdateFileSize, fsize); + updater->insert(recordedid, kPIUpdateFileSize, fsize); ProgramInfo::SaveFilesize(fsize); // Temporary } @@ -1628,7 +1628,7 @@ void RecordingInfo::SetFilesize(uint64_t fsize) if (!GetRecordingFile()) LoadRecordingFile(); GetRecordingFile()->m_fileSize = fsize; - updater->insert(chanid, recstartts, kPIUpdateFileSize, fsize); + updater->insert(recordedid, kPIUpdateFileSize, fsize); //ProgramInfo::SetFilesize(fsize); } diff --git a/mythtv/programs/mythbackend/mainserver.cpp b/mythtv/programs/mythbackend/mainserver.cpp index 1d70cf7da02..746acde5b0d 100644 --- a/mythtv/programs/mythbackend/mainserver.cpp +++ b/mythtv/programs/mythbackend/mainserver.cpp @@ -1380,18 +1380,14 @@ void MainServer::customEvent(QEvent *e) return; MythEvent mod_me(""); - if (me->Message().startsWith("MASTER_UPDATE_PROG_INFO")) + if (me->Message().startsWith("MASTER_UPDATE_REC_INFO")) { QStringList tokens = me->Message().simplified().split(" "); - uint chanid = 0; - QDateTime recstartts; - if (tokens.size() >= 3) - { - chanid = tokens[1].toUInt(); - recstartts = MythDate::fromString(tokens[2]); - } + uint recordedid = 0; + if (tokens.size() >= 2) + recordedid = tokens[1].toUInt(); - ProgramInfo evinfo(chanid, recstartts); + ProgramInfo evinfo(recordedid); if (evinfo.GetChanID()) { QDateTime rectime = MythDate::current().addSecs( @@ -2462,8 +2458,8 @@ void MainServer::DoDeleteInDB(DeleteStruct *ds) sleep(1); // Notify the frontend so it can requery for Free Space - QString msg = QString("RECORDING_LIST_CHANGE DELETE %1 %2") - .arg(ds->m_chanid).arg(ds->m_recstartts.toString(Qt::ISODate)); + QString msg = QString("RECORDING_LIST_CHANGE DELETE %1") + .arg(ds->m_recordedid); gCoreContext->SendEvent(MythEvent(msg)); // sleep a little to let frontends reload the recordings list diff --git a/mythtv/programs/mythfrontend/playbackbox.cpp b/mythtv/programs/mythfrontend/playbackbox.cpp index b37570eea4a..30962569464 100644 --- a/mythtv/programs/mythfrontend/playbackbox.cpp +++ b/mythtv/programs/mythfrontend/playbackbox.cpp @@ -3950,13 +3950,9 @@ void PlaybackBox::customEvent(QEvent *event) if (message.startsWith("RECORDING_LIST_CHANGE")) { QStringList tokens = message.simplified().split(" "); - uint chanid = 0; - QDateTime recstartts; - if (tokens.size() >= 4) - { - chanid = tokens[2].toUInt(); - recstartts = MythDate::fromString(tokens[3]); - } + uint recordedid = 0; + if (tokens.size() >= 3) + recordedid = tokens[2].toUInt(); if ((tokens.size() >= 2) && tokens[1] == "UPDATE") { @@ -3964,19 +3960,18 @@ void PlaybackBox::customEvent(QEvent *event) if (evinfo.HasPathname() || evinfo.GetChanID()) HandleUpdateProgramInfoEvent(evinfo); } - else if (chanid && recstartts.isValid() && (tokens[1] == "ADD")) + else if (recordedid && (tokens[1] == "ADD")) { - ProgramInfo evinfo(chanid, recstartts); + ProgramInfo evinfo(recordedid); if (evinfo.GetChanID()) { evinfo.SetRecordingStatus(rsRecording); HandleRecordingAddEvent(evinfo); } } - else if (chanid && recstartts.isValid() && (tokens[1] == "DELETE")) + else if (recordedid && (tokens[1] == "DELETE")) { - if (chanid && recstartts.isValid()) - HandleRecordingRemoveEvent(chanid, recstartts); + HandleRecordingRemoveEvent(recordedid); } else { @@ -4015,19 +4010,17 @@ void PlaybackBox::customEvent(QEvent *event) { QStringList tokens = message.simplified().split(" "); bool ok = false; - uint chanid = 0; - QDateTime recstartts; + uint recordedid = 0; uint64_t filesize = 0ULL; - if (tokens.size() >= 4) + if (tokens.size() >= 3) { - chanid = tokens[1].toUInt(); - recstartts = MythDate::fromString(tokens[2]); - filesize = tokens[3].toLongLong(&ok); + recordedid = tokens[1].toUInt(); + filesize = tokens[2].toLongLong(&ok); } - if (chanid && recstartts.isValid() && ok) + if (recordedid && ok) { - HandleUpdateProgramInfoFileSizeEvent( - chanid, recstartts, filesize); + + HandleUpdateProgramInfoFileSizeEvent(recordedid, filesize); } } else if (message == "UPDATE_UI_LIST") @@ -4261,14 +4254,15 @@ void PlaybackBox::customEvent(QEvent *event) ScheduleCommon::customEvent(event); } -void PlaybackBox::HandleRecordingRemoveEvent( - uint chanid, const QDateTime &recstartts) +void PlaybackBox::HandleRecordingRemoveEvent(uint recordedid) { - if (!m_programInfoCache.Remove(chanid, recstartts)) + ProgramInfo evinfo(recordedid); + if (!m_programInfoCache.Remove(evinfo.GetChanID(), + evinfo.GetRecordingStartTime())) { LOG(VB_GENERAL, LOG_WARNING, LOC + - QString("Failed to remove %1:%2, reloading list") - .arg(chanid).arg(recstartts.toString(Qt::ISODate))); + QString("Failed to remove %1, reloading list") + .arg(recordedid)); m_programInfoCache.ScheduleLoad(); return; } @@ -4284,8 +4278,7 @@ void PlaybackBox::HandleRecordingRemoveEvent( ProgramList::iterator pit = (*git).begin(); while (pit != (*git).end()) { - if ((*pit)->GetChanID() == chanid && - (*pit)->GetRecordingStartTime() == recstartts) + if ((*pit)->GetRecordingID() == recordedid) { if (!git.key().isEmpty() && git.key() == groupname) { @@ -4367,12 +4360,15 @@ void PlaybackBox::HandleUpdateProgramInfoEvent(const ProgramInfo &evinfo) ScheduleUpdateUIList(); } -void PlaybackBox::HandleUpdateProgramInfoFileSizeEvent( - uint chanid, const QDateTime &recstartts, uint64_t filesize) +void PlaybackBox::HandleUpdateProgramInfoFileSizeEvent(uint recordedid, + uint64_t filesize) { - m_programInfoCache.UpdateFileSize(chanid, recstartts, filesize); + ProgramInfo evinfo(recordedid); + m_programInfoCache.UpdateFileSize(evinfo.GetChanID(), + evinfo.GetRecordingStartTime(), filesize); - ProgramInfo *dst = FindProgramInUILists(chanid, recstartts); + ProgramInfo *dst = FindProgramInUILists(evinfo.GetChanID(), + evinfo.GetRecordingStartTime()); if (dst) UpdateUIListItem(dst, false); } diff --git a/mythtv/programs/mythfrontend/playbackbox.h b/mythtv/programs/mythfrontend/playbackbox.h index a88439ed156..e68bc0263d7 100644 --- a/mythtv/programs/mythfrontend/playbackbox.h +++ b/mythtv/programs/mythfrontend/playbackbox.h @@ -314,11 +314,10 @@ class PlaybackBox : public ScheduleCommon bool force_preview_reload = true); void HandlePreviewEvent(const QStringList &list); - void HandleRecordingRemoveEvent(uint chanid, const QDateTime &recstartts); + void HandleRecordingRemoveEvent(uint recordedid); void HandleRecordingAddEvent(const ProgramInfo &evinfo); void HandleUpdateProgramInfoEvent(const ProgramInfo &evinfo); - void HandleUpdateProgramInfoFileSizeEvent( - uint chanid, const QDateTime &recstartts, uint64_t filesize); + void HandleUpdateProgramInfoFileSizeEvent(uint recordedid, uint64_t filesize); void ScheduleUpdateUIList(void); void ShowMenu(void);