Skip to content

Commit

Permalink
Update the ProgramInfoUpdater to use recordedid
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stuartm committed Jan 29, 2015
1 parent c7638ce commit b220116
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 108 deletions.
2 changes: 1 addition & 1 deletion mythtv/bindings/perl/MythTV.pm
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mythtv/bindings/php/MythBackend.php
Expand Up @@ -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 = '[]:[]';
Expand Down
14 changes: 8 additions & 6 deletions mythtv/html/tv/js/recordings.js
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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];

}
};
};
Expand Down
19 changes: 10 additions & 9 deletions mythtv/libs/libmyth/programinfo.cpp
Expand Up @@ -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());
Expand All @@ -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.
Expand Down Expand Up @@ -2813,6 +2813,8 @@ void ProgramInfo::SaveWatched(bool watched)
MythDB::DBError("Set watched flag", query);
else
UpdateLastDelete(watched);

SendUpdateEvent();
}
else if (IsVideoFile())
{
Expand All @@ -2839,7 +2841,6 @@ void ProgramInfo::SaveWatched(bool watched)
}

set_flag(programflags, FL_WATCHED, watched);
SendUpdateEvent();
}

/** \brief Queries "recorded" table for its "editing" field
Expand Down Expand Up @@ -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
Expand Down
32 changes: 11 additions & 21 deletions mythtv/libs/libmyth/programinfoupdater.cpp
Expand Up @@ -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<PIKey,PIKeyData>::iterator it = needsUpdate.find(key);
QHash<uint,PIKeyData>::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..
Expand Down Expand Up @@ -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);
Expand All @@ -79,23 +71,21 @@ void ProgramInfoUpdater::run(void)

// Send updates in any old order, we just need
// one per updated ProgramInfo.
QHash<PIKey,PIKeyData>::iterator itu = needsUpdate.begin();
QHash<uint,PIKeyData>::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;
Expand Down
28 changes: 9 additions & 19 deletions mythtv/libs/libmyth/programinfoupdater.h
Expand Up @@ -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
{
Expand All @@ -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);

Expand All @@ -71,7 +61,7 @@ class MPUBLIC ProgramInfoUpdater : public QRunnable
QWaitCondition moreWork;
bool isRunning;
std::vector<PIKeyAction> needsAddDelete;
QHash<PIKey,PIKeyData> needsUpdate;
QHash<uint,PIKeyData> needsUpdate;
};

#endif // _PROGRAM_INFO_UPDATER_H_
4 changes: 2 additions & 2 deletions mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/recordinginfo.cpp
Expand Up @@ -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
}
Expand All @@ -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);
}

Expand Down
18 changes: 7 additions & 11 deletions mythtv/programs/mythbackend/mainserver.cpp
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b220116

Please sign in to comment.